Esempio n. 1
0
        /// <summary>
        /// 插入图片.
        /// </summary>
        /// <param name="picture">
        /// 图片实体.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Insert(Picture picture)
        {
            if (picture == null)
            {
                throw new ArgumentNullException("picture");
            }

            int id;
            var parameters = new List<SqlParameter>
                                 {
                                     this.SqlServer.CreateSqlParameter(
                                         "ParentCategoryID",
                                         SqlDbType.Int,
                                         picture.ParentCategoryID,
                                         ParameterDirection.Input),
                                         this.SqlServer.CreateSqlParameter(
                                         "ProductCategoryID",
                                         SqlDbType.Int,
                                         picture.ProductCategoryID,
                                         ParameterDirection.Input),
                                         this.SqlServer.CreateSqlParameter(
                                         "ParentBrandID",
                                         SqlDbType.Int,
                                         picture.ParentBrandID,
                                         ParameterDirection.Input),
                                         this.SqlServer.CreateSqlParameter(
                                         "ProductBrandID",
                                         SqlDbType.Int,
                                         picture.ProductBrandID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Name",
                                         SqlDbType.NVarChar,
                                         picture.Name,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Type",
                                         SqlDbType.NVarChar,
                                         picture.Type,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Path",
                                         SqlDbType.NVarChar,
                                         picture.Path,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ThumbnailPath",
                                         SqlDbType.NVarChar,
                                         picture.ThumbnailPath,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "FileName",
                                         SqlDbType.NVarChar,
                                         picture.FileName,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Size",
                                         SqlDbType.Int,
                                         picture.Size,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Height",
                                         SqlDbType.Int,
                                         picture.Height,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Width",
                                         SqlDbType.Int,
                                         picture.Width,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Status",
                                         SqlDbType.Int,
                                         picture.Status,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "UploadTime",
                                         SqlDbType.DateTime,
                                         picture.UploadTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "CreateTime",
                                         SqlDbType.DateTime,
                                         picture.CreateTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ReferenceID",
                                         SqlDbType.Int,
                                         null,
                                         ParameterDirection.Output)
                                 };

            try
            {
                this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Picture_Insert", parameters, null);
                id = (int)parameters[11].Value;
            }
            catch (Exception exception)
            {
                throw new Exception("Exception - PictureDA - Insert", exception);
            }

            return id;
        }
Esempio n. 2
0
 /// <summary>
 /// 修改图片信息.
 /// </summary>
 /// <param name="picture">
 /// 图片实体.
 /// </param>
 public void Update(Picture picture)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
 /// <summary>
 /// 添加图片.
 /// </summary>
 /// <param name="picture">
 /// 图片实体
 /// </param>
 /// <returns>
 /// 添加记录的主键值.
 /// </returns>
 public int AddPicture(Picture picture)
 {
     return this.pictureDA.Insert(picture);
 }
Esempio n. 4
0
 /// <summary>
 /// 修改图片信息.
 /// </summary>
 /// <param name="picture">
 /// 图片实体.
 /// </param>
 public void ModifyPicture(Picture picture)
 {
     this.pictureDA.Update(picture);
 }
        /// <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);
        }