protected void butUpFile_Click(object sender, EventArgs e) { ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile(); uf.ExtensionLim = ".jpe|.jpeg|.jpg|.gif|.png|.tif|.tiff|.bmp"; uf.FileLengthLim = 4000; uf.PostedFile = this.fufile; uf.SavePath = this.path.Value; uf.FileSaveMethod = "d"; if (uf.Upload()) { if (uf.HaveLoad) { this.ltlMsg.Text = "操作成功,上传文件以保存."; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionOk"; } } else { this.ltlMsg.Text = "操作失败," + uf.Message + ""; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionOk"; return; } }
/// <summary> /// 上传商品相册图 /// </summary> /// <param name="albumthumbnail"></param> /// <param name="ImagesThumbnailsWidth"></param> /// <param name="ImagesThumbnailsHeight"></param> /// <param name="WhetherWater"></param> /// <param name="ImageWatermarkTransparent"></param> /// <param name="TextWatermarkTransparent"></param> /// <param name="WatermarkPosition"></param> /// <param name="WatermarkImage"></param> /// <param name="WatermarkText"></param> /// <param name="TextOrImagesWatermark"></param> protected string Album(int ImagesThumbnailsWidth, int ImagesThumbnailsHeight, bool IsModfiy, int ProductId) { ShowShop.Common.SysParameter sp = new ShowShop.Common.SysParameter(); string gomessage = ""; int proId = 0; ShowShop.BLL.Product.ProductInfo bll = new ShowShop.BLL.Product.ProductInfo(); if (IsModfiy) { proId = ProductId; } else { //if (bll.GetMax() == 0) //{ // return gomessage = "相册上传失败"; //} //else //{ // proId = bll.GetMax() + 1; //} } System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; ShowShop.BLL.Product.ProductAlbum pabll = new ShowShop.BLL.Product.ProductAlbum(); ShowShop.Model.Product.ProductAlbum pamodel = new ShowShop.Model.Product.ProductAlbum(); string[] rd = null; string des = ChangeHope.WebPage.PageRequest.GetFormString("description"); if (!string.IsNullOrEmpty(des)) { rd = des.Split(',');//获得图片描述的文本框字符串数组,为对应的图片的描述 } if (files.Count > 1)//说明图片大小和格式都没问题 { ShowShop.BLL.Product.ProductAlbum PGBLL = new ShowShop.BLL.Product.ProductAlbum(); ShowShop.Model.Product.ProductAlbum PGModel = new ShowShop.Model.Product.ProductAlbum(); int autouFile = files.Count; ChangeHope.Common.UploadProcesedImages wm = new ChangeHope.Common.UploadProcesedImages(); ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile(); string AlbumOriginalSave = "/imageFile/product/album"; string AlbumThumbnail = string.Empty; string AlbumOriginal = string.Empty; string Message = string.Empty; uf.ExtensionLim = ".gif,.jpg,.jpeg,.bmp"; uf.FileLengthLim = sp.ImageSize; for (int i = 1; i < files.Count; i++) { uf.MyFile = files[i]; uf.SavePath = AlbumOriginalSave; if (uf.HTMLUpLoad()) { if (uf.HaveLoad) { AlbumOriginal = uf.FilePath; //原图缩略图 wm.SourceImagePath = AlbumOriginal; wm.ThumbnailImagePath = AlbumOriginalSave; wm.ThumbnailImageWidth = ImagesThumbnailsWidth; wm.ThumbnailImageHeight = ImagesThumbnailsHeight; if (wm.ToThumbnailImage()) { AlbumThumbnail = wm.FilePath; } else { gomessage += "<br>" + wm.Message; } } else { gomessage += "<br>" + uf.Message; } } pamodel.Productid = proId; pamodel.OriginalAddress = AlbumOriginal; pamodel.ThumbnailAddress = AlbumThumbnail; pamodel.Description = ""; if (AlbumThumbnail != string.Empty) { pabll.Add(pamodel); } } } return gomessage; }
protected void butSave_Click(object sender, EventArgs e) { ShowShop.BLL.Product.ProductInfo bll = new ShowShop.BLL.Product.ProductInfo(); ShowShop.Model.Product.ProductInfo model = new ShowShop.Model.Product.ProductInfo(); #region 数据准备 model.ProductNo = lb_ProductNo.Text.Trim();//商品编号 model.ProductName = this.txtProductName.Text;//商品名称 model.ProductAttachName = txtProductAttachName.Text.Trim();//附加名称 model.ClassID = this.hfcid.Value != "" ? int.Parse(this.hfcid.Value) : 0;//商品类别Id model.BrandID = Convert.ToInt32(ChangeHope.WebPage.PageRequest.GetFormString("selBrand"));//品牌 model.Unit = ChangeHope.WebPage.PageRequest.GetFormString("selUnit") == "0" ? "" : ChangeHope.WebPage.PageRequest.GetFormString("selUnit");//商品单位 model.MarketPrice = this.txtMarketPrice.Text.Trim() != "" ? Convert.ToDecimal(this.txtMarketPrice.Text.Trim()) : 0;//市场价格 model.ShopPrice = this.txtCostPrice.Text.Trim() != "" ? Convert.ToDecimal(this.txtCostPrice.Text.Trim()) : 0;//商城价格 model.Synopsis = this.txtDescription.Text;//商品简介 model.ProductContent = this.txtContent.Value;//商品明细 model.AutoUp = this.txtFilingTime.Text.Trim() != "" ? Convert.ToDateTime(this.txtFilingTime.Text.Trim()) : System.DateTime.Now;//上架时间 model.AutoDown = this.txtDownTime.Text.Trim() != "" ? Convert.ToDateTime(this.txtDownTime.Text.Trim()) : Convert.ToDateTime("2020-01-01");//下架时间 model.UpdateTime = System.DateTime.Now;//更新时间 model.IsAuto = Convert.ToInt32(rblIsShelves.SelectedValue);//是否上架 #endregion #region 图片 string thumbnailPath = System.Configuration.ConfigurationManager.AppSettings["ImgThumbnailPath"].ToString(); string SavePath = "/imageFile/product/thumbnail"; string thumbnail = string.Empty; if (fuPic.HasFile) { //原图 ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile(); uf.ExtensionLim = ".gif,.jpg,.jpeg,.bmp"; uf.FileLengthLim = 1024; uf.PostedFile = this.fuPic; uf.SavePath = SavePath; if (uf.Upload()) { thumbnail = uf.FilePath; } else { this.ltlMsg.Text = "操作失败," + uf.Message + ""; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionOk"; return; } } model.Thumbnail = thumbnail;//缩略图地址 #endregion if (ViewState["ID"] != null) { ShowShop.Common.PromptInfo.Popedom("001008004", "对不起,您没有编辑权限"); model.ProductID = Convert.ToInt32(ViewState["ID"].ToString()); //相册 string AlbumInfo = Album(100, 100, true, Convert.ToInt32(ViewState["ID"].ToString())); string reStr = string.Empty; ChangeHope.WebPage.BasePage.PageRight("操作成功,您的已修改该商品信息。", "product_list.aspx?q_PutoutType=", "<li>" + reStr + "</li>"); } else { ShowShop.Common.PromptInfo.Popedom("001008002", "对不起,您没有新增权限"); //相册 int productId = bll.Add(model); string AlbumInfo = Album(100, 100, false, productId); string reStr = string.Empty; if (productId > 0) { ChangeHope.WebPage.BasePage.PageRight("操作成功,您的添加的商品信息已保存。", "product_info_edit.aspx?putoutType=", "<li>" + reStr + "</li>"); } else { ChangeHope.WebPage.BasePage.PageError("操作失败,您的添加的商品信息保存失败。", "product_info_edit.aspx?putoutType=", "<li>" + reStr + "</li>"); } } }