/// <summary>
        /// 加载用户图片数据返回
        /// </summary>
        /// <param name="context"></param>
        /// <param name="loadCount"></param>
        /// <param name="loadSize"></param>
        /// <param name="user"></param>
        private void LoadUserPicture(HttpContext context, int loadCount, int loadSize, User user)
        {
            //取数据
            Picture.BLL.PictureInfoBLL bllPicture = new Picture.BLL.PictureInfoBLL();
            var list = bllPicture.QueryList(loadCount + 1, loadSize, new { UId = user.UId }, "UploadDate").Select(p => new { imgUrl = CommonHelper.GetSmallImgPath(p.LargeImgPath), uploadDate = p.UploadDate, collectCount = p.CollectCount, pId = p.PId, width = p.Width, height = p.Height });

            //返回数据
            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            context.Response.Write(jss.Serialize(list));
        }
        public void ProcessRequest(HttpContext context)
        {
            /*
             *  与前端的规定
             *  1     未登入
             *  2     该用户没有这张图片
             *  3     数据库问题,图片未删除
             *
             */

            context.Response.ContentType = "text/plain";
            int pId = int.Parse(context.Request["pId"]);
            User user = context.Session["current_user"] as User;
            //校验是否登入
            if (user == null)
            {
                DeletePictureError(context, 1);
                return;
            }

            Picture.BLL.PictureInfoBLL picturebll = new Picture.BLL.PictureInfoBLL();
            //校验该用户是否有这张图片
            Picture.Model.PictureInfoModel picture=picturebll.QuerySingle(new { PId = pId, __o = "and", UId = user.UId });
            if ( picture==null)
            {
                DeletePictureError(context, 2);
                return;
            }

            //删除图片表图片
            if (picturebll.Delete(pId) <= 0)
            {
                DeletePictureError(context, 3);
                return;
            }
            else
            {
                //大图路径
                string picPath = context.Request.MapPath(picture.LargeImgPath);
                //小图路径
                string smallPath = context.Request.MapPath(CommonHelper.GetSmallImgPath(picture.LargeImgPath));
                if (File.Exists(picPath))
                {
                    File.Delete(picPath);
                }
                if (File.Exists(smallPath))
                {
                    File.Delete(smallPath);
                }

            }
            context.Response.Write(JSONHelper.ToJSONString(new { isDelete = true }));
        }
        public void ProcessRequest(HttpContext context)
        {
            /*
             * 约定
             * 1   用户未登入
             * 2   图片不存在
             * 3   在点击收藏情况下,图片已收藏
             * 4   在删除收藏的情况下,图片已删除收藏
             * 5   未知错误: 图片更新后返回的影响条数不为1
             *
             */

            context.Response.ContentType = "text/plain";
            int pId = int.Parse(context.Request["pId"]);
            bool isCollect = bool.Parse(context.Request["isCollect"]);

            //用户登入校验
            User user = context.Session["current_user"] as User;
            if (user == null)
            {
                CollectError(context, 1);
                return;
            }

            Picture.BLL.PictureCollectBLL collectBll = new Picture.BLL.PictureCollectBLL();
            Picture.BLL.PictureInfoBLL pictureBll = new Picture.BLL.PictureInfoBLL();

            if (!isCollect)
            {
                //收藏
                //先看图片是否存在
                var pic = pictureBll.QuerySingle(new { PId = pId });
                if (pic==null)
                {
                    CollectError(context, 2);
                    return;
                }

                //是否已经收藏了
                int cCount = collectBll.QueryCount(new
                {
                    PId = pId,
                    __o = "and",
                    CuId = user.UId
                });
                if (cCount > 0)
                {
                    CollectError(context, 3);
                    return;
                }

                //用户已登入,图片存在,图片未收藏

                //添加收藏
                collectBll.Insert(new Picture.Model.PictureCollectModel()
                {
                    CollectDate = DateTime.Now,
                    CuId = user.UId,
                    PId = pId
                });

                pic.CollectCount++;
                //修改图片数据
                if (pictureBll.Update(pic)!=1)
                {
                    CollectError(context, 5);
                    return;
                }

            }
            else
            {
                //取消收藏

                //图片是否存在
                var pic = pictureBll.QuerySingle(new { PId = pId });
                if (pic == null)
                {
                    CollectError(context, 2);
                    return;
                }

                //是否已经收藏了
                var collect = collectBll.QuerySingle(new
                {
                    PId=pId,
                    __o="and",
                    CuId=user.UId
                });
                //如果已经取消收藏了
                if (collect==null)
                {
                    CollectError(context, 4);
                    return;
                }

                //用户已登入,图片存在,图片已收藏
                //删除收藏
                collectBll.Delete(collect.CId);
                //修改图片数据
                pic.CollectCount--;
                if (pictureBll.Update(pic) != 1)
                {
                    CollectError(context, 5);
                    return;
                }
            }

            //添加/删除收藏成功
            context.Response.Write(JSONHelper.ToJSONString(new
            {
                isCollect = true
            }));
        }
        public void ProcessRequest(HttpContext context)
        {
            //并不知道如何用参数获得文件只能用索引的方式,反正就一张图
            context.Response.ContentType = "text/plain";
            var file = context.Request.Files[0];
            string tags = context.Request["tags"];
            string pictreSummary = context.Server.HtmlEncode(context.Request["summary"]);

            List<String> Tags = new List<String>();

            foreach (var item in tags.Split(new char[] { ',' }))
            {
                Tags.Add(item.Trim());
            }

            //去除重复的标签
            HashSet<string> hsTag = new HashSet<string>(Tags);

            #region 用户登入校验
            if (context.Session["current_user"] == null)
            {
                PictureUploadError(context, 1);
                return;
            }

            User user = context.Session["current_user"] as User;

            #endregion

            #region 用户是否被禁止上传图片
            if (user.UserStatus == 1)
            {
                PictureUploadError(context, 4);
                return;
            }
            #endregion

            #region 文件类型校验
            string fileName = file.FileName;
            string extName = Path.GetExtension(fileName);
            if (!(extName == ".jpeg" || extName == ".jpg" || extName == ".bmp" || extName == ".png" || extName == ".gif"))
            {
                PictureUploadError(context, 2);
                return;
            }
            #endregion

            #region 文件大小校验
            if (file.ContentLength > IMAGE_SIZE_LIMIT)
            {
                PictureUploadError(context, 3);
                return;
            }
            #endregion

            #region 保存文件

            #region  保存到磁盘
            //大小图所在的文件夹的相对路径
            string bigRelativePathDir = BIG_IMAGE_SAVE_PATH + DateTime.Now.ToString("yyyyMMdd");
            string smallRelativePathDir = BIG_IMAGE_SAVE_PATH + "SmallImg_" + DateTime.Now.ToString("yyyyMMdd");

            //大,小图所在的文件夹绝对路径
            string bigPathDir = context.Request.MapPath("../" + bigRelativePathDir);
            string smallPathDir = context.Request.MapPath("../" + smallRelativePathDir);
            //创建文件夹
            if (!Directory.Exists(bigPathDir))
            {
                Directory.CreateDirectory(bigPathDir);
                Directory.CreateDirectory(smallPathDir);
            }

            //算出文件的MD5
            string fileMD5Name = GetMD5FromFile(file.InputStream);
            string fileExt = Path.GetExtension(file.FileName);

            //大,小图所在的相对路径
            string bigImgRelativePath = bigRelativePathDir + "/" + fileMD5Name + fileExt;
            string smallImgRelativePath = smallRelativePathDir + "/" + "small_" + fileMD5Name + ".jpg";

            //大,小图所在的绝对路径
            string bigImgPath = context.Request.MapPath("../" + bigImgRelativePath);
            string smallImgPath = context.Request.MapPath("../" + smallImgRelativePath);

            //保存
            file.SaveAs(bigImgPath);

            PictureProcessHelper.MakeThumbnail(bigImgPath, smallImgPath, 400, 0, "W");

            #endregion

            #region 保存到数据库

            #region 获取标签对象,判断标签是否已经存在了,不存在则创建
            Picture.BLL.TagBLL tagBll = new Picture.BLL.TagBLL();
            List<Picture.Model.TagModel> tagModelList = new List<Picture.Model.TagModel>();
            Picture.Model.TagModel tempModel = null;

            foreach (var item in hsTag)
            {
                tempModel = tagBll.QuerySingle(new { TagName = item });
                if (tempModel == null)
                {
                    int tagId = tagBll.Insert(new Picture.Model.TagModel()
                    {
                        TagName = item
                    });
                    tagModelList.Add(new Picture.Model.TagModel()
                    {
                        TagName = item,
                        TId = tagId
                    });
                }
                else
                {
                    tagModelList.Add(tempModel);
                }
                tempModel = null;
            }

            #endregion

            #region  更新索引
            foreach (var item in tagModelList)
            {
                IndexManager.tagIndex.Add(item);
            }

            #endregion

            #region 保存图片

            Picture.BLL.PictureInfoBLL pictureBll = new Picture.BLL.PictureInfoBLL();

            int width = 0;
            int height = 0;
            PictureProcessHelper.GetPictureShap(bigImgPath, out width, out height);

            Picture.Model.PictureInfoModel model = new Picture.Model.PictureInfoModel()
            {
                CollectCount = 0,
                Height = height,
                Width = width,
                ImgSummary = pictreSummary,
                LargeImgPath = bigImgRelativePath,
                UId = user.UId,
                UploadDate = DateTime.Now
            };

            int pId = pictureBll.Insert(model);
            #endregion

            #region 保存图片与标签的关系
            Picture.BLL.TagImgRelationBLL bllTIR = new Picture.BLL.TagImgRelationBLL();

            foreach (var item in tagModelList)
            {
                bllTIR.Insert(new Picture.Model.TagImgRelationModel()
                {
                    ImgId = pId,
                    TagId = item.TId
                });
            }

            #endregion

            #endregion

            #endregion

            context.Response.Write(JSONHelper.ToJSONString(new { isUpload = true }));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     CurrentUser = Session["current_user"] as Model.User;
     Picture.BLL.PictureInfoBLL bllPictureInfo = new Picture.BLL.PictureInfoBLL();
     List = bllPictureInfo.QueryList(-1, 10, new { UId = CurrentUser.UId }, "UploadDate");
 }