62,074
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
ViewState["startTime"] = DateTime.Now;
string ff = "",ff1="";
string url = "" ,url2="";
string fileName = "";
int time = 0;
Encoding code = Encoding.GetEncoding("gb2312"); //定义编码
Info IF = new Info();
if (IF.ReadTemplate("30", out myTable) == 1)
{
url = myTable.Rows[0]["Code"].ToString();
}
//获得流
StreamWriter sw = null;
Regex r = new Regex(@"{&(.*?)&}");//获取列表标签
MatchCollection ms = r.Matches(url);
foreach (Match m in ms)
{
string[] text = m.ToString().Replace("{&", "").Replace("&}", "").Split('/');
string t2 = text[1].ToString();
int t1 =Convert.ToInt32(text[2].ToString());
int t3 = 0;
if (myDispNews.ReturnNewsDataByIP(t2, out dtRs) == 1)
{
Random rr = new Random();
decimal k = decimal.Round((Convert.ToDecimal(dtRs.Rows.Count) / Convert.ToDecimal(t1)), 2);
string [] n = Convert.ToString(k).Split('.');
if (n.Length > 1)
{
t3 = Convert.ToInt32(n[0]) + 1;
}
else
{
t3 = Convert.ToInt32(n[0]);
}
for (int i = 0; i <t3; i++)
{
int random = rr.Next(100, 999);
if (IF.ReadTemplate("30", out myTable) == 1)//读取列表模板
{
url2 = myTable.Rows[0]["Code"].ToString();
}
int ss = 0;
int pp = Convert.ToInt32(i * t1 + t1);
if (pp > dtRs.Rows.Count)
{
ss = dtRs.Rows.Count;
}
else
{
ss = pp;
}
for (int tt = Convert.ToInt32(i * t1); tt < ss; tt++)
{
ff += "<li><span>" + Convert.ToDateTime(dtRs.Rows[tt]["outtime"]).ToString("yyyy-MM-dd") + "</span><a href='" + SetInfoPath(dtRs.Rows[tt]["path"].ToString()) + "'";
ff += "target=\"_blank\" title='" + dtRs.Rows[tt]["title"].ToString() + "'>" + dtRs.Rows[tt]["title"].ToString() + "</a></li>";
}
if (i == 0)
{
fileName = "list.html";
ff1 += "<a href=\"list.html?"+random+" \">首页</a> |上一页";
}
else if (i == 1)
{
fileName = "list.html";
ff1 += "<a href=\"list.html?" + random + " \">首页</a> |<a href=\"list.html?" + random + " \">上一页</a>";
}
else
{
fileName = "list_"+i+".html";
ff1 += "<a href=\"list.html?"+random+" \">首页</a> |<a href=\"list_" + Convert.ToInt32(i - 1).ToString() + ".html?"+random+" \">上一页</a>";
}
if (dtRs.Rows.Count < 2)
{
ff1 += "|下一页";
}
else if (i == Convert.ToInt32(t3 - 1))
{
ff1 += "|下一页";
}
else
{
ff1 += "|<a href=\"list_" + Convert.ToInt32(i + 1).ToString() + ".html?"+random+" \">下一页</a>";
}
if (t3 == 1)
{
ff1 += "|<a href=\"list.html?"+random+" \">尾页</a> |页次:" + Convert.ToInt32(i + 1).ToString() + "/" + t3 + "|";
}
else
{
ff1 += "|<a href=\"list_" + Convert.ToInt32(t3 - 1).ToString() + ".html?a="+random+" \">尾页</a> |页次:" + Convert.ToInt32(i + 1).ToString() + "/" + t3 + "|";
}
ff1 += "转到第 <select id=\"list1\" onchange='document.location.href(this.options[this.selectedIndex].value)' size=\"1\" name=\"list1\">";
for (int s = 0; s < t3; s++)
{
if (s == 0)
{
ff1 += "<option value=\"list.html?a="+random+" \" >1</option>";
}
else
{
ff1 += "<option value=\"list_" + Convert.ToInt32(s).ToString() + ".html?a="+random+" \">" + Convert.ToInt32(s + 1).ToString() + "</option>";
}
}
ff1 += "页";
url2 = url2.Replace("{$fy$}", ff1.ToString());//替换分页标签
url2 = url2.Replace(m.ToString(), ff.ToString());
ff1 = "";
ff = "";
try
{
sw = new StreamWriter(HttpContext.Current.Server.MapPath(fileName), false, code);
sw.Write(url2);
time++;
sw.Flush();
sw.Close();
}
catch
{
Label1.Text += "第" + i + "行错误";
}
}
}
}
DateTime endTime = DateTime.Now;
DateTime startTime = Convert.ToDateTime(ViewState["startTime"]);
System.TimeSpan ts = endTime - startTime;
Label1.Text += "一共执行"+time+"个页面";
LblExecTime.Text = "服务器端执行时间: " + ts.Milliseconds.ToString() + " ms";
}