private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; //validation GridColumn ma_nvCol = view.Columns["MA_NV"]; string ma_nv = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_nvCol), ""); if (ma_nv.Trim().Length == 0) { e.Valid = false; if (ma_nv.Trim().Length == 0) view.SetColumnError(ma_nvCol, "Mã nhân viên không được rổng"); return; } _KTCNLuongTVRepo = new KTCNLuongTVRepo(); //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert if (view.IsNewItemRow(e.RowHandle)) { //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại KT_CNLuongTV obj = new KT_CNLuongTV(); obj.MA_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NV"), ""); obj.TEN_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NV"), ""); obj.CMND = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CMND"), ""); obj.NAM_SINH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NAM_SINH"), ""); obj.THANG_SINH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THANG_SINH"), ""); obj.NGAY_SINH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NGAY_SINH"), ""); obj.NGHE_NGHIEP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NGHE_NGHIEP"), ""); obj.NGUYEN_QUAN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NGUYEN_QUAN"), ""); obj.THUONG_TRU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THUONG_TRU"), ""); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_CAP"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_CAP"), DateTime.MinValue); obj.NGAY_CAP = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "TU_NGAY"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "TU_NGAY"), DateTime.MinValue); obj.TU_NGAY = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "DEN_NGAY"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "DEN_NGAY"), DateTime.MinValue); obj.DEN_NGAY = temp; obj.NOI_CAP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NOI_CAP"), ""); obj.CHUC_DANH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CHUC_DANH"), ""); obj.CHUC_VU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CHUC_VU"), ""); obj.CONG_VIEC = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CONG_VIEC"), ""); obj.TIEN_LUONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TIEN_LUONG"), 0); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCNLuongTVRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_CNLuongTV obj = _KTCNLuongTVRepo.GetById(id); if (obj != null) { obj.MA_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NV"), ""); obj.TEN_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NV"), ""); obj.CMND = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CMND"), ""); obj.NAM_SINH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NAM_SINH"), ""); obj.THANG_SINH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THANG_SINH"), ""); obj.NGAY_SINH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NGAY_SINH"), ""); obj.NGHE_NGHIEP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NGHE_NGHIEP"), ""); obj.NGUYEN_QUAN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NGUYEN_QUAN"), ""); obj.THUONG_TRU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THUONG_TRU"), ""); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_CAP"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_CAP"), DateTime.MinValue); obj.NGAY_CAP = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "TU_NGAY"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "TU_NGAY"), DateTime.MinValue); obj.TU_NGAY = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "DEN_NGAY"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "DEN_NGAY"), DateTime.MinValue); obj.DEN_NGAY = temp; obj.NOI_CAP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NOI_CAP"), ""); obj.CHUC_DANH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CHUC_DANH"), ""); obj.CHUC_VU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CHUC_VU"), ""); obj.CONG_VIEC = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CONG_VIEC"), ""); obj.TIEN_LUONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TIEN_LUONG"), 0); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCNLuongTVRepo.Update(obj); } } Load_Data(); } catch (Exception ex) { e.Valid = false; MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Save_Duplicate() { try { if (MessageBox.Show("Bạn có muốn copy dòng này thành dòng mới?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _KTCNLuongTVRepo = new KTCNLuongTVRepo(); KT_CNLuongTV obj = new KT_CNLuongTV(); obj.MA_NV = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_NV"), ""); obj.TEN_NV = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_NV"), ""); obj.CMND = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CMND"), ""); obj.NAM_SINH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NAM_SINH"), ""); obj.THANG_SINH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "THANG_SINH"), ""); obj.NGAY_SINH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_SINH"), ""); obj.NGHE_NGHIEP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGHE_NGHIEP"), ""); obj.NGUYEN_QUAN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGUYEN_QUAN"), ""); obj.THUONG_TRU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "THUONG_TRU"), ""); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_CAP"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_CAP"), DateTime.MinValue); obj.NGAY_CAP = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TU_NGAY"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TU_NGAY"), DateTime.MinValue); obj.TU_NGAY = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DEN_NGAY"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DEN_NGAY"), DateTime.MinValue); obj.DEN_NGAY = temp; obj.NOI_CAP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NOI_CAP"), ""); obj.CHUC_DANH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CHUC_DANH"), ""); obj.CHUC_VU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CHUC_VU"), ""); obj.CONG_VIEC = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CONG_VIEC"), ""); obj.TIEN_LUONG = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TIEN_LUONG"), 0); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); _KTCNLuongTVRepo.Create(obj); MessageBox.Show("Đã copy dòng này vào cuối bảng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
partial void UpdateKT_CNLuongTV(KT_CNLuongTV instance);
partial void DeleteKT_CNLuongTV(KT_CNLuongTV instance);
partial void InsertKT_CNLuongTV(KT_CNLuongTV instance);