Ejemplo n.º 1
0
        /// <summary>
        /// 添加产品图片
        /// </summary>
        /// <param name="productID"></param>
        protected void AddProductPhoto(int productID)
        {
            string productPhotoList = RequestHelper.GetForm <string>("ProductPhoto");

            if (productPhotoList != string.Empty)
            {
                foreach (string temp in productPhotoList.Split(','))
                {
                    ProductPhotoInfo productPhoto = new ProductPhotoInfo();
                    productPhoto.ProductId = productID;
                    productPhoto.Name      = temp.Split('|')[0];
                    productPhoto.ImageUrl  = temp.Split('|')[1];
                    ProductPhotoBLL.Add(productPhoto);
                }
            }
        }
Ejemplo n.º 2
0
        protected void AddProductPhoto(int productId)
        {
            string productPhotoList = RequestHelper.GetForm <string>("ProductPhoto");

            if (!string.IsNullOrEmpty(productPhotoList))
            {
                foreach (string temp in productPhotoList.Split(','))
                {
                    ProductPhotoInfo productPhoto = new ProductPhotoInfo();
                    productPhoto.ProductId = productId;
                    productPhoto.Name      = temp.Split('|')[0];
                    productPhoto.ImageUrl  = temp.Split('|')[1].Replace("75-75", "Original");
                    ProductPhotoBLL.Add(productPhoto);
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult UploadImage()
        {
            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;

                    //前台上传图片不打水印直接保存
                    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 (!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.GetForm <int>("proStyle");
                    if (proStyle < 0)
                    {
                        proStyle = 0;
                    }

                    int pcid = RequestHelper.GetForm <int>("pcid");
                    ProductPhotoInfo productPhoto = new ProductPhotoInfo();
                    productPhoto.ProductId = pcid;
                    productPhoto.ImageUrl  = originalFile;
                    productPhoto.ProStyle  = proStyle;
                    productPhoto.OrderId   = 0;

                    ProductPhotoBLL.Add(productPhoto);
                    return(Content("ok|" + originalFile.Replace("Original", "75-75")));
                }
                catch (Exception ex)
                {
                    return(Content(ex.Message));
                }
            }
            else
            {
                return(Content(ShopLanguage.ReadLanguage("ErrorPathName")));
            }
        }
Ejemplo n.º 4
0
        protected void ImportProducts(object sender, EventArgs e)
        {
            string categoryId    = ProductClass.ClassID;
            int    saleStatus    = Convert.ToInt32(IsSale.SelectedValue);
            string selectedValue = dropFiles.SelectedValue;

            selectedValue = Path.Combine(_dataPath, selectedValue);

            if (!File.Exists(selectedValue))
            {
                ScriptHelper.Alert("选择的数据包文件有问题!");
            }
            else
            {
                PrepareDataFiles(new object[] { selectedValue });
                string    path        = Path.Combine(_dataPath, Path.GetFileNameWithoutExtension(selectedValue));
                DataTable productData = (DataTable)ProductBLL.ParseProductData(new object[] { path })[0];
                if ((productData != null) && (productData.Rows.Count > 0))
                {
                    foreach (DataRow row in productData.Rows)
                    {
                        ProductInfo product = new ProductInfo
                        {
                            ClassId       = categoryId,
                            Name          = (string)row["ProductName"],
                            ProductNumber = (string)row["SKU"],
                            BrandId       = 0
                        };
                        if (row["Description"] != DBNull.Value)
                        {
                            product.Introduction1 = (string)row["Description"];
                        }
                        product.AddDate           = DateTime.Now;
                        product.IsSale            = saleStatus;
                        product.MarketPrice       = (decimal)row["SalePrice"];
                        product.TotalStorageCount = (int)row["Stock"];

                        product.Spelling  = ChineseCharacterHelper.GetFirstLetter((string)row["ProductName"]);
                        product.SendPoint = 0;
                        product.Weight    = 0;
                        product.IsSpecial = 0;
                        product.IsNew     = 0;
                        product.IsHot     = 0;
                        if (row["Has_ShowCase"] != DBNull.Value)
                        {
                            product.IsTop = Convert.ToInt32(row["Has_ShowCase"]);
                        }
                        product.AllowComment = 0;
                        product.LowerCount   = 0;
                        product.UpperCount   = 0;
                        product.StandardType = 0;
                        product.AddDate      = RequestHelper.DateNow;

                        product.OrderId   = 0;
                        product.SalePrice = (decimal)row["SalePrice"];

                        if (row["ImageUrl1"] != DBNull.Value)
                        {
                            product.Photo = (string)row["ImageUrl1"];
                        }

                        int proID = ProductBLL.Add(product);
                        #region 生成缩略图和产品相册图
                        if (!(string.IsNullOrEmpty(product.Photo) || (product.Photo.Length <= 0)))
                        {
                            UploadImage(product.Photo, PhotoType.Product);
                        }

                        if (row["ImageUrl2"] != DBNull.Value)
                        {
                            ProductPhotoInfo tempPhoto = new ProductPhotoInfo()
                            {
                                ProductId = proID,
                                Name      = "ImageUrl2",
                                ImageUrl  = (string)row["ImageUrl2"],
                                AddDate   = DateTime.Now
                            };
                            ProductPhotoBLL.Add(tempPhoto);
                            UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto);
                        }
                        if (row["ImageUrl3"] != DBNull.Value)
                        {
                            ProductPhotoInfo tempPhoto = new ProductPhotoInfo()
                            {
                                ProductId = proID,
                                Name      = "ImageUrl3",
                                ImageUrl  = (string)row["ImageUrl3"],
                                AddDate   = DateTime.Now
                            };
                            ProductPhotoBLL.Add(tempPhoto);
                            UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto);
                        }
                        if (row["ImageUrl4"] != DBNull.Value)
                        {
                            ProductPhotoInfo tempPhoto = new ProductPhotoInfo()
                            {
                                ProductId = proID,
                                Name      = "ImageUrl4",
                                ImageUrl  = (string)row["ImageUrl4"],
                                AddDate   = DateTime.Now
                            };
                            ProductPhotoBLL.Add(tempPhoto);
                            UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto);
                        }
                        if (row["ImageUrl5"] != DBNull.Value)
                        {
                            ProductPhotoInfo tempPhoto = new ProductPhotoInfo()
                            {
                                ProductId = proID,
                                Name      = "ImageUrl5",
                                ImageUrl  = (string)row["ImageUrl5"],
                                AddDate   = DateTime.Now
                            };
                            ProductPhotoBLL.Add(tempPhoto);
                            UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto);
                        }
                        #endregion
                    }

                    File.Delete(selectedValue);
                    Directory.Delete(path, true);
                    BindFiles();
                    ScriptHelper.Alert("此次商品批量导入操作已成功!", RequestHelper.RawUrl);
                }
            }
        }