| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 566 人关注过本帖
标题:帮我看下生成静态页面的
只看楼主 加入收藏
loveglf
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-7-30
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
帮我看下生成静态页面的
     //定义参数
        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:08
loveglf
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-7-30
收藏
得分:0 
回复 楼主 loveglf
生成的页面里显示:
文件“F:\net\PF\Web\html\index_3.html”正由另一进程使用,因此该进程无法访问该文件。 上一页 下一页
2009-08-31 10:09
ginpq
Rank: 2
等 级:论坛游民
帖 子:34
专家分:50
注 册:2007-8-21
收藏
得分:20 
看看是不是其它程序,比如浏览器之类的正在打开index_3.html
2009-09-01 09:59
快速回复:帮我看下生成静态页面的
数据加载中...
 
   



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

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