protected void refreshbutton_Click(object sender, ImageClickEventArgs e) { GridView sourceGridview = OrderGridview as GridView; List <OrderDetailInfo> inputlist = new List <OrderDetailInfo>(); 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.OrderQty = int.Parse(orderqty.Text.ToString()); orderdetailinfo.UnitCost = decimal.Parse(unitcost.Text.ToString()); orderdetailinfo.ItemCost = orderdetailinfo.UnitCost / orderdetailinfo.UnitSize; orderdetailinfo.ExtendedCost = orderdetailinfo.OrderQty * orderdetailinfo.UnitCost; 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); } decimal subtotal = 0; decimal tax; decimal total; foreach (var a in inputlist) { subtotal += a.ExtendedCost; if (a.ItemCost < a.ItemPrice) { a.warning = "!!"; } else { a.warning = ""; } } tax = subtotal * 5 / 100; total = subtotal + tax; Subtotal.Text = Math.Round(subtotal, 2).ToString(); Tax.Text = Math.Round(tax, 2).ToString(); Total.Text = Math.Round(total, 2).ToString(); OrderGridview.DataSource = inputlist; OrderGridview.DataBind(); }
protected void VendorSelect_Click(object sender, EventArgs e) { if (int.Parse(VendorDropDown.SelectedValue.ToString()) != 0) { var controller = new PurchasingController(); var info = controller.GetVendorInfo(int.Parse(VendorDropDown.SelectedValue.ToString())); VendorName.Text = info.Name; VendorContact.Text = info.Address + ", " + info.City + ", " + info.PostalCode; VendorPhone.Text = info.Phone; var info2 = controller.GetOrder(int.Parse(VendorDropDown.SelectedValue.ToString())); if (info2 != null) { if (info2.OrderNumber != null) { PlaceOrder.Visible = false; SaveOrder.Visible = false; DeleteOrder.Visible = true; messenger.Text = $"Order already placed in {info2.OrderDate}. OrderNumber: {info2.OrderNumber}"; OrderGridview.Enabled = false; VendorRepeater.Visible = false; } else { OrderGridview.Enabled = true; VendorRepeater.Visible = true; DeleteOrder.Visible = true; PlaceOrder.Visible = true; SaveOrder.Visible = true; messenger.Text = ""; } Subtotal.Text = Math.Round(info2.SubTotal, 2).ToString(); Tax.Text = Math.Round(info2.Tax, 2).ToString(); Total.Text = Math.Round(info2.Total, 2).ToString(); OrderID = info2.OrderID; if (!string.IsNullOrEmpty(info2.VendorComment)) { VendorComments.Text = info2.VendorComment; } var x = info2.OrderDetails; foreach (var i in x) { i.ExtendedCost = Math.Round(i.ExtendedCost, 2); i.ItemPrice = Math.Round(i.ItemPrice, 2); i.ItemCost = Math.Round(i.ItemCost, 2); i.UnitCost = Math.Round(i.UnitCost, 2); } OrderGridview.DataSource = x; OrderGridview.DataBind(); } else { Subtotal.Text = "0"; Tax.Text = "0"; Total.Text = "0"; VendorComments.Text = ""; OrderGridview.DataSource = null; OrderGridview.DataBind(); VendorRepeater.Visible = true; OrderGridview.Enabled = true; messenger.Text = ""; OrderID = 0; DeleteOrder.Visible = false; PlaceOrder.Visible = true; SaveOrder.Visible = true; } var info3 = controller.GetVendorProducts(int.Parse(VendorDropDown.SelectedValue.ToString())); if (info3 != null) { VendorRepeater.DataSource = info3; VendorRepeater.DataBind(); int q = 0; foreach (var i in info3) // binding the gridviews of repeater { GridView a = VendorRepeater.Items[q].FindControl("VendorProductsGridview") as GridView; a.DataSource = i.Items; a.DataBind(); q++; } } OrderGridview.Visible = true; } }
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"); }