//Place order protected void Button2_Click(object sender, EventArgs e) { try { foreach (GridViewRow row in GridView1.Rows) { if (row.Visible == true) { int POnum = Convert.ToInt32(Label16.Text); string ItemCode = (row.FindControl("Label7") as Label).Text; string Category = (row.FindControl("Label8") as Label).Text; string desp = (row.FindControl("Label9") as Label).Text; int qty = Convert.ToInt32((row.FindControl("TextBox1") as TextBox).Text); string suppCode = (row.FindControl("Label14") as Label).Text; double price = Convert.ToDouble((row.FindControl("Label15") as Label).Text); int orderedQty; using (Model1 entities = new Model1()) { Stock s = entities.Stocks.Where(p => p.ItemCode == ItemCode).First <Stock>(); orderedQty = Convert.ToInt32(s.OrderedQty) + qty; } if (qty >= 0) { StoreBusinessLogic.AddPO(POnum, ItemCode, desp, qty, price, suppCode); StoreBusinessLogic.UpdateStock(ItemCode, orderedQty); PoNo(); BindGrid(); Label18.Text = "Successful"; } else { Label18.Text = "Please input Positive Integer"; } } } PoNo(); string supp = DropDownList1.SelectedValue.ToString(); BindGrid(supp); Label17.Text = ""; } catch (Exception ex) { Label18.Text = "Invalid PO number!"; } }
protected void Button2_Click(object sender, EventArgs e) { int DOnum; int POnum; string ItemCode; string desp; int POQty; int DeliveredQty; string suppcode; int currentQty; int orderedQty; try { if (GridView1.Rows.Count > 0) { foreach (GridViewRow row in GridView1.Rows) { DOnum = Convert.ToInt32(TextBox2.Text); POnum = Convert.ToInt32(TextBox1.Text); ItemCode = (row.FindControl("Label8") as Label).Text; desp = (row.FindControl("Label9") as Label).Text; POQty = Convert.ToInt32((row.FindControl("Label11") as Label).Text); DeliveredQty = Convert.ToInt32((row.FindControl("TextBox4") as TextBox).Text); suppcode = TextBox3.Text; if (DeliveredQty > POQty || DeliveredQty < 0) { Session["count"] = 1; } } } else { Label17.Text = "Delivery Order Successfully"; } } catch (Exception EX) { Label17.Text = "Invalid DeliveredQty!"; } if (Convert.ToInt32(Session["count"]) == 1) { Label17.Text = "Invalid DeliveredQty!"; Session["count"] = 0; } else { try { foreach (GridViewRow row in GridView1.Rows) { DOnum = Convert.ToInt32(TextBox2.Text); POnum = Convert.ToInt32(TextBox1.Text); ItemCode = (row.FindControl("Label8") as Label).Text; desp = (row.FindControl("Label9") as Label).Text; POQty = Convert.ToInt32((row.FindControl("Label11") as Label).Text); DeliveredQty = Convert.ToInt32((row.FindControl("TextBox4") as TextBox).Text); suppcode = TextBox3.Text; using (Model1 entities = new Model1()) { Stock s = entities.Stocks.Where(p => p.ItemCode == ItemCode).First <Stock>(); currentQty = Convert.ToInt32(s.CurrentQty); orderedQty = Convert.ToInt32(s.OrderedQty); } StoreBusinessLogic.AddDO(DOnum, POnum, ItemCode, desp, POQty, DeliveredQty, suppcode); currentQty = currentQty + DeliveredQty; orderedQty = orderedQty - DeliveredQty; StoreBusinessLogic.UpdateStock(ItemCode, currentQty, orderedQty); } Session["count"] = 2; Response.Redirect("Delivered Items.aspx"); } catch (Exception EX) { Label17.Text = "Invalid DeliveredQty!"; } } }