/// <summary> /// 提交按钮点击方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SubmitButton_Click(object sender, EventArgs e) { PhotoSizeInfo photoSize = new PhotoSizeInfo(); photoSize.Id = RequestHelper.GetQueryString <int>("ID"); int photoType = (int)PhotoType.Article; if (!int.TryParse(Type.SelectedValue, out photoType)) { photoType = (int)PhotoType.Article; } photoSize.Type = photoType; photoSize.Title = Title.Text; photoSize.Introduce = Introduce.Text; photoSize.Width = Convert.ToInt32(Width.Text) < 0 ? 0 : Convert.ToInt32(Width.Text); photoSize.Height = Convert.ToInt32(Height.Text) < 0 ? 0 : Convert.ToInt32(Height.Text); string alertMessage = ShopLanguage.ReadLanguage("AddOK"); if (photoSize.Id == int.MinValue) { CheckAdminPower("AddPhotoSize", PowerCheckType.Single); int id = PhotoSizeBLL.Add(photoSize); AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("PhotoSize"), id); } else { CheckAdminPower("UpdatePhotoSize", PowerCheckType.Single); PhotoSizeBLL.Update(photoSize); AdminLogBLL.Add(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("PhotoSize"), photoSize.Id); alertMessage = ShopLanguage.ReadLanguage("UpdateOK"); } ScriptHelper.Alert(alertMessage, "photosize.aspx"); }
/// <summary> /// 页面加载方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { int ID = RequestHelper.GetQueryString <int>("ID"); if (ID != int.MinValue) { CheckAdminPower("ReadPhotoSize", PowerCheckType.Single); PhotoSizeInfo photoSize = PhotoSizeBLL.Read(ID); Type.Text = photoSize.Type.ToString(); Title.Text = photoSize.Title; Introduce.Text = photoSize.Introduce; Width.Text = photoSize.Width.ToString(); Height.Text = photoSize.Height.ToString(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckAdminPower("ReadPhotoSize", PowerCheckType.Single); string action = RequestHelper.GetQueryString <string>("Action"); int type = RequestHelper.GetQueryString <int>("photoType"); Type.Text = type.ToString(); if (action == "Delete") { CheckAdminPower("DeletePhotoSize", PowerCheckType.Single); int id = RequestHelper.GetQueryString <int>("Id"); if (id > 0) { PhotoSizeBLL.Delete(id); AdminLogBLL.Add(ShopLanguage.ReadLanguage("DeleteRecord"), ShopLanguage.ReadLanguage("PhotoSize"), id); //ScriptHelper.Alert(ShopLanguage.ReadLanguage("DeleteOK"), RequestHelper.RawUrl); } } BindControl(PhotoSizeBLL.SearchList(type, CurrentPage, PageSize, ref Count), RecordList, MyPager); } }
protected void UploadImage(object sender, EventArgs e) { //取得传递值 string control = RequestHelper.GetQueryString <string>("Control"); int tableID = RequestHelper.GetQueryString <int>("TableID"); string filePath = RequestHelper.GetQueryString <string>("FilePath"); string fileType = ShopConfig.ReadConfigInfo().UploadImage; if (FileHelper.SafeFullDirectoryName(filePath)) { try { //上传文件 UploadHelper upload = new UploadHelper(); upload.Path = "/Upload/" + filePath + "/" + RequestHelper.DateNow.ToString("yyyyMM") + "/"; upload.FileType = fileType; upload.FileNameType = FileNameType.Guid; upload.MaxWidth = ShopConfig.ReadConfigInfo().AllImageWidth; //整站图片压缩开启后的压缩宽度 upload.AllImageIsNail = ShopConfig.ReadConfigInfo().AllImageIsNail; //整站图片压缩开关 int needNail = RequestHelper.GetQueryString <int>("NeedNail"); if (needNail == 0) { upload.AllImageIsNail = 0; //如果页面有传值且值为0不压缩图片,以页面传值为准; } int curMaxWidth = RequestHelper.GetQueryString <int>("CurMaxWidth"); //页面传值最大宽度 if (curMaxWidth > 0) { upload.AllImageIsNail = 1; upload.MaxWidth = curMaxWidth;//如果有页面传值设置图片最大宽度,以页面传值为准 } FileInfo file = null; int waterType = ShopConfig.ReadConfigInfo().WaterType; if (waterType == 2 || waterType == 3) { string needMark = RequestHelper.GetQueryString <string>("NeedMark"); if (needMark == string.Empty || needMark == "1") { int waterPossition = ShopConfig.ReadConfigInfo().WaterPossition; string text = ShopConfig.ReadConfigInfo().Text; string textFont = ShopConfig.ReadConfigInfo().TextFont; int textSize = ShopConfig.ReadConfigInfo().TextSize; string textColor = ShopConfig.ReadConfigInfo().TextColor; string waterPhoto = Server.MapPath(ShopConfig.ReadConfigInfo().WaterPhoto); file = upload.SaveAs(waterType, waterPossition, text, textFont, textSize, textColor, waterPhoto); } else if (needMark == "0") { file = upload.SaveAs(); } } else { file = upload.SaveAs(); } //生成处理 string originalFile = upload.Path + file.Name; string otherFile = string.Empty; string makeFile = string.Empty; Dictionary <int, int> dic = new Dictionary <int, int>(); if (tableID == ProductBLL.TableID) { foreach (var phototype in PhotoSizeBLL.SearchList((int)PhotoType.Product)) { dic.Add(phototype.Width, phototype.Height); } if (!dic.ContainsKey(90)) { dic.Add(90, 90); //后台商品列表默认使用尺寸(如果不存在则手动添加) } } else if (tableID == ProductBrandBLL.TableID) { dic.Add(88, 31); } else if (tableID == ThemeActivityBLL.TableID) { dic.Add(300, 150); } else if (tableID == ArticleBLL.TableID) { foreach (var phototype in PhotoSizeBLL.SearchList((int)PhotoType.Article)) { dic.Add(phototype.Width, phototype.Height); } } else if (tableID == FavorableActivityGiftBLL.TableID) { dic.Add(100, 100); } else { } if (dic.Count > 0) { foreach (KeyValuePair <int, int> kv in dic) { makeFile = originalFile.Replace("Original", kv.Key.ToString() + "-" + kv.Value.ToString()); otherFile += makeFile + "|"; ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(originalFile), ServerHelper.MapPath(makeFile), kv.Key, kv.Value, ThumbnailType.InBox); } otherFile = otherFile.Substring(0, otherFile.Length - 1); } ResponseHelper.Write("<script>alert('上传成功'); window.parent.o('" + IDPrefix + control + "').value='" + originalFile + "';if(window.parent.o('img_" + control + "')){window.parent.o('img_" + control + "').src='" + originalFile + "';};if(window.parent.o('imgurl_" + control + "')){window.parent.o('imgurl_" + control + "').href='" + originalFile + "';window.parent.o('imgurl_" + control + "').target='_blank'}</script>"); //保存数据库 UploadInfo tempUpload = new UploadInfo(); tempUpload.TableID = tableID; tempUpload.ClassID = 0; tempUpload.RecordID = 0; tempUpload.UploadName = originalFile; tempUpload.OtherFile = otherFile; tempUpload.Size = Convert.ToInt32(file.Length); tempUpload.FileType = file.Extension; tempUpload.RandomNumber = Cookies.Admin.GetRandomNumber(false); tempUpload.Date = RequestHelper.DateNow; tempUpload.IP = ClientHelper.IP; UploadBLL.AddUpload(tempUpload); } catch (Exception ex) { //ExceptionHelper.ProcessException(ex, false); ResponseHelper.Write("<script>alert('" + ex.Message + "'); </script>"); } } else { ScriptHelper.Alert(ShopLanguage.ReadLanguage("ErrorPathName")); } }
/// <summary> /// 提交按钮点击方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SubmitButton_Click(object sender, EventArgs e) { //try //{ //上传文件 //UploadHelper upload = new UploadHelper(); //upload.Path = "/Upload/ProductPhoto/Original/" + RequestHelper.DateNow.ToString("yyyyMM") + "/"; //upload.FileNameType = FileNameType.Guid; //upload.FileType = ShopConfig.ReadConfigInfo().UploadFile; //FileInfo file = upload.SaveAs(); string filePath = "/Upload/ProductPhoto/Original/" + RequestHelper.DateNow.ToString("yyyyMM") + "/"; if (FileHelper.SafeFullDirectoryName(filePath)) { try { //上传文件 UploadHelper upload = new UploadHelper(); upload.Path = "/Upload/ProductPhoto/Original/" + RequestHelper.DateNow.ToString("yyyyMM") + "/"; upload.FileType = ShopConfig.ReadConfigInfo().UploadFile; upload.FileNameType = FileNameType.Guid; upload.MaxWidth = ShopConfig.ReadConfigInfo().AllImageWidth; //整站图片压缩开启后的压缩宽度 upload.AllImageIsNail = ShopConfig.ReadConfigInfo().AllImageIsNail; //整站图片压缩开关 int needNail = RequestHelper.GetQueryString <int>("NeedNail"); if (needNail <= 0) { upload.AllImageIsNail = 0; //如果页面传值不压缩图片,以页面传值为准; } int curMaxWidth = RequestHelper.GetQueryString <int>("CurMaxWidth"); //页面传值最大宽度 if (curMaxWidth > 0) { upload.AllImageIsNail = 1; upload.MaxWidth = curMaxWidth;//如果有页面传值设置图片最大宽度,以页面传值为准 } FileInfo file = null; int waterType = ShopConfig.ReadConfigInfo().WaterType; if (waterType == 2 || waterType == 3) { string needMark = RequestHelper.GetQueryString <string>("NeedMark"); if (needMark == string.Empty || needMark == "1") { int waterPossition = ShopConfig.ReadConfigInfo().WaterPossition; string text = ShopConfig.ReadConfigInfo().Text; string textFont = ShopConfig.ReadConfigInfo().TextFont; int textSize = ShopConfig.ReadConfigInfo().TextSize; string textColor = ShopConfig.ReadConfigInfo().TextColor; string waterPhoto = Server.MapPath(ShopConfig.ReadConfigInfo().WaterPhoto); file = upload.SaveAs(waterType, waterPossition, text, textFont, textSize, textColor, waterPhoto); } else if (needMark == "0") { file = upload.SaveAs(); } } else { file = upload.SaveAs(); } //生成处理 string originalFile = upload.Path + file.Name; string otherFile = string.Empty; string makeFile = string.Empty; //Hashtable ht = new Hashtable(); //ht.Add("60", "60"); //ht.Add("90", "60"); //ht.Add("240", "180"); //ht.Add("340", "340"); //ht.Add("418", "313"); Dictionary <int, int> dic = new Dictionary <int, int>(); foreach (var phototype in PhotoSizeBLL.SearchList((int)PhotoType.ProductPhoto)) { dic.Add(phototype.Width, phototype.Height); } if (!dic.ContainsKey(75)) { dic.Add(75, 75); //后台商品图集默认使用尺寸(如果不存在则手动添加) } foreach (KeyValuePair <int, int> de in dic) { makeFile = originalFile.Replace("Original", de.Key + "-" + de.Value); otherFile += makeFile + "|"; ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(originalFile), ServerHelper.MapPath(makeFile), Convert.ToInt32(de.Key), Convert.ToInt32(de.Value), ThumbnailType.AllFix); } otherFile = otherFile.Substring(0, otherFile.Length - 1); int proStyle = RequestHelper.GetQueryString <int>("proStyle"); if (proStyle < 0) { proStyle = 0; } ResponseHelper.Write("<script>window.parent.addProductPhoto('" + originalFile.Replace("Original", "75-75") + "','" + Name.Text + "','" + proStyle + "');</script>"); //保存数据库 UploadInfo tempUpload = new UploadInfo(); tempUpload.TableID = ProductPhotoBLL.TableID; tempUpload.ClassID = 0; tempUpload.RecordID = 0; tempUpload.UploadName = originalFile; tempUpload.OtherFile = otherFile; tempUpload.Size = Convert.ToInt32(file.Length); tempUpload.FileType = file.Extension; tempUpload.RandomNumber = Cookies.Admin.GetRandomNumber(false); tempUpload.Date = RequestHelper.DateNow; tempUpload.IP = ClientHelper.IP; UploadBLL.AddUpload(tempUpload); } catch (Exception ex) { //ExceptionHelper.ProcessException(ex, false); ResponseHelper.Write("<script>alert('" + ex.Message + "'); </script>"); } } else { ScriptHelper.Alert(ShopLanguage.ReadLanguage("ErrorPathName")); } }
protected void UploadImage(string fileName, PhotoType photoType) { //取得传递值 string fileType = ShopConfig.ReadConfigInfo().UploadImage; try { //上传文件 UploadHelper upload = new UploadHelper(); upload.Path = _photoPath + "/Original/"; upload.FileType = fileType; upload.FileNameType = FileNameType.Guid; upload.MaxWidth = ShopConfig.ReadConfigInfo().AllImageWidth; //整站图片压缩开启后的压缩宽度 upload.AllImageIsNail = ShopConfig.ReadConfigInfo().AllImageIsNail; //整站图片压缩开关 int needNail = RequestHelper.GetQueryString <int>("NeedNail"); if (needNail == 0) { upload.AllImageIsNail = 0; //如果页面有传值且值为0则不压缩图片,以页面传值为准; } int curMaxWidth = RequestHelper.GetQueryString <int>("CurMaxWidth"); //页面传值最大宽度 if (curMaxWidth > 0) { upload.AllImageIsNail = 1; upload.MaxWidth = curMaxWidth;//如果有页面传值设置图片最大宽度,以页面传值为准 } FileInfo file = null; int waterType = ShopConfig.ReadConfigInfo().WaterType; if (waterType == 2 || waterType == 3) { string needMark = RequestHelper.GetQueryString <string>("NeedMark"); if (needMark == string.Empty || needMark == "1") { int waterPossition = ShopConfig.ReadConfigInfo().WaterPossition; string text = ShopConfig.ReadConfigInfo().Text; string textFont = ShopConfig.ReadConfigInfo().TextFont; int textSize = ShopConfig.ReadConfigInfo().TextSize; string textColor = ShopConfig.ReadConfigInfo().TextColor; string waterPhoto = Server.MapPath(ShopConfig.ReadConfigInfo().WaterPhoto); file = upload.SaveFromTaobao(waterType, waterPossition, text, textFont, textSize, textColor, waterPhoto, fileName); } else if (needMark == "0") { file = upload.SaveFromTaobao(fileName); } } else { file = upload.SaveFromTaobao(fileName); } //生成处理 string originalFile = fileName; string otherFile = string.Empty; string makeFile = string.Empty; Dictionary <int, int> dic = new Dictionary <int, int>(); foreach (var phototype in PhotoSizeBLL.SearchList((int)photoType)) { dic.Add(phototype.Width, phototype.Height); } if (!dic.ContainsKey(90)) { dic.Add(90, 90); //后台商品列表默认使用尺寸(如果不存在则手动添加) } if (!dic.ContainsKey(75)) { dic.Add(75, 75); //后台商品图集默认使用尺寸(如果不存在则手动添加) } if (dic.Count > 0) { foreach (KeyValuePair <int, int> kv in dic) { makeFile = originalFile.Replace("Original", kv.Key.ToString() + "-" + kv.Value.ToString()); otherFile += makeFile + "|"; ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(originalFile), ServerHelper.MapPath(makeFile), kv.Key, kv.Value, ThumbnailType.InBox); } otherFile = otherFile.Substring(0, otherFile.Length - 1); } } catch (Exception ex) { ExceptionHelper.ProcessException(ex, false); } }
/// <summary> /// 从图片中截取部分生成新图 /// </summary> /// <param name="sFromFilePath">原始图片</param> /// <param name="saveFilePath">生成新图</param> /// <param name="width">截取图片宽度</param> /// <param name="height">截取图片高度</param> /// <param name="spaceX">截图图片X坐标</param> /// <param name="spaceY">截取图片Y坐标</param> public void CaptureImage(string sFromFilePath, string saveFilePath, int width, int height, int spaceX, int spaceY, string tarimg, string targetID) { //载入底图 System.Drawing.Image fromImage = System.Drawing.Image.FromFile(sFromFilePath); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height); //创建作图区域 System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bitmap); //截取原图相应区域写入作图区 graphic.DrawImage(fromImage, new System.Drawing.Rectangle(0, 0, width, height), new System.Drawing.Rectangle(spaceX, spaceY, width, height), System.Drawing.GraphicsUnit.Pixel); //从作图区生成新图 System.Drawing.Image saveImage = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap()); //保存图象 saveImage.Save(saveFilePath, ImageFormat.Jpeg); bitmap.Dispose(); graphic.Dispose(); saveImage.Dispose(); fromImage.Dispose(); //string delTarget = tarimg.Replace("nail.", "."); //FileHelper.DeleteFile(new List<string> { delTarget });//删除原图 FileHelper.DeleteFile(new List <string> { tarimg }); //删除原图 string delTarget = saveFilePath.Replace(Server.MapPath("/"), ""); //FileInfo fileInfo = new FileInfo(saveFilePath); //fileInfo.MoveTo(sFromFilePath); if (makeNail == 1)//是否需要生成缩略图 { string makeFile = string.Empty; //if (targetType == 0) //{ Dictionary <int, int> dic = new Dictionary <int, int>(); if (tableID == ProductBLL.TableID) { foreach (var phototype in PhotoSizeBLL.SearchList((int)PhotoType.Product)) { dic.Add(phototype.Width, phototype.Height); } if (!dic.ContainsKey(90)) { dic.Add(90, 90); //后台商品列表默认使用尺寸(如果不存在则手动添加) } } else if (tableID == ProductBrandBLL.TableID) { dic.Add(88, 31); } else if (tableID == ThemeActivityBLL.TableID) { dic.Add(300, 150); } else if (tableID == ArticleBLL.TableID) { dic.Add(90, 90); //后台列表缩略图 dic.Add(200, 150); //前台列表缩略图 } else if (tableID == ProductPhotoBLL.TableID) { foreach (var phototype in PhotoSizeBLL.SearchList((int)PhotoType.ProductPhoto)) { dic.Add(phototype.Width, phototype.Height); } if (!dic.ContainsKey(75)) { dic.Add(75, 75); //后台商品图集默认使用尺寸(如果不存在则手动添加) } } if (dic.Count > 0) { foreach (KeyValuePair <int, int> kv in dic) { //string nailStr = delTarget.Replace("Original", kv.Key.ToString() + "-" + kv.Value.ToString()); string nailStr = tarimg.Replace("Original", kv.Key.ToString() + "-" + kv.Value.ToString()); FileHelper.DeleteFile(new List <string> { nailStr }); //删除原有缩略图 //makeFile = nailStr; makeFile = delTarget.Replace("Original", kv.Key.ToString() + "-" + kv.Value.ToString()); ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(delTarget), ServerHelper.MapPath(makeFile), kv.Key, kv.Value, ThumbnailType.InBox); } } //} //else //{ // Hashtable ht = new Hashtable(); // if (tableID == ProductPhotoBLL.TableID) // { // foreach (var phototype in PhotoSizeBLL.SearchList((int)PhotoType.ProductPhoto)) // { // ht.Add(phototype.Width, phototype.Height); // } // if (!ht.ContainsKey(75)) ht.Add(75, 75);//后台商品图集默认使用尺寸(如果不存在则手动添加) // } // else // { // ht.Add("75", "75"); // ht.Add("350", "350"); // } // foreach (DictionaryEntry de in ht) // { // string nailStr = delTarget.Replace("Original", de.Key + "-" + de.Value); // FileHelper.DeleteFile(new List<string> { nailStr });//删除原有缩略图 // makeFile = nailStr; // ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(delTarget), ServerHelper.MapPath(makeFile), Convert.ToInt32(de.Key), Convert.ToInt32(de.Value), ThumbnailType.InBox); // } //} } //parent.layer.close(index); string strp_img2 = saveFilePath.Substring(saveFilePath.LastIndexOf('/'), saveFilePath.Length - saveFilePath.LastIndexOf('/')); if (targetType == 1)//产品多图 { if (ProductID <= 0) {//添加 //Response.Write("<script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name); parent.$('#" + targetID + ">img').attr('src','" + delTarget + "'); parent.layer.close(index);</script>"); string _str = "<script type='text/javascript' src='/Admin/Js/jquery-1.7.2.min.js'></script><script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.editProductPhoto('" + targetID + "', '" + delTarget + "', '" + ProductPhotoID + "');parent.layer.close(index);</script>"; //Response.Write("<script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.o('" + targetID + "').firstChild.src='" + delTarget + "';window.parent.o('" + targetID + "').getElementsByName('ProductPhoto')[0].value='" + _name + "|" + delTarget + "' ; parent.layer.close(index);</script>"); Response.Write("<script type='text/javascript' src='/Admin/Js/jquery-1.7.2.min.js'></script><script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.editProductPhoto('" + targetID + "', '" + delTarget + "', '" + ProductPhotoID + "');parent.layer.close(index);</script>"); } else { ProductPhotoInfo productPhoto = ProductPhotoBLL.Read(ProductPhotoID, ProStyle); productPhoto.ImageUrl = delTarget; ProductPhotoBLL.Update(productPhoto); string _str = "<script type='text/javascript' src='/Admin/Js/jquery-1.7.2.min.js'></script><script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.editProductPhoto('" + targetID + "', '" + delTarget + "', '" + ProductPhotoID + "');parent.layer.close(index);</script>"; //Response.Write("<script type='text/javascript' src='/Admin/Js/jquery-1.7.2.min.js'></script><script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.o('" + targetID + "').firstChild.src='" + delTarget + "';$('#" + targetID + "').find('.cut').attr('href','javascript:loadCut(\"" + delTarget + "\",\"" + targetID + "\",\"" + ProductPhotoID + "\")');parent.layer.close(index);</script>"); Response.Write("<script type='text/javascript' src='/Admin/Js/jquery-1.7.2.min.js'></script><script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.editProductPhoto('" + targetID + "', '" + delTarget + "', '" + ProductPhotoID + "');parent.layer.close(index);</script>"); } } else { Response.Write("<script>alert('裁剪成功');var index = parent.layer.getFrameIndex(window.name);window.parent.o('" + targetID + "').value='" + delTarget + "';window.parent.o('firstPhoto').src='" + delTarget + "';parent.layer.close(index); </script>"); } }