public static string WM_ConnString;//WM连接字符串 public static bool MakeDBConn_temp() { const string CryptStr = "sp"; bool result; result = false; string AppFile = Application.ExecutablePath;//应用程序路径(包括名称) AppFile = AppFile.ToLower(); AppFile = AppFile.Replace(".exe", ".ini"); labReadIni: StringBuilder temp = new StringBuilder(255); CommFunction.GetPrivateProfileString("temp连接数据库", "服务名", "", temp, 255, AppFile); string datasource = temp.ToString(); CommFunction.GetPrivateProfileString("temp连接数据库", "用户", "", temp, 255, AppFile); string user = temp.ToString(); CommFunction.GetPrivateProfileString("temp连接数据库", "口令", "", temp, 255, AppFile); string pwd = temp.ToString(); pwd = CommFunction.DeCryptStr(pwd, CryptStr); string newconnstr = ""; newconnstr = newconnstr + "data source=" + datasource + ";"; newconnstr = newconnstr + "User ID=" + user + ";"; newconnstr = newconnstr + "Password="******";"; newconnstr = newconnstr + "Provider=OraOLEDB.Oracle.1";//WIN7下一定要先这样,MSDAORA.1:才连得上,太怪了! OleDbConnection odbconn = new OleDbConnection(newconnstr); try { odbconn.Open(); result = true; } catch { result = false; } if (result == false) { string ss = "服务名" + Convert.ToChar(0x2) + "Edit" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "0" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + Convert.ToChar(0x3) + "用户" + Convert.ToChar(0x2) + "Edit" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "0" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + Convert.ToChar(0x3) + "口令" + Convert.ToChar(0x2) + "Edit" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "0" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "1" + CryptStr + Convert.ToChar(0x3); if (CommFunction.ShowOptionForm("temp连接数据库", "temp连接数据库", ss, AppFile)) { goto labReadIni; } else { Application.Exit(); } } return(true); }
///<summary> ///程序启动必需的WMS数据库连接设置 ///</summary> ///<param name=""></param> ///<returns></returns> public static bool MakeDBConn_HCWL() { const string CryptStr = "sp"; bool result; result = false; string AppFile = Application.ExecutablePath;//应用程序路径(包括名称) AppFile = AppFile.ToLower(); AppFile = AppFile.Replace(".exe", ".ini"); labReadIni: StringBuilder temp = new StringBuilder(255); CommFunction.GetPrivateProfileString("HCWL连接数据库", "服务名", "", temp, 255, AppFile); string datasource = temp.ToString(); CommFunction.GetPrivateProfileString("HCWL连接数据库", "用户", "", temp, 255, AppFile); string user = temp.ToString(); CommFunction.GetPrivateProfileString("HCWL连接数据库", "口令", "", temp, 255, AppFile); string pwd = temp.ToString(); pwd = CommFunction.DeCryptStr(pwd, CryptStr); string newconnstr = ""; newconnstr = newconnstr + "data source=" + datasource + ";"; newconnstr = newconnstr + "User ID=" + user + ";"; newconnstr = newconnstr + "Password="******";"; newconnstr = newconnstr + "Provider=MSDAORA.1:";//Unicode=True;//OraOleDb.Oracle OleDbConnection odbconn = new OleDbConnection(newconnstr); try { odbconn.Open(); result = true; CommFunction.cfServerName = datasource; CommFunction.cfUserID = user; CommFunction.cfPassword = pwd; LoginCs.LoginClass.ConnectString = newconnstr;//传递给登录模块以便登录 CommFunction.ConnectString = newconnstr; } catch { result = false; } if (result == false) { string ss = "服务名" + Convert.ToChar(0x2) + "Edit" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "0" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + Convert.ToChar(0x3) + "用户" + Convert.ToChar(0x2) + "Edit" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "0" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + Convert.ToChar(0x3) + "口令" + Convert.ToChar(0x2) + "Edit" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "0" + Convert.ToChar(0x2) + Convert.ToChar(0x2) + "1" + CryptStr + Convert.ToChar(0x3); if (CommFunction.ShowOptionForm("HCWL连接数据库", "HCWL连接数据库", ss, AppFile)) { goto labReadIni; } else { Application.Exit(); } } return(true); }