Ejemplo n.º 1
0
        /// <summary>
        /// 生成数据库文件
        /// </summary>
        /// <param name="DefaultDatabase">数据库类型,MSSQL,MYSQL,Oracle,OleDB,SQLite</param>
        /// <param name="ConnectName">连接字符串名称</param>
        /// <param name="ServerIP">数据库IP地址</param>
        /// <param name="DatabaseName">数据库名字</param>
        /// <param name="UserName">用户名</param>
        /// <param name="Password">密码</param>
        /// <param name="Type"></param>
        public static void SetDatabaseString(String DefaultDatabase, String ConnectName, String ServerIP, String DatabaseName, String UserName, String Password, StringEncrypt.EncryptType Type)
        {
            String Value = "";

            if (DefaultDatabase == "MSSQL")
            {
                Value = "Data Source=" + ServerIP + ";database=" + DatabaseName + ";uid=" + UserName + ";pwd=" + Password;
            }
            else if (DefaultDatabase == "MYSQL")
            {
                Value = "server=" + ServerIP + ";database=" + DatabaseName + ";uid=" + UserName + ";pwd=" + Password;
            }
            else if (DefaultDatabase == "Oracle")
            {
                Value = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = " + ServerIP
                        + "(PORT = 1521));(CONNECT_DATA = (SID =" + DatabaseName + ")));User Id=" + UserName + ";Password="******"SQLite")
            {
                Value = "Data Source=" + ServerIP + ";Version=3;";
            }
            else
            {
                Value = "";
            }

            if (Type != StringEncrypt.EncryptType.None)
            {
                Value = StringEncrypt.DataEncrypt(Type, Value);
            }

            XmlStream.setXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", ConnectName, "ConnectString", Value);
            XmlStream.setXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", ConnectName, "Name", DefaultDatabase);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  return connstring from formatted of xml file
        /// 返回XML文件指定元素属性连接字符串
        /// </summary>
        /// <param name="fileName">XMl file path</param>
        /// <param name="xmlElement">XML element name</param>
        /// <param name="xmlAttribute">XML Attribute name</param>
        /// <returns></returns>
        public static String GetDbConfigXml(String fileName, String xmlElement, String xmlAttribute)
        {
            String s = XmlStream.getXmlValue(fileName, xmlElement, xmlAttribute);

            if (string.IsNullOrEmpty(s))
            {
                throw new Exception("XML Attribute not found");
            }
            return(s);
        }
Ejemplo n.º 3
0
        /// <GetConnectionString>
        /// GetConnectionString
        /// </GetConnectionString>
        /// <returns></returns>
        public SQLServerDatabase(String ConnectName, StringEncrypt.EncryptType type)
        {
            String EncryptString = XmlStream.getXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", ConnectName, "ConnectString");

            if (type != StringEncrypt.EncryptType.None)
            {
                ConnectString = StringEncrypt.DataDecrypt(type, EncryptString);
            }
            else
            {
                ConnectString = EncryptString;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  return connstring from formatted of xml file
        /// 返回XML文件指定元素属性加密方式连接字符串
        /// </summary>
        /// <param name="fileName">XMl file path</param>
        /// <param name="xmlElement">XML element name</param>
        /// <param name="xmlAttribute">XML Attribute name</param>
        /// <param name="encryptType">String Encrypt</param>
        /// <returns></returns>
        public static String GetDbConfigXml(String fileName, String xmlElement, String xmlAttribute, StringEncrypt.EncryptType encryptType)
        {
            String s = XmlStream.getXmlValue(fileName, xmlElement, xmlAttribute);

            if (string.IsNullOrEmpty(s))
            {
                throw  new Exception("XML Attribute not found");
            }
            if (encryptType != StringEncrypt.EncryptType.None)
            {
                s = StringEncrypt.DataDecrypt(encryptType, s);
            }
            return(s);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 计算解密密匙
        /// </summary>
        /// <returns></returns>
        private static String GetEncryptKey()
        {
            try
            {
                if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "DatabaseCon.xml"))
                {
                    string s = XmlStream.getXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseCon.xml", "String", "Value");

                    s = AESDecrypt(s, "Database");

                    return(GetMD5Hash(s).Substring(0, 8));
                }
                else
                {
                    return("RBACSkey");
                }
            }
            catch (Exception)
            {
                return("RBACSkey");
            }
        }
Ejemplo n.º 6
0
 /// <GetConnectionString>
 /// GetConnectionString
 /// </GetConnectionString>
 /// <returns></returns>
 public SQLServerDatabase(String ConnectName)
 {
     ConnectString = XmlStream.getXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", ConnectName, "ConnectString");
 }
Ejemplo n.º 7
0
 /// <GetConnectionString>
 /// GetConnectionString
 /// </GetConnectionString>
 /// <returns></returns>
 public OracleDatabase()
 {
     ConnectString = XmlStream.getXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", "Oracle", "ConnectString");
 }
Ejemplo n.º 8
0
 /// <GetConnectionString>
 /// GetConnectionString
 /// </GetConnectionString>
 /// <returns></returns>
 public RedisDBDatabase()
 {
     ConnectString = XmlStream.getXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", "MongoDB", "ConnectString");
 }
 /// <GetConnectionString>
 /// GetConnectionString
 /// </GetConnectionString>
 /// <returns></returns>
 public PostgreSQL()
 {
     ConnectString = XmlStream.getXmlValue(AppDomain.CurrentDomain.BaseDirectory + "DatabaseConfig.xml", "PostgreSQL", "ConnectString");
 }