using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mysqlserver;
using System.IO;
using System.Text;
namespace NewsAdd
{
public partial class Admin_AdminPanel_NewsAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
protected void Button1_Click(object sender, EventArgs e)
{
string strDate = DateTime.Now.ToString("yyMMdd") + "/" + DateTime.Now.ToString("yyyymmddhhmmss");
string strFileName = strDate + ".shtml";
string strTitle=Request.Form["Title"].ToString().Trim();
string strContent=Request.Form["Content"].ToString().Trim();
string[] content = strContent.Split(new Char[] ...{'|'});
int upbound = content.Length;
SqlServerDataBase db = new SqlServerDataBase();
bool success = db.Insert("insert into inNews(Title,Content,FilePath)values('" + strTitle + "','" + strContent + "','" + strFileName + "')", null);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
{
for (int i = 0; i < content.Length; i++)
{
//string[] newContent = new string[4];
StringBuilder strhtml = new StringBuilder();
using (StreamReader sr = new StreamReader(Server.MapPath("../../" + "NewsFiles/") + "/template.html",Encoding.GetEncoding("gb2312")))
{
String oneline;
while ((oneline = sr.ReadLine()) != null)
{
strhtml.Append(oneline);
}
sr.Close();
}
DataSet ds = db.Select("select top 1 NewsId from inNews order by NewsId desc", null);
string strTable = "<table><tr><td>$upUrl</td><td>$Number</td><td>$downUrl</td></tr></table>";
string FilePath="";
strhtml = strhtml.Replace("$Title", strTitle);
strhtml = strhtml.Replace("$NewsId", ds.Tables[0].Rows[0]["NewsId"].ToString());
strhtml = strhtml.Replace("$Time", DateTime.Now.ToString("yyyy/MM/dd"));
strhtml = strhtml.Replace("$Content", content[i]);
string strNumber = "";
for (int m = 1; m <=upbound; m++)
{
if (m == 1)
strNumber = strNumber + " ["+"<a href=" + "../" + strDate + ".shtml" + ">" + m + "</a>"+"] ";
else
{
int n = m - 1;
strNumber = strNumber + " [" +"<a href=" + "../" + strDate + "_" + n + ".shtml" + ">" + m + "</a>"+"] ";
}
}
if (upbound == 0)
{
FilePath = Server.MapPath("../../") + "NewsFiles" + "//" + strDate + ".shtml";
strhtml = strhtml.Replace("$Pager", "");
}
else
{
if (i == 0)
FilePath = Server.MapPath("../../") + "NewsFiles" + "//" + strDate + ".shtml";
else
FilePath = Server.MapPath("../../") + "NewsFiles" + "//" + strDate + "_" + i + ".shtml";
if (i == 0)
strTable = strTable.Replace("$upUrl", "");
strTable = strTable.Replace("$upUrl", "<a href=" + "../" + strDate + ".shtml" + ">上一页</a>");
else
{
int p = i - 1;
strTable = strTable.Replace("$upUrl", "<a href=" + "../" + strDate + "_" + p + ".shtml" + ">上一页</a>");
}
if(upbound==1)
strTable = strTable.Replace("$Number", "");
else
strTable = strTable.Replace("$Number", strNumber);
if(i==upbound-1)
strTable = strTable.Replace("$downUrl", "");
{
int q = i + 1;
strTable = strTable.Replace("$downUrl", "<a href=" + "../" + strDate + "_" + q + ".shtml" + ">下一页</a>");
}
else
{
int j = upbound - 1;
strTable = strTable.Replace("$downUrl", "<a href=" + "../" + strDate + "_" + j + ".shtml" + ">下一页</a>");
}
}
FileInfo finfo = new FileInfo(FilePath);
using (FileStream fs = finfo.OpenWrite())
{
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.WriteLine(strhtml);
sw.Flush();
sw.Close();
}
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
}
}
}
string[] pageNum = System.Text.RegularExpressions.Regex.Split(str,"分页标记");
for(int i = 0;i<pageNum.Length;i++)
{
//生成文件 和内容
string FileName = "m_" + i.ToString() + ".htm";
....
}
====================================================================================
using System;
using System.Collections.Generic;
using System.Text;
namespace Pagination
{
/// <summary>
/// 完成分页导航的生成
/// </summary>
public class PageNavigate
{
private PageNavigate() { }
/// <summary>
/// 生成分页导航条
/// </summary>
/// <param name="totalRecord">总记录数</param>
/// <param name="pageSize">页面记录数</param>
/// <param name="DistLen">数字长度</param>
/// <param name="page">当前页数</param>
/// <param name="QueryParametet">URL参数</param>
/// <param name="scriptName">页名前缀</param>
/// <returns></returns>
public static string GetNavigate(int totalRecord,int pageSize,int DistLen,int page,string QueryParameter,string scriptName,string extName)
{
int pageNum; //页面数量
string HTML="";
if ((totalRecord % pageSize) != 0)
pageNum = (totalRecord / pageSize) + 1;
else
pageNum = totalRecord / pageSize;
if (pageNum < 1)
return HTML;
//统计信息
HTML += "显示" + ((page - 1) * pageSize + 1) + "━";
if (page >= pageNum)
HTML += totalRecord + "条";
else
HTML += page * pageSize + "条";
HTML += "共<B>" + totalRecord + "</B>条 " + pageSize + "条/页";
//首页,上一页
if (page > 1)
{
HTML += "<a href=/"" + scriptName + "1" + extName + "?" + QueryParameter + "/" > 首 页 </a>";
HTML += "<a href=/"" + scriptName + (page - 1) + extName + "?" + QueryParameter + "/" > 上一页 </a>";
}
//数字序列
int page_t;
if (page < DistLen * 2)
{
if (pageNum > DistLen * 2)
page_t = DistLen * 2;
else
page_t = pageNum;
for (int i = 1; i <= page_t; i++)
{
if (i == page)
HTML += "<B> " + page + "</B>";
else
HTML += "<a href=/""+ scriptName + i + extName+ "?" +QueryParameter+ "/"> " + i + "</a>";
}
}
else
{
if (pageNum > (page + DistLen))
page_t = page + DistLen;
else
page_t = pageNum;
for (int i = (page - DistLen); i <= page_t; i++)
{
if (i == page)
HTML += "<B> " + page + "</B>";
else
HTML += "<a href=/"" + scriptName + i + extName + "?" + QueryParameter + "/" > " + i + "</a>";
}
}
//下一页,尾页
if (page < pageNum)
{
HTML += "<a href=/"" + scriptName + (page + 1) + extName + "?" + QueryParameter + "/" > 下一页 </a>";
HTML += "<a href=/"" + scriptName + pageNum + extName + "?" + QueryParameter + "/" > 尾页 </a>";
}
return HTML;
}
/// <summary>
/// 带下拉框的分页
/// </summary>
/// <param name="pageCount">总页数</param>
/// <param name="page">当前页</param>
/// <param name="pageSize">页面大小</param>
/// <param name="QueryParameter">页面参数</param>
/// <param name="scriptName">页面前缀</param>
/// <returns></returns>
public static string GetNavigate(int pageCount, int page, int pageSize, string QueryParameter, string scriptName,string extName)
{
string HTML = "";
if (pageCount < 1) return HTML;
//首页,上一页
if (page > 1)
{
HTML += "<a href=/"" + scriptName + "1" + extName + "?" + QueryParameter + "/"> 首页 </a>";
HTML += "<a herf=/"" + scriptName + (page - 1) + extName + "?" + QueryParameter + "/"> 上一页 </a>";
}
else
{
HTML += " 首页 上一页 ";
}
//下一页,尾页
if (page < pageCount)
{
HTML +="<a href=/"" + scriptName + (page+1)+ extName +"?" + QueryParameter + "/"> 下一页 </a>";
HTML += "<a href=/"" + scriptName + (pageCount) + extName +"?" + QueryParameter + "/"> 尾页 </a>";
}
else
{
HTML += " 下一页 尾页 ";
}
HTML += " <select name=/"page___/" id=/"page___/" onChange=/" GoToSelectedPage();/">" + Environment.NewLine; ;
HTML += " <option> 选择 </option>" +Environment.NewLine;
for (int i = 1; i <= pageCount; i++)
{
if (i == page)
HTML += "<option value=/"" + scriptName + i + extName + "?" + QueryParameter+ "/" selected>" + i + "</option>" + Environment.NewLine;
else
HTML += "<option value=/"" + scriptName + i + extName + "?" + QueryParameter + "/">" + i + "</option>" + Environment.NewLine;
}
HTML += "</select>" + Environment.NewLine;
HTML += "<script language=/"JScript/">" + Environment.NewLine;
HTML += "<!--" + Environment.NewLine;
HTML += " function GoToSelectedPage(){ " + Environment.NewLine;
HTML += " var page___=document.getElementById(/"page___/");" + Environment.NewLine;
HTML += " var index=page___.selectedIndex;" + Environment.NewLine;
HTML += " if(index==0) return;" + Environment.NewLine;
HTML += " window.location=page___.value;" +Environment.NewLine;
HTML += " }" + Environment.NewLine;
HTML += " //-->" + Environment.NewLine;
HTML += " </script>" + Environment.NewLine;
return HTML;
}
/// <summary>
/// 计算页面数量
/// </summary>
/// <param name="totalRecord">总记录数</param>
/// <param name="pageSize">页面大小</param>
/// <returns>页面数量</returns>
public static int GetPageCount(int totalRecord, int pageSize)
{
if (totalRecord % pageSize == 0)
return totalRecord / pageSize;
else
return (totalRecord / pageSize) + 1;
}
/// <summary>
/// 返回合成的文件名
/// </summary>
/// <param name="scritpName">页面前缀</param>
/// <param name="page">当前页</param>
/// <param name="extName">扩展名</param>
/// <returns></returns>
public static string GetShortFileName(string scritpName,int page,string extName)
{
return scritpName + page + extName;
}
}
}