protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //显示表格
                dt = menu.searchMenu(m);

                //给ddlSelectFood下拉框动态赋值
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.ddlSelectFood.Items.Add(dt.Rows[i]["foodname"].ToString());
                }
            }
        }
예제 #2
0
        protected void btnOK_Click(object sender, EventArgs e)
        {
            bool flag = false;

            dt_search_menu = menu.searchMenu(m);
            if (this.txtFoodname == null || this.txtFoodno == null || this.txtFoodprice == null)//信息不能为空
            {
                Response.Write("<script language='javascript'>alert('请把菜的信息填写完整!');</script>");
            }
            else
            {
                if (dt_search_menu.Rows.Count > 8)//即只能在菜单上显示9道菜
                {
                    Response.Write("<script language='javascript'>alert('您的菜单数量已达上限,不可添加新菜!');</script>");
                }
                else
                {
                    int foodno = int.Parse(this.txtFoodno.Text);
                    m.Foodno     = foodno;
                    dt_search_no = menu.AddInfo(m);
                    if (dt_search_no.Rows.Count > 0)//编号不可以重复
                    {
                        this.Label6.Visible = true;
                    }
                    else
                    {
                        string fooname   = this.txtFoodname.Text;
                        int    foodprice = int.Parse(this.txtFoodprice.Text);
                        m.Foodname  = fooname;
                        m.Foodprice = foodprice;
                        if (FileUpload1.HasFile)                           //是否上传文件
                        {
                            string savePath = Server.MapPath("~/images/"); //指定上传文件在服务器上的保存路径
                            //检查服务器上是否存在这个物理路径,如果不存在则创建
                            if (!System.IO.Directory.Exists(savePath))
                            {
                                System.IO.Directory.CreateDirectory(savePath);
                            }
                            savePath = savePath + "\\" + FileUpload1.FileName;
                            FileUpload1.SaveAs(savePath);
                            m.FoodImage = "images" + "\\" + FileUpload1.FileName;
                            flag        = menu.addFood(m);
                            if (flag)
                            {
                                Response.Write("<script language='javascript'>alert('" + m.Foodname + " 已加入到菜单中!');</script>");
                                Response.Write("<script language=javascript>javascript:location.href='MenuInformation.aspx'</script>");
                            }
                            else
                            {
                                Response.Write("<script language='javascript'>alert('添加失败!');</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script language='javascript'>alert('您还没有上传文件!');</script>");
                        }
                    }
                }
            }
        }
예제 #3
0
 //显示菜单名
 public void showFoodname()
 {
     dt_menu = menu.searchMenu(m);
     //食物1
     this.Label1.Text   = dt_menu.Rows[0]["foodname"].ToString();
     this.img1.Src      = dt_menu.Rows[0]["foodimage"].ToString();
     this.lbPrice1.Text = dt_menu.Rows[0]["foodprice"].ToString() + "¥";
     //食物2
     this.Label2.Text   = dt_menu.Rows[1]["foodname"].ToString();
     this.img2.Src      = dt_menu.Rows[1]["foodimage"].ToString();
     this.lbPrice2.Text = dt_menu.Rows[1]["foodprice"].ToString() + "¥";
     //食物3
     this.Label3.Text   = dt_menu.Rows[2]["foodname"].ToString();
     this.img3.Src      = dt_menu.Rows[2]["foodimage"].ToString();
     this.lbPrice3.Text = dt_menu.Rows[2]["foodprice"].ToString() + "¥";
     //食物4
     this.Label4.Text   = dt_menu.Rows[3]["foodname"].ToString();
     this.img4.Src      = dt_menu.Rows[3]["foodimage"].ToString();
     this.lbPrice4.Text = dt_menu.Rows[3]["foodprice"].ToString() + "¥";
     //食物5
     this.Label5.Text   = dt_menu.Rows[4]["foodname"].ToString();
     this.img5.Src      = dt_menu.Rows[4]["foodimage"].ToString();
     this.lbPrice5.Text = dt_menu.Rows[4]["foodprice"].ToString() + "¥";
     //食物6
     this.Label6.Text   = dt_menu.Rows[5]["foodname"].ToString();
     this.img6.Src      = dt_menu.Rows[5]["foodimage"].ToString();
     this.lbPrice6.Text = dt_menu.Rows[5]["foodprice"].ToString() + "¥";
     //食物7
     this.Label7.Text   = dt_menu.Rows[6]["foodname"].ToString();
     this.img7.Src      = dt_menu.Rows[6]["foodimage"].ToString();
     this.lbPrice7.Text = dt_menu.Rows[6]["foodprice"].ToString() + "¥";
     //食物8
     this.Label8.Text   = dt_menu.Rows[7]["foodname"].ToString();
     this.img8.Src      = dt_menu.Rows[7]["foodimage"].ToString();
     this.lbPrice8.Text = dt_menu.Rows[7]["foodprice"].ToString() + "¥";
     //食物9
     this.Label9.Text   = dt_menu.Rows[8]["foodname"].ToString();
     this.img9.Src      = dt_menu.Rows[8]["foodimage"].ToString();
     this.lbPrice9.Text = dt_menu.Rows[8]["foodprice"].ToString() + "¥";
 }