Exemplo n.º 1
0
 void ShowParameters()
 {
     if (!System.IO.File.Exists(serverParameters) && Registry.CurrentUser.OpenSubKey(serverParametersRegkey) == null)
     {
         bConnectionTrue = false; return;
     }
     if (System.IO.File.Exists(serverParameters))
     {
         XmlDocument doc = new XmlDocument();
         try {
             doc.Load(serverParameters);
         } catch { }
         if (doc.DocumentElement.Name == "Parameters")
         {
             string[] prm = doc.DocumentElement.InnerText.Split(new char[] { ';' });
             cbServer.Text             = prm[0];
             radioGroup1.SelectedIndex = Convert.ToInt32(prm[1]);
             teLogin.Text          = prm[2];
             tePassword.Text       = BaseEncryption.Decrypt(prm[3], Application.ProductName + "??a");
             checkSavePass.Checked = Convert.ToInt32(prm[4]) == 1 ? true : false;
             cbDatabase.Text       = prm[5];
         }
     }
     else if (Registry.CurrentUser.OpenSubKey(serverParametersRegkey) != null)
     {
         try
         {
             RegistryKey rk  = Registry.CurrentUser;
             RegistryKey reg = rk.OpenSubKey(serverParametersRegkey);
             cbServer.Text             = (string)reg.GetValue("Server", "");
             cbDatabase.Text           = (string)reg.GetValue("Database");
             teLogin.Text              = (string)reg.GetValue("Login");
             tePassword.Text           = BaseEncryption.Decrypt((string)reg.GetValue("Password"), Application.ProductName + "??a");
             radioGroup1.SelectedIndex = (Int32)reg.GetValue("SSPI", 1);
             checkSavePass.Checked     = (int)reg.GetValue("SavePassword", false) == 0 ? false : true;
             reg.Close(); rk.Close();
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(ex.Message, "Open Config", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     ConnParameters  = new ConnectionElements(cbServer.Text, cbDatabase.Text, teLogin.Text, tePassword.Text);
     bConnectionTrue = CorrectConnection(GetServerConnectionString(), false);
 }
Exemplo n.º 2
0
 void SaveAndCloseForm()
 {
     if (!CorrectConnection(GetServerConnectionString(), true))
     {
         bConnectionTrue = false; return;
     }
     else
     {
         bConnectionTrue = true;
     }
     try
     {
         if (radioGroup2.SelectedIndex == 1)
         {
             using (XmlTextWriter tw = new XmlTextWriter(serverParameters, System.Text.Encoding.UTF8))
             {
                 tw.WriteElementString("Parameters", BaseEncryption.Encrypt(ConnectionStringParameters, Application.ProductName + "??a"));
             }
         }
         else
         {
             RegistryKey rk = Registry.CurrentUser;
             using (RegistryKey reg = rk.CreateSubKey(serverParametersRegkey))
             {
                 reg.SetValue("Server", cbServer.Text, RegistryValueKind.String);
                 reg.SetValue("Database", cbDatabase.Text, RegistryValueKind.String);
                 reg.SetValue("SSPI", radioGroup1.SelectedIndex, RegistryValueKind.DWord);
                 reg.SetValue("Login", teLogin.Text, RegistryValueKind.String);
                 reg.SetValue("Password", BaseEncryption.Encrypt(tePassword.Text, Application.ProductName + "??a"), RegistryValueKind.String);
                 reg.SetValue("SavePassword", Convert.ToByte(checkSavePass.Checked), RegistryValueKind.DWord);
                 reg.Close();
             }
             rk.Close();
         }
         ConnParameters = new ConnectionElements(cbServer.Text, cbDatabase.Text, teLogin.Text, tePassword.Text);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Save Config", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     this.Close();
 }