/// <summary> /// 装载评分日志信息 /// </summary> /// <param name="reader"></param> /// <returns></returns> private static RateLogInfo LoadSingleRateLogInfo(IDataReader reader) { RateLogInfo rateLogInfo = new RateLogInfo(); rateLogInfo.Id = TypeConverter.ObjectToInt(reader["id"]); rateLogInfo.Pid = TypeConverter.ObjectToInt(reader["pid"]); rateLogInfo.PostDateTime = reader["postdatetime"].ToString(); rateLogInfo.Reason = reader["reason"].ToString(); rateLogInfo.Score = TypeConverter.ObjectToInt(reader["score"]); rateLogInfo.Uid = TypeConverter.ObjectToInt(reader["uid"]); rateLogInfo.UserName = reader["username"].ToString().Trim(); rateLogInfo.ExtCredits = TypeConverter.ObjectToInt(reader["extcredits"]); return(rateLogInfo); }
/// <summary> /// 获得帖子评分列表 /// </summary> public void GetRateLogList() { System.Text.StringBuilder xmlnode = new System.Text.StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); //如果不是提交... if (!DNTRequest.IsPost() || ForumUtils.IsCrossSitePost()) { xmlnode.Append("<error>您的请求来路不正确,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。</error>"); ResponseXML(xmlnode); return; } try { List <RateLogInfo> rateList = Posts.GetPostRateLogList(DNTRequest.GetFormInt("pid", 0)); if (rateList == null || rateList.Count == 0) { xmlnode.Append("<error>该帖没有评分记录</error>"); ResponseXML(xmlnode); return; } xmlnode.Append("<data>\r\n"); List <RateLogInfo> finalRateList = new List <RateLogInfo>(); //该循环用于将评分列表中多次评分用户的分值聚合成一条数据 foreach (RateLogInfo info in rateList) { Predicate <RateLogInfo> match = new Predicate <RateLogInfo>(delegate(RateLogInfo rateLog) { return(rateLog.Uid == info.Uid && rateLog.ExtCredits == info.ExtCredits); }); RateLogInfo finalRateInfo = finalRateList.Find(match); if (finalRateInfo == null) { finalRateList.Add(info); } else { finalRateInfo.Score += info.Score; finalRateInfo.Reason = string.IsNullOrEmpty(finalRateInfo.Reason) ? info.Reason : finalRateInfo.Reason; } } string[] scorename = Scoresets.GetValidScoreName(); string[] scoreunit = Scoresets.GetValidScoreUnit(); int uidCount = 0; int previoursUid = 0; foreach (RateLogInfo rate in finalRateList) { if (previoursUid != rate.Uid) { uidCount++; } xmlnode.Append("<ratelog>"); xmlnode.AppendFormat("\r\n\t<rateid>{0}</rateid>", rate.Id); xmlnode.AppendFormat("\r\n\t<uid>{0}</uid>", rate.Uid); xmlnode.AppendFormat("\r\n\t<username>{0}</username>", rate.UserName.Trim()); xmlnode.AppendFormat("\r\n\t<extcredits>{0}</extcredits>", rate.ExtCredits); xmlnode.AppendFormat("\r\n\t<extcreditsname>{0}</extcreditsname>", scorename[rate.ExtCredits]); xmlnode.AppendFormat("\r\n\t<extcreditsunit>{0}</extcreditsunit>", scoreunit[rate.ExtCredits]); xmlnode.AppendFormat("\r\n\t<postdatetime>{0}</postdatetime>", ForumUtils.ConvertDateTime(rate.PostDateTime)); xmlnode.AppendFormat("\r\n\t<score>{0}</score>", rate.Score > 0 ? ("+" + rate.Score.ToString()) : rate.Score.ToString()); xmlnode.AppendFormat("\r\n\t<reason>{0}</reason>", rate.Reason.Trim()); xmlnode.Append("\r\n</ratelog>\r\n"); previoursUid = rate.Uid; } xmlnode.Append("</data>"); ResponseXML(xmlnode); if (DNTRequest.GetFormInt("ratetimes", 0) != uidCount) { Posts.UpdatePostRateTimes(DNTRequest.GetFormInt("tid", 0), DNTRequest.GetFormInt("pid", 0).ToString()); } } catch //添加try语法, 以防止在并发情况下, 服务器端远程链接被关闭后出现应用程序 '警告'(事件查看器) { System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.Expires = 0; System.Web.HttpContext.Current.Response.Cache.SetNoStore(); System.Web.HttpContext.Current.Response.End(); } }