partial void DeleteKT_CTTP(KT_CTTP instance);
partial void UpdateKT_CTTP(KT_CTTP instance);
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; ////validation GridColumn ma_tpCol = view.Columns["MA_TP"]; GridColumn ma_ctCol = view.Columns["MA_CT"]; string ma_tp = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tpCol), ""); string ma_ct = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_ctCol), ""); if (ma_tp.Trim().Length == 0 || ma_ct.Trim().Length == 0) { e.Valid = false; if (ma_tp.Trim().Length == 0) view.SetColumnError(ma_tpCol, "Mã thành phẩm không được rổng"); if (ma_ct.Trim().Length == 0) view.SetColumnError(ma_ctCol, "Mã công trình không được rổng"); return; } _KTCTTPRepo = new KTCTTPRepo(); //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_CTTP obj = new KT_CTTP(); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue); obj.NGAY_HD = temp; obj.SO_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_HD"), ""); obj.MA_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TP"), ""); obj.TEN_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TP"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.SL_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "SL_DH"), 0); obj.DG_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DG_DH"), 0); obj.TT_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TT_DH"), 0); //obj.tk_no = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DTPN_NO"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); obj.MA_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_KH"), ""); obj.TEN_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_KH"), ""); _KTCTTPRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_CTTP obj = _KTCTTPRepo.GetById(id); if (obj != null) { obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue); obj.NGAY_HD = temp; obj.SO_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_HD"), ""); obj.MA_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TP"), ""); obj.TEN_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TP"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.SL_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "SL_DH"), 0); obj.DG_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DG_DH"), 0); obj.TT_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TT_DH"), 0); //obj.tk_no = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DTPN_NO"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); obj.MA_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_KH"), ""); obj.TEN_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_KH"), ""); _KTCTTPRepo.Update(obj); } } Load_Data(); } catch (Exception ex) { e.Valid = false; MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
partial void InsertKT_CTTP(KT_CTTP instance);
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) { _KTCTTPRepo = new KTCTTPRepo(); KT_CTTP obj = new KT_CTTP(); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_HD"), DateTime.MinValue); obj.NGAY_HD = temp; obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_HD"), ""); obj.MA_TP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TP"), ""); obj.TEN_TP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_TP"), ""); obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DON_VI"), ""); obj.SL_DH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SL_DH"), 0); obj.DG_DH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DG_DH"), 0); obj.TT_DH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TT_DH"), 0); //obj.tk_no = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DTPN_NO"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); obj.MA_KH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_KH"), ""); obj.TEN_KH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_KH"), ""); _KTCTTPRepo.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); } }