예제 #1
0
        /// <summary>
        /// ajaxfileUpload 上传图片
        /// </summary>
        /// <returns></returns>
        protected void UploadPhoto()
        {
            var    flag         = true;
            string originalFile = string.Empty;

            if (HttpContext.Current.Request.Files[0].FileName != string.Empty)
            {
                try
                {
                    //上传文件
                    UploadHelper upload = new UploadHelper();
                    upload.Path     = "/Upload/UserPhoto/Original/";
                    upload.FileType = ShopConfig.ReadConfigInfo().UploadFile;
                    FileInfo file = upload.SaveAs();
                    //生成处理
                    originalFile = upload.Path + file.Name;
                    string otherFile          = string.Empty;
                    string makeFile           = string.Empty;
                    Dictionary <int, int> dic = new Dictionary <int, int>();
                    dic.Add(70, 70);
                    dic.Add(190, 190);
                    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);
                    //保存数据库
                    UploadInfo tempUpload = new UploadInfo();
                    tempUpload.TableID    = UserBLL.TableID;
                    tempUpload.ClassID    = 0;
                    tempUpload.RecordID   = 0;
                    tempUpload.UploadName = originalFile;
                    tempUpload.OtherFile  = otherFile;
                    tempUpload.Size       = Convert.ToInt32(file.Length);
                    tempUpload.FileType   = file.Extension;
                    tempUpload.Date       = RequestHelper.DateNow;
                    tempUpload.IP         = ClientHelper.IP;
                    UploadBLL.AddUpload(tempUpload);
                }
                catch (Exception ex)
                {
                    ExceptionHelper.ProcessException(ex, false);
                }
            }
            if (!string.IsNullOrEmpty(originalFile))
            {
                flag = true;
            }
            else
            {
                flag = false;
            }
            //return originalFile;
            Response.Clear();
            Response.Write(JsonConvert.SerializeObject(new { flag = flag, imgPath = originalFile }));
            Response.End();
        }
예제 #2
0
 protected void SubmitButton_Click(object sender, EventArgs e)
 {
     try
     {
         UploadHelper helper = new UploadHelper();
         helper.Path         = "/Upload/ProductPhoto/Original/" + RequestHelper.DateNow.ToString("yyyyMM") + "/";
         helper.FileNameType = FileNameType.Guid;
         helper.FileType     = ShopConfig.ReadConfigInfo().UploadFile;
         FileInfo  info      = helper.SaveAs();
         string    filePath  = helper.Path + info.Name;
         string    str2      = string.Empty;
         string    str3      = string.Empty;
         Hashtable hashtable = new Hashtable();
         hashtable.Add("60", "60");
         hashtable.Add("340", "340");
         foreach (DictionaryEntry entry in hashtable)
         {
             str3 = filePath.Replace("Original", entry.Key + "-" + entry.Value);
             str2 = str2 + str3 + "|";
             ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(filePath), ServerHelper.MapPath(str3), Convert.ToInt32(entry.Key), Convert.ToInt32(entry.Value), ThumbnailType.InBox);
         }
         str2 = str2.Substring(0, str2.Length - 1);
         ResponseHelper.Write("<script>window.parent.addProductPhoto('" + filePath.Replace("Original", "340-340") + "','" + this.Name.Text + "');</script>");
         UploadInfo upload = new UploadInfo();
         upload.TableID      = ProductPhotoBLL.TableID;
         upload.ClassID      = 0;
         upload.RecordID     = 0;
         upload.UploadName   = filePath;
         upload.OtherFile    = str2;
         upload.Size         = Convert.ToInt32(info.Length);
         upload.FileType     = info.Extension;
         upload.RandomNumber = Cookies.Admin.GetRandomNumber(false);
         upload.Date         = RequestHelper.DateNow;
         upload.IP           = ClientHelper.IP;
         UploadBLL.AddUpload(upload);
     }
     catch (Exception exception)
     {
         ExceptionHelper.ProcessException(exception, false);
     }
 }
예제 #3
0
        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"));
            }
        }
예제 #4
0
        /// <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"));
            }
        }
예제 #5
0
        protected void UploadImage(object sender, EventArgs e)
        {
            string queryString   = RequestHelper.GetQueryString <string>("Control");
            int    num           = RequestHelper.GetQueryString <int>("TableID");
            string directoryName = RequestHelper.GetQueryString <string>("FilePath");
            string uploadFile    = ShopConfig.ReadConfigInfo().UploadFile;

            if (FileHelper.SafeFullDirectoryName(directoryName))
            {
                //try
                {
                    UploadHelper helper = new UploadHelper();
                    helper.Path         = "/Upload/" + directoryName + "/" + RequestHelper.DateNow.ToString("yyyyMM") + "/";
                    helper.FileType     = uploadFile;
                    helper.FileNameType = FileNameType.Guid;
                    FileInfo info     = helper.SaveAs();
                    string   filePath = helper.Path + info.Name;
                    string   str5     = string.Empty;
                    string   str6     = string.Empty;
                    Dictionary <int, int> dictionary = new Dictionary <int, int>();
                    if (num == ProductBLL.TableID)
                    {
                        dictionary.Add(60, 60);
                        dictionary.Add(120, 120);
                        dictionary.Add(340, 340);
                    }
                    else if (num == ProductBrandBLL.TableID)
                    {
                        dictionary.Add(0x58, 0x1f);
                    }
                    else if (num == LinkBLL.TableID)
                    {
                        dictionary.Add(0x58, 0x1f);
                    }
                    else if (num == StandardBLL.TableID)
                    {
                        dictionary.Add(0x19, 0x19);
                    }
                    else if (num == ThemeActivityBLL.TableID)
                    {
                        dictionary.Add(300, 150);
                    }
                    else if (num == GiftPackBLL.TableID)
                    {
                        dictionary.Add(150, 60);
                    }
                    else if (num == FavorableActivityBLL.TableID)
                    {
                        dictionary.Add(300, 120);
                    }
                    else if (num == GiftBLL.TableID)
                    {
                        dictionary.Add(100, 100);
                    }
                    if (dictionary.Count > 0)
                    {
                        foreach (KeyValuePair <int, int> pair in dictionary)
                        {
                            str6 = filePath.Replace("Original", pair.Key.ToString() + "-" + pair.Value.ToString());
                            str5 = str5 + str6 + "|";
                            ImageHelper.MakeThumbnailImage(ServerHelper.MapPath(filePath), ServerHelper.MapPath(str6), pair.Key, pair.Value, ThumbnailType.InBox);
                        }
                        str5 = str5.Substring(0, str5.Length - 1);
                    }
                    ResponseHelper.Write("<script> window.parent.o('" + base.IDPrefix + queryString + "').value='" + filePath + "';</script>");
                    UploadInfo upload = new UploadInfo();
                    upload.TableID      = num;
                    upload.ClassID      = 0;
                    upload.RecordID     = 0;
                    upload.UploadName   = filePath;
                    upload.OtherFile    = str5;
                    upload.Size         = Convert.ToInt32(info.Length);
                    upload.FileType     = info.Extension;
                    upload.RandomNumber = Cookies.Admin.GetRandomNumber(false);
                    upload.Date         = RequestHelper.DateNow;
                    upload.IP           = ClientHelper.IP;
                    UploadBLL.AddUpload(upload);
                }
                //catch (Exception exception)
                //{
                //    ExceptionHelper.ProcessException(exception, false);
                //}
            }
            else
            {
                ScriptHelper.Alert(ShopLanguage.ReadLanguage("ErrorPathName"));
            }
        }
예제 #6
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Upload(object sender, EventArgs e)
        {
            //取得传递值
            string control  = RequestHelper.GetQueryString <string>("Control");
            int    tableID  = RequestHelper.GetQueryString <int>("TableID");
            string filePath = RequestHelper.GetQueryString <string>("FilePath");
            string fileType = RequestHelper.GetQueryString <string>("FileType");

            if (!string.IsNullOrEmpty(fileType))
            {
                if (fileType == "Image")
                {
                    fileType = ShopConfig.ReadConfigInfo().UploadImage;
                }
                else
                {
                    fileType = ShopConfig.ReadConfigInfo().UploadFile;
                }
            }
            else
            {
                fileType = ShopConfig.ReadConfigInfo().UploadFile;
            }
            if (FileHelper.SafeFullDirectoryName(filePath))
            {
                try
                {
                    //上传文件
                    UploadHelper upload = new UploadHelper();
                    upload.Path         = "/Upload/" + filePath + "/" + RequestHelper.DateNow.ToString("yyyyMM") + "/";
                    upload.FileType     = fileType;
                    upload.FileNameType = FileNameType.Guid;
                    FileInfo 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 == UserBLL.TableID)
                    {
                        dic.Add(150, 150);
                    }
                    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.AllFix);
                        }
                        otherFile = otherFile.Substring(0, otherFile.Length - 1);
                    }

                    string script = "<script> window.parent.o('" + control + "').value='" + originalFile + "';var warningMessageObj = window.parent.o('" + control + "WarningMessage'); (typeof warningMessageObj.textContent == 'string') ? warningMessageObj.textContent='上传成功。' : warningMessageObj.innerText='上传成功。';window.parent.triggerValidate('" + control + "');";
                    if (RequestHelper.GetQueryString <string>("Required") == "1")
                    {
                        script += "window.parent.o('Check" + control + "').value='1';";
                    }
                    script += "</script>";

                    ResponseHelper.Write(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);
                }
            }
            else
            {
                ScriptHelper.Alert(ShopLanguage.ReadLanguage("ErrorPathName"));
            }
        }