private void btnDangNhap_Click(object sender, EventArgs e) { //Kiểm tra null or empty if (string.IsNullOrEmpty(txtTenTaiKhoan.Text)) { MetroFramework.MetroMessageBox.Show(this, "Vui lòng điền tên đăng nhập", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenTaiKhoan.Focus(); return; } try { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } //Excute sql query, then map data return from sql to User class UserThiSinh obj = db.Query <UserThiSinh>($"select * from TTHocVien where SoCMND ='{txtTenTaiKhoan.Text}'", commandType: CommandType.Text).SingleOrDefault(); string mahocvien = obj.MaHV; Properties.Settings.Default.mahocvien = mahocvien; Properties.Settings.Default.KMaHV = mahocvien; Properties.Settings.Default.KTenHV = obj.TenHV; Properties.Settings.Default.KHoHV = obj.HoHV; Properties.Settings.Default.KSoCMND = obj.SoCMND; Properties.Settings.Default.KKyThi = obj.KyThi; if (obj != null) { if (obj.MaHV == txtMatKhau.Text)//True { Console.WriteLine("\n\n Gia tri cua mahocvien la: " + Properties.Settings.Default.KHoHV); using (NavigateForm frm = new NavigateForm())//Open main form and hide login form { this.Hide(); frm.ShowDialog(); } } else { MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnLogin_Click(object sender, EventArgs e) { //Kiểm tra null or empty if (string.IsNullOrEmpty(txtUsername.Text)) { MetroFramework.MetroMessageBox.Show(this, "Vui lòng điền tên đăng nhập", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtUsername.Focus(); return; } try { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } //Excute sql query, then map data return from sql to User class User obj = db.Query <User>($"select * from TTNhanVien where TaiKhoan ='{txtUsername.Text}'", commandType: CommandType.Text).SingleOrDefault(); if (obj != null) { if (obj.MatKhau == txtPassword.Text) //True { using (NavigateForm frm = new NavigateForm()) //Open main form and hide login form { this.Hide(); frm.metroTile13.Visible = true; frm.metroTile8.Visible = true; frm.metroTile10.Visible = true; frm.metroTile15.Visible = true; frm.metroTile9.Visible = true; frm.metroTile11.Visible = true; frm.ShowDialog(); } } else { MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }