Пример #1
0
        public int Update(CommunionPictureInfo model)
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"update CommunionPicture 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.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parms));
        }
Пример #2
0
        public IList <CommunionPictureInfo> GetList()
        {
            StringBuilder sb = new StringBuilder(250);

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

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

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString()))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CommunionPictureInfo model = new CommunionPictureInfo();
                        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);
        }
Пример #3
0
        public IList <CommunionPictureInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(250);

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

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

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CommunionPictureInfo model = new CommunionPictureInfo();
                        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);
        }
Пример #4
0
        public int Insert(CommunionPictureInfo model)
        {
            StringBuilder sb = new StringBuilder(250);

            sb.Append(@"insert into CommunionPicture (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.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parms));
        }
Пример #5
0
        public CommunionPictureInfo GetModel(object Id)
        {
            CommunionPictureInfo model = null;

            StringBuilder sb = new StringBuilder(300);

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

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

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new CommunionPictureInfo();
                        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 <CommunionPictureInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(250);

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

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

            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 CommunionPicture "                    );
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex);

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

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CommunionPictureInfo model = new CommunionPictureInfo();
                        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 Bind()
        {
            if (!Id.Equals(Guid.Empty))
            {
                Page.Title = "编辑电视台视频";
                HWTV bll   = new HWTV();
                var  model = bll.GetModel(Id);
                if (model != null)
                {
                    txtName.Value       = model.HWTVName;
                    hId.Value           = Id.ToString();
                    hTurnTo.Value       = model.IsTurnTo.ToString();
                    txtSort.Value       = model.Sort.ToString();
                    txtProgramURL.Value = model.ProgramAddress;

                    if (model.HWTVIcon != null && !string.IsNullOrEmpty(model.HWTVIcon.ToString()))
                    {
                        CommunionPictureInfo md = new CommunionPictureInfo();// GetModel(object Id)
                        CommunionPicture     communionPicture = new CommunionPicture();
                        md = communionPicture.GetModel(Guid.Parse(model.HWTVIcon.ToString()));
                        if (md != null)
                        {
                            imgSinglePicture.Src = string.Format("{0}{1}/PC/{1}_1{2}", md.FileDirectory, md.RandomFolder, md.FileExtension);
                            hdimg.Value          = md.Id.ToString();
                        }
                    }

                    if (model.IsDisable)
                    {
                        rdFalse.Checked = false;
                        rdTrue.Checked  = true;
                    }
                    else
                    {
                        rdFalse.Checked = true;
                        rdTrue.Checked  = false;
                    }
                }
            }
        }
Пример #8
0
        private void OnUploadCommunionPicture(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(ConfigHelper.GetValueByKey("UploadFileSize"));
                        if (fileSize > uploadFileSize)
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】大小超出字节" + uploadFileSize + ",无法上传,请正确操作!");
                        }
                        if (!UploadFilesHelper.IsFileValidated(file.InputStream, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】为受限制的文件,请正确操作!");
                        }

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

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

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

                        CommunionPictureInfo model = new CommunionPictureInfo();
                        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);

                        string rndDirFullPath = context.Server.MapPath(string.Format("~{0}{1}", model.FileDirectory, model.RandomFolder));
                        if (!Directory.Exists(rndDirFullPath))
                        {
                            Directory.CreateDirectory(rndDirFullPath);
                        }
                        File.Copy(context.Server.MapPath(originalUrl), string.Format("{0}\\{1}{2}", rndDirFullPath, randomFolder, model.FileExtension), true);

                        string[] platformNames = Enum.GetNames(typeof(EnumData.Platform));
                        foreach (string name in platformNames)
                        {
                            string platformUrl         = string.Format("{0}/{1}/{2}", model.FileDirectory, model.RandomFolder, name);
                            string platformUrlFullPath = context.Server.MapPath("~" + platformUrl);
                            if (!Directory.Exists(platformUrlFullPath))
                            {
                                Directory.CreateDirectory(platformUrlFullPath);
                            }
                            string   sizeAppend = ConfigHelper.GetValueByKey(name);
                            string[] sizeArr    = sizeAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            for (int i = 0; i < sizeArr.Length; i++)
                            {
                                string   bmsPicUrl = string.Format("{0}\\{1}_{2}{3}", platformUrlFullPath, model.RandomFolder, i, model.FileExtension);
                                string[] wh        = sizeArr[i].Split('*');

                                ih.CreateThumbnailImage(context.Server.MapPath(originalUrl), bmsPicUrl, int.Parse(wh[0]), int.Parse(wh[1]), "DB", 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 + "\"}");
        }
Пример #9
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(CommunionPictureInfo model)
 {
     return(dal.Update(model));
 }
Пример #10
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(CommunionPictureInfo model)
 {
     return(dal.Insert(model));
 }