protected void BindData(CY.UME.Core.Business.Activities active) { CY.UME.Core.PagingInfo pageInfo = new CY.UME.Core.PagingInfo(); pageInfo.CurrentPage = 1; pageInfo.PageSize = 15; CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); if (active != null) { album = active.GetActiveAlbum(); picList = album.GetPictures(pageInfo); } int count = album.GetPictureCount(); minPubDate.Value = ""; maxPubDate.Value = ""; picname.Value = ""; authorName.Value = ""; gpm_HiddenPageSize.Value = "15"; gpm_HiddenRecordCount.Value = count.ToString(); gpm_HiddenSiteUrl.Value = SiteUrl; }
protected void BindData(CY.UME.Core.Business.Group group) { CY.UME.Core.PagingInfo pageInfo = new CY.UME.Core.PagingInfo(); pageInfo.CurrentPage = 1; pageInfo.PageSize = 15; CY.UME.Core.Business.Album album =new CY.UME.Core.Business.Album(); if (group != null) { album = group.GetGroupAlbum(); picList = album.GetPictures(pageInfo); } int count = album.GetPictureCount(); DDLGroup.SelectedValue = group.Id.ToString(); minPubDate.Value = ""; maxPubDate.Value = ""; picname.Value = ""; authorName.Value = ""; gpm_HiddenPageSize.Value = "15"; gpm_HiddenRecordCount.Value = count.ToString(); gpm_HiddenSiteUrl.Value = SiteUrl; }
/// <summary> /// 分页处理 /// </summary> /// <param name="src"></param> /// <param name="e"></param> protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); album.AccountName = HFAccountName.Value; album.Name = HFAlbumName.Value; Bind(album, HFSort.Value, false); }
/// <summary> /// 查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void BtnSearch_Click(object sender, EventArgs e) { HFAccountName.Value = TxtAccountName.Text.Trim(); HFAlbumName.Value = TxtAlbumName.Text.Trim(); HFSort.Value = DDLSort.SelectedValue; CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); album.AccountName = HFAccountName.Value; album.Name = HFAlbumName.Value; Bind(album, HFSort.Value, true); }
/// <summary> /// 0 登录失败 -1请求失败 -2系统错误 albumId 成功 /// </summary> /// <param name="context"></param> /// <returns></returns> public string AddAlbum(HttpContext context) { string albumName = String.Empty;//相册名 CY.UME.Core.Business.AccountExtend ae;//当前用户 string email = context.Request.QueryString["email"].ToString().Trim(); #region validate if (String.IsNullOrEmpty(email)) { return "0"; } ae = CY.UME.Core.Business.AccountExtend.Load(email); if (ae == null) { return "0"; } if (context.Request.QueryString["Name"] != null) { albumName = context.Request.QueryString["Name"].ToString().Trim(); } #endregion try { CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); album.AccountId = ae.Id; album.DateCreated = DateTime.Now; album.IsAvatar = false; album.LastModifiedTime = DateTime.Now; album.Name = albumName; album.ViewPermission = 0; album.CoverPath = CY.UME.Core.Global.AlbumCoverAddress; album.Save(); return album.Id.ToString(); } catch { return "-2"; } }
private CY.UME.Core.Business.Album GetActivityAlbum(string type, string instanceId, string albumName) { IList<CY.UME.Core.Business.AlbumExtend> aeList = CY.UME.Core.Business.AlbumExtend.GetAlbumExtend(CurrentAccount.Id, type, instanceId); long aId = 0; CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); if (aeList.Count != 0) { aId = aeList[0].Id; } //创建活动相册 if (aId == 0) { album.AccountId = CurrentAccount.Id; album.DateCreated = DateTime.Now; album.IsAvatar = false; album.LastModifiedTime = DateTime.Now; album.Name = albumName; album.ViewPermission = 0; album.Save(); CY.UME.Core.Business.AlbumExtend ae = new CY.UME.Core.Business.AlbumExtend(); ae.Type = type; ae.InstanceId = instanceId; ae.AccountId = album.AccountId; ae.Id = album.Id; ae.Save(); aId = album.Id; } else { album = CY.UME.Core.Business.Album.Load(aId); } return album; }
/// <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; } }
/// <summary> /// 0 登录失败 -1请求失败 -2系统错误 /// </summary> /// <param name="context"></param> /// <returns></returns> public string GetAlbumList(HttpContext context) { string email = context.Request.QueryString["email"].ToString().Trim(); if (String.IsNullOrEmpty(email)) { return "0"; } try { CY.UME.Core.Business.AccountExtend ae = CY.UME.Core.Business.AccountExtend.Load(email); if (ae == null || ae.Id == 0) { return "0"; } CY.UME.Core.Business.Account account; long accountId = 0; if (context.Request.QueryString["FriendId"] == null) { account = CY.UME.Core.Business.Account.Load(ae.Id); } else { if (!long.TryParse(context.Request.QueryString["FriendId"].ToString(), out accountId)) { account = CY.UME.Core.Business.Account.Load(ae.Id); } else { account = CY.UME.Core.Business.Account.Load(accountId); } } if (account == null) { return "-1"; } List<CY.UME.Core.Business.Album> albumAvatarList = CY.UME.Core.Business.Album.GetAll(account, true); CY.UME.Core.Business.Album albumAvatar = new CY.UME.Core.Business.Album(); if (albumAvatarList.Count > 0) { albumAvatar = albumAvatarList[0]; } List<CY.UME.Core.Business.Album> albumList = CY.UME.Core.Business.Album.GetAll(account, false); if (albumList == null || albumList.Count == 0) { CY.UME.Core.Business.Album al = new CY.UME.Core.Business.Album(); al.AccountId = account.Id; al.DateCreated = DateTime.Now; al.IsAvatar = false; al.LastModifiedTime = DateTime.Now; al.Name = "默认相册"; al.ViewPermission = 0; al.Save(); albumList.Add(al); } StringBuilder sb = new StringBuilder(); sb.Append("["); if (albumAvatar != null) { sb.Append("{\"Id\":" + albumAvatar.Id); sb.Append(",\"Name\":\"" + albumAvatar.Name + "\""); sb.Append(",\"Count\":" + albumAvatar.PhotoCount + "},"); } foreach (CY.UME.Core.Business.Album album in albumList) { sb.Append("{\"Id\":" + album.Id); sb.Append(",\"Name\":\"" + album.Name.Replace("\"", """) + "\""); sb.Append(",\"Count\":" + album.PhotoCount + "},"); } sb.Remove(sb.Length - 1, 1); sb.Append("]"); return sb.ToString(); } catch { return "-2"; } }
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(); } }
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; } }
protected void Page_Load(object sender, EventArgs e) { int spaceId = 0; if (Request.QueryString["activeID"] != null) { activeID = CY.Utility.Common.ConvertUtility.ConvertToInt(Request.QueryString["activeID"], 0); CY.UME.Core.Business.Activities active = CY.UME.Core.Business.Activities.Load(activeID); if (active != null) SetTitle(active.Name + "活动图片"); if (CurrentAccount != null) SpaceAccount = CurrentAccount; } else { if (Request.QueryString["SpaceId"] == null) { throw new Exception("参数错误"); } else if (!int.TryParse(Request.QueryString["SpaceId"].ToString(), out spaceId)) { throw new Exception("参数错误"); } SetTitle("相册 "); SpaceAccount = CY.UME.Core.Business.Account.Load(spaceId); if (SpaceAccount == null) SpaceAccount = CurrentAccount; } CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); bool IsAdaPage = false; #region validate if (Request.QueryString["albumId"] == null) { throw new Exception("参数无效"); } if (!long.TryParse(Request.QueryString["albumId"].ToString(), out albumId)) { throw new Exception("参数错误"); } album = CY.UME.Core.Business.Album.Load(albumId); #endregion if (!IsPostBack) { if (album == null) { //LblError.Text = "请求相册不存在或已被删除"; //LblError.Visible = true; //pictureListControl.pictureList = null; } else { int pageSize = CY.Utility.Common.ConvertUtility.ConvertToInt(pl_HiddenPageSize.Value, 9); CY.UME.Core.PagingInfo pageInfo = new CY.UME.Core.PagingInfo(); pageInfo.CurrentPage = 1; pageInfo.PageSize = pageSize; IList<CY.UME.Core.Business.Picture> picList = CY.UME.Core.Business.Picture.GetAllPicture(album, pageInfo); RPT_PictureList.DataSourceID = ""; RPT_PictureList.DataSource = picList; RPT_PictureList.DataBind(); if (SpaceAccount != null) { pl_HiddenAccountId.Value = SpaceAccount.Id.ToString(); HF_CurrentAccount_Id.Value = pl_HiddenAccountId.Value; } HF_SiteUrl.Value = SiteUrl; pl_HiddenTotalRecords.Value = album.PhotoCount.ToString(); pl_HiddenAlbumId.Value = album.Id.ToString(); HiddenAccountDiff.Value = accountDiff; if (activeID == 0) { if (CurrentAccount != null && spaceId != 0) LBLAlbumList.Text = "<a href=\"AlbumList.aspx?SpaceId=" + spaceId + "\">我的相册</a>>"; else LBLAlbumList.Text = "<a href=\"AlbumList.aspx?SpaceId=" + spaceId + "\">" + SpaceAccount.Name + "的相册</a>>"; } LblAlbumName.Text = CY.Utility.Common.StringUtility.CutString(album.Name, 20, "..."); LblAlbumName.ToolTip = album.Name; } //uploadPic.Visible = avtarPic.Visible = createdAlbum.Visible = DeleteAlbum.Visible = true; if (activeID == 0 && CurrentAccount != null && SpaceAccount.Id == CurrentAccount.Id) { if (IsAdaPage) { DeleteAlbum.Visible = false; uploadPic.Visible = true; return; } createdAlbum.Visible = true; DeleteAlbum.Visible = true; uploadPic.Visible = true; uploadPic.InnerHtml = "<a href=\"UploadPicture.aspx?SpaceId=" + SpaceAccount.Id + "&albumId=" + album.Id + "\">上传照片</a>"; if (!album.IsAvatar) { avtarPic.Visible = false; uploadPic.Visible = true; modifyAlbum.Visible = true; modifyAlbum.InnerHtml = "<a href=\"AlbumEdit.aspx?SpaceId=" + SpaceAccount.Id + "&albumId=" + album.Id + "\">编辑相册</a>"; } else { avtarPic.Visible = true; uploadPic.Visible = false; } } else { //if (album.ViewPermission == 2) //{ // if (Session["AlbumPassword"] == null || Session["AlbumPassword"].ToString() != album.ViewPassword) // { // Response.Redirect("ViewEnAlbum.aspx?uid=" + SpaceAccount.Id.ToString() + "&albumId=" + albumId.ToString()); // return; // } //} } if (CurrentAccount == null) { //personalState.Visible = false; } else { BingAlbumType(CurrentAccount, album.Id); } UserInfo1.SpaceAccount = SpaceAccount; FollowerListId.CurrentFollower = SpaceAccount; //personalState.CurrentAccount = CurrentAccount; //pictureListControl.currentAccount = CurrentAccount; //pictureListControl.spaceAccount = SpaceAccount; } }
protected void Save_OnClick(object sender, EventArgs e) { if (ViewState["accountId"] == null) { throw new Exception("系统异常"); } CY.UME.Core.Business.Album alb = new CY.UME.Core.Business.Album(); if (ViewState["albumId"] != null && ViewState["IsModify"] != null && bool.Parse(ViewState["IsModify"].ToString())) { alb = CY.UME.Core.Business.Album.Load(long.Parse(ViewState["albumId"].ToString())); } else { alb.AccountId = int.Parse(ViewState["accountId"].ToString()); alb.DateCreated = DateTime.Now; alb.CoverPath = CY.UME.Core.Global.AlbumCoverAddress; } alb.LastModifiedTime = DateTime.Now; alb.Name = TBXAlbumName.Text.Trim(); if (alb.ViewPermission==2 && alb.ViewPermission != int.Parse(SelViewPermission.Value)) { alb.ViewPassword = String.Empty; } alb.ViewPermission = int.Parse(SelViewPermission.Value); if (SelViewPermission.Value == "2") { if (TBXpassword.Text.Trim().Length == 0) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '密码不能为空'})</script>"); return; } CY.Security.SecurityHelper sh = new CY.Security.SecurityHelper(); alb.ViewPassword =sh.ComputeMD5Hash(TBXpassword.Text.Trim()); alb.CoverPath = CY.UME.Core.Global.AlbumCoverNoPublishAddress; } else { CY.UME.Core.PagingInfo pageinfo = new CY.UME.Core.PagingInfo(); pageinfo.CurrentPage=1; pageinfo.PageSize =1; List<CY.UME.Core.Business.Picture> picList = CY.UME.Core.Business.Picture.GetAllPicture(album, pageinfo); if (picList != null && picList.Count > 0) alb.CoverPath = picList[0].MiddlePath; } try { alb.Save(); Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '提示', content: '修改成功'});window.location.href='AlbumList.aspx?spaceId=" + long.Parse(ViewState["accountId"].ToString()) + "'</script>"); } catch { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '保存失败,发生意外错误'});</script>"); } }
protected void Page_Load(object sender, EventArgs e) { //CY.UME.Core.Business.Account currentAccount = Session["user"] as CY.UME.Core.Business.Account; //if (currentAccount == null) //{ // Response.Redirect("~/Login.aspx"); // return; //} ViewState["accountId"] = CurrentAccount.Id; long spaceId = 0; if (Request.QueryString["SpaceId"] == null || !long.TryParse(Request.QueryString["SpaceId"].ToString(),out spaceId)) { throw new Exception("参数错误"); } if (spaceId != CurrentAccount.Id) { throw new Exception("您无权执行此操作"); } SetTitle("相册"); SpaceAccount = CY.UME.Core.Business.Account.Load(spaceId); personalState.SpaceAccount = SpaceAccount; personalState.CurrentAccount = CurrentAccount; if (!IsPostBack) { if (Request.QueryString["albumId"] == null)//添加 { ViewState["IsModify"] = false; } else { ViewState["IsModify"] = true; long albumId = 0; if (!long.TryParse(Request.QueryString["albumId"].ToString(),out albumId)) { throw new Exception("参数不合法"); } ViewState["albumId"] = albumId; album = CY.UME.Core.Business.Album.Load(albumId); TBXAlbumName.Text = album.Name; SelViewPermission.Value = album.ViewPermission.ToString(); if (album.ViewPermission == 2) { passPanel.Attributes.Remove("style"); passPanel.Visible = true; modPassPanel.Visible = true; } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { long albumId = 0; if (Request.QueryString["albumId"] == null) { throw new Exception("页面不存在"); } if (!long.TryParse(Request.QueryString["albumId"].ToString(), out albumId)) { throw new Exception("页面不存在"); } album = CY.UME.Core.Business.Album.Load(albumId); if (album == null) { throw new Exception("该相册不存在或已被删除"); } CY.UME.Core.Business.AlbumExtend ae = CY.UME.Core.Business.AlbumExtend.Load(album.Id); if (ae == null) { throw new Exception("系统异常错误"); } if (ae.Type != "group" || !int.TryParse(ae.InstanceId, out groupId)) { throw new Exception("该群组相册不存在或已被删除"); } group = CY.UME.Core.Business.Group.Load(groupId); if (group == null) { throw new Exception("该相册所在群组不存在或已被删除"); } LBLAlbumList.Text = "<a href=\"AlbumList.aspx?groupId=" + group.Id + "\">" + group.Name + "的相册</a>"; LblAlbumName.Text = CY.Utility.Common.StringUtility.CutString(album.Name,20,"..."); if (group.CheckIsManager(CurrentAccount)) {//判断是否是群组管理员 isMagager = true; } picList = CY.UME.Core.Business.Picture.GetAllPicture(album, new CY.UME.Core.PagingInfo { CurrentPage = 1, PageSize = CY.Utility.Common.ConvertUtility.ConvertToInt(pl_HiddenPageSize.Value, 15) }); RPT_PictureList.DataSourceID = ""; RPT_PictureList.DataSource = picList; RPT_PictureList.DataBind(); int PictureCount = album.GetPictureCount(); if (PictureCount > picList.Count) { isShowPaged = true; } //uc_GroupInfo.group = group; //uc_NewestTopices.group = group; BingAlbum(group, album.Id); pl_HiddenPageSize.Value = "15"; pl_HiddenAlbumId.Value = albumId.ToString(); pl_HiddenCurrentAccountId.Value = CurrentAccount.Id.ToString(); pl_HiddenGroupId.Value = groupId.ToString(); pl_HiddenSiteUrl.Value = SiteUrl; pl_HiddenTotalRecords.Value = PictureCount.ToString(); SetTitle(group.Name + " - " + album.Name); } //base.CSSName = "ume2"; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { long albumId = 0; if (Request.QueryString["albumId"] == null) { throw new Exception("页面不存在"); } if (!long.TryParse(Request.QueryString["albumId"].ToString(), out albumId)) { throw new Exception("页面不存在"); } album = CY.UME.Core.Business.Album.Load(albumId); if (album == null) { throw new Exception("该相册不存在或已被删除"); } ViewState["albumId"] = albumId; bind(albumId); } SetTitle(group.Name + " - " + album.Name); base.CSSName = "ume2"; }
protected void Page_Load(object sender, EventArgs e) { CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); #region validate al_HiddenSiteUrl.Value = SiteUrl; al_HiddenCurrentAccountId.Value = CurrentAccount.Id.ToString(); long spaceId = 0, albumId = 0; int groupId = 0; SetTitle("上传照片 "); if (Request.QueryString["uid"] == null) { SpaceAccount = CurrentAccount; } else if (long.TryParse(Request.QueryString["uid"].ToString(), out spaceId)) { SpaceAccount = CY.UME.Core.Business.Account.Load(spaceId); } else { SpaceAccount = CurrentAccount; } if (Request.QueryString["albumId"] != null && long.TryParse(Request.QueryString["albumId"].ToString(), out albumId)) { album = CY.UME.Core.Business.Album.Load(albumId); } if (Request.QueryString["gid"] == null) { throw new Exception("页面不存在"); } if (!int.TryParse(Request.QueryString["gid"].ToString(), out groupId)) { throw new Exception("页面不存在"); } al_HiddenGroupId.Value = groupId.ToString(); group = CY.UME.Core.Business.Group.Load(groupId); #endregion //UserInfo1.SpaceAccount = SpaceAccount; if (!IsPostBack) { if (Request.QueryString["code"] != null) { string advParam = Request.QueryString["code"].ToString(); CY.UME.Core.Business.AdvancedPage ap = CY.UME.Core.Business.AdvancedPage.SelectByCode(advParam); if (ap != null) { flashUpload.QueryParameters = "code=" + advParam + "&"; album = GetActivityAlbum(ap.Code, ap.Id.ToString(), ap.Name); HiddenActivityAlbumId.Value = album.Id.ToString(); } } /*********************第一天活动************************/ else if (Request.QueryString["mfd"] != null) { string myfirstdayParam = Server.UrlDecode(Request.QueryString["mfd"].ToString()); if (myfirstdayParam == "myfirstday") { flashUpload.QueryParameters = "IsFirstDay=myfirstday&"; HiddenIsFirstDay.Value = "myfirstday"; album = GetActivityAlbum("myfirstday", "myfirstday", "找人相册"); HiddenActivityAlbumId.Value = album.Id.ToString(); } } /***********************第一天活动结束*****************/ if (album == null || album.Id == 0) { string strAlbumId = BingAlbumType(CurrentAccount,group); if (strAlbumId == "false") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({ title: '提示', content:'请先创建相册'});window.location.href='AlbumEdit.aspx?SpaceId=" + CurrentAccount.Id.ToString() + "'</script>"); return; } LblTitle.Text = "上传图片"; flashUpload.QueryParameters = "albumId=" + strAlbumId + "&accountId=" + CurrentAccount.Id.ToString() + "&groupId=" + groupId.ToString(); //LblAlbum.Visible = false; } else { LblDescription.Visible = false; DDLAlbum.Visible = false; //LblAlbum.Visible = true; //LblAlbum.Text = album.Name; LblTitle.Text = album.Name; flashUpload.QueryParameters += "albumId=" + album.Id.ToString() + "&accountId=" + CurrentAccount.Id.ToString() + "&groupId=" + groupId.ToString(); } string noticeContent = String.Empty; noticeContent = TBXNoticeInfo.Text.Trim(); if (noticeContent.Length == 0) { noticeContent = "上传了新照片"; } if (CBMagic.Checked) { noticeContent = "<span class=\"magic\">" + noticeContent; noticeContent += "</span>"; } flashUpload.QueryParameters += "¬iceContent=" + Server.UrlEncode(noticeContent); } }
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 }
private void SaveFiles(int id, string name, HttpPostedFile files) { string fileExtension = CY.Utility.Common.FileUtility.GetFileExtension(files.FileName).ToLower();//后缀名 if (fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".gif" && fileExtension != ".png" && fileExtension != ".bmp") { base.ExecuteClientScript("$('#add_msg').html('图片格式不正确,请重新选择图片上传。').fadeOut(10000, function () { $(this).html('').show(); });"); return; } CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); album.AccountId = 0;// CurrentAccount.Id;//当前用户ID() album.DateCreated = DateTime.Now; album.IsAvatar = false; album.Name = name;//活动名称 string appPath = Request.PhysicalApplicationPath; string baseurl = "/Content/Activites/" + CurrentAccount.Id; string bPath = @"\Content\Activites\" + CurrentAccount.Id; DirectoryInfo di = new DirectoryInfo(appPath + bPath); if (!di.Exists) { di.Create(); } string fileSHowName = files.FileName; int dotIndex = files.FileName.IndexOf("\\"); string fileName = string.Empty; if (dotIndex == -1) { fileName = CY.Utility.Common.FileUtility.GetFileName(files.FileName);//文件名 } else { string fileNameTemp = CY.Utility.Common.FileUtility.GetFileName(files.FileName); int indElx = fileNameTemp.LastIndexOf("\\") + 1; fileName = fileNameTemp.Substring(indElx); } //string saveFileName = fileName + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString(); string saveFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString(); files.SaveAs(appPath + bPath + "\\" + saveFileName + fileExtension); album.CoverPath = baseurl + "/" + saveFileName + fileExtension; album.Save(); string temp = bPath + "\\" + saveFileName; CompressImg(appPath, temp, fileExtension, id, album.Id); }