private static void InsertData(Receipt obj, List <Receiptitems> items, string newDB) { DAL dalsession; try { dalsession = new DAL(); dalsession.BeginTransaction(); List <Receiptitems> list_new = new List <Receiptitems>(); if (obj != null) { if (CheckData(obj, newDB) != true) { CReceipt.Insert(obj, dalsession); var vId = DAL.GetIdentity(dalsession); for (int k = 0; k < items.Count; k++) { Receiptitems v = new Receiptitems() { Receipt_id = vId, Receipt_by = items[k].Receipt_by, Invoiced_no = items[k].Invoiced_no, Invoiced_amount = items[k].Invoiced_amount, Receipt_amount = items[k].Receipt_amount }; list_new.Add(v); } CReceiptitems.Insert(list_new, dalsession); dalsession.Commit(); } } } catch (Exception ex) { MessageBox.Show("error : " + ex); } }
private void Save_Event() { if (Validation() != false) { switch (fAction) { case BtnEvent.Open: this.Hide(); Form_NeedToRefresh(); break; case BtnEvent.New: try { var vData = CollectData(); dalsession = new DAL(); dalsession.BeginTransaction(); CReceipt.Insert(vData, dalsession); vId = DAL.GetIdentity(dalsession); var itemsList = Collectitems(vId); CReceiptitems.Insert(itemsList, dalsession); //CReceipt_refered.Refered(itemsList, dalsession); dalsession.Commit(); MessageBox.Show(this.FindForm(), "Record Saved Successfully.", "Save...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Form_NeedToRefresh(); } catch (Exception ex) { if (dalsession != null) { dalsession.Rollback(); } MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Save...", MessageBoxButtons.OK, MessageBoxIcon.Error); SetFocus(); return; } break; case BtnEvent.Edit: try { var vData = CollectData(); dalsession = new DAL(); dalsession.BeginTransaction(); CReceiptitems.Delete(vId, dalsession); CReceipt.Update(vData, dalsession); var itemsList = Collectitems(vId); CReceiptitems.Insert(itemsList, dalsession); //CReceipt_refered.Refered(itemsList, dalsession); dalsession.Commit(); MessageBox.Show(this.FindForm(), "Record Updated Successfully.", "Update...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Form_NeedToRefresh(); } catch (Exception ex) { if (dalsession != null) { dalsession.Rollback(); } MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error); SetFocus(); return; } break; case BtnEvent.Delete: try { dalsession = new DAL(); dalsession.BeginTransaction(); CReceiptitems.Delete(vId, dalsession); CReceipt.Delete(vId, dalsession); //CReceipt_refered.Refered(list, dalsession); dalsession.Commit(); MessageBox.Show(this.FindForm(), "Record Deleted Successfully.", "Delete...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Form_NeedToRefresh(); } catch (Exception ex) { if (dalsession != null) { dalsession.Rollback(); } MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error); SetFocus(); return; } break; case BtnEvent.Print: this.Hide(); Form_NeedToRefresh(); break; } } }