protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int ID = Convert.ToInt32(Request.QueryString["id"]); Ye_Product pro = ProductBll.GetProductById(ID); ProImage.ImageUrl = pro.ProductImage; } }
protected void btnOk_OnClick(object sender, EventArgs e) { int productId = Convert.ToInt32(Request.QueryString["id"]); if (ProductBll.GetProducts().Count(p => p.ShopID == YeShopId && p.ProductNo == tbxProductNO.Text.Trim() && p.ProductID != productId) > 0) { WebUtil.Alert("菜单编号重复,请重新填写菜单编号!"); return; } var product = new Ye_Product() { ProductID = productId, ProductDesc = tbxProductDesc.Text, Price = Convert.ToDecimal(tbxPrice.Text), ShopID = YeShopId, ProductName = tbxProductName.Text, ProductNo = tbxProductNO.Text, ProductTypeID = Convert.ToInt32(ddlProductTypes.SelectedValue), UnitId = Convert.ToInt32(ddlUnits.SelectedValue), CreateDate = DateTime.Now, }; if (!fupProductImage.HasFile) { product.ProductImage = imgProductImage.ImageUrl; } else { var oldImage = Server.MapPath(product.ProductImage); string str = string.Empty; if (WebUtil.UploadImage(fupProductImage, "../upload/", new[] { ".gif", ".jpg", ".png", ".jpeg" }, out str)) { product.ProductImage = "/upload/" + str; try { File.Delete(oldImage); } catch { } } else { WebUtil.Alert("餐馆 Logo 图片格式不被支持!"); return; } } if (ProductBll.UpdateProduct(product)) { WebUtil.Alert("菜单修改成功!"); } else { WebUtil.Alert("菜单修改失败!"); } }
protected void btnOk_OnClick(object sender, EventArgs e) { int productId=Convert.ToInt32(Request.QueryString["id"]); if (ProductBll.GetProducts().Count(p=>p.ShopID==YeShopId&& p.ProductNo==tbxProductNO.Text.Trim() && p.ProductID!=productId)>0) { WebUtil.Alert("菜单编号重复,请重新填写菜单编号!"); return; } var product = new Ye_Product() { ProductID = productId, ProductDesc = tbxProductDesc.Text, Price = Convert.ToDecimal(tbxPrice.Text), ShopID = YeShopId, ProductName = tbxProductName.Text, ProductNo = tbxProductNO.Text, ProductTypeID = Convert.ToInt32(ddlProductTypes.SelectedValue), UnitId = Convert.ToInt32(ddlUnits.SelectedValue), CreateDate = DateTime.Now, }; if (!fupProductImage.HasFile) { product.ProductImage = imgProductImage.ImageUrl; } else { var oldImage = Server.MapPath(product.ProductImage); string str = string.Empty; if (WebUtil.UploadImage(fupProductImage, "../upload/", new[] { ".gif", ".jpg", ".png", ".jpeg" }, out str)) { product.ProductImage = "/upload/" + str; try { File.Delete(oldImage); } catch { } } else { WebUtil.Alert("餐馆 Logo 图片格式不被支持!"); return; } } if (ProductBll.UpdateProduct(product)) { WebUtil.Alert("菜单修改成功!"); } else { WebUtil.Alert("菜单修改失败!"); } }
/// <summary> /// 修改菜单信息 /// </summary> /// <param name="product"></param> /// <returns></returns> public static bool UpdateProduct(Ye_Product product) { var p = ProductBll.GetProductById(product.ProductID); p.ProductNo = product.ProductNo; p.ProductName = product.ProductName; p.RecommendLevel = product.RecommendLevel; p.ProductImage = product.ProductImage; p.ProductDesc = product.ProductDesc; p.Price = product.Price; p.UnitId = product.UnitId; p.ProductTypeID = product.ProductTypeID; return(_entities.SaveChanges() > 0); }
protected void btnOk_OnClick(object sender, EventArgs e) { if (ProductBll.GetProducts().Count(p => p.ShopID == YeShopId && p.ProductNo == tbxProductNO.Text.Trim()) > 0) { WebUtil.Alert("菜单编号重复,请重新填写菜单编号!"); return; } var product = new Ye_Product() { ProductDesc = tbxProductDesc.Text, Price = Convert.ToDecimal(tbxPrice.Text), ShopID = YeShopId, ProductName = tbxProductName.Text, ProductNo = tbxProductNO.Text, ProductTypeID = Convert.ToInt32(ddlProductTypes.SelectedValue), UnitId = Convert.ToInt32(ddlUnits.SelectedValue), CreateDate = DateTime.Now, }; var fileName = string.Empty; if (!fupProductImage.HasFile) { WebUtil.Alert("请上传产品图片!"); return; } else if (fupProductImage.FileBytes.Length > 1024 * 5120) { WebUtil.Alert("菜单图片不能超过 5 M!"); return; } if (WebUtil.UploadImage(fupProductImage, "../upload/", new [] { ".png", ".jpeg", ".jpg" }, out fileName)) { product.ProductImage = "/upload/" + fileName; } else { WebUtil.Alert("上传图片失败,请重试。支持 jpg、png 格式!"); return; } if (ProductBll.AddProduct(product)) { WebUtil.AlertAndReload("添加菜单成功!"); } else { WebUtil.AlertAndReload("添加菜单失败!"); } }
protected void btnOk_OnClick(object sender, EventArgs e) { if (ProductBll.GetProducts().Count(p => p.ShopID == YeShopId && p.ProductNo == tbxProductNO.Text.Trim()) > 0) { WebUtil.Alert("菜单编号重复,请重新填写菜单编号!"); return; } var product = new Ye_Product() { ProductDesc = tbxProductDesc.Text, Price = Convert.ToDecimal(tbxPrice.Text), ShopID = YeShopId, ProductName = tbxProductName.Text, ProductNo = tbxProductNO.Text, ProductTypeID = Convert.ToInt32(ddlProductTypes.SelectedValue), UnitId = Convert.ToInt32(ddlUnits.SelectedValue), CreateDate = DateTime.Now, }; var fileName = string.Empty; if (!fupProductImage.HasFile) { WebUtil.Alert("请上传产品图片!"); return; }else if (fupProductImage.FileBytes.Length > 1024*5120) { WebUtil.Alert("菜单图片不能超过 5 M!"); return; } if (WebUtil.UploadImage(fupProductImage,"../upload/",new []{".png",".jpeg",".jpg"},out fileName)) { product.ProductImage = "/upload/" + fileName; } else { WebUtil.Alert("上传图片失败,请重试。支持 jpg、png 格式!"); return; } if (ProductBll.AddProduct(product)) { WebUtil.AlertAndReload("添加菜单成功!"); } else { WebUtil.AlertAndReload("添加菜单失败!"); } }
/// <summary> /// 添加菜单 /// </summary> /// <param name="product">菜单</param> /// <returns></returns> public static bool AddProduct(Ye_Product product) { _entities.Ye_Product.Add(product); return(_entities.SaveChanges() > 0); }