| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 697 人关注过本帖
标题:请高手指点(按产品分类循环生成静态页面)
只看楼主 加入收藏
loveglf
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-7-30
结帖率:50%
收藏
 问题点数:0 回复次数:1 
请高手指点(按产品分类循环生成静态页面)

        //定义参数
        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();
            }
        }

搜索更多相关主题的帖子: 静态 页面 分类 
2009-08-31 10:12
loveglf
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-7-30
收藏
得分:0 
回复 楼主 loveglf
生成的静态页面内容为:

文件“F:\net\PF\Web\html\index_3.html”正由另一进程使用,因此该进程无法访问该文件。 上一页 下一页

2009-08-31 10:13
快速回复:请高手指点(按产品分类循环生成静态页面)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024251 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved