/// <summary>
        /// The upload picture.
        /// </summary>
        /// <param name="pictureUpload">
        /// The picture Upload.
        /// </param>
        /// <param name="parentCategoryID">
        /// The parent category id.
        /// </param>
        /// <param name="productCategoryID">
        /// The product category id.
        /// </param>
        /// <param name="parentBrandID">
        /// The parent brand id.
        /// </param>
        /// <param name="productBrandID">
        /// The product brand id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult UploadPicture(IEnumerable<HttpPostedFileBase> pictureUpload, string parentCategoryID, string productCategoryID, string parentBrandID, string productBrandID)
        {
            this.pictureService = new PictureService();

            if (pictureUpload == null)
            {
                return this.Json(string.Empty);
            }

            try
            {
                foreach (var file in pictureUpload)
                {
                    var displayName = Path.GetFileName(file.FileName);
                    if (displayName == null)
                    {
                        continue;
                    }

                    var fileName = Guid.NewGuid().ToString();  // 文件名
                    var rootPath = this.Server.MapPath("~/Upload_V5/Product/");  // 图片保存根目录
                    string savePath; // 数据库保存地址
                    var path = this.CreateDirectory(rootPath, out savePath); // 图片文件保存地址
                    savePath += fileName + Path.GetExtension(file.FileName);
                    savePath = "/Upload_V5/Product/" + savePath;

                    var stream = file.InputStream;
                    var image = Image.FromStream(stream);

                    var picture = new Picture
                                      {
                                          Name = Path.GetFileNameWithoutExtension(file.FileName),
                                          Type = Path.GetExtension(file.FileName),
                                          ParentCategoryID = Convert.ToInt32(parentCategoryID),
                                          ProductCategoryID = string.IsNullOrEmpty(productCategoryID) ? (int?)null : Convert.ToInt32(productCategoryID),
                                          ParentBrandID = string.IsNullOrEmpty(parentBrandID) ? (int?)null : Convert.ToInt32(parentBrandID),
                                          ProductBrandID = string.IsNullOrEmpty(productBrandID) ? (int?)null : Convert.ToInt32(productBrandID),
                                          Size = file.ContentLength,
                                          Width = image.Width,
                                          Height = image.Height,
                                          Path = savePath,
                                          ThumbnailPath = string.Empty,
                                          FileName = Guid.NewGuid().ToString(),
                                          Status = 1,
                                          CreateTime = DateTime.Now,
                                          UploadTime = DateTime.Now
                                      };

                    // 保存原图
                    file.SaveAs(path + fileName + picture.Type);

                   // 生成对应缩略图
                    var pic = new ImageEditService();
                    pic.CreateProductPic(path + fileName + picture.Type, path);

                    picture.ID = this.pictureService.AddPicture(picture);
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(string.Empty);
        }
        /// <summary>
        /// The query.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="pictureName">
        /// The picture name.
        /// </param>
        /// <param name="startTime">
        /// The start time.
        /// </param>
        /// <param name="endTime">
        /// The end time.
        /// </param>
        /// <param name="brandID">
        /// The brand id.
        /// </param>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Query([DataSourceRequest] DataSourceRequest request, string pictureName, string startTime, string endTime, string brandID, string type)
        {
            this.pictureService = new PictureService();

            int pageCount;
            int totalCount;

            var condition = " IsDelete = 0 ";
            if (!string.IsNullOrEmpty(brandID))
            {
                switch (type)
                {
                    case "1":
                        condition += " and id in (select pictureid from product, product_picture where product_picture.productid = product.id and product.isdelete = 0 and product_picture.isdelete = 0 and product.ParentCategoryID = " + brandID + ")";
                        break;
                    case "2":
                        condition += " and id in (select pictureid from product, product_picture where product_picture.productid = product.id and product.isdelete = 0 and product_picture.isdelete = 0 and product.ProductCategoryID = " + brandID + ")";
                        break;
                    case "3":
                        condition += " and id in (select pictureid from product, product_picture where product_picture.productid = product.id and product.isdelete = 0 and product_picture.isdelete = 0 and product.ParentBrandID = " + brandID + ")";
                        break;
                    case "4":
                        condition += " and id in (select pictureid from product, product_picture where product_picture.productid = product.id and product.isdelete = 0 and product_picture.isdelete = 0 and product.ProductBrandID = " + brandID + ")";
                        break;
                }
            }

            if (!string.IsNullOrEmpty(pictureName))
            {
                condition += " and [Name] like '%" + pictureName + "%' ";
            }

            if (!string.IsNullOrEmpty(startTime))
            {
                condition += " and [UploadTime] > '" + startTime + "' ";
            }

            if (!string.IsNullOrEmpty(endTime))
            {
                condition += " and [UploadTime] < '" + endTime + "' ";
            }

            var paging = new Paging("[Picture]", null, "ID", condition, request.Page, request.PageSize, "CreateTime", 1);
            var list = this.pictureService.Query(paging, out pageCount, out totalCount);

            var result = new DataSourceResult();
            if (list != null)
            {
                var modelList = new List<PictureModel>();

                foreach (var picture in list)
                {
                    picture.Path = Utils.GetProductImage(picture.Path, "1");
                    modelList.Add(
                        DataTransfer.Transfer<PictureModel>(picture, typeof(Picture)));
                }

                result.Data = list;
                result.Total = totalCount;

                return this.Json(result);
            }

            result.Data = null;
            result.Total = 0;
            return this.Json(result);
        }
        /// <summary>
        /// The remove.
        /// </summary>
        /// <param name="pictures">
        /// The pictures.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Remove(List<string> pictures)
        {
            AjaxResponse jsonResponse;

            try
            {
                this.pictureService = new PictureService();

                foreach (var picture in pictures)
                {
                    this.pictureService.RemovePictureByID(Convert.ToInt32(picture));
                }

                jsonResponse = new AjaxResponse(1);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(jsonResponse);
        }
        /// <summary>
        /// The modify picture category.
        /// </summary>
        /// <param name="pictures">
        /// The pictures.
        /// </param>
        /// <param name="parentCategoryID">
        /// The parent category id.
        /// </param>
        /// <param name="productCategoryID">
        /// The product category id.
        /// </param>
        /// <param name="parentBrandID">
        /// The parent brand id.
        /// </param>
        /// <param name="productBrandID">
        /// The product brand id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult ModifyPictureCategory(List<string> pictures, string parentCategoryID, string productCategoryID, string parentBrandID, string productBrandID)
        {
            AjaxResponse jsonResponse;

            try
            {
                this.pictureService = new PictureService();

                foreach (var picture in pictures)
                {
                    this.pictureService.ModifyPictureCategory(Convert.ToInt32(picture), parentCategoryID, productCategoryID, parentBrandID, productBrandID);
                }

                jsonResponse = new AjaxResponse(1);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(jsonResponse);
        }