private void frm_Login_Load(object sender, EventArgs e) { //Read the connection string from the registry S118 string registryConnectionString = ""; RegistryKey ConnectionString = Registry.CurrentUser.CreateSubKey("SOFTWARE\\AutomationConnection"); registryConnectionString = ConnectionString.GetValue("ConnectionForAutomation").ToString(); try { if (registryConnectionString == "") { MessageBox.Show("The connection to the server is not established, please check the connection parameters with the server."); frm_setServerParameters frm_ssparam = new frm_setServerParameters(); frm_ssparam.ShowDialog(); btn_enter.Enabled = false; } else { PublicVariable.MainConnectionString = CryptionAlgorithm.DecryptTextUsingUTF8(registryConnectionString); } } catch { btn_enter.Enabled = false; MessageBox.Show("No connection to the server"); } // show date System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar(); PublicVariable.TodayDate = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime((pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now)))); lbl_date.Text = PublicVariable.TodayDate; // show ip string computerName = System.Environment.MachineName; string IP = ""; IPHostEntry ipe = Dns.GetHostByName(computerName); IPAddress[] IpAddress = ipe.AddressList; lbl_IP.Text = IpAddress[0].ToString(); //show time timer1_Tick(sender, e); }
private void frmLogin_Load(object sender, EventArgs e) { ///خواندن رشته اتصال از رجیستری string RegisteryConnectionString = ""; RegistryKey ConnectionString = Registry.CurrentUser.CreateSubKey("SOFTWARE\\AutomationConnection"); RegisteryConnectionString = ConnectionString.GetValue("ConnectionForAutomation").ToString(); try { if (RegisteryConnectionString == "") { MessageBox.Show("ارتباط با سرور برقرار نیست"); btn_enter.Enabled = false; } else { PublicVariable.MainConnectionString = CryptionAlgorithm.DecryptTextUsingUTF8(RegisteryConnectionString); } } catch { btn_enter.Enabled = false; MessageBox.Show("ارتباط با سرور برقرار نیست"); } //Show Date System.Globalization.PersianCalendar PC = new System.Globalization.PersianCalendar(); lbl_date.Text = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime((PC.GetYear(DateTime.Now) + "/" + PC.GetMonth(DateTime.Now) + "/" + PC.GetDayOfMonth(DateTime.Now)))); PublicVariable.TodayDate = lbl_date.Text.Trim(); //Show IP string ComputerName = System.Environment.MachineName; lblComputername.Text = ComputerName.ToString(); // string IP = ""; IPHostEntry ipe = Dns.GetHostByName(ComputerName); IPAddress[] IpAdrress = ipe.AddressList; lbl_IP.Text = IpAdrress[0].ToString(); //Show Time timer1_Tick(sender, e); }
private void btn_enter_Click(object sender, EventArgs e) { /// Set up the client computer connection to the server if (txt_DBName.Text == "" || txt_DBPassword.Text == "" || txt_serverIP.Text == "") { MessageBox.Show("Please enter all requests."); return; } var EntityConnectionString = BuildEntityConnection("Data Source=" + txt_serverIP.Text.Trim() + ";Initial Catalog=" + txt_DBName.Text.Trim() + ";user Id=sa;Password="******";Integrated Security=false"); /// The last phrase means do not enter without a password, be sure to get a password. try { RegistryKey connctionKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\AutomationConnection"); try { connctionKey.SetValue("ConnectionForAutomation", CryptionAlgorithm.EncryptTextUsingUTF8(EntityConnectionString)); } catch { MessageBox.Show("There is a problem with the server."); } finally { connctionKey.Close(); } MessageBox.Show("The connection to the server was established successfully. Please log out and log back in."); this.Close(); } catch { MessageBox.Show("There is a problem with the server."); } }