private void Save_Data(bool msg) { try { _KTDMHHRepo = new KTDMHHRepo(); int i = 0; foreach (int pos in _listUpdate) { int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0); KT_DMHH obj = _KTDMHHRepo.GetById(id); if (obj != null) { obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_TK"), ""); obj.MA_DM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_DM"), ""); obj.TEN_DM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_DM"), ""); obj.MA_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_NHOM"), ""); obj.TEN_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_NHOM"), ""); obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DON_VI"), ""); obj.TON_DK_SL = Utils.CDblDef(gridView1.GetRowCellValue(pos, "TON_DK_SL"), 0); obj.TON_DK_GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(pos, "TON_DK_GT_VND"), 0); obj.NHAP_SL = Utils.CDblDef(gridView1.GetRowCellValue(pos, "NHAP_SL"), 0); obj.NHAP_GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(pos, "NHAP_GT_VND"), 0); obj.XUAT_SL = Utils.CDblDef(gridView1.GetRowCellValue(pos, "XUAT_SL"), 0); obj.XUAT_GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(pos, "XUAT_GT_VND"), 0); obj.TON_CK_SL = Utils.CDblDef(gridView1.GetRowCellValue(pos, "TON_CK_SL"), 0); obj.TON_CK_GT_VND = Utils.CDblDef(gridView1.GetRowCellValue(pos, "TON_CK_GT_VND"), 0); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), ""); obj.TK_DT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_DT"), ""); obj.TK_GV = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_GV"), ""); obj.TK_CK = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_CK"), ""); obj.TK_TRALAI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_TRALAI"), ""); _KTDMHHRepo.Update(obj); i++; } } _listUpdate = new List<int>(); //if (i > 0 && msg) //{ // MessageBox.Show("Lưu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); //} } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cboVTHHCo_KeyDown(object sender, KeyEventArgs e) { _KTDMHHRepo = new KTDMHHRepo(); var item = _KTDMHHRepo.GetById(Utils.CIntDef(cboVTHHCo.SelectedValue, 0)); if (item != null) txtVTHHCo.Text = item.TEN_DM; }
private void Save_Tick() { try { _KTDMHHRepo = new KTDMHHRepo(); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0); KT_DMHH obj = _KTDMHHRepo.GetById(id); if (obj != null) { obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T"; _KTDMHHRepo.Update(obj); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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_dmCol = view.Columns["MA_DM"]; string ma_tk = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tkCol), ""); string ma_dm = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_dmCol), ""); if (ma_tk.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_dm.Trim().Length == 0) view.SetColumnError(ma_dmCol, "Mã danh mục không được rổng"); return; } _KTDMHHRepo = new KTDMHHRepo(); //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_DMHH obj = new KT_DMHH(); obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), ""); obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.TON_DK_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_DK_SL"), 0); obj.TON_DK_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_DK_GT_VND"), 0); obj.NHAP_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NHAP_SL"), 0); obj.NHAP_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NHAP_GT_VND"), 0); obj.XUAT_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "XUAT_SL"), 0); obj.XUAT_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "XUAT_GT_VND"), 0); obj.TON_CK_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_CK_SL"), 0); obj.TON_CK_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_CK_GT_VND"), 0); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TK_DT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DT"), ""); obj.TK_GV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_GV"), ""); obj.TK_CK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_CK"), ""); obj.TK_TRALAI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_TRALAI"), ""); _KTDMHHRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_DMHH obj = _KTDMHHRepo.GetById(id); if (obj != null) { obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), ""); obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.TON_DK_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_DK_SL"), 0); obj.TON_DK_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_DK_GT_VND"), 0); obj.NHAP_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NHAP_SL"), 0); obj.NHAP_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NHAP_GT_VND"), 0); obj.XUAT_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "XUAT_SL"), 0); obj.XUAT_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "XUAT_GT_VND"), 0); obj.TON_CK_SL = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_CK_SL"), 0); obj.TON_CK_GT_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TON_CK_GT_VND"), 0); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TK_DT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DT"), ""); obj.TK_GV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_GV"), ""); obj.TK_CK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_CK"), ""); obj.TK_TRALAI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_TRALAI"), ""); _KTDMHHRepo.Update(obj); } } Load_Data(); } catch (Exception ex) { e.Valid = false; MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }