private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; //validation GridColumn ma_tkCol = view.Columns["MA_TK"]; GridColumn ma_ctCol = view.Columns["MA_CT"]; GridColumn ma_ytcpCol = view.Columns["MA_YTCP"]; GridColumn ma_dmCol = view.Columns["MA_DM"]; string ma_tk = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tkCol), ""); string ma_ct = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_ctCol), ""); string ma_ytcp = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_ytcpCol), ""); string ma_dm = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_dmCol), ""); if (ma_tk.Trim().Length == 0 || ma_ct.Trim().Length == 0 || ma_ytcp.Trim().Length == 0 || ma_dm.Trim().Length == 0) { e.Valid = false; if (ma_tk.Trim().Length == 0) view.SetColumnError(ma_tkCol, "Mã TK không được rổng"); if (ma_ct.Trim().Length == 0) view.SetColumnError(ma_ctCol, "Mã chương trình không được rổng"); if (ma_ytcp.Trim().Length == 0) view.SetColumnError(ma_ytcpCol, "Mã YTCP không được rổng"); if (ma_dm.Trim().Length == 0) view.SetColumnError(ma_dmCol, "Mã danh mục không được rổng"); return; } _KTCPCTRepo = new KTCPCTRepo(); //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_CPCT obj = new KT_CPCT(); obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.MA_YTCP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_YTCP"), ""); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.TEN_YTCP_V = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_YTCP_V"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0); obj.PSNO_VND = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "PSNO_VND"), 0); obj.PSCO_VND = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "PSCO_VND"), 0); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCPCTRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_CPCT obj = _KTCPCTRepo.GetById(id); if (obj != null) { obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.MA_YTCP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_YTCP"), ""); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.TEN_YTCP_V = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_YTCP_V"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0); obj.PSNO_VND = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "PSNO_VND"), 0); obj.PSCO_VND = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "PSCO_VND"), 0); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCPCTRepo.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) { _KTCPCTRepo = new KTCPCTRepo(); KT_CPCT obj = new KT_CPCT(); obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TK"), ""); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), ""); obj.MA_YTCP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_YTCP"), ""); obj.MA_DM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DM"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.TEN_YTCP_V = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_YTCP_V"), ""); obj.TEN_DM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_DM"), ""); obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DON_VI"), ""); obj.SL = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SL"), 0); obj.PSNO_VND = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PSNO_VND"), 0); obj.PSCO_VND = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PSCO_VND"), 0); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); _KTCPCTRepo.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_CPCT(KT_CPCT instance);
partial void DeleteKT_CPCT(KT_CPCT instance);
partial void InsertKT_CPCT(KT_CPCT instance);