//
生成静态页面方法
protected void BuildHtml( string title, string pid, string cid, string content, string forlder, string keyword)
{
// 取值
string sql = " select top 1 nid from mynewslist order by nid desc " ;
string nid = new DataAccess(connstr).GetScalarData(sql).ToString();
string pname = new Common().GetIndexCaption( int .Parse(pid.ToString()));
string cname = new DataAccess(connstr).GetScalarData( " select cname from mynews_type where cid= " + cid).ToString();
DataTable dt = new DataAccess(connstr).GetDataTable( " select userIP,content,replydate from myreplynewslist where nid= " + nid + " order by replydate asc " );
// 相关文章
DataTable xgdt = new DataAccess(connstr).GetDataTable( " select top 10 title,filename,forlder from mynewslist where cid=(select cid from mynewslist where nid= " + nid + " ) and nid< " + nid + " order by nid desc " );
if (xgdt.Rows.Count < 10 )
{
xgdt = new DataAccess(connstr).GetDataTable( " select top 10 title,filename,forlder from (select title,filename,forlder from mynewslist where cid=(select cid from mynewslist where nid= " + nid + " ) and nid<> " + Request.QueryString[ " nid " ].ToString() + " union all select top 10 title,filename,forlder from mynewslist where pid=(select pid from mynewslist where nid= " + nid + " ) and nid not in (select nid from mynewslist where cid =(select cid from mynewslist where nid= " + nid + " )) ) " );
}
// 热点文章
DataTable hotdt = new DataAccess(connstr).GetDataTable( " select top 10 title,filename,forlder from mynewslist where nid<=397 order by looknums desc ,nid desc " );
/
if (keyword.Length > 1 )
{
keyword = " , " + keyword;
}
// 读取页面模板
StringBuilder htmltext = new StringBuilder();
try
{
using (StreamReader sr = new StreamReader(Server.MapPath( " ../UserControl/*.html " ), System.Text.Encoding.GetEncoding( " GB2312 " )))
{
String line;
while ((line = sr.ReadLine()) != null )
{
htmltext.Append(line + " " );
}
sr.Close();
}
}
catch
{
Response.Write( " <Script>alert('读取文件错误')</Script> " );
}
// 生成的文件名
string htmlfilename = pid.ToString() + " _ " + DateTime.Now.ToString( " yyyyMMddHHmmss " ) + " .html " ;
StringBuilder sb = new StringBuilder();
// 相关文章和热点文章
sb.Append( " <table width="760" height="30" border="0" align="center" cellpadding="0" cellspacing="0"> " );
sb.Append( " <tr> " );
sb.Append( " <td height="23" align="left" valign="middle" bgcolor="#3399FF"> <strong>相关文章:</strong></td> " );
sb.Append( " <td align="center" valign="middle" bgcolor="#3399FF"> </td> " );
sb.Append( " <td align="left" valign="middle" bgcolor="#3399FF"> <strong>站内热点文章:</strong></td> " );
sb.Append( " </tr> " );
sb.Append( " <tr> " );
sb.Append( " <td width="337" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> " );
for ( int j = 0 ; j < xgdt.Rows.Count; j ++ )
{
sb.Append( " <tr> " );
sb.Append( " <td width="20" height="20" align="center">·</td> " );
sb.Append( " <td width="295" height="20" align="left"><a href="../ " + xgdt.Rows[j][ " forlder " ].ToString() + " / " + xgdt.Rows[j][ " filename " ].ToString() + " " target="_blank"> " + xgdt.Rows[j][ " title " ].ToString() + " </a></td> " );
sb.Append( " </tr> " );
}
sb.Append( " </table></td> " );
sb.Append( " <td width="67"> </td> " );
sb.Append( " <td width="346" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> " );
for ( int k = 0 ; k < hotdt.Rows.Count; k ++ )
{
sb.Append( " <tr> " );
sb.Append( " <td width="22" height="20" align="center">·</td> " );
sb.Append( " <td width="324" height="20" align="left"><a href="../ " + hotdt.Rows[k][ " forlder " ].ToString() + " / " + hotdt.Rows[k][ " filename " ].ToString() + " " target="_blank"> " + hotdt.Rows[k][ " title " ].ToString() + " </a></td> " );
sb.Append( " </tr> " );
}
sb.Append( " </table></td> " );
sb.Append( " </tr> " );
sb.Append( " </table> " );
// 替换内容
string des = pname + " , " + cname + keyword + " , " + title + " -- " + (( string )(content.Length >= 150 ? content.Substring( 0 , 150 ) : content));
des = Common.NoHTML(des);
string plink = " <a href="../ " + PageName(pid) + " "> " + pname + " </a> " ;
string clink = " <a href="../ " + PageName(pid) + " ?cid= " + cid + " "> " + cname + " </a> " ;
string Url = " http://www.jgking.cn/ " ; + forlder + " / " + htmlfilename;
htmltext.Replace( " $ptype " , plink);
htmltext.Replace( " $ctype " , clink);
htmltext.Replace( " $nid " ,nid);
htmltext.Replace( " $Key " , pname + " , " + cname + keyword);
htmltext.Replace( " $Des " , des);
htmltext.Replace( " $Url " ,Url);
htmltext.Replace( " $title " , cname + " -- " + new Common().ReadString(title));
htmltext.Replace( " $caption " , new Common().ReadString(title));
htmltext.Replace( " $others " , sb.ToString());
htmltext.Replace( " $content " , new Common().ReadString(content));
// 生成页面
string path = HttpContext.Current.Server.MapPath( " ~/ " + forlder + " / " );
try
{
using (StreamWriter sw = new StreamWriter(path + htmlfilename, false , System.Text.Encoding.GetEncoding( " GB2312 " )))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
new DataAccess(connstr).ExcuteSQL( " update mynewslist set filename=' " + htmlfilename + " ' where nid= " + nid);
}
}
catch
{
Response.Write( " The file could not be wirte: " );
}
}
protected void BuildHtml( string title, string pid, string cid, string content, string forlder, string keyword)
{
// 取值
string sql = " select top 1 nid from mynewslist order by nid desc " ;
string nid = new DataAccess(connstr).GetScalarData(sql).ToString();
string pname = new Common().GetIndexCaption( int .Parse(pid.ToString()));
string cname = new DataAccess(connstr).GetScalarData( " select cname from mynews_type where cid= " + cid).ToString();
DataTable dt = new DataAccess(connstr).GetDataTable( " select userIP,content,replydate from myreplynewslist where nid= " + nid + " order by replydate asc " );
// 相关文章
DataTable xgdt = new DataAccess(connstr).GetDataTable( " select top 10 title,filename,forlder from mynewslist where cid=(select cid from mynewslist where nid= " + nid + " ) and nid< " + nid + " order by nid desc " );
if (xgdt.Rows.Count < 10 )
{
xgdt = new DataAccess(connstr).GetDataTable( " select top 10 title,filename,forlder from (select title,filename,forlder from mynewslist where cid=(select cid from mynewslist where nid= " + nid + " ) and nid<> " + Request.QueryString[ " nid " ].ToString() + " union all select top 10 title,filename,forlder from mynewslist where pid=(select pid from mynewslist where nid= " + nid + " ) and nid not in (select nid from mynewslist where cid =(select cid from mynewslist where nid= " + nid + " )) ) " );
}
// 热点文章
DataTable hotdt = new DataAccess(connstr).GetDataTable( " select top 10 title,filename,forlder from mynewslist where nid<=397 order by looknums desc ,nid desc " );
/
if (keyword.Length > 1 )
{
keyword = " , " + keyword;
}
// 读取页面模板
StringBuilder htmltext = new StringBuilder();
try
{
using (StreamReader sr = new StreamReader(Server.MapPath( " ../UserControl/*.html " ), System.Text.Encoding.GetEncoding( " GB2312 " )))
{
String line;
while ((line = sr.ReadLine()) != null )
{
htmltext.Append(line + " " );
}
sr.Close();
}
}
catch
{
Response.Write( " <Script>alert('读取文件错误')</Script> " );
}
// 生成的文件名
string htmlfilename = pid.ToString() + " _ " + DateTime.Now.ToString( " yyyyMMddHHmmss " ) + " .html " ;
StringBuilder sb = new StringBuilder();
// 相关文章和热点文章
sb.Append( " <table width="760" height="30" border="0" align="center" cellpadding="0" cellspacing="0"> " );
sb.Append( " <tr> " );
sb.Append( " <td height="23" align="left" valign="middle" bgcolor="#3399FF"> <strong>相关文章:</strong></td> " );
sb.Append( " <td align="center" valign="middle" bgcolor="#3399FF"> </td> " );
sb.Append( " <td align="left" valign="middle" bgcolor="#3399FF"> <strong>站内热点文章:</strong></td> " );
sb.Append( " </tr> " );
sb.Append( " <tr> " );
sb.Append( " <td width="337" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> " );
for ( int j = 0 ; j < xgdt.Rows.Count; j ++ )
{
sb.Append( " <tr> " );
sb.Append( " <td width="20" height="20" align="center">·</td> " );
sb.Append( " <td width="295" height="20" align="left"><a href="../ " + xgdt.Rows[j][ " forlder " ].ToString() + " / " + xgdt.Rows[j][ " filename " ].ToString() + " " target="_blank"> " + xgdt.Rows[j][ " title " ].ToString() + " </a></td> " );
sb.Append( " </tr> " );
}
sb.Append( " </table></td> " );
sb.Append( " <td width="67"> </td> " );
sb.Append( " <td width="346" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> " );
for ( int k = 0 ; k < hotdt.Rows.Count; k ++ )
{
sb.Append( " <tr> " );
sb.Append( " <td width="22" height="20" align="center">·</td> " );
sb.Append( " <td width="324" height="20" align="left"><a href="../ " + hotdt.Rows[k][ " forlder " ].ToString() + " / " + hotdt.Rows[k][ " filename " ].ToString() + " " target="_blank"> " + hotdt.Rows[k][ " title " ].ToString() + " </a></td> " );
sb.Append( " </tr> " );
}
sb.Append( " </table></td> " );
sb.Append( " </tr> " );
sb.Append( " </table> " );
// 替换内容
string des = pname + " , " + cname + keyword + " , " + title + " -- " + (( string )(content.Length >= 150 ? content.Substring( 0 , 150 ) : content));
des = Common.NoHTML(des);
string plink = " <a href="../ " + PageName(pid) + " "> " + pname + " </a> " ;
string clink = " <a href="../ " + PageName(pid) + " ?cid= " + cid + " "> " + cname + " </a> " ;
string Url = " http://www.jgking.cn/ " ; + forlder + " / " + htmlfilename;
htmltext.Replace( " $ptype " , plink);
htmltext.Replace( " $ctype " , clink);
htmltext.Replace( " $nid " ,nid);
htmltext.Replace( " $Key " , pname + " , " + cname + keyword);
htmltext.Replace( " $Des " , des);
htmltext.Replace( " $Url " ,Url);
htmltext.Replace( " $title " , cname + " -- " + new Common().ReadString(title));
htmltext.Replace( " $caption " , new Common().ReadString(title));
htmltext.Replace( " $others " , sb.ToString());
htmltext.Replace( " $content " , new Common().ReadString(content));
// 生成页面
string path = HttpContext.Current.Server.MapPath( " ~/ " + forlder + " / " );
try
{
using (StreamWriter sw = new StreamWriter(path + htmlfilename, false , System.Text.Encoding.GetEncoding( " GB2312 " )))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
new DataAccess(connstr).ExcuteSQL( " update mynewslist set filename=' " + htmlfilename + " ' where nid= " + nid);
}
}
catch
{
Response.Write( " The file could not be wirte: " );
}
}