private void gridView_Employee_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; int rowfocus = e.RowHandle; if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_EmployeeName)))) { e.Valid = false; view.SetColumnError(col_EmployeeName, "Họ tên nhân viên không được để trống!"); } if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_EmployeeUsername)))) { e.Valid = false; view.SetColumnError(col_EmployeeUsername, "Tên đăng nhập được để trống!"); } if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_Employee_Sex)))) { e.Valid = false; view.SetColumnError(col_Employee_Sex, "Chưa chọn giới tính!"); } if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_EmployeePosition)))) { e.Valid = false; view.SetColumnError(col_EmployeePosition, "Chưa chức danh cho nhân viên!"); } if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_EmployeeGroup)))) { e.Valid = false; view.SetColumnError(col_EmployeeGroup, "Chưa nhóm cho nhân viên!"); } if (e.Valid) { PSEmployee emp = new PSEmployee(); emp.EmployeeCode = gridView_Employee.GetRowCellValue(e.RowHandle, "EmployeeCode").ToString(); emp.EmployeeName = gridView_Employee.GetRowCellValue(e.RowHandle, "EmployeeName").ToString(); if (gridView_Employee.GetRowCellValue(e.RowHandle, "Sex").ToString() != "") { emp.Sex = int.Parse(gridView_Employee.GetRowCellValue(e.RowHandle, "Sex").ToString()); } emp.Mobile = gridView_Employee.GetRowCellValue(e.RowHandle, "Mobile").ToString(); emp.IDCard = gridView_Employee.GetRowCellValue(e.RowHandle, "IDCard").ToString(); emp.Address = gridView_Employee.GetRowCellValue(e.RowHandle, "Address").ToString(); if (!string.IsNullOrEmpty(gridView_Employee.GetRowCellValue(e.RowHandle, "Birthday").ToString())) { emp.Birthday = DateTime.Parse(gridView_Employee.GetRowCellValue(e.RowHandle, "Birthday").ToString()); } emp.PositionCode = int.Parse(gridView_Employee.GetRowCellValue(e.RowHandle, "PositionCode").ToString()); emp.CreateDate = DateTime.Now; emp.Username = gridView_Employee.GetRowCellValue(e.RowHandle, "Username").ToString(); emp.EmployeeGroupID = int.Parse(gridView_Employee.GetRowCellValue(e.RowHandle, "EmployeeGroupID").ToString()); if (e.RowHandle < 0) { if (!BioBLL.CheckExistUser(emp.Username)) { XtraMessageBox.Show("Tên đăng nhập đã tồn tại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_Employee.DataSource = BioBLL.DTEmployee(string.Empty); return; } if (BioBLL.InsEmployee(emp)) { XtraMessageBox.Show("Thêm mới nhân viên thành công!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Thêm nhân viên thất bại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { PSEmployee empOld = BioBLL.GetEmployeeByCode(emp.EmployeeCode); if (empOld.Username != emp.Username) { if (!BioBLL.CheckExistUser(emp.Username)) { XtraMessageBox.Show("Tên đăng nhập đã tồn tại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_Employee.DataSource = BioBLL.DTEmployee(string.Empty); return; } } if (BioBLL.UpdEmployee(emp)) { XtraMessageBox.Show("Cập nhật nhân viên thành công!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Cập nhật nhân viên thất bại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.gridControl_Employee.DataSource = BioBLL.DTEmployee(string.Empty); } } catch { XtraMessageBox.Show("Thao tác thất bại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); } }