//when a Delivery is committed, the dishes in the delivery is commiteed to db at one time
        public void CommitDelivery(Delivery pD)
        {
            DataContextDataContext dc = new DataContextDataContext();
            dc.insert_delivery(
                (Guid?)pD.id,
                pD.userFrom,
                pD.customerName,
                pD.phone,
                pD.address,
                (DateTime?)pD.commitTime,
                (DateTime?)pD.deliveryTime
                );

            foreach (DishQuota dq in pD.dishQuotaList)
            {
                dc.insert_delivery_dish((Guid?)dq.id, pD.id, dq.dishName, (int?)dq.quota, dq.note);
            }
        }
        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            List<DishQuota> dishQuotaList = new List<DishQuota>();

            foreach (GridViewRow r in GridView1.Rows)
            {
                //这个相当于购物车的内容了,这里还可以添加,删除东西
                string quotaStr = ((DropDownList)(r.Cells[5].FindControl("DropDownList1"))).SelectedItem.Text.ToString(); //吧数量取出来
                if (quotaStr == "0")
                { } //不用处理
                else
                {
                    string dishName = r.Cells[0].Text; //名字取出来
                    double price = Convert.ToDouble(r.Cells[2].Text.Substring(1));//价格
                    int quota = Convert.ToInt32(quotaStr);//数量的数据类型转换下

                    DishQuota dishQuota = new DishQuota(Guid.NewGuid(), dishName, price, quota, "");//实例化一个dish
                    dishQuotaList.Add(dishQuota);//放到list
                }
            }

            if (dishQuotaList.Count != 0)//list 有东西
            {
                if (Session["Delivery"] != null)  //delivery 在session已经有
                {
                    ((Delivery)Session["Delivery"]).dishQuotaList = dishQuotaList; //设置session里的delivery的list为刚刚设置的list
                }
                else
                {
                    Delivery delivery = new Delivery(); //new 一个delivery
                    delivery.dishQuotaList = dishQuotaList;

                    Session["Delivery"] = delivery;  //把new的放到sesion
                }
                Response.Redirect(ConfigurationManager.AppSettings["NewDelivery"]); //转到填写用户信息的页面
            }
            else
            {
                Response.Write("<Script>alert('no dishes is selected!')</script>"); //list空的,错误提示

            }
        }
        public static List<Delivery> GetAllHistoryDelivery()
        {
            List<Delivery> deliveryList = new List<Delivery>();
            DataContextDataContext dc = new DataContextDataContext();

            ISingleResult<select_all_history_deliveryResult> rs = dc.select_all_history_delivery();
            foreach (select_all_history_deliveryResult r in rs)
            {
                List<DishQuota> dishQuotaLish = new List<DishQuota>();

                ISingleResult<get_dishquota_by_deliveryResult> rs2 = dc.get_dishquota_by_delivery(r.id);
                foreach (get_dishquota_by_deliveryResult r2 in rs2)
                {
                    double price = 0;
                    ISingleResult<get_dish_by_nameResult> rs3 = dc.get_dish_by_name(r2.dish_name);
                    foreach (get_dish_by_nameResult r3 in rs3)
                    {
                        price = (double)r3.price;
                    }

                    DishQuota dishQuota = new DishQuota(r2.id, r2.dish_name, price, (int)r2.quota, r2.note);
                    dishQuotaLish.Add(dishQuota);
                }

                Delivery delivery = new Delivery(
                    (Guid)r.id,
                    r.user_from,
                    r.customer_name,
                    r.phone,
                    r.address,
                    (DateTime)r.commit_time,
                    (DateTime)r.delivery_time,
                    (DeliveryState)r.state,
                    dishQuotaLish);

                deliveryList.Add(delivery);
            }

            return deliveryList;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Customer"] != null)
            {
                customer = (Customer)Session["Customer"];
                LabelCustomerName.Text = customer.name;
            }
            else
            {
                Response.Write("<Script>alert('please login first')</script>");
            }
            if (Session["Delivery"] != null)
            {
                delivery = (Delivery)Session["Delivery"];
                if (delivery.dishQuotaList.Count == 0)
                {
                    GridView1.Dispose();
                    LabelCart.Text = "No dishes is in your shopping cart";
                }
                else
                { }
            }
            else
            {
                GridView1.Dispose();
                LabelCart.Text = "No dishes is in your shopping cart";
            }//error

            //初始化时间选择的下拉菜单
            if (!IsPostBack)
            {
                //init conponent
                int hourNow = DateTime.Now.Hour;
                TextBoxDate.Text = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day;

                for (int i = 6; i <= 20; i++)
                {
                    string hour = i.ToString();
                    DropDownListHour.Items.Add(hour);
                }

                for (int j = 0; j <= 6; j += 1)
                {
                    DropDownListMinute.Items.Add(j.ToString() + "0");
                }

                LabelTime.Text = DropDownListHour.SelectedItem.Text + ":" + DropDownListMinute.SelectedItem.Text;
            }
            else
            { }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            customer = new Customer();

            if (Session["Delivery"] != null)
            {
                delivery = (Delivery)Session["Delivery"];
            }
            else
            {
                delivery = new Delivery();
            }

            if (Request.QueryString["DishName"] != null)
            {
                dishName = Request.QueryString["DishName"];
                dish = customer.GetDishByName(dishName);
            }
            else
            {//defalut dish
                dish = customer.GetDishByName(dishName);
            }

            ImageDish.ImageUrl = dish.pictPath;

            LabelTag1.Text = dish.tagList.ElementAt(0).name;
            LabelTag2.Text = dish.tagList.ElementAt(1).name;
            LabelTag3.Text = dish.tagList.ElementAt(0).name;
        }