/// <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); }
/// <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; } }
/// <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); }
/// <summary> /// set SetString Encrypt user key /// 使用默认秘钥 /// </summary> public static void SetStringEncrypt() { StringEncrypt.SetEncryptKey(); }
/// <summary> /// set SetString Encrypt default key /// 设置加密秘钥 /// </summary> /// <param name="EncryptKey"></param> public static void SetStringEncrypt(String EncryptKey) { StringEncrypt.SetEncryptKey(EncryptKey); }