Exemple #1
0
        /// <summary>
        /// 接受手机上传图片
        /// </summary>
        /// <param name="context"></param>
        /// <returns>0 登录失败 -1请求失败 -2系统错误 -3无图片</returns>
        public string UploadPicture(HttpContext context)
        {
            string email = String.Empty;
            string description = String.Empty;
            string strAlbumId = String.Empty;
            long albumId = 0;
            string imgName = String.Empty;
            CY.UME.Core.Business.AccountExtend accountExtend;

            try
            {
                System.IO.Stream s1 = context.Request.InputStream;
                System.IO.StreamReader sr1 = new System.IO.StreamReader(s1);
                #region 获取参数并验证
                //取参数
                if (context.Request.QueryString["AlbumId"] == null ||
                    context.Request.QueryString["email"] == null)
                {
                    return "-1";
                }
                strAlbumId = context.Request.QueryString["AlbumId"].ToString();
                if (context.Request.QueryString["Description"] != null)
                {
                    description = context.Request.QueryString["Description"].ToString();
                }
                email = context.Request.QueryString["email"].ToString();

                if (context.Request.QueryString["ImgName"] != null)
                {
                    imgName = context.Request.QueryString["ImgName"].ToString();
                }

                if (!long.TryParse(strAlbumId, out albumId))
                {
                    return "-1";
                }

                accountExtend = CY.UME.Core.Business.AccountExtend.Load(email);

                if (accountExtend == null)
                {
                    return "0";
                }
                #endregion

                string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgName);
                string imgRealName = CY.Utility.Common.FileUtility.GetFileName(imgName);

                string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                string dirPath = appPath + "/Content/Album/" + accountExtend.Id + "/";
                string fileName = "/Content/Album/" + accountExtend.Id + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                if (context.Request.InputStream.Length == 0)
                {
                    return "-3";
                }

                System.IO.Stream s = context.Request.InputStream;
                byte[] bytes = new byte[s.Length];
                s.Read(bytes, 0, bytes.Length);
                s.Seek(0, SeekOrigin.Begin);

                Stream stream = new MemoryStream(bytes);

                Image image = Image.FromStream(stream);

                s.Close();

                int width = image.Width;
                int height = image.Height;

                string bImgName = appPath + fileName + "_big" + imgExtention;
                string mImgName = appPath + fileName + "_middle" + imgExtention;
                string sImgName = appPath + fileName + "_small" + imgExtention;

                if (height < width)
                {
                    if (width > 600)
                    {
                        height = Convert.ToInt32(width > 600 ? (600f / width) * height : height);
                        width = 600;
                    }
                }
                else
                {
                    if (height > 600)
                    {
                        width = Convert.ToInt32(height > 600 ? (600f / height) * width : height);
                        height = 600;
                    }
                }

                CY.Utility.Common.ImageUtility.ThumbAsJPG(stream, bImgName, width, height);//大图片

                if (height < width)
                {
                    if (width > 200)
                    {
                        height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                        width = 200;
                    }
                }
                else
                {
                    if (height > 200)
                    {
                        width = Convert.ToInt32(height > 200 ? (200f / height) * width : height);
                        height = 200;
                    }
                }

                CY.Utility.Common.ImageUtility.ThumbAsJPG(stream, sImgName, width, height);

                if (height < width)
                {
                    if (width > 100)
                    {
                        height = Convert.ToInt32(width > 100 ? (100f / width) * height : height);
                        width = 100;
                    }
                }
                else
                {
                    if (height > 100)
                    {
                        width = Convert.ToInt32(height > 100 ? (100f / height) * width : height);
                        height = 100;
                    }
                }

                CY.Utility.Common.ImageUtility.ThumbAsJPG(stream, mImgName, width, height);

                //更换相册封面
                CY.UME.Core.Business.Album album = CY.UME.Core.Business.Album.Load(albumId);

                if (album == null)
                {
                    album = new CY.UME.Core.Business.Album();
                    album.AccountId = accountExtend.Id;
                    album.DateCreated = DateTime.Now;
                    album.IsAvatar = false;
                    album.Name = "默认相册";
                    album.ViewPermission = 0;

                    album.CoverPath = fileName + "_middle" + imgExtention;
                    album.Save();
                }
                else if (album.PhotoCount == 0 || album.CoverPath.Trim().Length == 0)
                {
                    album.CoverPath = fileName + "_middle" + imgExtention;
                    album.Save();
                }

                //将路径及图片信息保存到数据库
                CY.UME.Core.Business.Picture pic = new CY.UME.Core.Business.Picture();

                pic.AlbumId = album.Id;
                pic.BigPath = fileName + "_big" + imgExtention;
                pic.DateCreated = DateTime.Now;
                pic.MiddlePath = fileName + "_middle" + imgExtention;
                pic.Name = CY.Utility.Common.StringUtility.HTMLEncode(imgRealName);
                pic.SmallPath = fileName + "_small" + imgExtention;
                pic.Remark = description;

                pic.Save();
                CY.UME.Core.Business.Account account = CY.UME.Core.Business.Account.Load(accountExtend.Id);

                account.SendNoticeToAllFriendAndFollower("picture", "上传了新照片", pic.Id.ToString());

                return "1";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
        protected void CreatAlbum_OnClick(object sebder, EventArgs e)
        {
            int groupId = 0;
            CY.UME.Core.Business.Group group;

            #region validate
            if (TBXAlbumName.Text.Trim().Length == 0)
            {
                ShowAlert("提示", "相册名不能为空");
                return;
            }

            if (HF_groupId.Value != "" && int.TryParse(HF_groupId.Value.ToString(), out groupId))
            {
                group = CY.UME.Core.Business.Group.Load(groupId);

                if (group == null)
                {
                    throw new Exception("该群组不存在或已被删除");
                }
            }
            else
            {
                throw new Exception("参数错误");
            }
            #endregion

            #region creat album
            int viewPermission = 1;
            int.TryParse(selViewPermission.Value, out viewPermission);
            long albumId = 0;

            CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album();

            if (HF_albumId.Value != "" && long.TryParse(HF_albumId.Value.ToString(), out albumId))
            {
                album = CY.UME.Core.Business.Album.Load(albumId);

                if (album == null)
                {
                    album = group.CreateGroupAlbum(TBXAlbumName.Text.Trim(), viewPermission);

                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({ title: '提示', content: '创建相册成功' });window.location.href='PictureList.aspx?albumId=" + album.Id + "'</script>");
                }
                else
                {
                    album.Name = TBXAlbumName.Text.Trim();
                    album.ViewPermission = int.Parse(selViewPermission.Value);
                    album.Save();

                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({ title: '提示', content: '修改相册成功' });window.location.href='PictureList.aspx?albumId=" + album.Id + "'</script>");
                }
            }
            else
            {
                album = group.CreateGroupAlbum(TBXAlbumName.Text.Trim(), viewPermission);

                Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({ title: '提示', content: '创建相册成功' });window.location.href='PictureList.aspx?albumId=" + album.Id + "'</script>");
            }
            #endregion

            #region upload pic

            string strPicId = String.Empty;
            List<HttpPostedFile> hfList = new List<HttpPostedFile>();
            if (PortugueseFileUpload1.HasFile)
            {
                hfList.Add(PortugueseFileUpload1.PostedFile);
            }
            if (PortugueseFileUpload2.HasFile)
            {
                hfList.Add(PortugueseFileUpload2.PostedFile);
            }
            if (PortugueseFileUpload3.HasFile)
            {
                hfList.Add(PortugueseFileUpload3.PostedFile);
            }
            if (PortugueseFileUpload4.HasFile)
            {
                hfList.Add(PortugueseFileUpload4.PostedFile);
            }
            if (PortugueseFileUpload5.HasFile)
            {
                hfList.Add(PortugueseFileUpload5.PostedFile);
            }

            for (int i = 0; i < hfList.Count; i++)
            {
                HttpPostedFile imgFile = hfList[i];
                if (imgFile == null || imgFile.ContentLength == 0)
                {
                    break;
                }
                string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgFile.FileName).ToLower();
                string imgName = CY.Utility.Common.FileUtility.GetFileName(imgFile.FileName);

                string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                string dirPath = appPath + "/Content/Group/Album/" + groupId + "/";
                string fileName = "/Content/Group/Album/" + groupId + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                string bImgName = appPath + fileName + "_big" + imgExtention;
                string mImgName = appPath + fileName + "_middle" + imgExtention;
                string sImgName = appPath + fileName + "_small" + imgExtention;

                imgFile.SaveAs(appPath + fileName + imgExtention);//临时保存原始图片

                Bitmap bmp = new Bitmap(appPath + fileName + imgExtention);
                int width = bmp.Width;
                int height = bmp.Height;

                bmp.Dispose();

                if (height <= width && width >= 600)
                {
                    height = Convert.ToInt32(width > 600 ? (600f / width) * height : height);
                    width = 600;
                }
                else if (width < height && height > 600)
                {
                    width = Convert.ToInt32(height > 600 ? (600f / height) * width : height);
                    height = 600;
                }

                // 将原始图压缩为大缩略图
                using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height);
                }

                if (width > 200)
                {
                    height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                    width = 200;
                }

                // 生成图片(好友上传图片最新通知中显示)
                using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, sImgName, width, height);
                }

                if (height <= width && width >= 100)
                {
                    height = Convert.ToInt32(width > 100 ? (100f / width) * height : height);
                    width = 100;
                }
                else if (width < height && height > 100)
                {
                    width = Convert.ToInt32(height > 100 ? (100f / height) * width : height);
                    height = 100;
                }

                // 将大图片压缩为中等缩略图
                using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, width, height);
                }

                try
                {
                    File.Delete(appPath + fileName + imgExtention);
                }
                catch
                {
                    ;
                }

                //更换相册封面
                if (album.PhotoCount == 0 || album.CoverPath.Trim().Length == 0)
                {
                    album.CoverPath = fileName + "_middle" + imgExtention;
                    album.Save();
                }

                //将路径及图片信息保存到数据库
                CY.UME.Core.Business.Picture pic = new CY.UME.Core.Business.Picture();

                pic.AlbumId = album.Id;
                pic.BigPath = fileName + "_big" + imgExtention;
                pic.DateCreated = DateTime.Now;
                pic.MiddlePath = fileName + "_middle" + imgExtention;
                pic.Name = CY.Utility.Common.StringUtility.HTMLEncode(imgName.Substring(0, imgName.Length > 30 ? 30 : imgName.Length));
                pic.SmallPath = fileName + "_small" + imgExtention;

                pic.Save();

                strPicId += pic.Id.ToString() + ",";
                //保存pictureextend
                CY.UME.Core.Business.PictureExtend pe = new CY.UME.Core.Business.PictureExtend();

                pe.Id = pic.Id;
                pe.AccountId = CurrentAccount.Id;
                pe.ActivityId = "group";
                pe.ActivityPicId = "0";

                pe.Save();
            }

            if (viewPermission == 0 && strPicId.Length > 0)
            {
                IList<CY.UME.Core.Business.Friendship> fsList = CurrentAccount.GetFriendships();

                foreach (CY.UME.Core.Business.Friendship fs in fsList)
                {
                    CY.UME.Core.Business.Notice n = new CY.UME.Core.Business.Notice();

                    n.AccountId = fs.FriendId;
                    n.AuthorId = fs.AccountId;
                    n.Content = "上传了新照片";
                    n.DateCreated = DateTime.Now;
                    n.InstanceId = strPicId.Remove(strPicId.Length - 1);
                    n.IsReaded = false;
                    n.Type = "grouppicture";

                    n.Save();
                }
            }
            #endregion
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SetTitle("群组照片 ");

            #region 判断验证
            long pictureId = 0;
            int groupId = 0;

            if (Request.QueryString["pictureId"] == null)
            {
                throw new Exception("参数不存在");
            }
            else if (!long.TryParse(Request.QueryString["pictureId"].ToString(), out pictureId))
            {
                throw new Exception("参数不合法");
            }

            picture = CY.UME.Core.Business.Picture.Load(pictureId);

            if (picture == null)
            {
                throw new Exception("图片不存在或已被删除");
            }

            album = CY.UME.Core.Business.Album.Load(picture.AlbumId);

            albumExtend = CY.UME.Core.Business.AlbumExtend.Load(album.Id);

            SpaceAccount = CY.UME.Core.Business.Account.Load(albumExtend.AccountId);

            if (SpaceAccount == null)
            {
                throw new Exception("访问页面不存在");
            }

            if (Request.QueryString["groupId"] == null)
            {
                throw new Exception("参数不存在");
            }

            if (!int.TryParse(Request.QueryString["groupId"].ToString(), out groupId))
            {
                throw new Exception("参数不合法");
            }

            group = CY.UME.Core.Business.Group.Load(groupId);
            al_HiddenGroupId.Value = groupId.ToString();
            if (CurrentAccount == null || CurrentAccount.Id != SpaceAccount.Id)
            {
                if (album.ViewPermission == 1)//仅好友才能访问
                {
                    if (CurrentAccount == null || !SpaceAccount.HasFriendshipWith(CurrentAccount))//判断是否是好友
                    {
                        Response.Write("您无权访问该页面");
                        return;
                    }
                }
                else if (album.ViewPermission == 2)//密码访问
                {
                    if (Session["AlbumPassword"] == null)
                    {
                        Response.Redirect("ViewEnAlbum.aspx?uid=" + SpaceAccount.Id + "&albumId=" + album.Id);
                        return;
                    }
                    else
                    {
                        string password = Session["AlbumPassword"].ToString();
                        if (password != album.ViewPassword)//判断密码是否正确
                        {
                            Response.Redirect("ViewEnAlbum.aspx?uid=" + SpaceAccount.Id + "&albumId=" + album.Id);
                            return;
                        }
                    }
                }
                else if (album.ViewPermission == 3)
                {
                    Response.Write("您无权访问该页面");
                    return;
                }
            }

            #endregion

            if (!IsPostBack)
            {
                if (CurrentAccount != null)
                {
                    HF_CurrentAccount_Id.Value = CurrentAccount.Id.ToString();
                }

                LblTitleName.Text = group.Name;
                picInfoMana.Visible = true;

                LblAlbumName.Text = album.Name;

                if (album.IsAvatar)
                {//头像相册
                    uploadPic.Visible = false;
                    UploadAvatar.Visible = true;
                }
                else
                {//普通相册
                    uploadPic.Visible = true;
                    UploadAvatar.Visible = false;
                }

                LBLAlbumNameAndLink.Text = "<a href=\"PictureList.aspx?albumId=" + album.Id + "&spaceId=" + CurrentAccount.Id + "\">" + LblAlbumName.Text + "</a>";

                //UserInfo1.SpaceAccount = SpaceAccount;//个人信息
                FollowerListId.CurrentFollower = SpaceAccount;

                CY.UME.Core.PagingInfo pagingInfo = new CY.UME.Core.PagingInfo();
                pagingInfo.CurrentPage = 1;
                pagingInfo.PageSize = int.MaxValue;

                IList<CY.UME.Core.Business.Picture> picList = CY.UME.Core.Business.Picture.GetAllPicture(album, pagingInfo);

                StringBuilder sb = new StringBuilder();

                sb.Append("{");
                sb.Append("TotalRecords:'" + album.PhotoCount.ToString() + "'");
                sb.Append(",AccountId:'" + SpaceAccount.Id.ToString() + "'");
                sb.Append(",CurrentId:'" + (CurrentAccount == null ? "0" : CurrentAccount.Id.ToString()) + "'");
                sb.Append(",AlbumId:'" + album.Id.ToString() + "'");
                sb.Append(",PictureId:'" + pictureId.ToString() + "'");
                sb.Append(",SiteUrl:'" + SiteUrl + "'");
                sb.Append(",Pictures:[");

                int Num = 1;
                bool IsCheck = false;

                foreach (CY.UME.Core.Business.Picture pic in picList)
                {
                    if (pic.Id == picture.Id)
                    {
                        IsCheck = true;
                    }
                    if (!IsCheck)
                    {
                        Num++;
                    }

                    sb.Append("{");
                    sb.Append("Id:'" + pic.Id + "'");
                    sb.Append(",Remark:'" + pic.Remark + "'");
                    sb.Append(",DateCreated:'" + pic.DateCreated.ToString("yyyy年MM月dd") + "'");
                    sb.Append(",Name:'" + pic.Name + "'");
                    sb.Append(",AlbumViewPermission:'" + album.ViewPermission + "'");
                    sb.Append("},");
                }

                sb.Remove(sb.Length - 1, 1);
                sb.Append("],CurrentNum:'" + Num.ToString() + "'");
                sb.Append("}");

                HiddenJson.Value = sb.ToString();
                HF_SiteUrl.Value = SiteUrl;
                HF_Album_Id.Value = album.Id.ToString();
                HF_TotalRecords.Value = CY.UME.Core.Business.Picture.GetAllPicture(album, pagingInfo).Count.ToString();//该相册照片数量
                //HiddenAccountDiff.Value = accountDiff;

                //绑定评论
                pictureCommentList = CY.UME.Core.Business.PictureComment.GetPicCommentByPagesAndPicId(picture);

                RPT_PicCommentList.DataSourceID = "";
                RPT_PicCommentList.DataSource = pictureCommentList;
                RPT_PicCommentList.DataBind();
            }
        }
Exemple #4
0
        /// <summary>
        /// 获取好友最新更新图片
        /// </summary>
        /// <param name="context"></param>
        /// <returns> 0 登录失败 -1请求失败 -2系统错误</returns>
        public string GetPicNoticeList(HttpContext context)
        {
            string email = String.Empty;
            CY.UME.Core.Business.Account currentAccount;

            if (context.Request.QueryString["email"] == null)
            {
                return "0";
            }

            email = context.Request.QueryString["email"].ToString();

            CY.UME.Core.Business.AccountExtend ae = CY.UME.Core.Business.AccountExtend.Load(email);

            if (ae == null)
            {
                return "0";
            }

            currentAccount = CY.UME.Core.Business.Account.Load(ae.Id);

            string[] type = { "picture" };
            IList<CY.UME.Core.Business.Notice> nList = GetNoticeList(currentAccount, type);
            StringBuilder sb = new StringBuilder();
            long picId = 0;
            sb.Append("[");
            bool check = false;
            try
            {
                foreach (CY.UME.Core.Business.Notice notice in nList)
                {
                    CY.UME.Core.Business.Picture picture = new CY.UME.Core.Business.Picture();

                    if (!CY.Utility.Common.ParseUtility.TryParseInt64(notice.InstanceId, out picId))
                    {
                        continue;
                    }
                    else
                    {
                        if (picId < 1) { continue; }
                        else
                        {
                            picture = CY.UME.Core.Business.Picture.Load(picId);
                        }
                    }

                    if (picture == null)
                    {
                        notice.DeleteOnSave();
                        notice.Save();
                        continue;
                    }

                    CY.UME.Core.Business.Album album = CY.UME.Core.Business.Album.Load(picture.AlbumId);
                    if (album == null)
                    {
                        continue;
                    }

                    CY.UME.Core.Business.Account author = CY.UME.Core.Business.Account.Load(notice.AuthorId);
                    if (author == null)
                    {
                        continue;
                    }

                    sb.Append("{");
                    sb.Append("\"AlbumId\":\"" + album.Id + "\"");
                    sb.Append(",\"AlbumName\":\"" + CY.Utility.Common.StringUtility.HTMLDecode(album.Name).Replace("\"", "&quot;") + "\"");
                    sb.Append(",\"Description\":\"" + CY.Utility.Common.StringUtility.HTMLDecode(picture.Remark).Replace("\"", "&quot;") + "\"");
                    sb.Append(",\"PicId\":\"" + picture.Id + "\"");
                    sb.Append(",\"PubDate\":\"" + picture.DateCreated.ToString("yyyy-MM-dd HH:mm") + "\"");
                    sb.Append(",\"AuthorId\":\"" + author.Id + "\"");
                    sb.Append(",\"AuthorName\":\"" + author.Name + "\"");
                    sb.Append("},");

                    check = true;
                }

                if (check)
                {
                    sb.Remove(sb.Length - 1, 1);
                }

                sb.Append("]");

                return sb.ToString();
            }
            catch
            {
                return "-2";
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string strPictureId = context.Request.Form["pictureId"].ToString();
            string strASpaceccountId = context.Request.Form["spaceAccountId"].ToString();
            long spaceAccountId = 0;

            long pictureId = 0;
            if (!long.TryParse(strPictureId, out pictureId) || !long.TryParse(strASpaceccountId,out spaceAccountId))
            {
                context.Response.Write("{success:false,msg:'参数错误'}");
                return;
            }

            CY.UME.Core.Business.Account currentAccount = CY.UME.Core.Global.GetCurrentAccount();

            if (currentAccount == null)
            {
                context.Response.Write("{success:false,msg:'用户登录超时'}");
                return;
            }
            if (spaceAccountId != currentAccount.Id)
            {
                context.Response.Write("{success:false,msg:'您无权设置'}");
                return;
            }

            CY.UME.Core.Business.Picture pic = CY.UME.Core.Business.Picture.Load(pictureId);

            if (pic == null)
            {
                context.Response.Write("success:false,msg:'图片不存在或已被删除'");
                return;
            }

            try
            {
                string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                string dirPath = appPath + "/Content/Album/" + spaceAccountId + "/";
                string fileName = "/Content/Album/" + spaceAccountId + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名
                string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(pic.BigPath);

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                string bImgName = appPath + fileName + "_big" + imgExtention;
                string mImgName = appPath + fileName + "_middle" + imgExtention;
                string sImgName = appPath + fileName + "_small" + imgExtention;

                Bitmap bmp = new Bitmap(appPath + pic.BigPath);

                int width = bmp.Width;
                int height = bmp.Height;

                // 保存大图片
                using (StreamReader reader = new StreamReader(appPath + pic.BigPath))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height);
                }

                bmp.Dispose();

                height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                width = 200;

                // 将大图片压缩为中等缩略图
                using (StreamReader reader = new StreamReader(bImgName))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, width, height);
                }
                // 将小头像压缩到48*48
                height = Convert.ToInt32(width > 48 ? (48f / width) * height : height);
                width = 48;
                using (StreamReader reader = new StreamReader(mImgName))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, sImgName, height, width);
                }

                CY.UME.Core.Business.Album album = CY.UME.Core.Business.Album.Load(pic.AlbumId);

                CY.UME.Core.Business.Account account = CY.UME.Core.Business.Account.Load(album.AccountId);

                album = account.GetMyAvatarAlbum();

                CY.UME.Core.Business.Picture picture = new CY.UME.Core.Business.Picture();

                picture.AlbumId = album.Id;
                picture.BigPath = fileName + "_big" + imgExtention;
                picture.DateCreated = DateTime.Now;
                picture.MiddlePath =fileName+ "_middle" + imgExtention;
                picture.Name = pic.Name;
                picture.SmallPath = fileName + "_small" + imgExtention;
                picture.Save();

                if (!account.HasAvatar)
                {
                    account.HasAvatar = true;
                    account.Save();
                }

                context.Response.Write("{success:true}");
            }
            catch (Exception ex)
            {
                context.Response.Write("success:false,msg:'" + ex.Message + "'");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            CY.UME.Core.Business.Account account;
            string bigImgPath, smallImgPath, imgExtention, imgName;
            string sitePath = CY.Utility.Common.SiteUtility.CurSitePath;

            String Id = context.Request.QueryString["accountId"].ToString();

            long accountId = CY.Utility.Common.ConvertUtility.ConvertToInt(Id, -1);

            #region -Validation and Get Basic Data-

            //account = CY.UME.Core.Global.GetCurrentAccount();
            account = CY.UME.Core.Business.Account.Load(accountId);
            if (account == null)
            {
                context.Response.Write("{success: false, msg: '用户登录超时,请重新登录!'}");
                return;
            }

            // post data
            bigImgPath = context.Request.Form["bigImgPath"];
            smallImgPath = context.Request.Form["smallImgPath"];
            imgExtention = context.Request.Form["imgExtention"];
            imgName = context.Request.Form["imgName"];
            if (string.IsNullOrEmpty(bigImgPath) ||
                string.IsNullOrEmpty(smallImgPath) ||
                string.IsNullOrEmpty(imgExtention))
            {
                context.Response.Write("{success: false, msg: '参数错误'}");
                return;
            }

            if (!File.Exists(sitePath + bigImgPath))
            {
                context.Response.Write("{success: false, msg: '照片不存在'}");
                return;
            }
            if (!File.Exists(sitePath + smallImgPath))
            {
                context.Response.Write("{success: false, msg: '小头像不存在'}");
                return;
            }
            #endregion

            CY.UME.Core.Business.Album avatarAlbum = account.GetMyAvatarAlbum();
            if (avatarAlbum == null)
            {
                avatarAlbum = new CY.UME.Core.Business.Album();
                avatarAlbum.AccountId = account.Id;
                avatarAlbum.DateCreated = DateTime.Now;
                avatarAlbum.IsAvatar = true;
                avatarAlbum.LastModifiedTime = avatarAlbum.DateCreated;
                avatarAlbum.Name = "头像相册";
                avatarAlbum.Save();
            }

            // 相册目录为: 网站根目录 + /Content/Avatar/ + 用户标识
            string avatarRelativePath = "/Content/Avatar/" + account.Id + "/";
            DirectoryInfo di = new DirectoryInfo(sitePath + avatarRelativePath); // 相册目录
            if (!di.Exists)
            {
                di.Create();
            }

            string uniqueId = Guid.NewGuid().ToString("N");

            string bImgName = uniqueId + "_big" + imgExtention;
            string mImgName = uniqueId + "_mid" + imgExtention;
            string sImgName = uniqueId + "_small" + imgExtention;

            try
            {
                Bitmap bmp = new Bitmap(sitePath + bigImgPath);
                int width = bmp.Width;
                int height = bmp.Height;

                bmp.Dispose();

                height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                width = 200;

                // 将大图片压缩为中等缩略图
                using (StreamReader reader = new StreamReader(sitePath + bigImgPath))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, di.FullName + mImgName, width, height);
                }
                // 将小头像从120*120压缩到48*48
                using (StreamReader reader = new StreamReader(sitePath + smallImgPath))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, di.FullName + sImgName, 48, 48);
                }

                // 将大图移动到头像目录下
                FileInfo fi = new FileInfo(sitePath + bigImgPath);
                fi.MoveTo(di.FullName + bImgName);

                try
                {
                    // File.Delete(sitePath + bigImgPath);
                    File.Delete(sitePath + smallImgPath);
                }
                catch
                {
                    ;
                }

                // 添加照片记录
                CY.UME.Core.Business.Picture picture = new CY.UME.Core.Business.Picture();
                picture.AlbumId = avatarAlbum.Id;
                picture.BigPath = avatarRelativePath + bImgName;
                picture.DateCreated = DateTime.Now;
                picture.MiddlePath = avatarRelativePath + mImgName;
                picture.Name = imgName;
                picture.Remark = string.Empty;
                picture.SmallPath = avatarRelativePath + sImgName;
                picture.Save();

                if (!account.HasAvatar)
                {
                    account.HasAvatar = true;

                    #region 积分

                    int uploadAvatarCredit;
                    if (CY.UME.Core.Business.SystemSetting.TryLoadInt32Setting("CreditUploadAvatar", out uploadAvatarCredit) &&
                        (uploadAvatarCredit != 0))
                    {
                        int orgCredit = account.Credit;
                        int modifiedCredit = orgCredit + uploadAvatarCredit;
                        account.Credit = modifiedCredit;

                        CY.UME.Core.Business.CreditHistory ch = new CY.UME.Core.Business.CreditHistory();
                        ch.AccountId = account.Id;
                        ch.DateCreated = DateTime.Now;
                        ch.Id = Guid.NewGuid();
                        ch.InstanceId = "";
                        ch.Original = orgCredit;
                        ch.Modified = modifiedCredit;
                        ch.Variation = uploadAvatarCredit;
                        ch.Type = "uploadavatar";
                        ch.Description = "上传头像";
                        ch.Save();
                    }

                    #endregion

                    account.Save();
                }

                //添加通知
                //account.SendNoticeToAllFriend("picture", "更新了头像", picture.Id.ToString());

                context.Response.Write("{success: true}");
                return;
            }
            catch
            {
                context.Response.Write("{success: false, msg: '保存头像失败'}");
                return;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            HttpPostedFile imgFile;
            int activeID = 0;
            long accountId = 0;

            if (!int.TryParse(context.Request.QueryString["activeID"].ToString(), out activeID)
                || !long.TryParse(context.Request.QueryString["accountId"].ToString(), out accountId))
            {
                return;
            }

            CY.UME.Core.Business.Activities active = CY.UME.Core.Business.Activities.Load(activeID);

            if (active == null)
            {
                return;
            }

            CY.UME.Core.Business.Account account = CY.UME.Core.Business.Account.Load(accountId);
            if (account == null || account.Id == 0)
            {
                return;
            }

            CY.UME.Core.Business.Album album = active.GetActiveAlbum();

            if (album == null || album.Id == 0)
            {
                album = active.CreateActiveAlbum();
            }

            //if (accountId != active.Sponsor)
            //{
            //    context.Response.Write("只有活动发起人才能上传图片");
            //    return;
            //}
            //else
            //{
            //获取上传的文件并保存
            if (context.Request.Files.Count > 0)
            {
                for (int i = 0; i < context.Request.Files.Count; i++)
                {
                    imgFile = context.Request.Files[i];

                    if (imgFile == null)
                    {
                        continue;
                    }

                    string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgFile.FileName).ToLower();
                    string imgName = CY.Utility.Common.FileUtility.GetFileName(imgFile.FileName);

                    string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                    string dirPath = appPath + "/Content/Activites/" + accountId + "/";
                    string fileName = "/Content/Activites/" + accountId + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名

                    System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                    if (!di.Exists)
                    {
                        di.Create();
                    }

                    string bImgName = appPath + fileName + "_big" + imgExtention;
                    string mImgName = appPath + fileName + "_middle" + imgExtention;
                    string sImgName = appPath + fileName + "_small" + imgExtention;

                    imgFile.SaveAs(appPath + fileName + imgExtention);//临时保存原始图片

                    Bitmap bmp = new Bitmap(appPath + fileName + imgExtention);
                    int width = bmp.Width;
                    int height = bmp.Height;

                    bmp.Dispose();

                    if (height <= width && width >= 600)
                    {
                        height = Convert.ToInt32(width > 600 ? (600f / width) * height : height);
                        width = 600;
                    }
                    else if (width < height && height > 600)
                    {
                        width = Convert.ToInt32(height > 600 ? (600f / height) * width : height);
                        height = 600;
                    }

                    // 将原始图压缩为大缩略图
                    using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                    {
                        CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height);
                    }

                    if (width > 200)
                    {
                        height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                        width = 200;
                    }

                    // 生成图片(好友上传图片最新通知中显示)
                    using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                    {
                        CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, sImgName, width, height);
                    }

                    if (height <= width && width >= 100)
                    {
                        height = Convert.ToInt32(width > 100 ? (100f / width) * height : height);
                        width = 100;
                    }
                    else if (width < height && height > 100)
                    {
                        width = Convert.ToInt32(height > 100 ? (100f / height) * width : height);
                        height = 100;
                    }

                    // 将大图片压缩为中等缩略图
                    using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                    {
                        CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, width, height);
                    }

                    try
                    {
                        File.Delete(appPath + fileName + imgExtention);
                    }
                    catch
                    {
                        ;
                    }

                    //将路径及图片信息保存到数据库
                    CY.UME.Core.Business.Picture pic = new CY.UME.Core.Business.Picture();

                    pic.AlbumId = album.Id;
                    pic.BigPath = fileName + "_big" + imgExtention;
                    pic.DateCreated = DateTime.Now;
                    pic.MiddlePath = fileName + "_middle" + imgExtention;
                    pic.Name = CY.Utility.Common.StringUtility.HTMLEncode(imgName.Substring(0, imgName.Length > 30 ? 30 : imgName.Length));
                    pic.SmallPath = fileName + "_small" + imgExtention;

                    pic.Save();

                    //保存pictureextend
                    CY.UME.Core.Business.PictureExtend pe = new CY.UME.Core.Business.PictureExtend();

                    pe.Id = pic.Id;
                    pe.AccountId = account.Id;
                    pe.ActivityId = "active";
                    pe.ActivityPicId = "0";

                    pe.Save();

                    context.Response.Write("1");
                }
            }
        }