/// <summary>
        /// 创建商品与图片关联信息
        /// </summary>
        /// <param name="productImageEntity"></param>
        public static void CreateProductCommonInfoImage(ProductGroupInfoImageEntity productImageEntity, string commonSKUNumber)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("CreateProductCommonInfoImage");

            cmd.SetParameterValue("@ProductGroupImageSysno", productImageEntity.SysNo);
            cmd.SetParameterValue("@ProductGroupSysNo", productImageEntity.ProductGroupSysno);
            cmd.SetParameterValue("@CommonSKUNumber", commonSKUNumber);
            cmd.SetParameterValue("@InUser", productImageEntity.Header.OperationUser.FullName);
            cmd.SetParameterValue("@CompanyCode", productImageEntity.Header.CompanyCode);
            cmd.SetParameterValue("@StoreCompanyCode", productImageEntity.Header.CompanyCode);
            cmd.SetParameterValue("@LanguageCode", LanguageCode);
            cmd.ExecuteNonQuery();
        }
        /// <summary>
        /// 创建图片与商品组关联信息
        /// </summary>
        /// <param name="productImageEntity"></param>
        /// <returns></returns>
        public static ProductGroupInfoImageEntity CreateProductGroupInfoImage(ProductGroupInfoImageEntity productImageEntity)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("CreateProductGroupInfoImage");

            cmd.SetParameterValue("@ProductGroupSysno", productImageEntity.ProductGroupSysno);
            cmd.SetParameterValue("@ResourceUrl", productImageEntity.ResourceUrl);
            cmd.SetParameterValue("@Type", productImageEntity.Type);
            cmd.SetParameterValue("@Status", productImageEntity.Status);
            cmd.SetParameterValue("@InUser", productImageEntity.Header.OperationUser.FullName);
            cmd.SetParameterValue("@CompanyCode", productImageEntity.Header.CompanyCode);
            cmd.SetParameterValue("@StoreCompanyCode", productImageEntity.Header.CompanyCode);
            cmd.SetParameterValue("@LanguageCode", LanguageCode);
            cmd.ExecuteNonQuery();
            productImageEntity.SysNo = (int)cmd.GetParameterValue("@SysNo");

            return(productImageEntity);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 文件保存到相对路径,并重命名
        /// </summary>
        /// <param name="productGroupInfoMedia"></param>
        public ProductGroupInfoMediaEntity SaveFile(ProductGroupInfoMediaEntity productGroupInfoMedia, string commonSKUNumber)
        {
            try
            {
                string savePath = "";

                //读取图片根据GroupSysNo分段存储信息
                string fileFix = GetFileFixByType(productGroupInfoMedia.FileType);

                //读取文件相对存储路径
                savePath = GetFileSavePath(fileFix);

                //临时文件名
                string sfileName = productGroupInfoMedia.FileGuid.ToString();
                string dfileName = productGroupInfoMedia.FileName;

                //int fileNameNo = 0;

                //fileNameNo = ProductImageDA.GetGroupInfoMaxImage(productGroupInfoMedia.ProductGroupSysno,productGroupInfoMedia.FileType, productGroupInfoMedia.Header.CompanyCode);
                //dfileName = string.Format("NeweggShowPic{0}-{1}{2}", productGroupInfoMedia.ProductGroupSysno.ToString(), fileNameNo.ToString(), fileFix);

                savePath += GetSubFolderName(dfileName);

                //创建图片与商品组关联信息以及图片与商品关联信息
                ProductGroupInfoImageEntity productImage = new ProductGroupInfoImageEntity();
                //productImage.IsShow = "Y";
                productImage.ProductGroupSysno = productGroupInfoMedia.ProductGroupSysno;

                productImage.ResourceUrl = dfileName;

                productImage.Status = "A";
                productImage.Type   = productGroupInfoMedia.FileType;
                productImage.Header = productGroupInfoMedia.Header;

                //取得文件名中CommonInfoSkuNumber
                //string commonSKUNumber = "";
                //var re = new Regex(@"^([^\._]+)(_(([0-9]+)|(0[1-9]?)))?\..+?$", RegexOptions.IgnoreCase);
                //var match = re.Match(productGroupInfoMedia.FileName);
                //if (match.Success) commonSKUNumber = match.Groups[1].Value;

                SellerPortalProductDescAndImageDA.CreateProductGroupInfoImage(productImage);

                //创建商品与图片关联信息
                SellerPortalProductDescAndImageDA.CreateProductCommonInfoImage(productImage, commonSKUNumber);

                //配置存储路径
                foreach (string localPath in LocalPathList)
                {
                    string filePath = localPath + savePath.Replace("/", "\\");


                    //判断文件夹是否存在
                    if (!Directory.Exists(filePath))
                    {
                        Directory.CreateDirectory(filePath);
                    }

                    //判断上传的文件是否为图片,如果为图片需要进行套图处理
                    if (fileFix == ".jpg")
                    {
                        using (Image uploadImage = Image.FromFile(TemporaryPath + sfileName))
                        {
                            //判断是否为标准图片
                            if (CheckImagePixels(uploadImage))
                            {
                                //重命名文件
                                FileCopy(TemporaryPath + sfileName, dfileName, filePath);
                            }
                            else
                            {
                                //非标准图片需将临时文件压缩为标准图片
                                SaveFixedImage(uploadImage, 800, 800, filePath, "Original", dfileName, true);
                            }
                        }

                        using (Image uploadImage = Image.FromFile(filePath + dfileName))
                        {
                            SaveFixedImageCase(uploadImage, filePath, dfileName);
                        }
                    }
                    else
                    {
                        //重命名文件
                        FileCopy(TemporaryPath + sfileName, dfileName, filePath);
                    }
                }

                //删除临时文件
                File.Delete(TemporaryPath + sfileName);

                return(productGroupInfoMedia);
            }
            catch (Exception ex)
            {
                throw new BusinessException(ex.Message);
            }
        }