private void btnLuu_Click(object sender, EventArgs e) { if (Them == true) { if (checkThem == true) { //int MaUser = int.Parse(txtMaUser.Text.ToString()); string TenUser = txtTenUser.Text.ToString(); string Username = txtUsername.Text.ToString(); string Password = txtPassword.Text.ToString(); string Diachi = txtDiaChi.Text.ToString(); string SDT = txtSDT.Text.ToString(); MessageBox.Show(Username); db.sp_Create_User(Username, Password, Diachi, SDT, TenUser); db.SaveChanges(); LoadData(); MessageBox.Show("Da them xong"); btnLuu.Enabled = false; btnCapNhat.Enabled = true; btnXoa.Enabled = true; Them = false; DisableComponent(); ClearClickedData(); } } else if (CapNhat == true) { try { db.Configuration.LazyLoadingEnabled = false; var userID = int.Parse(txtMaUser.Text); var userFounded = db.USERS.Where(x => x.MAUSER == userID).ToList().FirstOrDefault(); userFounded.USERNAME = txtUsername.Text.ToString(); userFounded.MATKHAU = txtPassword.Text.ToString(); userFounded.DIACHI = txtDiaChi.Text.ToString(); userFounded.SDT = txtSDT.Text.ToString(); userFounded.TEN = txtTenUser.Text.ToString(); db.SaveChanges(); LoadData(); DisableComponent(); MessageBox.Show("Đã cập nhật xong !!!"); } catch { MessageBox.Show("Không cập nhật được. Lỗi rồi!"); } btnHuy.Enabled = false; btnLuu.Enabled = false; btnThem.Enabled = true; btnXoa.Enabled = true; btnCapNhat.Enabled = true; } }