private int CheckLevelPositionWithPosCode(string empLogin) { try { PSEmployee employeeLogin = new PSEmployee(); employeeLogin = BioBLL.GetEmployeeByCode(empLogin); PSEmployeePosition postion = new PSEmployeePosition(); postion = BioBLL.GetPositionByCode(this.positionCode); int levelLogin = employeeLogin.PSEmployeePosition.Level; int level = postion.Level; if (levelLogin < level) { return(1); } else if (levelLogin == level) { return(-1); } else { return(0); } } catch { return(-2); } }
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_EmployeePosition)))) { e.Valid = false; view.SetColumnError(col_EmployeePosition, "Không được để trống chức danh!"); } if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_Level)))) { e.Valid = false; view.SetColumnError(col_Level, "Không được để trống cấp bậc"); } if (e.Valid) { PSEmployeePosition emp = new PSEmployeePosition(); emp.PositionName = gridView_Employee.GetRowCellValue(e.RowHandle, "PositionName").ToString(); try { emp.PositionCode = Convert.ToInt32((gridView_Employee.GetRowCellValue(e.RowHandle, "PositionCode") ?? "0").ToString()); } catch { emp.PositionCode = 0; } emp.Level = Convert.ToInt32(gridView_Employee.GetRowCellValue(e.RowHandle, "Level") ?? "0"); if (e.RowHandle < 0) { if (!BioBLL.CheckExistPosition(emp.PositionName, emp.PositionCode)) { XtraMessageBox.Show("Tên chức danh đã tồn tại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_Employee.DataSource = BioBLL.DTEmployeePosition(); return; } if (BioBLL.InsEmployeePosition(emp)) { XtraMessageBox.Show("Thêm mới chức danh thành công!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Thêm chức danh thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { PSEmployeePosition empOld = BioBLL.GetPositionByCode(emp.PositionCode); if (empOld.PositionName != emp.PositionName) { if (!BioBLL.CheckExistPosition(emp.PositionName, emp.PositionCode)) { XtraMessageBox.Show("Tên chức danh đã tồn tại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_Employee.DataSource = BioBLL.DTEmployeePosition(); return; } } if (BioBLL.updEmployeePosition(emp)) { XtraMessageBox.Show("Cập nhật chức danh thành công!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Cập nhật chức danh thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.gridControl_Employee.DataSource = BioBLL.DTEmployeePosition(); } } catch { XtraMessageBox.Show("Thao tác thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error); } }