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(); } }
private void ListViewUser_SelectedIndexChanged(object sender, EventArgs e) { btnUpdateUser.Enabled = true; btnXoaUser.Enabled = true; btnAddUser.Enabled = false; try { var localuser = (Users)listViewUser.SelectedItems[0].Tag; Users users = UsersBus.GetUsersByUserName(localuser.Username); txtNameUser.Text = users.Name; txtUserName.Text = users.Username; txtPassword.Text = users.Password; txtGhiChu.Text = users.Ghichu; CbRole.Text = users.Role; txtEmail.Text = users.Email; idUpdate = users.Id; } catch (Exception) { idUpdate = 0; } }
private void Button1_Click(object sender, EventArgs e) { Users users = new Users(); users.Username = txtUsername.Text.Trim(); users.Password = txtPassword.Text.Trim(); if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text)) { lbThongBao.Text = "Vui Lòng Nhập Đầy Đủ"; return; } if (UsersBus.CheckUsers(users)) { Account = UsersBus.GetUsersByUserName(users.Username); this.Hide(); MainAdmin main = new MainAdmin(); main.Show(); } else { lbThongBao.Text = "Tài Khoản Hoặc Mật Khẩu Sai"; } }