protected void OrderGridview_RowCommand(object sender, GridViewCommandEventArgs e) { MessageUserControl.TryRun(() => { Subtotal.Text = ""; Tax.Text = ""; Total.Text = ""; if (e.CommandName == "Refresh") { } else { GridView sourceGridview = e.CommandSource as GridView; List <VendorCatalogInfo> outputList = new List <VendorCatalogInfo>(); List <OrderDetailInfo> inputlist = new List <OrderDetailInfo>(); int selectedindex; if (int.TryParse(e.CommandArgument.ToString(), out selectedindex)) { foreach (GridViewRow row in sourceGridview.Rows) // taking data from gridview and copying it to a List { var productid = row.FindControl("ProductID") as HiddenField; var categoryname = row.FindControl("CategoryName") as HiddenField; var productname = row.FindControl("ProductNameLabel") as Label; var unitsize = row.FindControl("UnitSize") as HiddenField; var itemprice = row.FindControl("ItemPriceLabel") as HiddenField; var itemcost = row.FindControl("PerItemCost") as Label; var orderqty = row.FindControl("OrderQtyLabel") as TextBox; var unitcost = row.FindControl("UnitCostLabel") as TextBox; var extendedcost = row.FindControl("ExtendedCostLabel") as Label; var reorderqty = row.FindControl("ReorderQty") as HiddenField; var instockqty = row.FindControl("QuantityOnHand") as HiddenField; var onorderqty = row.FindControl("QuantityOnOrder") as HiddenField; var orderdetailinfo = new OrderDetailInfo(); orderdetailinfo.ProductID = int.Parse(productid.Value.ToString()); orderdetailinfo.ProductName = productname.Text.Trim(); orderdetailinfo.UnitSize = int.Parse(unitsize.Value.ToString()); orderdetailinfo.ItemPrice = decimal.Parse(itemprice.Value.ToString()); orderdetailinfo.ItemCost = decimal.Parse(itemcost.Text.ToString()); orderdetailinfo.OrderQty = int.Parse(orderqty.Text.ToString()); orderdetailinfo.UnitCost = decimal.Parse(unitcost.Text.ToString()); orderdetailinfo.ExtendedCost = decimal.Parse(extendedcost.Text.ToString()); orderdetailinfo.ReorderQty = int.Parse(reorderqty.Value.ToString()); orderdetailinfo.QuantityOnHand = int.Parse(instockqty.Value.ToString()); orderdetailinfo.QuantityOnOrder = int.Parse(onorderqty.Value.ToString()); orderdetailinfo.CategoryName = categoryname.Value.ToString(); inputlist.Add(orderdetailinfo); } foreach (RepeaterItem item in VendorRepeater.Items) { var catname = item.FindControl("CategoryName") as Label; if (catname.Text.Trim() == inputlist[selectedindex].CategoryName.Trim()) // filtering by category { GridView outGridview = item.FindControl("VendorProductsGridview") as GridView; // taking data from gridview and copying it to a List foreach (GridViewRow row in outGridview.Rows) { var productname = row.FindControl("VendorProductName") as Label; var productid = row.FindControl("ProductID") as HiddenField; var reorderqty = row.FindControl("ReOrderLabel") as Label; var instockqty = row.FindControl("InStockLabel") as Label; var onorderqty = row.FindControl("OnOrderLabel") as Label; var size = row.FindControl("UnitSize") as HiddenField; var itemcost = row.FindControl("ItemCost") as HiddenField; var cat = row.FindControl("CategoryName") as HiddenField; var vendorcataloginfo = new VendorCatalogInfo(); vendorcataloginfo.ProductID = int.Parse(productid.Value.ToString()); vendorcataloginfo.ProductName = productname.Text; vendorcataloginfo.Category = cat.Value.ToString().Trim(); vendorcataloginfo.ReorderQty = int.Parse(reorderqty.Text.ToString()); vendorcataloginfo.QuantityOnHand = int.Parse(instockqty.Text.ToString()); vendorcataloginfo.QuantityOnOrder = int.Parse(onorderqty.Text.ToString()); vendorcataloginfo.ItemCost = decimal.Parse(itemcost.Value.ToString()); vendorcataloginfo.UnitSize = int.Parse(size.Value.ToString()); outputList.Add(vendorcataloginfo); } break; } } var addto = inputlist[selectedindex]; var vendorcatinfo = new VendorCatalogInfo(); vendorcatinfo.ProductName = addto.ProductName; vendorcatinfo.ReorderQty = addto.ReorderQty; vendorcatinfo.QuantityOnHand = addto.QuantityOnHand; vendorcatinfo.QuantityOnOrder = addto.QuantityOnOrder; vendorcatinfo.UnitSize = addto.UnitSize; vendorcatinfo.ItemCost = addto.ItemPrice; vendorcatinfo.Category = addto.CategoryName; outputList.Add(vendorcatinfo); foreach (RepeaterItem item in VendorRepeater.Items) { var catname = item.FindControl("CategoryName") as Label; if (catname.Text.Trim() == inputlist[selectedindex].CategoryName.Trim()) { GridView outGridview = item.FindControl("VendorProductsGridview") as GridView; outGridview.DataSource = outputList; outGridview.DataBind(); break; } } inputlist.RemoveAt(selectedindex); sourceGridview.DataSource = inputlist; sourceGridview.DataBind(); } } }, "Success", "Product successfully removed from the Purchase Order form"); }
protected void VendorProductsGridview_RowCommand(object sender, GridViewCommandEventArgs e) // adding products to purchase order { MessageUserControl.TryRun(() => { Subtotal.Text = "0"; Tax.Text = "0"; Total.Text = "0"; GridView sourceGridview = e.CommandSource as GridView; List <OrderDetailInfo> outputList = new List <OrderDetailInfo>(); List <VendorCatalogInfo> inputlist = new List <VendorCatalogInfo>(); int selectedindex; if (int.TryParse(e.CommandArgument.ToString(), out selectedindex)) { foreach (GridViewRow row in sourceGridview.Rows) // taking data from gridview and copying it to a List { var cat = row.FindControl("CategoryName") as HiddenField; var productid = row.FindControl("ProductID") as HiddenField; var productname = row.FindControl("VendorProductName") as Label; var reorderqty = row.FindControl("ReOrderLabel") as Label; var instockqty = row.FindControl("InStockLabel") as Label; var onorderqty = row.FindControl("OnOrderLabel") as Label; var size = row.FindControl("UnitSize") as HiddenField; var itemcost = row.FindControl("ItemCost") as HiddenField; var vendorcataloginfo = new VendorCatalogInfo(); vendorcataloginfo.ProductID = int.Parse(productid.Value.ToString()); vendorcataloginfo.ProductName = productname.Text; vendorcataloginfo.Category = cat.Value.ToString().Trim(); vendorcataloginfo.ReorderQty = int.Parse(reorderqty.Text.ToString()); vendorcataloginfo.QuantityOnHand = int.Parse(instockqty.Text.ToString()); vendorcataloginfo.QuantityOnOrder = int.Parse(onorderqty.Text.ToString()); vendorcataloginfo.ItemCost = decimal.Parse(itemcost.Value.ToString()); vendorcataloginfo.UnitSize = int.Parse(size.Value.ToString()); inputlist.Add(vendorcataloginfo); } foreach (GridViewRow row in OrderGridview.Rows) // taking data from gridview and copying it to a List { var productid = row.FindControl("ProductID") as HiddenField; var productname = row.FindControl("ProductNameLabel") as Label; var unitsize = row.FindControl("UnitSize") as HiddenField; var itemprice = row.FindControl("ItemPriceLabel") as HiddenField; var itemcost = row.FindControl("PerItemCost") as Label; var orderqty = row.FindControl("OrderQtyLabel") as TextBox; var unitcost = row.FindControl("UnitCostLabel") as TextBox; var extendedcost = row.FindControl("ExtendedCostLabel") as Label; var categoryname = row.FindControl("CategoryName") as HiddenField; var reorderqty = row.FindControl("ReorderQty") as HiddenField; var instockqty = row.FindControl("QuantityOnHand") as HiddenField; var onorderqty = row.FindControl("QuantityOnOrder") as HiddenField; var warning = row.FindControl("warning") as Label; var orderdetailinfo = new OrderDetailInfo(); orderdetailinfo.ProductID = int.Parse(productid.Value.ToString()); orderdetailinfo.ProductName = productname.Text.Trim(); orderdetailinfo.UnitSize = int.Parse(unitsize.Value.ToString()); orderdetailinfo.ItemPrice = decimal.Parse(itemprice.Value.ToString()); orderdetailinfo.ItemCost = decimal.Parse(itemcost.Text.ToString()); orderdetailinfo.OrderQty = int.Parse(orderqty.Text.ToString()); orderdetailinfo.UnitCost = decimal.Parse(unitcost.Text.ToString()); orderdetailinfo.ExtendedCost = decimal.Parse(extendedcost.Text.ToString()); orderdetailinfo.CategoryName = categoryname.Value.ToString().Trim(); orderdetailinfo.ReorderQty = int.Parse(reorderqty.Value.ToString()); orderdetailinfo.QuantityOnHand = int.Parse(instockqty.Value.ToString()); orderdetailinfo.QuantityOnOrder = int.Parse(onorderqty.Value.ToString()); orderdetailinfo.warning = warning.Text; outputList.Add(orderdetailinfo); } var addto = inputlist[selectedindex]; var orderdetailinfo2 = new OrderDetailInfo(); orderdetailinfo2.ProductID = addto.ProductID; orderdetailinfo2.ProductName = addto.ProductName; orderdetailinfo2.ItemPrice = Math.Round(addto.ItemCost, 2); orderdetailinfo2.ItemCost = orderdetailinfo2.ItemPrice; orderdetailinfo2.UnitSize = addto.UnitSize; orderdetailinfo2.CategoryName = addto.Category; orderdetailinfo2.OrderQty = 1; orderdetailinfo2.UnitCost = orderdetailinfo2.ItemPrice * orderdetailinfo2.UnitSize; orderdetailinfo2.ExtendedCost = orderdetailinfo2.UnitCost; orderdetailinfo2.QuantityOnHand = addto.QuantityOnHand; orderdetailinfo2.QuantityOnOrder = addto.QuantityOnOrder; orderdetailinfo2.ReorderQty = addto.ReorderQty; outputList.Add(orderdetailinfo2); OrderGridview.DataSource = outputList; OrderGridview.DataBind(); inputlist.RemoveAt(selectedindex); sourceGridview.DataSource = inputlist; sourceGridview.DataBind(); } }, "Success", "Product successfully added to the Purchase Order Form"); }