private void Load_Data() { try { _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); gridData.DataSource = _KTCNLTVTheoCTRepo.GetAll(); //_db = new dbVstoreAppDataContext(Const.builder.ConnectionString); //gridData.DataSource = null; //gridData.DataSource = _db.KT_DMHHs; //gridData.RefreshDataSource(); //gridView1.RefreshData(); } catch (Exception) { } }
private void Save_Data(bool msg) { try { _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); int i = 0; foreach (int pos in _listUpdate) { int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0); KT_CNLTVTheoCT obj = _KTCNLTVTheoCTRepo.GetById(id); if (obj != null) { obj.THANG = Utils.CStrDef(gridView1.GetRowCellValue(pos, "THANG"), ""); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(gridView1.GetRowCellValue(pos, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(gridView1.GetRowCellValue(pos, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(gridView1.GetRowCellValue(pos, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(gridView1.GetRowCellValue(pos, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(gridView1.GetRowCellValue(pos, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(pos, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.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 Save_Tick() { try { _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0); KT_CNLTVTheoCT obj = _KTCNLTVTheoCTRepo.GetById(id); if (obj != null) { obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T"; _KTCNLTVTheoCTRepo.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 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; //} _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); //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_CNLTVTheoCT obj = new KT_CNLTVTheoCT(); obj.THANG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THANG"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_CNLTVTheoCT obj = _KTCNLTVTheoCTRepo.GetById(id); if (obj != null) { obj.THANG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "THANG"), ""); obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.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); _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); _KTCNLTVTheoCTRepo.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) { _KTCNLTVTheoCTRepo = new KTCNLTVTheoCTRepo(); KT_CNLTVTheoCT obj = new KT_CNLTVTheoCT(); obj.THANG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "THANG"), ""); obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.MA_NV = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_NV"), ""); obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), ""); obj.CONG_VIEC = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CONG_VIEC"), ""); obj.LUONG_CB = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LUONG_CB"), 0); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_VAO"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_VAO"), DateTime.MinValue); obj.NGAY_VAO = temp; temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_RA"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_RA"), DateTime.MinValue); obj.NGAY_RA = temp; obj.NGAY_CONG = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_CONG"), 0); obj.LUONG_TN = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LUONG_TN"), 0); obj.KY_NHAN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "KY_NHAN"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); _KTCNLTVTheoCTRepo.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); } }