public static int SaveOptions(this options options_to_save, SccompDbf selected_comp) { try { using (LocalDbEntities db = DBX.DataSet(selected_comp)) { options option = db.options.Where(o => o.key == options_to_save.key).FirstOrDefault(); if (option != null) // update { option.value_datetime = options_to_save.value_datetime; option.value_num = options_to_save.value_num; option.value_str = options_to_save.value_str; return(db.SaveChanges()); } else // add new { db.options.Add(options_to_save); return(db.SaveChanges()); } } } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); return(0); } }
public ActionResult Create(Catalog catalog) { if (ModelState.IsValid) { db.Catalog.Add(catalog); db.SaveChanges(); return(RedirectToAction(@"Edit/" + catalog.Code)); } return(View(catalog)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Product.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
private void GetBojData() { this.isinfo = DbfTable.GetIsinfo(this.main_form.selected_comp); using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { this.boj5_header = db.boj5_header.FirstOrDefault(); if (this.boj5_header == null) { db.boj5_header.Add(new boj5_header { accSource = ACC_SOURCE.B.ToString(), foreignShareholder = 0, headerStatus = "A", meetingNo = "", meetingType = MEETING_TYPE.B.ToString(), parValue = 0, sourceDate = null, thaiShareholder = 0, totalCapital = 0, totalForeignShare = 0, totalShare = 0, totalThaiShare = 0, userId = "", yearEnd = null }); db.SaveChanges(); this.boj5_header = db.boj5_header.First(); } this.boj5_detail = db.boj5_detail.Include("boj5_person").OrderBy(d => d.itemNo).ToList(); } }
public static options GetOptions(this OPTIONS options_key, SccompDbf selected_comp) { try { using (LocalDbEntities db = DBX.DataSet(selected_comp)) { options opt = db.options.Where(o => o.key == options_key.ToString()).FirstOrDefault(); if (opt != null) { return(opt); } else { options o = new options { key = options_key.ToString() }; db.options.Add(o); db.SaveChanges(); return(o); } } } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); return(null); } }
public Prodotto CreateProdotto(Prodotto prodotto) { Prodotto existingProdotto = GetProdotto(prodotto.Id); if (existingProdotto == null) { context.ProdottoSet.Add(prodotto); context.SaveChanges(); } else { throw new DbUpdateException(); } return prodotto; }
private void btnDown_Click(object sender, EventArgs e) { if (this.dgvPerson.CurrentCell.RowIndex == this.dgvPerson.Rows.Count - 1 || this.dgvPerson.Rows.Count <= 1) { return; } using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { if (db.boj5_person.Count() <= 1) { return; } var curr_person = db.boj5_person.Find(((boj5_person)(this.dgvPerson).Rows[this.dgvPerson.CurrentCell.RowIndex].Cells[this.col_boj5_person.Name].Value).id); if (curr_person == null) { XMessageBox.Show("ค้นหารายการที่ต้องการแก้ไขไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop); return; } var next_person = db.boj5_person.Where(p => p.itemSeq > curr_person.itemSeq).OrderBy(p => p.itemSeq).FirstOrDefault(); if (next_person == null) { XMessageBox.Show("รายการนี้อยู่ในลำดับสุดท้ายแล้ว ไม่สามารถเลื่อนลงได้อีก", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop); return; } long?curr_seq = curr_person.itemSeq; long?next_seq = next_person.itemSeq; curr_person.itemSeq = next_seq; next_person.itemSeq = curr_seq; db.SaveChanges(); long?seq = 0; db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++seq); db.SaveChanges(); this.LoadPersonToDatagrid(); var selected_row = this.dgvPerson.Rows.Cast <DataGridViewRow>().Where(r => ((boj5_person)r.Cells[this.col_boj5_person.Name].Value).id == curr_person.id).FirstOrDefault(); if (selected_row != null) { selected_row.Cells[selected_row.DataGridView.FirstDisplayedScrollingColumnIndex].Selected = true; } } }
public void AddCatalog(Catalog c) { using (LocalDbEntities context = new LocalDbEntities()) { context.Catalog.Add(c); context.SaveChanges(); } }
private void btnDeleteItem_Click(object sender, EventArgs e) { if (this.dgv.CurrentCell == null) { return; } this.dgv.Rows[this.dgv.CurrentCell.RowIndex].DrawDeletingRowOverlay(); if (XMessageBox.Show("ลบรายการที่เลือก, ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, XMessageBoxIcon.Question) != DialogResult.OK) { this.dgv.Rows[this.dgv.CurrentCell.RowIndex].ClearDeletingRowOverlay(); return; } var deleting_id = ((boj5_detail)this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Cells[this.col_boj5_detail.Name].Value).id; try { using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { var deleting_data = db.boj5_detail.Find(deleting_id); if (deleting_data != null) { db.boj5_detail.Remove(deleting_data); db.SaveChanges(); long?seq = 0; db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++seq); db.SaveChanges(); this.GetBojData(); this.FillForm(this.boj5_header, this.boj5_detail); } else { XMessageBox.Show("ค้นหารายการที่ต้องการลบไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop); } } } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); } }
public void UpdateCatalog(Catalog c) { using (LocalDbEntities context = new LocalDbEntities()) { var Catalog = context.Catalog.Find(c.Id); Catalog.Description = c.Description; Catalog.Code = c.Code; context.Catalog.Attach(Catalog); context.Entry(Catalog).State = System.Data.EntityState.Modified; context.SaveChanges(); } }
public void DeleteCatalog(int IdCatalog) { using (LocalDbEntities context = new LocalDbEntities()) { var Catalog = context.Catalog.Find(IdCatalog); var Cp = context.CatalogProduct.Where(w => w.IdCatalog == IdCatalog); foreach (var item in Cp) { context.CatalogProduct.Remove(item); } context.Catalog.Remove(Catalog); context.SaveChanges(); } }
public void DeleteProduct(int IdProduct) { using (LocalDbEntities context = new LocalDbEntities()) { List <CatalogProduct> cPList = new List <CatalogProduct>(); var Product = context.Product.Find(IdProduct); var Cp = context.CatalogProduct.Where(w => w.IdProduct == IdProduct); foreach (var item in Cp) { context.CatalogProduct.Remove(item); } context.Product.Remove(Product); context.SaveChanges(); } }
public void AddProduct(Product p) { using (LocalDbEntities context = new LocalDbEntities()) { try { context.Product.Add(p); context.SaveChanges(); } catch (Exception ex) { throw ex; } } }
public void UpdateProduct(Product p) { using (LocalDbEntities context = new LocalDbEntities()) { var Product = context.Product.Find(p.Id); Product.Code = p.Code; Product.Description = p.Description; //foreach (var item in p.CatalogProduct) //{ // var Cp = context.CatalogProduct.Where(w => w.IdProduct == p.Id && w.IdCatalog == item.IdCatalog); // foreach (var sItem in Cp) // { // context.CatalogProduct.Remove(sItem); // } //} //Product.CatalogProduct = p.CatalogProduct; context.Entry <Product>(Product); context.SaveChanges(); } }
public void AddAssociation(List <CatalogProduct> c) { using (LocalDbEntities context = new LocalDbEntities()) { foreach (var item in c) { var Cp = context.CatalogProduct.Where(w => w.IdCatalog == item.IdCatalog); foreach (var sItem in Cp) { context.CatalogProduct.Remove(sItem); } } foreach (var item in c) { context.CatalogProduct.Add(item); } context.SaveChanges(); } }
public Listino CreateListino(Listino listino) { Listino existingListino = GetListino(listino.Id); if (existingListino == null) { context.ListinoSet.Add(listino); context.SaveChanges(); } else { throw new DbUpdateException(); } return(listino); }
private void btnSave_Click(object sender, EventArgs e) { if (this.tmp_boj5_header == null) { return; } try { using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { var header_to_update = db.boj5_header.Find(1); header_to_update.accSource = this.tmp_boj5_header.accSource; header_to_update.foreignShareholder = this.tmp_boj5_header.foreignShareholder; header_to_update.headerStatus = this.tmp_boj5_header.headerStatus; header_to_update.meetingNo = this.tmp_boj5_header.meetingNo; header_to_update.meetingType = this.tmp_boj5_header.meetingType; header_to_update.parValue = this.tmp_boj5_header.parValue; header_to_update.sourceDate = this.tmp_boj5_header.sourceDate; header_to_update.thaiShareholder = this.tmp_boj5_header.thaiShareholder; header_to_update.totalCapital = this.tmp_boj5_header.totalCapital; header_to_update.totalForeignShare = this.tmp_boj5_header.totalForeignShare; header_to_update.totalShare = this.tmp_boj5_header.totalShare; header_to_update.totalThaiShare = this.tmp_boj5_header.totalThaiShare; header_to_update.userId = this.tmp_boj5_header.userId; header_to_update.yearEnd = this.tmp_boj5_header.yearEnd; db.SaveChanges(); } this.tmp_boj5_header = null; this.ResetFormState(FORM_MODE.READ); this.GetBojData(); this.FillForm(this.boj5_header, this.boj5_detail); } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); } }
public int SaveModifed(Product product) { _context.Entry(product).State = EntityState.Modified; return(_context.SaveChanges()); }
private void btnOK_Click(object sender, EventArgs e) { if (this.boj5_person.shType.Trim().Length == 0) { XMessageBox.Show("กรุณาระบุประเภทของผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cShType.Focus(); return; } if (this.boj5_person.holderName.Trim().Length == 0) { XMessageBox.Show("กรุณาระบุชื่อผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cHolderName.Focus(); return; } if (this.boj5_person.nationality.Trim().Length == 0) { XMessageBox.Show("กรุณาระบุสัญชาติของผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cNationality.Focus(); return; } if (this.boj5_person.shId.Trim().Length == 0) { XMessageBox.Show("กรุณาระบุเลขนิติบุคคล/บัตรประชาชน", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cShId.Focus(); return; } try { using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { if (this.boj5_person.id > 0) // edit { var data_to_update = db.boj5_person.Find(this.boj5_person.id); if (data_to_update == null) { db.boj5_person.Add(this.boj5_person); } else { data_to_update.addrForeign = this.boj5_person.addrForeign; data_to_update.addrFull = this.boj5_person.addrFull; data_to_update.addrNo = this.boj5_person.addrNo; data_to_update.amphur = this.boj5_person.amphur; data_to_update.holderName = this.boj5_person.holderName; data_to_update.itemSeq = this.boj5_person.itemSeq; data_to_update.moo = this.boj5_person.moo; data_to_update.nationality = this.boj5_person.nationality; data_to_update.occupation = this.boj5_person.occupation; data_to_update.province = this.boj5_person.province; data_to_update.road = this.boj5_person.road; data_to_update.shId = this.boj5_person.shId; data_to_update.shType = this.boj5_person.shType; data_to_update.soi = this.boj5_person.soi; data_to_update.surname = this.boj5_person.surname; data_to_update.title = this.boj5_person.title; data_to_update.tumbol = this.boj5_person.tumbol; } } else // add { db.boj5_person.Add(this.boj5_person); } db.SaveChanges(); long?seq = 0; db.boj5_person.ToList().ForEach(p => p.itemSeq = ++seq); db.SaveChanges(); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); } }
public bool RemoveIngredientById(Guid ingredientId) { //get the item that will be removed var temp = localDb.Ingredients.Where(i => i.ID_Ingredients == ingredientId).Select(j => j).First(); if (temp != null) { localDb.Ingredients.Remove(temp); } return(localDb.SaveChanges() > 0); }
private void btnOK_Click(object sender, EventArgs e) { if (this.boj5_detail.shareDocId.Trim().Length == 0) { XMessageBox.Show("กรุณาระบุหมายเลขใบหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cShareDocId.Focus(); return; } if (this.boj5_detail.boj5_person_id == -1) { XMessageBox.Show("กรุณาระบุผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); //this.cHolderId.Focus(); this.dgvPerson.Focus(); return; } if (this.boj5_detail.shareNumber == 0) { XMessageBox.Show("กรุณาระบุจำนวนหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cShareNumber.Focus(); return; } if (!this.boj5_detail.shareDocDate.HasValue) { XMessageBox.Show("กรุณาระบุวันที่ออกเลขที่ใบหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cShareDocDate.Focus(); return; } if (!this.boj5_detail.shareRegExist.HasValue) { XMessageBox.Show("กรุณาระบุวันที่ลงทะเบียนผู้ถือหุ้น", "", MessageBoxButtons.OK, XMessageBoxIcon.Warning); this.cShareRegExist.Focus(); return; } try { using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { if (this.boj5_detail.id > 0) // edit { var data_to_update = db.boj5_detail.Find(this.boj5_detail.id); if (data_to_update == null) { db.boj5_detail.Add(this.boj5_detail); } else { data_to_update.asPaidAmount = this.boj5_detail.asPaidAmount; data_to_update.boj5_person_id = this.boj5_detail.boj5_person_id; data_to_update.paidAmount = this.boj5_detail.paidAmount; data_to_update.shareDocDate = this.boj5_detail.shareDocDate; data_to_update.shareDocId = this.boj5_detail.shareDocId; data_to_update.shareNumber = this.boj5_detail.shareNumber; data_to_update.shareRegExist = this.boj5_detail.shareRegExist; data_to_update.shareRegOmit = this.boj5_detail.shareRegOmit; data_to_update.shareType = this.boj5_detail.shareType; } } else // add { db.boj5_detail.Add(this.boj5_detail); } db.SaveChanges(); long?seq = 0; db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++seq); db.SaveChanges(); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); } }
private void btnDeleteHolder_Click(object sender, EventArgs e) { if (this.dgvPerson.CurrentCell == null) { return; } this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].DrawDeletingRowOverlay(); try { using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp)) { var deleting_id = ((boj5_person)this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].Cells[this.col_boj5_person.Name].Value).id; boj5_person person_to_delete; if (db.boj5_detail.Where(d => d.boj5_person_id == deleting_id).Count() > 0) { if (XMessageBox.Show("มีรายการใบหุ้นของผู้ถือหุ้นรายนี้อยู่\n - เลือก \"ตกลง\" เพื่อให้ลบทั้งรายการใบหุ้น และ ชื่อผู้ถือหุ้นรายนี้\n - เลือก \"ยกเลิก\" เพื่อยกเลิกการทำงานนี้", "", MessageBoxButtons.OKCancel, XMessageBoxIcon.Question) == DialogResult.OK) { person_to_delete = db.boj5_person.Find(deleting_id); if (person_to_delete != null) { db.boj5_detail.RemoveRange(db.boj5_detail.Where(d => d.boj5_person_id == deleting_id)); db.boj5_person.Remove(db.boj5_person.Find(deleting_id)); db.SaveChanges(); long?seq = 0; db.boj5_person.ToList().ForEach(p => p.itemSeq = ++seq); db.SaveChanges(); this.LoadPersonToDatagrid(); } else { XMessageBox.Show("ค้นหารายการที่ต้องการลบไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop); this.LoadPersonToDatagrid(); } } else { this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].ClearDeletingRowOverlay(); } return; } else { if (XMessageBox.Show("ลบรายการที่เลือก, ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, XMessageBoxIcon.Question) != DialogResult.OK) { this.dgvPerson.Rows[this.dgvPerson.CurrentCell.RowIndex].ClearDeletingRowOverlay(); } person_to_delete = db.boj5_person.Find(deleting_id); if (person_to_delete != null) { db.boj5_person.Remove(person_to_delete); db.SaveChanges(); long?seq = 0; db.boj5_person.ToList().ForEach(p => p.itemSeq = ++seq); db.SaveChanges(); this.LoadPersonToDatagrid(); } else { XMessageBox.Show("ค้นหารายการที่ต้องการลบไม่พบ", "", MessageBoxButtons.OK, XMessageBoxIcon.Stop); this.LoadPersonToDatagrid(); } } long?itemno = 0; db.boj5_detail.Include("boj5_person").OrderBy(d => d.boj5_person.itemSeq).ToList().ForEach(d => d.itemNo = ++itemno); db.SaveChanges(); } } catch (Exception ex) { XMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, XMessageBoxIcon.Error); } }
public void Save() { _context.SaveChanges(); }
public int SaveModifed(Catalog catalog) { _context.Entry(catalog).State = EntityState.Modified; return(_context.SaveChanges()); }