Esempio n. 1
0
        public int AddFood(Food food)
        {
            try
            {
                string sql = "INSERT INTO `food`(`cnName`,`enName`,`des`,`price`,`category`,`canDiscount`,`status`,`isHot`,`unit`,`createTime`,`updateTime`,`imageUpdateTime`,`delTime`,`needKC`,`needMaterials`,`isPlan`)VALUES (@cnName,@enName,@des,@price,@category,@canDiscount,@status,@isHot,@unit,@createTime,@updateTime,@imageUpdateTime,@delTime,@needKC,@needMaterials,@isPlan)";
                DbUtil.ExecuteNonQuery(sql,
                    new MySqlParameter("@cnName", food.cnName),
                    new MySqlParameter("@enName", food.enName),
                    new MySqlParameter("@des", food.des),
                    new MySqlParameter("@price", food.price),
                    new MySqlParameter("@category", food.category),
                    new MySqlParameter("@canDiscount", food.canDiscount),
                    new MySqlParameter("@status", food.status),
                    new MySqlParameter("@isHot", food.isHot),
                    new MySqlParameter("@unit", food.unit),
                    new MySqlParameter("@createTime", food.createTime),
                    new MySqlParameter("@updateTime", food.updateTime),
                    new MySqlParameter("@imageUpdateTime", food.imageUpdateTime),
                    new MySqlParameter("@delTime", food.delTime),
                    new MySqlParameter("@needKC", food.needKC),
                    new MySqlParameter("@needMaterials", food.needMaterials),
                    new MySqlParameter("@isPlan", food.isPlan));

                return Convert.ToInt32(DbUtil.ExecuteScalar("SELECT MAX(FOODID) FROM FOOD").ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("添加餐品失败"+ex.Message);
            }
        }
Esempio n. 2
0
        private void AddFood()
        {
            string cnName = tbCnName.Text.Trim();
            string enName = tbEnName.Text.Trim();
            float price = 0.0f;
            try
            {
                price = float.Parse(tbPrice.Text.Trim());
            }
            catch
            {
                MessageBox.Show("价格必须是数字");
                return;
            }
            string unit = cbUnit.Text;
            string category = cbCategory.Text;
            if (cnName == "" || enName == "" || unit == "")
            {
                MessageBox.Show("餐点名称和单位不能为空");
                return;
            }
            Food food = new Food();
            food.canDiscount = "否";
            if (rbCanDiscount.Checked)
                food.canDiscount = "能";
            food.category = category;
            food.cnName = cnName;
            food.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            food.delTime = "";
            food.des = tbDes.Text.Trim();
            food.enName = enName;
            food.imageUpdateTime = "";
            food.isHot = "否";
            food.isPlan = "否";
            if (cbIsPlan.Checked)
            {
                food.isPlan = "是";
                // 添加套餐详情
                foreach (DataGridViewRow row in dvPlanInfo.Rows)
                {
                    PlanFood planFood = new PlanFood();
                    planFood.planFoodCount = Convert.ToInt32(row.Cells["foodcount"].Value);
                    planFood.planFoodid = Convert.ToInt32(row.Cells["foodid"].Value);
                    planFood.planFoodname = row.Cells["name"].Value.ToString();
                    planFood.planFoodPrice = float.Parse(row.Cells["foodprice"].Value.ToString());
                    planFood.planName = cnName;
                    planFood.planFoodUnit = row.Cells["foodUnit"].Value.ToString();
                    PlanFoodService planService = new PlanFoodService();
                    planService.AddPlanFood(planFood);
                }
            }
            food.needKC = "否";
            if (cbKC.Checked)
            {
                food.needKC = "是";

                // 添加库存信息
            }
            food.needMaterials = "否";
            if (cbMaterials.Checked)
            {
                food.needMaterials = "是";

                // 添加原材料信息
            }
            food.price = price;
            food.status = "库存";
            food.unit = unit;
            food.updateTime = "";
            FoodService service = new FoodService();
            int id = service.AddFood(food);
            if (imagePath != "")
            {
                string savePath = @".\image\" + id + ".jpg";
                ImageUtil.MakeThumbnail(imagePath, savePath, 500, 350, "H");
            }
            MessageBox.Show("新增餐点信息成功");
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
Esempio n. 3
0
 private Food ToFood(DataRow row)
 {
     Food food = new Food();
     food.canDiscount = (string)row["canDiscount"];
     food.category = (string)row["category"];
     food.cnName = (string)row["cnName"];
     food.createTime = (string)row["createTime"];
     food.delTime = (string)row["delTime"];
     food.des = (string)row["des"];
     food.enName = (string)row["enName"];
     food.foodid = (int)row["foodid"];
     food.imageUpdateTime = (string)row["imageUpdateTime"];
     food.isHot = (string)row["isHot"];
     food.isPlan = (string)row["isPlan"];
     food.needKC = (string)row["needKC"];
     food.needMaterials = (string)row["needMaterials"];
     food.price = (float)row["price"];
     food.status = (string)row["status"];
     food.unit = (string)row["unit"];
     food.updateTime = (string)row["updateTime"];
     return food;
 }
Esempio n. 4
0
 public void UpdateFood(Food food)
 {
     string sql = "update food set cnName = @cnName,enName = @enName,des = @des,price = @price,category= @category,canDiscount = @canDiscount,status = @status,isHot = @isHot,unit = @unit,createTime = @createTime,updateTime = @updateTime,imageUpdateTime = @imageUpdateTime,delTime = @delTime,needKC = @needKC,needMaterials = @needMaterials,isPlan = @isPlan where foodid = @foodid";
     DbUtil.ExecuteNonQuery(sql,
             new MySqlParameter("@cnName", food.cnName),
             new MySqlParameter("@enName", food.enName),
             new MySqlParameter("@des", food.des),
             new MySqlParameter("@price", food.price),
             new MySqlParameter("@category", food.category),
             new MySqlParameter("@canDiscount", food.canDiscount),
             new MySqlParameter("@status", food.status),
             new MySqlParameter("@isHot", food.isHot),
             new MySqlParameter("@unit", food.unit),
             new MySqlParameter("@createTime", food.createTime),
             new MySqlParameter("@updateTime", food.updateTime),
             new MySqlParameter("@imageUpdateTime", food.imageUpdateTime),
             new MySqlParameter("@delTime", food.delTime),
             new MySqlParameter("@needKC", food.needKC),
             new MySqlParameter("@needMaterials", food.needMaterials),
             new MySqlParameter("@isPlan", food.isPlan),
             new MySqlParameter("@foodid",food.foodid));
 }