示例#1
0
 private bool TestLink(bool IsTest)
 {
     bool ret = false;
       int DBType = SystemInfo.DBType;
       string ServerName = "";
       bool WindowsNT = true;
       string UserName = "";
       string UserPass = "";
       string ConnStr = "";
       switch (DBType)
       {
     case 1:
     case 2:
       ServerName = txtMSSQLServer.Text.Trim();
       WindowsNT = rbMSSQLWindowsNT.Checked;
       if (!WindowsNT)
       {
     UserName = txtMSSQLUserName.Text.Trim();
     UserPass = txtMSSQLUserPass.Text.Trim();
       }
       break;
       }
       ConnStr = Pub.GetMSSQLConnStr(ServerName, WindowsNT, UserName, UserPass, "master");
       try
       {
     SystemInfo.db.Open(DBType, ConnStr);
     ret = true;
       }
       catch (Exception E)
       {
     Pub.ShowErrorMsg(E);
       }
       finally
       {
     SystemInfo.db.Close();
       }
       if (ret)
       {
     if (!IsTest)
     {
       switch (DBType)
       {
     case 1:
       SystemInfo.ini.WriteIni("MSSQL", "Server", ServerName);
       SystemInfo.ini.WriteIni("MSSQL", "WindowsNT", WindowsNT);
       SystemInfo.ini.WriteIni("MSSQL", "UserName", Pub.GetAesEncrypt(UserName, SystemInfo.Encry));
       SystemInfo.ini.WriteIni("MSSQL", "UserPass", Pub.GetAesEncrypt(UserPass, SystemInfo.Encry));
       break;
     case 2:
       SystemInfo.ini.WriteIni("MSDE", "Server", ServerName);
       SystemInfo.ini.WriteIni("MSDE", "WindowsNT", WindowsNT);
       SystemInfo.ini.WriteIni("MSDE", "UserName", Pub.GetAesEncrypt(UserName, SystemInfo.Encry));
       SystemInfo.ini.WriteIni("MSDE", "UserPass", Pub.GetAesEncrypt(UserPass, SystemInfo.Encry));
       break;
       }
     }
     Pub.MessageBoxShow(Pub.GetResText(formCode, "MsgTestDataLinkSuccess", ""), MessageBoxIcon.Information);
       }
       return ret;
 }