private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; ////validation //GridColumn thangCol = view.Columns["THANG"]; //GridColumn ma_tsCol = view.Columns["MA_TS"]; //string thang = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, thangCol), ""); //string ma_ts = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tsCol), ""); //if (ma_ts.Trim().Length == 0) //{ // e.Valid = false; // if (thang.Trim().Length == 0) // view.SetColumnError(thangCol, "Tháng không được rổng"); // if (ma_ts.Trim().Length == 0) // view.SetColumnError(ma_tsCol, "Mã tài sản không được rổng"); // return; //} _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); //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_CNLTVTheoCT obj = new KT_CNLTVTheoCT(); obj.THANG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THANG"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_CNLTVTheoCT obj = _KTCNLTVTheoCTRepo.GetById(id); if (obj != null) { obj.THANG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THANG"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.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) { _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); KT_CNLTVTheoCT obj = new KT_CNLTVTheoCT(); obj.THANG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "THANG"), ""); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.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_CNLTVTheoCT(KT_CNLTVTheoCT instance);
partial void DeleteKT_CNLTVTheoCT(KT_CNLTVTheoCT instance);
partial void InsertKT_CNLTVTheoCT(KT_CNLTVTheoCT instance);