private void Save_Data(bool msg) { try { _KTDMCPChoPBRepo = new KTDMCPChoPBRepo(); int i = 0; foreach (int pos in _listUpdate) { int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0); KT_DMCPChoPB obj = _KTDMCPChoPBRepo.GetById(id); if (obj != null) { obj.MA_TS = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_TS"), ""); obj.TEN_TS = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_TS"), ""); obj.CO_KH = Utils.CStrDef(gridView1.GetRowCellValue(pos, "CO_KH"), ""); obj.TK_CP = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_CP"), ""); obj.TK_HM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_HM"), ""); obj.DT_SUDUNG = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DT_SUDUNG"), ""); obj.MA_DTPN_NO = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_DTPN_NO"), ""); obj.MA_DTPN_CO = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_DTPN_CO"), ""); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_CT"), ""); obj.NGUYEN_GIA = Utils.CDblDef(gridView1.GetRowCellValue(pos, "NGUYEN_GIA"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_MUA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_MUA"), DateTime.MinValue); obj.NGAY_MUA = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_BAN"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_BAN"), DateTime.MinValue); obj.NGAY_BAN = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_TRICH_KH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_TRICH_KH"), DateTime.MinValue); obj.NGAY_TRICH_KH = temp; obj.THOI_GIAN_KH = Utils.CDblDef(gridView1.GetRowCellValue(pos, "THOI_GIAN_KH"), 0); obj.KH_1_THANG = Utils.CDblDef(gridView1.GetRowCellValue(pos, "KH_1_THANG"), 0); obj.LK_KH_DAUNAM = Utils.CDblDef(gridView1.GetRowCellValue(pos, "LK_KH_DAUNAM"), 0); obj.GT_CL_DAUNAM = Utils.CDblDef(gridView1.GetRowCellValue(pos, "GT_CL_DAUNAM"), 0); obj.MA_YTCP_NO = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_YTCP_NO"), ""); obj.DVT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DVT"), ""); obj.SO_LUONG = Utils.CDblDef(gridView1.GetRowCellValue(pos, "SO_LUONG"), 0); obj.TK_TS = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_TS"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(pos, "TRANG_THAI"), 0); _KTDMCPChoPBRepo.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 Load_Data() { try { _KTDMCPChoPBRepo = new KTDMCPChoPBRepo(); gridData.DataSource = _KTDMCPChoPBRepo.GetAll(); //_db = new dbVstoreAppDataContext(Const.builder.ConnectionString); //gridData.DataSource = null; //gridData.DataSource = _db.KT_DMHHs; //gridData.RefreshDataSource(); //gridView1.RefreshData(); } catch (Exception) { } }
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; //validation //GridColumn thangCol = view.Columns["THANG"]; GridColumn ma_tsCol = view.Columns["MA_TS"]; //string thang = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, thangCol), ""); string ma_ts = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tsCol), ""); if (ma_ts.Trim().Length == 0) { e.Valid = false; //if (thang.Trim().Length == 0) // view.SetColumnError(thangCol, "Tháng không được rổng"); if (ma_ts.Trim().Length == 0) view.SetColumnError(ma_tsCol, "Mã tài sản không được rổng"); return; } _KTDMCPChoPBRepo = new KTDMCPChoPBRepo(); //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_DMCPChoPB obj = new KT_DMCPChoPB(); obj.MA_TS = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TS"), ""); obj.TEN_TS = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TS"), ""); obj.CO_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CO_KH"), ""); obj.TK_CP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_CP"), ""); obj.TK_HM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_HM"), ""); obj.DT_SUDUNG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DT_SUDUNG"), ""); obj.MA_DTPN_NO = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN_NO"), ""); obj.MA_DTPN_CO = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN_CO"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.NGUYEN_GIA = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NGUYEN_GIA"), 0); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_MUA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_MUA"), DateTime.MinValue); obj.NGAY_MUA = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_BAN"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_BAN"), DateTime.MinValue); obj.NGAY_BAN = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_TRICH_KH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_TRICH_KH"), DateTime.MinValue); obj.NGAY_TRICH_KH = temp; obj.THOI_GIAN_KH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "THOI_GIAN_KH"), 0); obj.KH_1_THANG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "KH_1_THANG"), 0); obj.LK_KH_DAUNAM = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LK_KH_DAUNAM"), 0); obj.GT_CL_DAUNAM = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_CL_DAUNAM"), 0); obj.MA_YTCP_NO = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_YTCP_NO"), ""); obj.DVT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DVT"), ""); obj.SO_LUONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "SO_LUONG"), 0); obj.TK_TS = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_TS"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTDMCPChoPBRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_DMCPChoPB obj = _KTDMCPChoPBRepo.GetById(id); if (obj != null) { obj.MA_TS = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TS"), ""); obj.TEN_TS = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TS"), ""); obj.CO_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CO_KH"), ""); obj.TK_CP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_CP"), ""); obj.TK_HM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_HM"), ""); obj.DT_SUDUNG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DT_SUDUNG"), ""); obj.MA_DTPN_NO = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN_NO"), ""); obj.MA_DTPN_CO = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN_CO"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.NGUYEN_GIA = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NGUYEN_GIA"), 0); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_MUA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_MUA"), DateTime.MinValue); obj.NGAY_MUA = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_BAN"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_BAN"), DateTime.MinValue); obj.NGAY_BAN = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_TRICH_KH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_TRICH_KH"), DateTime.MinValue); obj.NGAY_TRICH_KH = temp; obj.THOI_GIAN_KH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "THOI_GIAN_KH"), 0); obj.KH_1_THANG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "KH_1_THANG"), 0); obj.LK_KH_DAUNAM = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LK_KH_DAUNAM"), 0); obj.GT_CL_DAUNAM = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_CL_DAUNAM"), 0); obj.MA_YTCP_NO = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_YTCP_NO"), ""); obj.DVT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DVT"), ""); obj.SO_LUONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "SO_LUONG"), 0); obj.TK_TS = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_TS"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTDMCPChoPBRepo.Update(obj); } } Load_Data(); } catch (Exception ex) { e.Valid = false; MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Remove_Data() { try { //if (_listUpdate.Count > 0) //{ // MessageBox.Show("Hãy thực hiện lưu trước khi xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} Save_Data(false); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); _KTDMCPChoPBRepo = new KTDMCPChoPBRepo(); _KTDMCPChoPBRepo.Remove(id); //MessageBox.Show("Xóa dòng ID:" + Id + " thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Load_Data(); } catch (Exception ex) { 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) { _KTDMCPChoPBRepo = new KTDMCPChoPBRepo(); KT_DMCPChoPB obj = new KT_DMCPChoPB(); obj.MA_TS = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TS"), ""); obj.TEN_TS = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_TS"), ""); obj.CO_KH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CO_KH"), ""); obj.TK_CP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_CP"), ""); obj.TK_HM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_HM"), ""); obj.DT_SUDUNG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DT_SUDUNG"), ""); obj.MA_DTPN_NO = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DTPN_NO"), ""); obj.MA_DTPN_CO = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DTPN_CO"), ""); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), ""); obj.NGUYEN_GIA = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGUYEN_GIA"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_MUA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_MUA"), DateTime.MinValue); obj.NGAY_MUA = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_BAN"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_BAN"), DateTime.MinValue); obj.NGAY_BAN = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_TRICH_KH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_TRICH_KH"), DateTime.MinValue); obj.NGAY_TRICH_KH = temp; obj.THOI_GIAN_KH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "THOI_GIAN_KH"), 0); obj.KH_1_THANG = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "KH_1_THANG"), 0); obj.LK_KH_DAUNAM = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LK_KH_DAUNAM"), 0); obj.GT_CL_DAUNAM = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_CL_DAUNAM"), 0); obj.MA_YTCP_NO = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_YTCP_NO"), ""); obj.DVT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DVT"), ""); obj.SO_LUONG = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_LUONG"), 0); obj.TK_TS = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_TS"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); _KTDMCPChoPBRepo.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); } }
private void Save_Tick() { try { _KTDMCPChoPBRepo = new KTDMCPChoPBRepo(); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0); KT_DMCPChoPB obj = _KTDMCPChoPBRepo.GetById(id); if (obj != null) { obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T"; _KTDMCPChoPBRepo.Update(obj); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }