private void simpleButtonGhi_Click(object sender, EventArgs e) { if (CboUtil.CheckSelectedNull(comboBoxEditNguoiDung) || CboUtil.CheckSelectedNull(comboBoxEditQuyenSuDung)) { MsgboxUtil.Error("Bạn chưa chọn người dùng hoặc chưa có giáo viên nào trong danh sách!"); return; } if (textEdittenTruyCap.Text == "") { MsgboxUtil.Error("Bạn chưa nhập tên đăng nhập"); return; } if (!_isAddButton && _nguoiDungBUS.KiemTraTonTai_TaiKhoan(textEdittenTruyCap.Text.Replace("'", "''").Trim())) { MsgboxUtil.Error("Tài khoản: " + textEdittenTruyCap.Text + " đã tồn tại. Hãy chọn tài khoản khác!"); return; } bool checkExistsUser = _nguoiDungBUS.KiemTraTonTai_NguoiDung( CboUtil.GetValueItem(comboBoxEditNguoiDung)); // không tồn tại và mk rỗng if (!checkExistsUser && textEditMatKhau.Text == "") { MsgboxUtil.Error("Bạn chưa nhập mật khẩu!"); return; } // nếu đang thêm if (!_isAddButton) { if (checkExistsUser) { if (MsgboxUtil.YesNo("Giáo viên: " + CboUtil.GetDisplayItem(comboBoxEditNguoiDung) + " đã được tạo tài khoản.\nBạn có muốn cập nhật lại thông tin tài khoản cho giáo viên này?") == DialogResult.No ) { return; } } } // Lay tt nguoi dung var user = new NguoiDungDTO(); user.MaND = CboUtil.GetValueItem(comboBoxEditNguoiDung); user.LoaiNguoiDung.MaLoai = CboUtil.GetValueItem(comboBoxEditQuyenSuDung); user.TenDNhap = textEdittenTruyCap.Text.Replace("'", "''"); user.MatKhau = (textEditMatKhau.Text == "") ? "" : textEditMatKhau.Text.Replace("'", "''"); user.TrangThai = radioGroupTrangThai.SelectedIndex; // Check nguoi dung ton tai hay chua if (!checkExistsUser) { // thêm if (_nguoiDungBUS.Them_NguoiDung(user)) { MsgboxUtil.Success("Thêm thành công user: "******" !"); } _Load_Lai_Gridview(); } else { _currentRowEdit = gridViewNguoiDung.FocusedRowHandle; // Sửa if (_nguoiDungBUS.Sua_NguoiDung(user)) { MsgboxUtil.Success("Sửa thành công user: "******" !"); } _Load_Lai_Gridview(_currentRowEdit); } }