Esempio n. 1
0
 private void btTiepTuc_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtTenServer.Text == "" || cbHinhThuc.Text == "")
         {
             MessageBox.Show("Thông tin bạn cung cấp chưa đủ, hãy kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
             if (cbHinhThuc.Text.Equals("Sử Dụng Tài Khoản"))
             {
                 if (txtTaiKhoan.Text == "" || txtMatKhau.Text == "")
                 {
                     MessageBox.Show("Thông tin bạn cung cấp chưa đủ, hãy kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     _config.AppSettings.Settings["Server"].Value   = txtTenServer.Text;
                     _config.AppSettings.Settings["Username"].Value = txtTaiKhoan.Text;
                     _config.AppSettings.Settings["Password"].Value = txtMatKhau.Text;
                     _config.AppSettings.Settings["LuaChon"].Value  = cbHinhThuc.SelectedItem.ToString();
                 }
             }
             if (cbHinhThuc.Text.Equals("Không Dùng Tài Khoản"))
             {
                 _config.AppSettings.Settings["Server"].Value   = txtTenServer.Text;
                 _config.AppSettings.Settings["LuaChon"].Value  = cbHinhThuc.SelectedItem.ToString();
                 _config.AppSettings.Settings["Username"].Value = "";
                 _config.AppSettings.Settings["Password"].Value = "";
             }
             _config.Save(ConfigurationSaveMode.Modified);
             ConfigurationManager.RefreshSection("appSettings");
             DangNhap DN = new DangNhap();
             DN.ShowDialog(this);
             this.Close();
         }
     }
     catch
     {
         MessageBox.Show("Thông tin bạn cung cấp bị sai, hãy kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void btTiepTuc_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtTenServer.Text == "" || cbHinhThuc.Text == "")
         {
             MessageBox.Show("Thông tin bạn cung cấp chưa đủ, hãy kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
             if (cbHinhThuc.Text.Equals("Sử Dụng Tài Khoản"))
             {
                 if (txtTaiKhoan.Text == "" || txtMatKhau.Text == "")
                 {
                     MessageBox.Show("Thông tin bạn cung cấp chưa đủ, hãy kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     _config.AppSettings.Settings["Server"].Value = txtTenServer.Text;
                     _config.AppSettings.Settings["Username"].Value = txtTaiKhoan.Text;
                     _config.AppSettings.Settings["Password"].Value = txtMatKhau.Text;
                     _config.AppSettings.Settings["LuaChon"].Value = cbHinhThuc.SelectedItem.ToString();
                 }
             }
             if (cbHinhThuc.Text.Equals("Không Dùng Tài Khoản"))
             {
                 _config.AppSettings.Settings["Server"].Value = txtTenServer.Text;
                 _config.AppSettings.Settings["LuaChon"].Value = cbHinhThuc.SelectedItem.ToString();
                 _config.AppSettings.Settings["Username"].Value = "";
                 _config.AppSettings.Settings["Password"].Value = "";
             }
             _config.Save(ConfigurationSaveMode.Modified);
             ConfigurationManager.RefreshSection("appSettings");
             DangNhap DN = new DangNhap();
             DN.ShowDialog(this);
             this.Close();
         }
     }
     catch
     {
         MessageBox.Show("Thông tin bạn cung cấp bị sai, hãy kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }