protected void OnRowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; //String ItemDesc = GridView1.SelectedRow.Cells[1].Text.ToString(); String itemid = GridView1.DataKeys[e.NewEditIndex].Values[0].ToString(); String name = Business.FindItemByID(itemid).First().Description.ToString(); Label11.Text = name; String stock = Business.FindItemByID(itemid).First().Stock.ToString(); Label8.Text = stock; var startdate = DateTime.Now.AddMonths(-6); var today = DateTime.Now; using (LastADEntities entities = new LastADEntities()) { int itemlist = entities.PurchaseOrders .Where(p => p.DeliveryDate > startdate && p.DeliveryDate < today) .Join(entities.PurchaseOrderDetails.Where(x => x.ItemId == itemid), m => m.PurchaseOrderId, f => f.PurchaseOrderId, (m, f) => new { f.ItemId }).Count(); Label9.Text = itemlist.ToString(); } BindGrid(); }
protected void Button2_Click(object sender, EventArgs e) { String itemID1 = TextBox1.Text; GridView1.DataSource = Business.FindItemByID(itemID1); GridView1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { using (LastADEntities ctx = new LastADEntities()) { //RetrievalListSimple is a method that consolidates the quantity of the items to collect from the warehouse // and will display this data in a gridview if (Session["a"] != null) { list2 = (ArrayList)Session["a"]; GridView1.DataSource = Business.RetrievalListSimple(list2); GridView1.DataBind(); } int quantityneed; String id; ItemList items; for (int i = 0; i < this.GridView1.Rows.Count; i++) { TextBox txt = (TextBox)this.GridView1.Rows[i].Cells[5].FindControl("TextBox1"); if (txt != null) { Control ctrl = GridView1.Rows[i].Cells[2].FindControl("Label7"); Label lab = ctrl as Label; id = lab.Text; items = Business.FindItemByID(id).First(); quantityneed = Business.GetTotalQtyNeededForSelectedItem(id, list2); //if we have more stock than requested quantity, we will retrieve the requested quantity //else we will only retrieve the amount we have in the store if (items.Stock > quantityneed) { txt.Text = quantityneed.ToString(); } else { txt.Text = items.Stock.ToString(); } } } } } }