protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { int index = e.RowIndex; long ItemDetailID = Convert.ToInt32(GridView1.Rows[index].Cells[0].Text); if (ItemDetailID < 0) { } else { PCSN.InvoiceSystem.BusinessLogicLayer.Stock stock = new PCSN.InvoiceSystem.BusinessLogicLayer.Stock(); PCSN.InvoiceSystem.BusinessLogicLayer.StockEnterExit StockEnterExit = new PCSN.InvoiceSystem.BusinessLogicLayer.StockEnterExit(); if (ItemDetailID > 0) { dtStockEdit = stock.GetStockDetailByID(ItemDetailID); // Checking if the Quantity is decreased or increased then Entering or Exiting stock item quantity long Quantity = 0; if (dtStockEdit.Rows.Count > 0) { if (Convert.ToInt32(dtStockEdit.Rows[0]["Quantity"].ToString()) > 0) { // Quantity That is going to be deleted is being recorded in Stock Exit Quantity = Convert.ToInt32(dtStockEdit.Rows[0]["Quantity"].ToString()); } StockEnterExit.InsertStockExit(ItemDetailID, Quantity, DateTime.Now.ToShortDateString(), "Item Updated Quantity Decreased/Deleted"); } stock.DeleteStockDetail(ItemDetailID); lblTotalAmount.Text = "0"; } dtStockEdit = stock.GetStockDetailTotalAmountByItemMasterID(Convert.ToInt32(txtItemMasterID.Text)); lblTotalAmount.Text = "0"; if (dtStockEdit.Rows.Count > 0) { lblTotalAmount.Text = dtStockEdit.Rows[0]["TotalAmount"].ToString(); } // Update Item Total Amount stock.UpdateStockMasterTotalAmount(Convert.ToInt32(txtItemMasterID.Text.ToString()), Convert.ToInt32(lblTotalAmount.Text.ToString())); } } catch (Exception ex) { throw ex; } }
protected void btnSaveStock_Click(object sender, EventArgs e) { PCSN.InvoiceSystem.BusinessLogicLayer.Stock Stock = new PCSN.InvoiceSystem.BusinessLogicLayer.Stock(); PCSN.InvoiceSystem.BusinessLogicLayer.StockEnterExit StockEnterExit = new PCSN.InvoiceSystem.BusinessLogicLayer.StockEnterExit(); long ItemMasterID = 0; long StockDetailID = 0; if (txtItemMasterID.Text == "") { // This runs When a new Stock is Created or New Item Add in a Stock if (txtItemMasterID.Text != "") { ItemMasterID = Convert.ToInt32(txtItemMasterID.Text); } if (ValidateClientSide()) { if (txtItemMasterID.Text == "") { ItemMasterID = Stock.InsertStockMaster(lblItemCode.Text, txtItemName.Text.ToString(), lblHeaderDate.Text.ToString(), txtDescription.Text.ToString(), Convert.ToInt32(lblTotalAmount.Text.ToString())); txtItemMasterID.Text = ItemMasterID.ToString(); } else { ItemMasterID = Convert.ToInt32(txtItemMasterID.Text); } if (ItemMasterID > 0) { if (txtSellingPrice.Text == "") { txtSellingPrice.Text = "0"; } txtItemMasterID.Text = ItemMasterID.ToString(); StockDetailID = Stock.InsertStockDetail(ItemMasterID, txtItemSize.Text.ToString(), txtColor.Text.ToString(), Convert.ToInt32(txtQuantity.Text), txtMake.Text.ToString(), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtSellingPrice.Text)); // Recording an entry for each item entered in Stock if (StockDetailID > 0) { StockEnterExit.InsertStockEnter(0, StockDetailID, Convert.ToInt32(txtQuantity.Text), DateTime.Now.ToShortDateString(), "Newly Entered Item"); } dtStockEdit = Stock.GetStockDetailTotalAmountByItemMasterID(ItemMasterID); lblTotalAmount.Text = "0"; if (dtStockEdit.Rows.Count > 0) { lblTotalAmount.Text = dtStockEdit.Rows[0]["TotalAmount"].ToString(); } // Update Item Total Amount Stock.UpdateStockMasterTotalAmount(Convert.ToInt32(txtItemMasterID.Text.ToString()), Convert.ToInt32(lblTotalAmount.Text.ToString())); } if (ItemMasterID > 0) { lblErrorMessage.Text = "This Item has been saved."; if (lblTotalAmount.Text == "") { lblTotalAmount.Text = "0"; } lblTotalAmount.Text = Convert.ToString(Convert.ToInt32(lblTotalAmount.Text) + Convert.ToInt32(txtQuantity.Text) * Convert.ToInt32(txtUnitPrice.Text)); ClearControlDetail(); } } } else { // This runs when an Item is being Edited if (ValidateClientSide()) { if (txtItemMasterID.Text != "") { ItemMasterID = Convert.ToInt32(txtItemMasterID.Text); // Checking if an Item is being altered if (txtItemDetailID.Text != "") { if (txtSellingPrice.Text == "") { txtSellingPrice.Text = "0"; } ItemMasterID = Convert.ToInt32(txtItemMasterID.Text); StockDetailID = Convert.ToInt32(txtItemDetailID.Text); dtStockEdit = Stock.GetStockDetailByID(StockDetailID); // Checking if the Quantity is decreased or increased then Entering or Exiting stock item quantity long Quantity = 0; if (dtStockEdit.Rows.Count > 0) { if (Convert.ToInt32(txtQuantity.Text) > Convert.ToInt32(dtStockEdit.Rows[0]["Quantity"].ToString())) { if (StockDetailID > 0) { // Increased Quantity is Entered in Stock Enter Quantity = Convert.ToInt32(txtQuantity.Text) - Convert.ToInt32(dtStockEdit.Rows[0]["Quantity"].ToString()); StockEnterExit.InsertStockEnter(0, StockDetailID, Quantity, DateTime.Now.ToShortDateString(), "Item Updated Quantity Increased"); } } else { if (StockDetailID > 0) { // Decreased Quantity is Entered in Stock Exit Quantity = Convert.ToInt32(dtStockEdit.Rows[0]["Quantity"].ToString()) - Convert.ToInt32(txtQuantity.Text); StockEnterExit.InsertStockExit(StockDetailID, Quantity, DateTime.Now.ToShortDateString(), "Item Updated Quantity Decreased"); } } } // Updating an Existing Item Stock.UpdateStockDetail(Convert.ToInt32(txtItemDetailID.Text), Convert.ToInt32(txtItemMasterID.Text), txtItemSize.Text.ToString(), txtColor.Text.ToString(), Convert.ToInt32(txtQuantity.Text), txtMake.Text.ToString(), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtSellingPrice.Text)); dtStockEdit = Stock.GetStockDetailTotalAmountByItemMasterID(ItemMasterID); lblTotalAmount.Text = "0"; if (dtStockEdit.Rows.Count > 0) { lblTotalAmount.Text = dtStockEdit.Rows[0]["TotalAmount"].ToString(); } // Updateing Total Amount Stock.UpdateStockMasterTotalAmount(Convert.ToInt32(txtItemMasterID.Text.ToString()), Convert.ToInt32(lblTotalAmount.Text.ToString())); } else { // Entering a New Item Detail if (txtSellingPrice.Text == "") { txtSellingPrice.Text = "0"; } StockDetailID = Stock.InsertStockDetail(ItemMasterID, txtItemSize.Text.ToString(), txtColor.Text.ToString(), Convert.ToInt32(txtQuantity.Text), txtMake.Text.ToString(), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtSellingPrice.Text)); // Recording an entry for each item entered in Stock if (StockDetailID > 0) { StockEnterExit.InsertStockEnter(0, StockDetailID, Convert.ToInt32(txtQuantity.Text), DateTime.Now.ToShortDateString(), "Newly Entered Item"); } dtStockEdit = Stock.GetStockDetailTotalAmountByItemMasterID(ItemMasterID); lblTotalAmount.Text = "0"; if (dtStockEdit.Rows.Count > 0) { lblTotalAmount.Text = dtStockEdit.Rows[0]["TotalAmount"].ToString(); } // Update Item Total Amount Stock.UpdateStockMasterTotalAmount(Convert.ToInt32(txtItemMasterID.Text.ToString()), Convert.ToInt32(lblTotalAmount.Text.ToString())); } } lblErrorMessage.Text = "This Item has been Updated."; ClearControlDetail(); } } if (ItemMasterID != 0) { PopulateStocks(ItemMasterID); lblTotalAmount.Text = "0"; dtStockEdit = Stock.GetStockDetailTotalAmountByItemMasterID(ItemMasterID); lblTotalAmount.Text = "0"; if (dtStockEdit.Rows.Count > 0) { lblTotalAmount.Text = dtStockEdit.Rows[0]["TotalAmount"].ToString(); } } }