publicstatic ArrayList GetNews(string classidstr, string keyword,int pageindex,int pagesize, string sortBy, outint totalcount) ...{ ArrayList NewsArray =new ArrayList(); 构造查询字符串#region 构造查询字符串 string[] keywords =newstring[10]; StringBuilder SqlStr =new StringBuilder(); SqlStr.AppendFormat("select id from {0} where 1=1",newsTable); if (classidstr !="") ...{ SqlStr.AppendFormat(" and (classid in ({0}) or classid in (select id from catalogs where tree like '%,{0},%'))", classidstr); } if (keyword.Trim() !=string.Empty) ...{ if (keyword.Contains(",")) ...{ keywords = keyword.Split(Convert.ToChar(",")); } else ...{ keywords[0] = keyword; } for (int i =0; i < keywords.Length; i++) ...{ if (i ==0) ...{ SqlStr.AppendFormat(" and (title like '%{0}%' or keywords like '%{0}%'", keywords[i]); } else ...{ if (keywords[i] !=null|| keywords[i] !="") ...{ SqlStr.AppendFormat(" or title like '%{0}%' or keywords like '%{0}%'", keywords[i]); } } } SqlStr.Append(")"); } // SqlStr.AppendFormat(" and photo<>'noimg.gif'"); if (sortBy !=string.Empty) ...{ SqlStr.AppendFormat(" order by {0} desc", sortBy); } #endregion 构造参数#region 构造参数 SqlParameter[] param = SqlHelperParameterCache.GetCachedParameterSet(conStr, "News_Gets"); if (param ==null) ...{ param = SqlHelperParameterCache.GetSpParameterSet(conStr, "News_Gets"); } param[0].Value = SqlStr.ToString(); param[1].Value = pageindex; param[2].Value = pagesize; #endregion using (SqlDataReader dr = SqlHelper.ExecuteReader(conStr,"News_Gets",param)) ...{ while (dr.Read()) ...{ NewsArray.Add(InitNews(new News(), dr)); } if (dr.NextResult()) ...{ dr.Read(); totalcount = Convert.ToInt32(dr[0]); } else ...{ totalcount =0; } return NewsArray; } }