private void Save_Data(bool msg) { try { _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo(); int i = 0; foreach (int pos in _listUpdate) { int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0); KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id); if (obj != null) { obj.MADM_ME = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MADM_ME"), ""); obj.MADM_CON = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MADM_CON"), ""); obj.TENDM_ME = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TENDM_ME"), ""); obj.TENDM_CON = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TENDM_CON"), ""); obj.SL = Utils.CIntDef(gridView1.GetRowCellValue(pos, "SL"), 0); obj.TK_DU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_DU"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), ""); _KTDMCauThanhSPRepo.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 { _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo(); gridData.DataSource = _KTDMCauThanhSPRepo.GetAll(); //_db = new dbVstoreAppDataContext(Const.builder.ConnectionString); //gridData.DataSource = null; //gridData.DataSource = _db.KT_DMCauThanhSPs; //gridData.RefreshDataSource(); //gridView1.RefreshData(); } catch (Exception) { } }
private void Save_Tick() { try { _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo(); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id); if (obj != null) { obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T"; _KTDMCauThanhSPRepo.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 madm_meCol = view.Columns["MADM_ME"]; GridColumn madm_conCol = view.Columns["MADM_CON"]; string madm_me = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, madm_meCol), ""); string madm_con = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, madm_conCol), ""); if (madm_me.Trim().Length == 0 || madm_con.Trim().Length == 0) { e.Valid = false; if (madm_me.Trim().Length == 0) view.SetColumnError(madm_meCol, "Mã danh mục mẹ không được rổng"); if (madm_con.Trim().Length == 0) view.SetColumnError(madm_conCol, "Mã danh mục con không được rổng"); return; } _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo(); //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_DMCauThanhSP obj = new KT_DMCauThanhSP(); obj.MADM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_ME"), ""); obj.MADM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_CON"), ""); obj.TENDM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_ME"), ""); obj.TENDM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_CON"), ""); obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0); obj.TK_DU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DU"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); _KTDMCauThanhSPRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0); KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id); if (obj != null) { obj.MADM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_ME"), ""); obj.MADM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_CON"), ""); obj.TENDM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_ME"), ""); obj.TENDM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_CON"), ""); obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0); obj.TK_DU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DU"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); _KTDMCauThanhSPRepo.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); _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo(); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); _KTDMCauThanhSPRepo.Remove(id); //Id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TK"), 0); //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) { _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo(); KT_DMCauThanhSP obj = new KT_DMCauThanhSP(); obj.MADM_ME = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MADM_ME"), ""); obj.MADM_CON = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MADM_CON"), ""); obj.TENDM_ME = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TENDM_ME"), ""); obj.TENDM_CON = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TENDM_CON"), ""); obj.SL = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SL"), 0); obj.TK_DU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_DU"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); _KTDMCauThanhSPRepo.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); } }