private void Get_Data(KB_LCTT_GT obj, int position) { try { obj.CHI_TIEU = Utils.CStrDef(gridView1.GetRowCellValue(position, "CHI_TIEU"), ""); obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(position, "MA_TK"), ""); obj.TEN_CT1 = Utils.CStrDef(gridView1.GetRowCellValue(position, "TEN_CT1"), ""); obj.TEN_CT2 = Utils.CStrDef(gridView1.GetRowCellValue(position, "TEN_CT2"), ""); obj.DK_CK = Utils.CStrDef(gridView1.GetRowCellValue(position, "DK_CK"), ""); obj.CONG_THUC = Utils.CStrDef(gridView1.GetRowCellValue(position, "CONG_THUC"), ""); obj.TEN_BANG = Utils.CStrDef(gridView1.GetRowCellValue(position, "TEN_BANG"), ""); obj.MA_SO = Utils.CStrDef(gridView1.GetRowCellValue(position, "MA_SO"), ""); obj.SO_DU = Utils.CStrDef(gridView1.GetRowCellValue(position, "SO_DU"), ""); obj.TK_NO = Utils.CStrDef(gridView1.GetRowCellValue(position, "TK_NO"), ""); obj.TK_CO = Utils.CStrDef(gridView1.GetRowCellValue(position, "TK_CO"), ""); obj.MA_DTPN_CO = Utils.CStrDef(gridView1.GetRowCellValue(position, "MA_DTPN_CO"), ""); obj.MA_DTPN_NO = Utils.CStrDef(gridView1.GetRowCellValue(position, "MA_DTPN_NO"), ""); obj.MA_YTCP_CO = Utils.CStrDef(gridView1.GetRowCellValue(position, "MA_YTCP_CO"), ""); obj.MA_YTCP_NO = Utils.CStrDef(gridView1.GetRowCellValue(position, "MA_YTCP_NO"), ""); obj.KIEU_LAY = Utils.CStrDef(gridView1.GetRowCellValue(position, "KIEU_LAY"), ""); obj.TT_KT_VND = Utils.CDblDef(gridView1.GetRowCellValue(position, "TT_KT_VND"), 0); obj.TT_KN_VND = Utils.CDblDef(gridView1.GetRowCellValue(position, "TT_KN_VND"), 0); obj.TT_KT_USD = Utils.CDblDef(gridView1.GetRowCellValue(position, "TT_KT_USD"), 0); obj.TT_KN_USD = Utils.CDblDef(gridView1.GetRowCellValue(position, "TT_KN_USD"), 0); obj.NHAN_VOI = Utils.CDblDef(gridView1.GetRowCellValue(position, "NHAN_VOI"), 0); obj.THUYET_MINH = Utils.CStrDef(gridView1.GetRowCellValue(position, "THUYET_MINH"), ""); obj.CO_IN = Utils.CStrDef(gridView1.GetRowCellValue(position, "CO_IN"), ""); obj.TT_LK_VND = Utils.CDblDef(gridView1.GetRowCellValue(position, "TT_LK_VND"), 0); obj.TT_LK_USD = Utils.CDblDef(gridView1.GetRowCellValue(position, "TT_LK_USD"), 0); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(position, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(position, "TRANG_THAI"), 0); } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
partial void DeleteKB_LCTT_GT(KB_LCTT_GT instance);
partial void UpdateKB_LCTT_GT(KB_LCTT_GT instance);
partial void InsertKB_LCTT_GT(KB_LCTT_GT instance);
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; _KBLCTT_GTRepo = new KBLCTT_GTRepo(); //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 KB_LCTT_GT obj = new KB_LCTT_GT(); Get_Data(obj, e.RowHandle); _KBLCTT_GTRepo.Create(obj); } //Cũ thì update else { string id = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "CHI_TIEU").ToString(), ""); KB_LCTT_GT obj = _KBLCTT_GTRepo.GetById(id); if (obj != null) { Get_Data(obj, e.RowHandle); _KBLCTT_GTRepo.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) { _KBLCTT_GTRepo = new KBLCTT_GTRepo(); KB_LCTT_GT obj = new KB_LCTT_GT(); Get_Data(obj, gridView1.FocusedRowHandle); _KBLCTT_GTRepo.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); } }