private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; _KTDMCongTrinhRepo = new KTDMCongTrinhRepo(); //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_DMCongTrinh obj = new KT_DMCongTrinh(); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.HOAN_THANH = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "HOAN_THANH"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue); obj.NGAY_HD = temp; obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "SO_HD"), ""); obj.NOI_DUNG = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "NOI_DUNG"), ""); obj.GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_VND"), 0); obj.GT_USD = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_USD"), 0); obj.GT_NT_VND = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_NT_VND"), 0); obj.GT_NT_VND = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_NT_VND"), 0); obj.SO_NGAY_LAM = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "SO_NGAY_LAM"), 0); temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_NT"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_NT"), DateTime.MinValue); obj.NGAY_NT = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_KC"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_KC"), DateTime.MinValue); obj.NGAY_KC = temp; obj.CP_DK_621 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_621"), 0); obj.CP_DK_622 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_622"), 0); obj.CP_DK_623 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_623"), 0); obj.CP_DK_627 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_627"), 0); obj.DO_DANG_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "DO_DANG_DK"), 0); obj.DOANH_THU_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "DOANH_THU_DK"), 0); obj.THUE_VAT_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "THUE_VAT_DK"), 0); obj.DS_HD_DK = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DS_HD_DK"), ""); obj.DS_HD_TK = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DS_HD_TK"), ""); obj.TONG_CP = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "TONG_CP"), 0); obj.CP_CK_621 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_621"), 0); obj.CP_CK_622 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_622"), 0); obj.CP_CK_623 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_623"), 0); obj.CP_CK_627 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_627"), 0); obj.DO_DANG_CK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "DO_DANG_CK"), 0); obj.LAI_GOP = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LAI_GOP"), 0); obj.TY_LE_LAI = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "TY_LE_LAI"), 0); obj.TY_LE_PB = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "TY_LE_PB"), 0); obj.GIA_VON_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GIA_VON_DK"), 0); obj.TK_DO_DANG = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "TK_DO_DANG"), ""); obj.TK_GIA_VON = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "TK_GIA_VON"), ""); obj.LK_CPDK_621 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_621"), 0); obj.LK_CPDK_622 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_622"), 0); obj.LK_CPDK_623 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_623"), 0); obj.LK_CPDK_627 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_627"), 0); obj.LK_CPDK_TONG = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_TONG"), 0); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); _KTDMCongTrinhRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0); KT_DMCongTrinh obj = _KTDMCongTrinhRepo.GetById(id); if (obj != null) { obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.HOAN_THANH = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "HOAN_THANH"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue); obj.NGAY_HD = temp; obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "SO_HD"), ""); obj.NOI_DUNG = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "NOI_DUNG"), ""); obj.GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_VND"), 0); obj.GT_USD = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_USD"), 0); obj.GT_NT_VND = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_NT_VND"), 0); obj.GT_NT_VND = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GT_NT_VND"), 0); obj.SO_NGAY_LAM = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "SO_NGAY_LAM"), 0); temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_NT"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_NT"), DateTime.MinValue); obj.NGAY_NT = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_KC"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(e.RowHandle, "NGAY_KC"), DateTime.MinValue); obj.NGAY_KC = temp; obj.CP_DK_621 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_621"), 0); obj.CP_DK_622 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_622"), 0); obj.CP_DK_623 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_623"), 0); obj.CP_DK_627 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_DK_627"), 0); obj.DO_DANG_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "DO_DANG_DK"), 0); obj.DOANH_THU_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "DOANH_THU_DK"), 0); obj.THUE_VAT_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "THUE_VAT_DK"), 0); obj.DS_HD_DK = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DS_HD_DK"), ""); obj.DS_HD_TK = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DS_HD_TK"), ""); obj.TONG_CP = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "TONG_CP"), 0); obj.CP_CK_621 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_621"), 0); obj.CP_CK_622 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_622"), 0); obj.CP_CK_623 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_623"), 0); obj.CP_CK_627 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "CP_CK_627"), 0); obj.DO_DANG_CK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "DO_DANG_CK"), 0); obj.LAI_GOP = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LAI_GOP"), 0); obj.TY_LE_LAI = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "TY_LE_LAI"), 0); obj.TY_LE_PB = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "TY_LE_PB"), 0); obj.GIA_VON_DK = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "GIA_VON_DK"), 0); obj.TK_DO_DANG = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "TK_DO_DANG"), ""); obj.TK_GIA_VON = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "TK_GIA_VON"), ""); obj.LK_CPDK_621 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_621"), 0); obj.LK_CPDK_622 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_622"), 0); obj.LK_CPDK_623 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_623"), 0); obj.LK_CPDK_627 = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_627"), 0); obj.LK_CPDK_TONG = Utils.CDblDef(gridView1.GetRowCellValue(e.RowHandle, "LK_CPDK_TONG"), 0); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); _KTDMCongTrinhRepo.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) { _KTDMCongTrinhRepo = new KTDMCongTrinhRepo(); KT_DMCongTrinh obj = new KT_DMCongTrinh(); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.HOAN_THANH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HOAN_THANH"), 0); 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.NOI_DUNG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NOI_DUNG"), ""); obj.GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_VND"), 0); obj.GT_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_USD"), 0); obj.GT_NT_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_NT_VND"), 0); obj.GT_NT_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_NT_VND"), 0); obj.SO_NGAY_LAM = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_NGAY_LAM"), 0); temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_NT"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_NT"), DateTime.MinValue); obj.NGAY_NT = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_KC"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_KC"), DateTime.MinValue); obj.NGAY_KC = temp; obj.CP_DK_621 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_DK_621"), 0); obj.CP_DK_622 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_DK_622"), 0); obj.CP_DK_623 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_DK_623"), 0); obj.CP_DK_627 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_DK_627"), 0); obj.DO_DANG_DK = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DO_DANG_DK"), 0); obj.DOANH_THU_DK = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DOANH_THU_DK"), 0); obj.THUE_VAT_DK = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "THUE_VAT_DK"), 0); obj.DS_HD_DK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DS_HD_DK"), ""); obj.DS_HD_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DS_HD_TK"), ""); obj.TONG_CP = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TONG_CP"), 0); obj.CP_CK_621 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_CK_621"), 0); obj.CP_CK_622 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_CK_622"), 0); obj.CP_CK_623 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_CK_623"), 0); obj.CP_CK_627 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CP_CK_627"), 0); obj.DO_DANG_CK = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DO_DANG_CK"), 0); obj.LAI_GOP = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LAI_GOP"), 0); obj.TY_LE_LAI = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TY_LE_LAI"), 0); obj.TY_LE_PB = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TY_LE_PB"), 0); obj.GIA_VON_DK = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GIA_VON_DK"), 0); obj.TK_DO_DANG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_DO_DANG"), ""); obj.TK_GIA_VON = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_GIA_VON"), ""); obj.LK_CPDK_621 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LK_CPDK_621"), 0); obj.LK_CPDK_622 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LK_CPDK_622"), 0); obj.LK_CPDK_623 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LK_CPDK_623"), 0); obj.LK_CPDK_627 = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LK_CPDK_627"), 0); obj.LK_CPDK_TONG = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LK_CPDK_TONG"), 0); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); _KTDMCongTrinhRepo.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_DMCongTrinh(KT_DMCongTrinh instance);
partial void DeleteKT_DMCongTrinh(KT_DMCongTrinh instance);
partial void InsertKT_DMCongTrinh(KT_DMCongTrinh instance);