//生成左边的推荐列表
DataTable dt_left = bll_tb_article.GetList(8, "ClassID="+classID+"and IsTop=1", "AddTime desc").Tables[0];
string hotNewsList = null;
foreach (DataRow dr in dt_left.Rows)
{
string newPath = "../../" + dr["SavePath"].ToString() + dr["FileName"].ToString() + dr["FileExName"].ToString();
string newTitle = dr["Title"].ToString().Length > 18 ? dr["Title"].ToString().Substring(0, 18) : dr["Title"].ToString();
hotNewsList += "<li><a href=\"/" + newPath + "\" target='_blank' title='" + dr["Title"].ToString() + "'>" + newTitle + "</a></li>";
}
tempContent = tempContent.Replace("{$HotNews$}", hotNewsList);
tempContent = tempContent.Replace("{$WebSiteKeyWords$}", xlmControl.GetXmlNodeValue("/basicSet/webSiteKeyWord"));
tempContent = tempContent.Replace("{$WebSiteDescription$}", xlmControl.GetXmlNodeValue("/basicSet/webSiteDescription"));
tempContent = MenuBuild(tempContent);
ZPY.Common.DirFile.CreateFile(saveClassListHtmlPath, tempContent);
/// <summary>
/// 菜单生成
/// </summary>
private string MenuBuild(string str)
{
ZPY.BLL.Tb_ArticleClass bll_tb_ac = new ZPY.BLL.Tb_ArticleClass();
DataSet ds = bll_tb_ac.GetList("1=1 order by SerialNumber Desc");
string menuStr = "";
foreach (DataRow dr in ds.Tables[0].Rows)
{
menuStr += " <li><a href=\"/news/" + dr["ClassDirectory"].ToString() + "/list_1.html\">" + dr["ClassName"].ToString() + "</a></li>";
}
str = str.Replace("{$MenuList$}", menuStr);
return str;
}
/// <summary>
/// 根据类别ID生成该类别的静态列表页面
/// </summary>
/// <param name="classID">类别ID</param>
protected void MakeClassListHtml(int classID)
{
ZPY.BLL.Tb_ArticleClass bll_tb_articleclass = new ZPY.BLL.Tb_ArticleClass();
ZPY.Model.Tb_ArticleClass model_tb_articleclass = bll_tb_articleclass.GetModel(classID);
string classDirectory = model_tb_articleclass.ClassDirectory;//得到类别目录
string className = model_tb_articleclass.ClassName;
classDirectory = "news/" + classDirectory;
int pageSize = model_tb_articleclass.ListCount;//读取页面的新闻条数
pageSize = (pageSize < 0 ? 20 : pageSize);
string templetPath = model_tb_articleclass.IndexTemplet;//得到列表页面的模板路径
BaseFunction.XmlControl xlmControl = new WebForm.BaseFunction.XmlControl("/XML/BasicSet.xml");
ZPY.BLL.Tb_Article bll_tb_article = new ZPY.BLL.Tb_Article();
DataSet ds = bll_tb_article.GetList("ClassID="+classID);
DataTable dt = ds.Tables[0];
int pageCount = dt.Rows.Count % pageSize == 0 ? dt.Rows.Count / pageSize : dt.Rows.Count / pageSize + 1;//得到分页的数量
//生成每一个分页
for (int i = 1; i <= pageCount; i++)
{
string tempContent = ZPY.Common.DirFile.ReadFile(templetPath);//读取列表页面的模板内容
string pageTitle = className + " - " +xlmControl.GetXmlNodeValue("/basicSet/webSiteName");
tempContent = tempContent.Replace("{$ClassName$}", className);
tempContent = tempContent.Replace("{$Head$}", pageTitle);
string saveClassListHtmlPath = classDirectory + "/list_"+i.ToString()+".html";//得到分页保存的路径和文件名
string filedOrder = "AddTime Desc";
string strWhere = " ClassID=" + classID + " and ID not in (Select top " + (i - 1).ToString() + " ID from Tb_Article where ClassID=" + classID.ToString() + " order by "+filedOrder+") ";
DataSet dataSet = bll_tb_article.GetList(pageSize, strWhere, filedOrder);
string listStr = "";
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
string newPath = "../../" + dr["SavePath"].ToString() + dr["FileName"].ToString() + dr["FileExName"].ToString();
listStr += "<li><a href=\"" + newPath + "\" target='_blank'>" + dr["Title"].ToString() + "</a> " + System.DateTime.Parse(dr["AddTime"].ToString()).ToShortDateString() + "</li>\r";
}
listStr = listStr == "" ? "暂无内容" : listStr;
tempContent = tempContent.Replace("{$ClassList$}",listStr);
tempContent = tempContent.Replace("{$Pagination$}", GetHtmlPager(pageCount, i, "./list_", ".html"));
//生成左边的推荐列表
DataTable dt_left = bll_tb_article.GetList(8, "ClassID="+classID+"and IsTop=1", "AddTime desc").Tables[0];
string hotNewsList = null;
foreach (DataRow dr in dt_left.Rows)
{
string newPath = "../../" + dr["SavePath"].ToString() + dr["FileName"].ToString() + dr["FileExName"].ToString();
string newTitle = dr["Title"].ToString().Length > 18 ? dr["Title"].ToString().Substring(0, 18) : dr["Title"].ToString();
hotNewsList += "<li><a href=\"/" + newPath + "\" target='_blank' title='" + dr["Title"].ToString() + "'>" + newTitle + "</a></li>";
}
tempContent = tempContent.Replace("{$HotNews$}", hotNewsList);
tempContent = tempContent.Replace("{$WebSiteKeyWords$}", xlmControl.GetXmlNodeValue("/basicSet/webSiteKeyWord"));
tempContent = tempContent.Replace("{$WebSiteDescription$}", xlmControl.GetXmlNodeValue("/basicSet/webSiteDescription"));
tempContent = MenuBuild(tempContent);
ZPY.Common.DirFile.CreateFile(saveClassListHtmlPath, tempContent);
}
}
/// <summary>
/// 写出分页
/// </summary>
/// <param name="pageCount">页数</param>
/// <param name="currentPage">当前页</param>
/// <returns></returns>
public static string GetHtmlPager(int pageCount, int currentPage, string prefix, string suffix)
{
int stepNum = 4;
int pageRoot = 1;
pageCount = pageCount == 0 ? 1 : pageCount;
currentPage = currentPage == 0 ? 1 : currentPage;
StringBuilder sb = new StringBuilder();
sb.Append("<table cellpadding=0 cellspacing=1 class=\"pager\">\r<tr>\r");
sb.Append("<td class=pagerTitle> 分页 </td>\r");
sb.Append("<td class=pagerTitle> " + currentPage.ToString() + "/" + pageCount.ToString() + " </td>\r");
if (currentPage - stepNum < 2)
pageRoot = 1;
else
pageRoot = currentPage - stepNum;
int pageFoot = pageCount;
if (currentPage + stepNum >= pageCount)
pageFoot = pageCount;
else
pageFoot = currentPage + stepNum;
if (pageRoot == 1)
{
if (currentPage > 1)
{
sb.Append("<td> <a href='" + prefix + "1" + suffix + "' title='首页'>首页</a> </td>\r");
sb.Append("<td> <a href='" + prefix + Convert.ToString(currentPage - 1) + suffix + "' title='上页'>上页</a> </td>\r");
}
}
else
{
sb.Append("<td> <a href='" + prefix + "1" + suffix + "' title='首页'>首页</a> </td>");
sb.Append("<td> <a href='" + prefix + Convert.ToString(currentPage - 1) + suffix + "' title='上页'>上页</a> </td>\r");
}
for (int i = pageRoot; i <= pageFoot; i++)
{
if (i == currentPage)
{
sb.Append("<td class='current'> " + i.ToString() + " </td>\r");
}
else
{
sb.Append("<td> <a href='" + prefix + i.ToString() + suffix + "' title='第" + i.ToString() + "页'>" + i.ToString() + "</a> </td>\r");
}
if (i == pageCount)
break;
}
if (pageFoot == pageCount)
{
if (pageCount > currentPage)
{
sb.Append("<td> <a href='" + prefix + Convert.ToString(currentPage + 1) + suffix + "' title='下页'>下页</a> </td>\r");
sb.Append("<td> <a href='" + prefix + pageCount.ToString() + suffix + "' title='尾页'>尾页</a> </td>\r");
}
}
else
{
sb.Append("<td> <a href='" + prefix + Convert.ToString(currentPage + 1) + suffix + "' title='下页'>下页</a> </td>\r");
sb.Append("<td> <a href='" + prefix + pageCount.ToString() + suffix + "' title='尾页'>尾页</a> </td>\r");
}
sb.Append("</tr>\r</table>");
return sb.ToString();
}
#endregion
}