//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!"; } }
//Add protected void Button1_Click(object sender, EventArgs e) { try { int POnum = Int32.Parse(TextBox5.Text); string ItemCode = TextBox1.Text; string desp = DropDownList2.SelectedValue.ToString(); int qty = Int32.Parse(TextBox2.Text); double price = double.Parse(TextBox3.Text); string suppCode; if (GridView1.Rows.Count <= 0) { suppCode = Label8.Text; StoreBusinessLogic.AddPO(POnum, ItemCode, desp, qty, price, suppCode); BindGrid(POnum); } else { PurchaseOrder po = ctx.PurchaseOrders.Where(p => p.POnumber == POnum).First(); if (Label8.Text.ToString() == po.SuppCode) { suppCode = Label8.Text; StoreBusinessLogic.AddPO(POnum, ItemCode, desp, qty, price, suppCode); BindGrid(POnum); } else { Label7.Text = "Please add same supplier to one purchaseOrder"; } } } catch (Exception ex) { Label7.Text = "Please Input Valid Quantity"; } }