Exemple #1
0
        /// <summary>
        /// 得到Oracle连接字符串
        /// </summary>
        /// <returns>连接字符串</returns>
        ///
        public static string getOracleConnection(int timeout, string connectionType)
        {
            string configFile        = string.Format("{0}\\{1}", System.IO.Directory.GetCurrentDirectory(), "Config.ini");
            string connectionStrings = string.Empty;
            string userId            = INIOperationClass.INIGetStringValue(configFile, string.Format("{0}{1}", connectionType, "Oracle"), "USER", null); //用户
            string passwordEncrypt   = INIOperationClass.INIGetStringValue(configFile, string.Format("{0}{1}", connectionType, "Oracle"), "PWD", null);  //密码
            string pwd         = EncAndDec.DESDecrypt(passwordEncrypt);                                                                                  //解密
            string host        = INIOperationClass.INIGetStringValue(configFile, string.Format("{0}{1}", connectionType, "Oracle"), "IP", null);         //服务器IP
            string port        = INIOperationClass.INIGetStringValue(configFile, string.Format("{0}{1}", connectionType, "Oracle"), "PORT", null);       //端口
            string serviceName = INIOperationClass.INIGetStringValue(configFile, string.Format("{0}{1}", connectionType, "Oracle"), "DBNAME", null);

            if (timeout == 0)
            {
                /*ConnectionStrings = "User Id=" + strUserId.Trim() + ";Password="******";Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + strHOST.Trim()
                 + ")(PORT=" + strPORT.Trim() + ")))(CONNECT_DATA=(SERVICE_NAME=" + strSERVICE_NAME.Trim() + ")))";*/
                connectionStrings = string.Format("User Id={0};Password={1};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={2})(PORT={3})))(CONNECT_DATA=(SERVICE_NAME={4})(SERVER = DEDICATED))) ; ",
                                                  userId, pwd, host, port, serviceName);
            }
            else
            {
                connectionStrings = string.Format("User Id={0};Password={1};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={2})(PORT={3})))(CONNECT_DATA=(SERVICE_NAME={4})(SERVER = DEDICATED))) ;Connection Timeout={5};",
                                                  userId, pwd, host, port, serviceName, timeout);
            }

            /*ConnectionStrings = "User Id=" + strUserId.Trim() + ";Password="******";Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + strHOST.Trim()
             + ")(PORT=" + strPORT.Trim() + ")))(CONNECT_DATA=(SERVICE_NAME=" + strSERVICE_NAME.Trim() + "))) ;Connection Timeout=" + timeout + "; "; //;Connection Timeout=" + timeout + ";*/
            return(connectionStrings);
        }
        private static bool iNIEmptySection(string iniFile, string section)
        {
            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("必须指定节点名称", "section");
            }

            return(INIOperationClass.WritePrivateProfileSection(section, string.Empty, iniFile));
        }
        private static bool iNIDeleteKey(string iniFile, string section, string key)
        {
            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("必须指定节点名称", "section");
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("必须指定键名称", "key");
            }

            return(INIOperationClass.WritePrivateProfileString(section, key, null, iniFile));
        }
        private static bool iNIWriteItems(string iniFile, string section, string items)
        {
            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("必须指定节点名称", "section");
            }

            if (string.IsNullOrEmpty(items))
            {
                throw new ArgumentException("必须指定键值对", "items");
            }

            return(INIOperationClass.WritePrivateProfileSection(section, items, iniFile));
        }
        private static bool iNIWriteValue(string iniFile, string section, string key, string value)
        {
            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("必须指定节点名称", "section");
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("必须指定键名称", "key");
            }

            if (value == null)
            {
                throw new ArgumentException("值不能为null", "value");
            }

            return(INIOperationClass.WritePrivateProfileString(section, key, value, iniFile));
        }
        private static string[] iNIGetAllItemKeys(string iniFile, string section)
        {
            string[]  value = new string[0];
            const int SIZE  = 1024 * 10;

            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("必须指定节点名称", "section");
            }

            char[] chars         = new char[SIZE];
            uint   bytesReturned = INIOperationClass.GetPrivateProfileString(section, null, null, chars, SIZE, iniFile);

            if (bytesReturned != 0)
            {
                value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }
            chars = null;

            return(value);
        }
Exemple #7
0
        public static readonly string NamespacePathBLL = "BLL";     // INIOperationClass.INIGetStringValue(_ConfigFile, "DBService", "NamespaceBLL", null);
        #endregion

        #region 数据库连接字符串

        #region getSqlServerConnection 得到SqlServer连接字符串
        /// <summary>
        /// 得到SqlServer连接字符串
        /// </summary>
        /// <returns>连接字符串</returns>
        public static string getSqlServerConnection(int timeout, string connectionType)
        {
            string ConfigFile    = System.IO.Directory.GetCurrentDirectory() + "\\Config.ini";
            string connectionSql = "";
            string strServer     = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "SqlServer"), "IP", null);     //服务器
            string strDataBase   = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "SqlServer"), "DBNAME", null); //数据库名称
            string strPORT       = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "SqlServer"), "PORT", null);   //密码
            string strUid        = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "SqlServer"), "USER", null);   //用户
            string strPwdEncrypt = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "SqlServer"), "PWD", null);    //密码
            string strPwd        = EncAndDec.DESDecrypt(strPwdEncrypt);                                                                                   //解密

            if (timeout == 0)
            {
                connectionSql = "Server=" + strServer + "," + strPORT + ";DataBase=" + strDataBase + ";User ID=" + strUid + ";Password="******";Persist Security Info=True;MultipleActiveResultSets=true;Application Name=Wms接口管理器;  ";
            }
            else
            {
                connectionSql = "Server=" + strServer + "," + strPORT + ";DataBase=" + strDataBase + ";User ID=" + strUid + ";Password="******";Persist Security Info=True;MultipleActiveResultSets=true;Application Name=Wms接口管理器;Connection Timeout=" + timeout + ";  ";  //Connection Timeout=30
            }
            return(connectionSql);
        }
Exemple #8
0
        /// <summary>
        /// 得到MySql连接字符串
        /// </summary>
        /// <returns>连接字符串</returns>
        public static string getMySqlConnection(int timeout, string connectionType)
        {
            string ConfigFile    = System.IO.Directory.GetCurrentDirectory() + "\\Config.ini";
            string connectionSql = "";
            string strServer     = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "MySql"), "IP", null);     //服务器
            string strDataBase   = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "MySql"), "DBNAME", null); //数据库名称
            string strPORT       = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "MySql"), "PORT", null);
            string strUid        = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "MySql"), "USER", null);   //用户
            string strPwdEncrypt = INIOperationClass.INIGetStringValue(ConfigFile, string.Format("{0}{1}", connectionType, "MySql"), "PWD", null);    //密码
            string strPwd        = EncAndDec.DESDecrypt(strPwdEncrypt);                                                                               //解密

            if (timeout == 0)
            {
                connectionSql = "Server=" + strServer + ";DataBase=" + strDataBase + ";User ID=" + strUid + ";Password="******";port=" + strPORT + ";CharSet=utf8;pooling=true;";  //ConnectionTimeout=30
            }
            else
            {
                connectionSql = "Server=" + strServer + ";DataBase=" + strDataBase + ";User ID=" + strUid + ";Password="******";port=" + strPORT + ";CharSet=utf8;pooling=true;Connection Timeout=" + timeout + "; ";  //ConnectionTimeout=30
            }
            return(connectionSql);
        }
        private static string[] iNIGetAllItems(string iniFile, string section)
        {
            //返回值形式为 key=value,例如 Color=Red
            uint MAX_BUFFER = 32767;        //默认为32767

            string[] items = new string[0]; //返回值

            //分配内存
            IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));

            uint bytesReturned = INIOperationClass.GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, iniFile);

            if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0))
            {
                string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned);
                items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }

            Marshal.FreeCoTaskMem(pReturnedString);     //释放内存

            return(items);
        }
        private static string[] iNIGetAllSectionNames(string iniFile)
        {
            uint MAX_BUFFER = 32767;           //默认为32767

            string[] sections = new string[0]; //返回值

            //申请内存
            IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));
            uint   bytesReturned   = INIOperationClass.GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, iniFile);

            if (bytesReturned != 0)
            {
                //读取指定内存的内容
                string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString();

                //每个节点之间用\0分隔,末尾有一个\0
                sections = local.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }

            //释放内存
            Marshal.FreeCoTaskMem(pReturnedString);

            return(sections);
        }