// method to update invoice items public void updateItem(Guid _invoiceID, string _item, double _cost, Guid _itemID) { try { // respective datacontext object InvoiceItemDataContext objItemDC = new InvoiceItemDataContext(); // get row to update var upItem = objItemDC.brdhc_InvoiceItems.Single(i => i.ItemId == _itemID); //updating values upItem.ItemName = _item; upItem.ItemCost = _cost; //updating table objItemDC.SubmitChanges(); //updating total InvoicesDataContext objInvDC = new InvoicesDataContext(); //get invoice row var inv = objInvDC.brdhc_Invoices.Single(i => i.InvoiceID == _invoiceID); //calculating total double total = getTotal(_invoiceID); //update total inv.TotalAmt = total; objInvDC.SubmitChanges(); } catch (Exception e) { clsCommon.saveError(e); } }
// to insert invoice items for the appropriate invoice ID public void insertItem(Guid _invoiceID, string _item, double _itemCost) { InvoiceItemDataContext objItemDC = new InvoiceItemDataContext(); try { brdhc_InvoiceItem objInvItem = new brdhc_InvoiceItem(); objInvItem.InvoiceID = _invoiceID; objInvItem.ItemName = _item; objInvItem.ItemCost = _itemCost; objItemDC.brdhc_InvoiceItems.InsertOnSubmit(objInvItem); objItemDC.SubmitChanges(); } catch (Exception e) { clsCommon.saveError(e); } }
//method to delete invoice public void deleteInvoice(Guid invID) { try { // delete all invoice items with this invID // respective datacontext object InvoiceItemDataContext objItemDC = new InvoiceItemDataContext(); //get rows to delete var delItem = from i in objItemDC.brdhc_InvoiceItems where (i.InvoiceID == invID) select i; // delete from table objItemDC.brdhc_InvoiceItems.DeleteAllOnSubmit(delItem); //commit delete objItemDC.SubmitChanges(); // delete invoice InvoicesDataContext objInvDC = new InvoicesDataContext(); //get row to delete var delInv = from i in objInvDC.brdhc_Invoices where (i.InvoiceID == invID) select i; //delete from table objInvDC.brdhc_Invoices.DeleteAllOnSubmit(delInv); //commit delete objInvDC.SubmitChanges(); } catch (Exception e) { clsCommon.saveError(e); } }
// method to get all invoice items by invoice id public List<brdhc_InvoiceItem> getItemsByInvoiceID(Guid invoiceID) { InvoiceItemDataContext objItemDC = new InvoiceItemDataContext(); var allItems = from x in objItemDC.brdhc_InvoiceItems where x.InvoiceID == invoiceID orderby x.ItemId select x; return allItems.ToList(); }
// method to get all invoice items public IQueryable<brdhc_InvoiceItem> getItems() { InvoiceItemDataContext objItemDC = new InvoiceItemDataContext(); var allItems = from x in objItemDC.brdhc_InvoiceItems orderby x.ItemId select x; return allItems; }
//method to delete invoice item public void deleteItem(Guid _itemID, Guid _invoiceID) { try { // respective datacontext object InvoiceItemDataContext objItemDC = new InvoiceItemDataContext(); //get row to delete var delItem = from i in objItemDC.brdhc_InvoiceItems where (i.ItemId == _itemID) select i; // delete from table objItemDC.brdhc_InvoiceItems.DeleteAllOnSubmit(delItem); //commit delete objItemDC.SubmitChanges(); //updating total InvoicesDataContext objInvDC = new InvoicesDataContext(); //get invoice row var inv = objInvDC.brdhc_Invoices.Single(i => i.InvoiceID == _invoiceID); //calculating total double total = getTotal(_invoiceID); //update total inv.TotalAmt = total; objInvDC.SubmitChanges(); } catch (Exception e) { clsCommon.saveError(e); } }