/// <summary>
        /// Creates a purchase and saves it do the database
        /// </summary>
        protected void btnSubmitPurchase_Click(object sender, EventArgs e)
        {
            //insert drink purchase
            if (ddlChooseItemForPurchase.SelectedIndex==0)
            {
                if (Session["drinklist"] != null)
                {
                    drinkPurchase = (List<IngredientPurchaseHistory>)Session["drinklist"];
                    //create a database connection
                    TreasureLandDataClassesDataContext db = new TreasureLandDataClassesDataContext();
                    IngredientPurchase addDrinkPurchase = new IngredientPurchase();

                    addDrinkPurchase.PurchaseDate= DateTime.Now;
                    db.IngredientPurchases.InsertOnSubmit(addDrinkPurchase);
                    db.SubmitChanges();

                    var pch = (from i in db.IngredientPurchases
                               select i.PurchaseID).Max();

                    foreach (var dp in drinkPurchase)
                    {
                        dp.PurchaseID = System.Convert.ToInt16(pch.ToString());
                        db.IngredientPurchaseHistories.InsertOnSubmit(dp);
                        db.SubmitChanges();
                    }

                }
            }
            //enter food purchase
            else
            {
                if (Session["ingredientlist"] != null)
                {
                    purchase = (List<IngredientPurchaseHistory>)Session["ingredientlist"];
                    //create a database connection
                    TreasureLandDataClassesDataContext db = new TreasureLandDataClassesDataContext();

                    //Create Ingredient Purchase
                    IngredientPurchase addIngredientPurchase = new IngredientPurchase();//create new purchase object

                    addIngredientPurchase.PurchaseDate = DateTime.Now;//get today
                    db.IngredientPurchases.InsertOnSubmit(addIngredientPurchase);
                    db.SubmitChanges();

                    //System.Diagnostics.Debug.WriteLine("");
                    //Query Recently added Purchase to get Purchase ID
                    var pch = (from i in db.IngredientPurchases
                               select i.PurchaseID).Max();//db.IngredientPurchases.Last(); //from p in db.IngredientPurchases select p.PurchaseDate//.Where(p => p. == purchaseTime )
                    //select p;

                    System.Diagnostics.Debug.WriteLine(pch.ToString());
                    //for each add to database
                    foreach (var ph in purchase)
                    {

                        ph.PurchaseID = System.Convert.ToInt16(pch.ToString());
                        db.IngredientPurchaseHistories.InsertOnSubmit(ph);
                        db.SubmitChanges();

                    }
                    Session["ingredientlist"] = null;
                    gvshowIngredientPurchases.DataSource = null;
                    gvshowIngredientPurchases.DataBind();
                }

            };
            gvshowIngredientPurchases.DataSource = null;
            gvshowIngredientPurchases.DataBind();
            btnSubmitPurchase.Enabled = false;
            btnManageCategories.Enabled = true;
            btnManageMenuItems.Enabled = true;
            btnEnterPurchase.Enabled = true;
            btnIngredients.Enabled = true;

            btnClear.Enabled = false;
        }
 partial void UpdateIngredientPurchase(IngredientPurchase instance);
 partial void DeleteIngredientPurchase(IngredientPurchase instance);
 partial void InsertIngredientPurchase(IngredientPurchase instance);