//Function: initialize a concrete user, return it as use of this session, if the user is valid
        //Paramaters:
        //Return: concrete user type, (Customer or Manager)
        //    null when the user is invalid
        //用户身份验证,根据名字密码查数据库,合法的话,返回出manager或者customer
        //不合法返回NUll
        public static User Login(string pName, string pPwd)
        {
            User user = null;
            DataContextDataContext dc = new DataContextDataContext();
            bool? isValid = false;
            ISingleResult<is_valid_userResult> rs = dc.is_valid_user(pName, pPwd, ref isValid);

            if (isValid == true)
            {
                foreach (is_valid_userResult s in rs)
                {
                    if (s.type == 1)
                    {
                        user = new Customer(s.name, s.pwd, s.mail);
                    }
                    else if (s.type == 2)
                    {
                        user = new Manager(s.name, s.pwd, s.mail);
                    }
                    else
                    { }

                }

            }
            else //invalid
            {}
            return user;
        }
        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;
        }
        protected void ButtonAddComment_Click(object sender, EventArgs e)
        {
            if (TextBoxComment.Visible == false)
            {
                if (Session["Customer"] != null)
                {
                    TextBoxComment.Visible = true;
                    ButtonAddComment.Text = "Publish Comment";
                }
                else
                {
                    Response.Write("<Script>alert('login first to add comment')</script>");

                }
            }
            else
            {
                customer = (Customer)Session["Customer"];
                string str = TextBoxComment.Text;
                Comment comment = new Comment(Guid.NewGuid(), str, dish.name, customer.name);
                customer.PublishComment(comment);

                Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["DishDetail"] + "?DishName=" + dish.name );
                //TextBoxComment.Visible = false;
                //ButtonAddComment.Text = "Add comment";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            customer = new Customer();

            if (!IsPostBack)
            {
                GridViewDish.DataSource = SqlDataSourceHotDish;
                GridViewDish.DataBind();
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["Customer"] != null)
     {
         customer = (Customer)Session["Customer"];
     }
     else
     {
         Response.Write("<Script>alert('Please login first!')</script>");
     }
 }
        //public void Logout()
        //{}
        //Function: initialize a customer, and insert a new record of custoemr into db
        //Return: custoemr newd if user name is valid
        //    null if pName exists in db
        //user注册后,返回custoemr,把注册记录插到SysUser表
        public static Customer Register(string pName, string pPwd, string pMail)
        {
            Customer custom = null;
            bool? isExist = false;

            DataContextDataContext dc = new DataContextDataContext();
            dc.is_registered(pName, ref isExist);

            if (isExist == true)
            { } //custom = null
            else // not exist, can insert
            {
                try
                {
                    dc.insert_customer(pName, pPwd, pMail);
                    custom = new Customer(pName, pPwd, pMail);
                }
                catch (Exception ex)
                { } //custom = null;

            }

            return custom;
        }
        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
            { }
        }
 public void ModifyCustom(Customer pCustom)
 {
     DataContextDataContext dc = new DataContextDataContext();
     dc.update_user(pCustom.name, pCustom.pwd, pCustom.mail);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            //$判断是否custoemr登录了
            if (Session["Customer"] == null)
            {
                divReservation.Visible = false;
                Response.Write("<Script>alert('please login first')</script>");

                //RequiredFieldValidatorName.Enabled = false;
                //RequiredFieldValidatorPhone.Enabled = false;
                //RequiredFieldValidatorAddress.Enabled = false;
            }
            else
            {
                customer = (Customer)Session["Customer"];
                UserNameLabel1.Text = customer.name;
            }

            if (!IsPostBack)
            {
                TextBoxArriveDate.Text = DateTime.Now.ToShortDateString();
                //DropDownListDuration.Items.Remove(DropDownListDuration.Items.FindByText("start"));
            }
        }