protected void grdInvoices_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == "RowClick" && e.Item is GridDataItem) { Context.Items["InvoiceId"] = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["InvoiceId"]; Server.Transfer("Invoice.aspx"); } else if (e.CommandName == "Delete" && e.Item.ItemType != GridItemType.GroupFooter) { var financialManager = new FinancialManager(this); try { if (e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["InvoiceId"] != null) financialManager.DeleteInvoice(Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["InvoiceId"]), Company.CompanyId); grdInvoices.DataBind(); } catch (System.Data.SqlClient.SqlException err) { DataManager.Rollback(); if (err.ErrorCode.Equals(Convert.ToInt32("0x80131904", 16))) ShowError(Resources.Exception.DeletingRegisterWithForeignKey); e.Canceled = true; } if (grdInvoices.Items.Count == 0) Response.Redirect("Invoices.aspx"); } }
/// <summary> /// This method cancels a sale and return the products to inventory /// </summary> /// <param name="saleId"></param> /// <param name="matrixId"></param> public void CancelSale(int saleId, int matrixId, Int32 userId) { var inventoryManager = new InventoryManager(this); var receiptManager = new ReceiptManager(this); var financialManager = new FinancialManager(this); var parcelManager = new ParcelsManager(this); Sale sale = GetSale(matrixId, saleId); sale.IsCanceled = true; if (sale.ReceiptId != null) { Receipt receipt = receiptManager.GetReceipt((int)sale.ReceiptId, sale.CompanyId); sale.ReceiptId = null; receiptManager.DeleteReceipt(receipt); receipt.IsCanceled = true; } sale.InvoiceId = null; // // return the products to inventory // foreach (SaleItem saleItem in sale.SaleItems) { if (saleItem.ProductId != null) { Inventory inventory = inventoryManager.GetProductInventory(saleItem.CompanyId, (int)saleItem.ProductId, (int)sale.DepositId); if (inventory != null) inventoryManager.StockDeposit(inventory, null, userId); } } // // Delete the invoice of sale // if (sale.InvoiceId.HasValue) financialManager.DeleteInvoice((int)sale.InvoiceId, sale.CompanyId); DbContext.SubmitChanges(); }