帮我看下生成静态页面的
//定义参数string html = "";
StreamWriter sw = null;
string htmlfilename;
string Vocation = "08";
string path = HttpContext.Current.Server.MapPath("/html/");
// 数据库生成分页
int onepage = 20;
SqlConnection myConnection = new SqlConnection(PF.SQLServerDAL.DbHelperSQL.connectionString);
string sSelect = "SELECT count(*) as pcount from Prod where Vocation like '" + Vocation + "%'";
SqlCommand cmd = new SqlCommand(sSelect, myConnection);
myConnection.Open();
SqlDataReader Dr = cmd.ExecuteReader();
Dr.Read();
int Count = int.Parse(Dr["pcount"].ToString());
// Response.Write("<script>alert(" + Count + ")</script>");
int allpages = Count % onepage; //一共有几页
if (allpages > 0)
{
allpages = Count / onepage + 1;
}
else
{
allpages = Count / onepage;
}
//Response.Write("<script>alert(" + allpages + ")</script>");
SqlConnection gConnection = new SqlConnection(PF.SQLServerDAL.DbHelperSQL.connectionString);
gConnection.Open();
for (int i = 0; i < allpages; i++)
{
htmlfilename = "index_" + "" + i + "" + ".html";
int start = i * onepage;
int nextpage = i + 1;
int perpage = i - 1;
if (nextpage == allpages)
{
nextpage = i;
}
if (perpage == -1)
{
perpage = 0;
}
// 写文件
try
{
string vQuery = "select top " + onepage + " a.ID,a.LoginID,a.ProdPic,a.ProdName,a.Description,a.ProdPlace,a.ProdPrice,a.UnitName,a.CreateDate,b.Level,b.AreaID,,b.QQ,b.PenName,b.TrustNum from Prod a inner join Member b on a.LoginID=b.LoginID where a.Status=1 and a.Vocation like '" + Vocation + "%'and (a.ID NOT IN (SELECT TOP " + start + " a.ID from Prod a inner join Member b on a.LoginID=b.LoginID where a.Status=1 and a.Vocation like '" + Vocation + "%' )) ";
// DataTable dtInfo = bllProd.Search1(start, onepage, ref _recordCount, ref _pageCount, Convert.ToString(Session["Classid"]), Subject, SearchType, OrderType, AreaID);
// string vQuery = "SELECT TOP " + onepage + " * FROM Prod WHERE Vocation like '" + Vocation + "%' and (ID NOT IN (SELECT TOP " + start + " Id FROM Prod where Vocation like '" + Vocation + "%' ORDER BY id)) ORDER BY ID";
SqlDataAdapter vmd = new SqlDataAdapter(vQuery, gConnection);
DataSet ds = new DataSet();
vmd.Fill(ds, "table"+i+"");
DataTable dt = ds.Tables["table" + i + ""];
repProdlist.DataSource = dt;
repProdlist.DataBind();
//string oldfile = Server.MapPath("~/product/pro.aspx");
//string newfile = Server.MapPath("~/html/pro.aspx");
//string oldfile2 = Server.MapPath("~/product/pro.aspx.cs");
//string newfile2 = Server.MapPath("~/html/pro.aspx.cs");
//File.Copy(oldfile, newfile, true);
//File.Copy(oldfile2, newfile2, true);
// File.Copy("/product/pro.aspx","/html/pro.aspx",true);
sw = new StreamWriter(path + htmlfilename, false, Encoding.GetEncoding("GB2312"));
//foreach(DataRow dr in dt.Rows)
//for (int j = 0; j < dt.Rows.Count; j++)
//{
html = Common.Get_Http("http://localhost/html/pro.aspx");
// Common.CreateFile(Server.MapPath("~/html/" + htmlfilename + ""), html);
// Response.Redirect("~/html/" + htmlfilename + "");
//sw.WriteLine(""+dr["LoginID"].ToString()+"<br>");
sw.WriteLine(html);
//}
sw.WriteLine("<a href=" + "index_" + "" + perpage + "" + ".html" + ">上一页</a>");
sw.WriteLine("<a href=" + "index_" + "" + nextpage + "" + ".html" + ">下一页</a>");
sw.Flush();
// sw.Close();
// Response.Write("<script>alert("+i+");</script>");
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}