Пример #1
0
        public IList <PictureServiceLinkInfo> GetList()
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"select Id,FileName,FileSize,FileExtension,FileDirectory,RandomFolder,LastUpdatedDate 
			            from Picture_ServiceLink
					    order by LastUpdatedDate desc "                    );

            IList <PictureServiceLinkInfo> list = new List <PictureServiceLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString()))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        PictureServiceLinkInfo model = new PictureServiceLinkInfo();
                        model.Id              = reader.GetGuid(0);
                        model.FileName        = reader.GetString(1);
                        model.FileSize        = reader.GetInt32(2);
                        model.FileExtension   = reader.GetString(3);
                        model.FileDirectory   = reader.GetString(4);
                        model.RandomFolder    = reader.GetString(5);
                        model.LastUpdatedDate = reader.GetDateTime(6);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #2
0
        public int Update(PictureServiceLinkInfo model)
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"update Picture_ServiceLink set FileName = @FileName,FileSize = @FileSize,FileExtension = @FileExtension,FileDirectory = @FileDirectory,RandomFolder = @RandomFolder,LastUpdatedDate = @LastUpdatedDate 
			            where Id = @Id
					    "                    );

            SqlParameter[] parms =
            {
                new SqlParameter("@Id",              SqlDbType.UniqueIdentifier),
                new SqlParameter("@FileName",        SqlDbType.NVarChar,          100),
                new SqlParameter("@FileSize",        SqlDbType.Int),
                new SqlParameter("@FileExtension",   SqlDbType.VarChar,            10),
                new SqlParameter("@FileDirectory",   SqlDbType.NVarChar,          100),
                new SqlParameter("@RandomFolder",    SqlDbType.VarChar,            20),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.FileName;
            parms[2].Value = model.FileSize;
            parms[3].Value = model.FileExtension;
            parms[4].Value = model.FileDirectory;
            parms[5].Value = model.RandomFolder;
            parms[6].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), parms));
        }
Пример #3
0
        public int Insert(PictureServiceLinkInfo model)
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"insert into Picture_ServiceLink (FileName,FileSize,FileExtension,FileDirectory,RandomFolder,LastUpdatedDate)
			            values
						(@FileName,@FileSize,@FileExtension,@FileDirectory,@RandomFolder,@LastUpdatedDate)
			            "            );

            SqlParameter[] parms =
            {
                new SqlParameter("@FileName",        SqlDbType.NVarChar, 100),
                new SqlParameter("@FileSize",        SqlDbType.Int),
                new SqlParameter("@FileExtension",   SqlDbType.VarChar,   10),
                new SqlParameter("@FileDirectory",   SqlDbType.NVarChar, 100),
                new SqlParameter("@RandomFolder",    SqlDbType.VarChar,   20),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value = model.FileName;
            parms[1].Value = model.FileSize;
            parms[2].Value = model.FileExtension;
            parms[3].Value = model.FileDirectory;
            parms[4].Value = model.RandomFolder;
            parms[5].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), parms));
        }
Пример #4
0
        public IList <PictureServiceLinkInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"select Id,FileName,FileSize,FileExtension,FileDirectory,RandomFolder,LastUpdatedDate
                        from Picture_ServiceLink ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }

            IList <PictureServiceLinkInfo> list = new List <PictureServiceLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        PictureServiceLinkInfo model = new PictureServiceLinkInfo();
                        model.Id              = reader.GetGuid(0);
                        model.FileName        = reader.GetString(1);
                        model.FileSize        = reader.GetInt32(2);
                        model.FileExtension   = reader.GetString(3);
                        model.FileDirectory   = reader.GetString(4);
                        model.RandomFolder    = reader.GetString(5);
                        model.LastUpdatedDate = reader.GetDateTime(6);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #5
0
        public PictureServiceLinkInfo GetModel(object Id)
        {
            PictureServiceLinkInfo model = null;

            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"select top 1 Id,FileName,FileSize,FileExtension,FileDirectory,RandomFolder,LastUpdatedDate 
			                   from Picture_ServiceLink
							   where Id = @Id "                            );
            SqlParameter parm = new SqlParameter("@Id", SqlDbType.UniqueIdentifier);

            parm.Value = Guid.Parse(Id.ToString());

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new PictureServiceLinkInfo();
                        model.Id              = reader.GetGuid(0);
                        model.FileName        = reader.GetString(1);
                        model.FileSize        = reader.GetInt32(2);
                        model.FileExtension   = reader.GetString(3);
                        model.FileDirectory   = reader.GetString(4);
                        model.RandomFolder    = reader.GetString(5);
                        model.LastUpdatedDate = reader.GetDateTime(6);
                    }
                }
            }

            return(model);
        }
Пример #6
0
        public IList <PictureServiceLinkInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"select count(*) from Picture_ServiceLink ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms);

            if (totalRecords == 0)
            {
                return(new List <PictureServiceLinkInfo>());
            }

            sb.Clear();
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber,
			          Id,FileName,FileSize,FileExtension,FileDirectory,RandomFolder,LastUpdatedDate
					  from Picture_ServiceLink "                    );
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex);

            IList <PictureServiceLinkInfo> list = new List <PictureServiceLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        PictureServiceLinkInfo model = new PictureServiceLinkInfo();
                        model.Id              = reader.GetGuid(1);
                        model.FileName        = reader.GetString(2);
                        model.FileSize        = reader.GetInt32(3);
                        model.FileExtension   = reader.GetString(4);
                        model.FileDirectory   = reader.GetString(5);
                        model.RandomFolder    = reader.GetString(6);
                        model.LastUpdatedDate = reader.GetDateTime(7);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #7
0
        private void OnUploadPictureServiceLink(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string errorMsg = "";

            try
            {
                HttpFileCollection files = context.Request.Files;
                if (files.Count == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                int effect            = 0;
                UploadFilesHelper ufh = new UploadFilesHelper();
                ImagesHelper      ih  = new ImagesHelper();

                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (string item in files.AllKeys)
                    {
                        HttpPostedFile file = files[item];
                        if (file == null || file.ContentLength == 0)
                        {
                            continue;
                        }

                        int fileSize       = file.ContentLength;
                        int uploadFileSize = int.Parse(WebConfigurationManager.AppSettings["UploadFileSize"]);
                        if (fileSize > uploadFileSize)
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】大小超出字节" + uploadFileSize + ",无法上传,请正确操作!");
                        }
                        if (!UploadFilesHelper.IsFileValidated(file.InputStream, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】为受限制的文件,请正确操作!");
                        }

                        string fileName = file.FileName;

                        PictureServiceLink bll = new PictureServiceLink();
                        if (bll.IsExist(file.FileName, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】已存在,请勿重复上传!");
                        }

                        string originalUrl = UploadFilesHelper.UploadOriginalFile(file, "PictureServiceLink");

                        //获取随机生成的文件名代码
                        string randomFolder = string.Format("{0}_{1}", DateTime.Now.ToString("MMdd"), UploadFilesHelper.GetRandomFolder("slp"));

                        PictureServiceLinkInfo model = new PictureServiceLinkInfo();
                        model.FileName        = VirtualPathUtility.GetFileName(originalUrl);
                        model.FileSize        = fileSize;
                        model.FileExtension   = VirtualPathUtility.GetExtension(originalUrl).ToLower();
                        model.FileDirectory   = VirtualPathUtility.GetDirectory(originalUrl.Replace("~", ""));
                        model.RandomFolder    = randomFolder;
                        model.LastUpdatedDate = DateTime.Now;

                        bll.Insert(model);

                        CreateThumbnailImage(context, ih, originalUrl, model.FileDirectory, model.RandomFolder, model.FileExtension);

                        effect++;
                    }

                    scope.Complete();
                }

                if (effect == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"已成功上传文件数:" + effect + "个\"}");

                return;
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            context.Response.Write("{\"success\": false,\"message\": \"" + errorMsg + "\"}");
        }
Пример #8
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(PictureServiceLinkInfo model)
 {
     return(dal.Update(model));
 }
Пример #9
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(PictureServiceLinkInfo model)
 {
     return(dal.Insert(model));
 }