private string Creatjson(CY.UME.Core.Business.Account currentAccount, string pageSize, string pageNum) { StringBuilder json = new StringBuilder(); try { currentAccount.GetUnreadNotice("inforeply"); CY.UME.Core.PagingInfo pageInfo1 = new CY.UME.Core.PagingInfo(); pageInfo1.CurrentPage = 1; pageInfo1.PageSize = int.MaxValue; string[] type = { "friend", "groupinvite", "activeInviteFriend" }; List<CY.UME.Core.Business.Notice> NoticeList = CY.UME.Core.Business.Notice.GetNoticeGroupByType(currentAccount, type, false, pageInfo1) as List<CY.UME.Core.Business.Notice>; int infonum = CY.UME.Core.Business.Notice.GetInfoNoticeCount(currentAccount); if (infonum != 0) { CY.UME.Core.Business.Notice newNotice = new CY.UME.Core.Business.Notice(); newNotice.Id = infonum; newNotice.Type = "info"; NoticeList.Add(newNotice); } CY.UME.Core.PagingInfo pageInfo = new CY.UME.Core.PagingInfo(); pageInfo.CurrentPage = int.Parse(pageNum); pageInfo.PageSize = int.Parse(pageSize); string[] type1 = { "activitesinforeply", "blogreply", "miniblogreply", "picreply", "firstpicreply", "topicreply", "groupinforeply", "activeTopicReply", "relativegroup" }; List<CY.UME.Core.Business.Notice> NoticeList1 = CY.UME.Core.Business.Notice.GetNoticeGroupByType(currentAccount, type1, false, pageInfo) as List<CY.UME.Core.Business.Notice>; NoticeList.AddRange(NoticeList1); string[] type2 = { "activeCheckNo" };//审核不通过 List<CY.UME.Core.Business.Notice> NoticeList2 = CY.UME.Core.Business.Notice.GetNoticeGroupByType(currentAccount, type2, false, pageInfo) as List<CY.UME.Core.Business.Notice>; NoticeList.AddRange(NoticeList2); string[] type3 = { "activeCheck" };//审核通过 List<CY.UME.Core.Business.Notice> NoticeList3 = CY.UME.Core.Business.Notice.GetNoticeGroupByType(currentAccount, type3, false, pageInfo) as List<CY.UME.Core.Business.Notice>; NoticeList.AddRange(NoticeList3); if (NoticeList != null && NoticeList.Count > 0) { bool check = false; json.Append("{success:true,"); if (NoticeList.Count < int.Parse(pageSize)) { json.Append("toend:true,"); } else { json.Append("toend:false,"); } json.Append("list:"); json.Append("["); for (int i = 0; i < NoticeList.Count; i++) { switch (NoticeList[i].Type) { case "friend": json.Append("{Count:'" + NoticeList[i].Id + "',Type:'" + NoticeList[i].Type + "'"); break; case "groupinvite": json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); break; case "activeInviteFriend": json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); break; case "info": json.Append("{Count:'" + NoticeList[i].Id + "',Type:'" + NoticeList[i].Type + "'"); break; //case "inforeply": // long inforId; // if (CY.Utility.Common.ParseUtility.TryParseInt64(NoticeList[i].InstanceId, out inforId)) // { // CY.UME.Core.Business.SpaceComment spacecomm = CY.UME.Core.Business.SpaceComment.Load(inforId); // CY.UME.Core.Business.SpaceComment spacecomm2 = CY.UME.Core.Business.SpaceComment.Load(spacecomm.ReferedId); // if (spacecomm2 == null) // { // NoticeList[i].DeleteOnSave(); // NoticeList[i].Save(); // continue; // } // else // { // json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); // json.Append(",SpaceComment:'"); // json.Append(CY.Utility.Common.StringUtility.EscapeString( // CY.Utility.Common.StringUtility.CutString(spacecomm2.Content, 50, "..."))); // json.Append("',SpaceOwerId:'"); // json.Append(spacecomm2.AccountId); // json.Append("'"); // } // } // break; case "blogreply": long blogId; if (CY.Utility.Common.ParseUtility.TryParseInt64(NoticeList[i].InstanceId, out blogId)) { CY.UME.Core.Business.Blog blog = CY.UME.Core.Business.Blog.Load(blogId); if (blog == null) { NoticeList[i].DeleteOnSave(); NoticeList[i].Save(); continue; } else { json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",blogSubject:'"); json.Append(CY.Utility.Common.StringUtility.EscapeString( CY.Utility.Common.StringUtility.CutString(blog.Subject, 50, "..."))); json.Append("',blogOwerId:'"); json.Append(blog.AccountId); json.Append("'"); } } break; case "miniblogreply": long miniblogId; if (CY.Utility.Common.ParseUtility.TryParseInt64(NoticeList[i].InstanceId, out miniblogId)) { CY.UME.Core.Business.MiniBlog miniblog = CY.UME.Core.Business.MiniBlog.Load(miniblogId); if (miniblog == null) { NoticeList[i].DeleteOnSave(); NoticeList[i].Save(); continue; } else { json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",MiniBlogContent:'"); json.Append(CY.Utility.Common.StringUtility.EscapeString( CY.Utility.Common.StringUtility.CutString(miniblog.Content, 50, "..."))); json.Append("',SpaceOwerId:'"); json.Append(miniblog.AccountId); json.Append("'"); } } break; case "picreply": long picId; if (CY.Utility.Common.ParseUtility.TryParseInt64(NoticeList[i].InstanceId, out picId)) { CY.UME.Core.Business.Picture pic = CY.UME.Core.Business.Picture.Load(picId); if (pic == null) { NoticeList[i].DeleteOnSave(); NoticeList[i].Save(); continue; } else { json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",pictureId:'"); json.Append(pic.Id); json.Append("',pictureName:'"); json.Append(CY.Utility.Common.StringUtility.EscapeString(CY.Utility.Common.StringUtility.CutString(pic.Name, 30, "..."))); json.Append("'"); } } break; case "topicreply": if (NoticeList[i].InstanceId.Length > 0) { Guid topicId = new Guid(NoticeList[i].InstanceId); CY.UME.Core.Business.Topic topic = CY.UME.Core.Business.Topic.Load(topicId); CY.UME.Core.Business.TopicExtend topicex = CY.UME.Core.Business.TopicExtend.Load(topicId); CY.UME.Core.Business.Group group = CY.UME.Core.Business.Group.Load(int.Parse(topicex.InstanceId)); if (topic == null) { NoticeList[i].DeleteOnSave(); NoticeList[i].Save(); continue; } else { json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",groupId:'"); json.Append(group.Id); json.Append("',groupName:'"); json.Append(CY.Utility.Common.StringUtility.EscapeString(CY.Utility.Common.StringUtility.CutString(group.Name, 30, "...")) + "'"); json.Append(",topicId:'"); json.Append(topicId); json.Append("',topicName:'"); json.Append(CY.Utility.Common.StringUtility.EscapeString(CY.Utility.Common.StringUtility.CutString(topic.Title, 30, "...")) + "'"); } } break; case "groupinforeply": if (NoticeList[i].InstanceId.Length > 0) { int groupinfoId = 0; if (!int.TryParse(NoticeList[i].InstanceId, out groupinfoId)) { continue; } CY.UME.Core.Business.Group groupInfo = CY.UME.Core.Business.Group.Load(groupinfoId); if (groupInfo == null) { continue; } json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",groupId:'" + groupinfoId); json.Append("',groupName:'" + CY.Utility.Common.StringUtility.EscapeString(groupInfo.Name) + "'"); } break; /**************************************************废除的代码/************************************************* case "firstpicreply": if (NoticeList[i].InstanceId.Length > 0) { Guid firstpicId = new Guid(NoticeList[i].InstanceId); CY.UME.Core.Business.FirstDayAccountPic firstpic = CY.UME.Core.Business.FirstDayAccountPic.Load(firstpicId); if (firstpic == null) { NoticeList[i].DeleteOnSave(); NoticeList[i].Save(); continue; } else { json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",firstPictureId:'"); json.Append(firstpicId); json.Append("'"); } } break;*/ case "activitesinforeply": if (NoticeList[i].InstanceId.Length > 0) { int activeId = 0; if (!int.TryParse(NoticeList[i].InstanceId, out activeId)) { continue; } CY.UME.Core.Business.Activities active = CY.UME.Core.Business.Activities.Load(activeId); if (active == null) { continue; } json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",activeId:'" + activeId); json.Append("',activeName:'" + CY.Utility.Common.StringUtility.EscapeString(active.Name) + "'"); } break; case "activeTopicReply": if (NoticeList[i].InstanceId.Length > 0) { Guid topicId = new Guid(); topicId = new Guid(NoticeList[i].InstanceId.ToString()); CY.UME.Core.Business.Topic topic = CY.UME.Core.Business.Topic.Load(topicId); if (topic == null) continue; CY.UME.Core.Business.TopicExtend te = CY.UME.Core.Business.TopicExtend.Load(topicId); if (te == null) continue; CY.UME.Core.Business.Activities active = CY.UME.Core.Business.Activities.Load(int.Parse(te.InstanceId)); if (active == null) { continue; } json.Append("{Count:'" + NoticeList[i].Id + "',InstanceId:'" + NoticeList[i].InstanceId + "',Type:'" + NoticeList[i].Type + "'"); json.Append(",activeId:'" + active.Id); json.Append("',activeName:'" + CY.Utility.Common.StringUtility.EscapeString(active.Name) + "'"); json.Append(",topicID:'" + topic.Id + "'"); json.Append(",topicTitle:'" + CY.Utility.Common.StringUtility.EscapeString(topic.Title) + "'"); } break; case "activeCheck": if (NoticeList[i].InstanceId.Length > 0) { int id = CY.Utility.Common.ConvertUtility.ConvertToInt(NoticeList[i].InstanceId, 0); CY.UME.Core.Business.Activities active = CY.UME.Core.Business.Activities.Load(id); if (active == null) continue; json.Append("{Count:1,InstanceId:'" + NoticeList[i].InstanceId + "'"); json.Append(",Type:'" + NoticeList[i].Type + "'"); json.Append(",activeId:" + active.Id); json.Append(",activeName:'" + CY.Utility.Common.StringUtility.EscapeString(active.Name) + "'"); } break; case "activeCheckNo": if (NoticeList[i].InstanceId.Length > 0) { int id = CY.Utility.Common.ConvertUtility.ConvertToInt(NoticeList[i].InstanceId, 0); CY.UME.Core.Business.Activities active = CY.UME.Core.Business.Activities.Load(id); if (active == null) continue; json.Append("{Count:1,InstanceId:'" + NoticeList[i].InstanceId + "'"); json.Append(",Type:'" + NoticeList[i].Type + "'"); json.Append(",activeId:" + active.Id); json.Append(",activeName:'" + CY.Utility.Common.StringUtility.EscapeString(active.Name) + "'"); json.Append(",content:'" + CY.Utility.Common.StringUtility.EscapeString(NoticeList[i].Content) + "'"); } break; case "relativegroup"://友情小组 if (NoticeList[i].InstanceId.Length > 0) { Guid id = new Guid(NoticeList[i].InstanceId); CY.UME.Core.Business.RelativeGroup rg = CY.UME.Core.Business.RelativeGroup.Load(id); if (rg == null || rg.IsChecked) continue; CY.UME.Core.Business.Group group = CY.UME.Core.Business.Group.Load(rg.GroupId); CY.UME.Core.Business.Group relativeGroup = CY.UME.Core.Business.Group.Load(rg.RelativeGroupId); if (group == null || relativeGroup == null) continue; json.Append("{Count:1,InstanceId:'" + NoticeList[i].InstanceId + "'"); json.Append(",Type:'" + NoticeList[i].Type + "'"); json.Append(",groupId:" + rg.GroupId); json.Append(",relativeGroupId:" + rg.RelativeGroupId); json.Append(",content:'" + CY.Utility.Common.StringUtility.EscapeString(NoticeList[i].Content) + "'"); json.Append(",groupName:'" + CY.Utility.Common.StringUtility.EscapeString(group.Name) + "'"); json.Append(",relativeGroupName:'" + CY.Utility.Common.StringUtility.EscapeString(relativeGroup.Name) + "'"); json.Append(",Id:" + NoticeList[i].Id); } break; } json.Append("},"); check = true; } if (check) { json.Remove(json.Length - 1, 1); } json.Append("]}"); } else { json.Append("{success: false, msg: '没有新的回复通知'}"); } } catch { json.Append("{success: false, msg: '服务器忙,请稍后再试'}"); } return json.ToString(); }