private void Button1_Click(object sender, EventArgs e) { if (!ValidateTextBox()) { lbThongBao.Text = "Vui Lòng Điền Đầy Đủ"; return; } if (txtPassword2.Text.Trim() != txtPassword.Text.Trim()) { lbThongBao.Text = "Mật Khẩu Nhập Lại Sai "; return; } try { Users user = Login.Account; user.Password = txtPassword2.Text; UsersBus.UpdateUsers(user); lbThongBao.Text = "Thành Công"; } catch (Exception) { lbThongBao.Text = "Thất Bại"; } finally { txtPassword2.Text = ""; txtPassword.Text = ""; } }
private void BtnUpdateUser_Click(object sender, EventArgs e) { if (!ValidateUsers()) { MessageBox.Show("Vui Lòng Điền Đầy Đủ", "Thông Báo"); return; } if (!string.IsNullOrEmpty(UsersBus.GetUsersByUserName(txtUserName.Text.Trim()).Name)) { if (UsersBus.GetUsersByUserName(txtUserName.Text.Trim()).Id != idUpdate) { MessageBox.Show("Tên đã tồn tại trong hệ thống", "Thông Báo"); return; } } if (!string.IsNullOrEmpty(UsersBus.GetUsersByEmail(txtEmail.Text.Trim()).Email)) { if (UsersBus.GetUsersByEmail(txtEmail.Text.Trim()).Id != idUpdate) { MessageBox.Show("Email đã tồn tại trong hệ thống", "Thông Báo"); return; } } try { Users users = new Users(); users.Name = txtNameUser.Text.Trim(); users.Username = txtUserName.Text.Trim(); users.Password = txtPassword.Text.Trim(); users.Ghichu = txtGhiChu.Text.Trim(); users.Role = CbRole.SelectedItem.ToString(); users.Email = txtEmail.Text.Trim(); users.Id = idUpdate; UsersBus.UpdateUsers(users); } catch (Exception) { MessageBox.Show("Vui Lòng Điền Theo Định Dạng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { btnUpdateUser.Enabled = false; btnXoaUser.Enabled = false; btnAddUser.Enabled = true; LoadDataListViewUser(); TextBoxClear(); } }