<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ★33°空間‰


                           ----★七彩服飾  【最潮拜☆日單精品】【Esprit】【Hotwind】滿150包郵-女裝-流行女裝    www.7color.hb.cn

                           ----智力比知識重要,素質比智力重要,覺悟比素質更重要
    posts - 110,comments - 35,trackbacks - 0

    在網上看了許多能生成靜態頁的新聞系統,但基于asp.net的系統極少,閑下時間來自己寫了一個,發出來,大家一起研究,代碼沒做什么優化,只是實現了功能

     

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Configuration;

    namespace makehtmlfile
    {
     /// <summary>
     /// makeallfiles 的摘要說明。
     /// </summary>
     public class makeallfiles : System.Web.UI.Page
     {
      public string strcon;
      public OleDbConnection conn;
      public string strSQL;

      private void Page_Load(object sender, System.EventArgs e)
      {
       
       InitialPages();// 在此處放置用戶代碼以初始化頁面
      }

      public void InitialPages()
      {
       strcon    = "provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath(ConfigurationSettings.AppSettings["MDBpath2"])+";";//連接字符竄// 在此處放置用戶代碼以初始化頁面
                strSQL = "select id,class1id,class2id from news order by id desc";
       MakeAreaForShow();
       ReadNewsForWriteFileUserDataReader();      //同過DataReader來讀取數據,
       //ReadNewsForWriteFileUserDataSet();      //將數據直接掛入DataSet中來讀取,
      }
      /// <summary>
      /// 用來產生循環顯示頁面的區域,裝載生成HTML頁的ASPX頁面的區域
      /// </summary>
      public void MakeAreaForShow()
      {
       Response.Write("<span id=showImport></span>");
       Response.Write("<IE:Download ID='oDownload' STYLE='behavior:url(#default#download)'/>");
      }

      /// <summary>
      /// 通過DATAREADER來讀取數據
      /// </summary>
      public void ReadNewsForWriteFileUserDataReader()
      {
       int              num        =   0   ;
       string           newsid     =   null;
       string           class1id   =   null;
       string           class2id   =   null;
       OleDbDataReader  dr         =   null;
       OleDbConnection  conn       =   new OleDbConnection(strcon);
       conn.Open();
       OleDbCommand     mycommand  =   new OleDbCommand(strSQL,conn);
       dr                          =   mycommand.ExecuteReader();
       while(dr.Read())
       {
        newsid                  =   dr["id"].ToString();
        class1id                =   dr["class1id"].ToString();
        class2id                =   dr["class2id"].ToString();
                    WriteJScript(newsid,class1id,class2id);
        num++;
       }
       dr.Close();
       conn.Close();
       Response.Write(num.ToString());

      }

      /// <summary>
      /// 通過DATASET來讀取數據
      /// </summary>
      public void ReadNewsForWriteFileUserDataSet()
      {
       DataSet          ds         =   new DataSet();
       int              num        =   0   ;
       string           newsid     =   null;
       string           class1id   =   null;
       string           class2id   =   null;

       OleDbConnection  conn       =   new OleDbConnection(strcon);
       conn.Open();
       OleDbDataAdapter da         =   new OleDbDataAdapter(strSQL,conn);
       da.Fill(ds,"news");
       conn.Close();
       num                         =   ds.Tables["news"].Rows.Count;
       foreach(DataRow dr in ds.Tables["news"].Rows)
       {
        newsid     =    dr["id"].ToString();
        class1id   =    dr["class1id"].ToString();
        class2id   =    dr["class2id"].ToString();
        WriteJScript(newsid,class1id,class2id);
       }
       ds = null;
       Response.Write(num.ToString());
       
      }

      public void WriteJScript(string newsid,string class1id,string class2id)
      {
       Response.Write("<script>");
       Response.Write("function onDownloadDone(downDate)");
       Response.Write("{");
       Response.Write("showImport.innerHTML=downDate");
       Response.Write("}");
       Response.Write("oDownload.startDownload('makefile2.aspx?id=");
       Response.Write(newsid);
       Response.Write("&class1id=");
       Response.Write(class1id);
       Response.Write("&class2id=");
       Response.Write(class2id);
       Response.Write("',onDownloadDone)");
       Response.Write("</script>");
      }

      

      #region Web 窗體設計器生成的代碼
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
      /// 此方法的內容。
      /// </summary>
      private void InitializeComponent()
      {   
       this.Load += new System.EventHandler(this.Page_Load);

      }
      #endregion
     }
    }

     

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Configuration;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Web;
    using System.IO;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace makehtmlfile
    {
     /// <summary>
     /// makefile2 的摘要說明。
     /// </summary>
     public class makefile2 : System.Web.UI.Page
     {
      public string strcon;
      public OleDbConnection conn;
      
      public string class1id;
      public string class2id;
      //***********************************
      public string previd;
      public string prevtitle;
      public string nextid;
      public string nexttitle;
      //***********************************
      public string newstitle;
      public string newscontent;
      public string newsdate;
      public string newsip;
      public string newsid;
      //************************************

     

      private void Page_Load(object sender, System.EventArgs e)
      {
       strcon    = "provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath(ConfigurationSettings.AppSettings["MDBpath2"])+";";//連接字符竄// 在此處放置用戶代碼以初始化頁面
       if(Request.Params["id"]!=null&&Request.Params["class1id"]!=null&&Request.Params["class2id"]!=null)
       {
        InitialPages();

       }// 在此處放置用戶代碼以初始化頁面
      }

      public void InitialPages()
      {
       strcon    = "provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath(ConfigurationSettings.AppSettings["MDBpath2"])+";";
       
       if(Request.Params["id"]!=null)
       {
        newsid  = Request.Params["id"].ToString();
       }
       if(Request.Params["class1id"]!=null)
       {
        class1id  = Request.Params["class1id"].ToString();
       }
       if(Request.Params["class2id"]!=null)
       {
        class2id  = Request.Params["class2id"].ToString();
       }
       ReadDataBase(newsid,class2id);
       MakeHtmlFile(newsid,class1id,class2id);
      }

      /// <summary>
      /// 讀寫同一分類中,上一篇,和下一篇文章
      /// </summary>
      /// <param name="inputid"> 該文章ID</param>
      /// <param name="class2id">該文章所屬分類ID</param>
      public void ReadPrevAndNext(string inputid,string class2id)
      {
       int               id                 =    int.Parse(inputid);
       string            strPrevSQL         =    "select top 1 id,newstitle,newsdate from news where class2id='"+ class2id +"' and id<"+id+" order by id desc";
       string            strNextSQL         =    "select top 1 id,newstitle,newsdate from news where class2id='"+ class2id +"' and id>"+id+" order by id asc";
       OleDbDataReader   datar              =    null;
       OleDbConnection con       = new OleDbConnection(strcon);
       con.Open();
       OleDbCommand newcommand   = new OleDbCommand(strPrevSQL,con);
       datar                     = newcommand.ExecuteReader();
       while(datar.Read())
       {
        previd    =  datar["id"].ToString();
        prevtitle =  datar["newstitle"].ToString();
       }
       datar.Close();
       newcommand.CommandText = strNextSQL ;
       datar                  = newcommand.ExecuteReader();
       while(datar.Read())
       {
        nextid     =  datar["id"].ToString();
        nexttitle  =  datar["newstitle"].ToString();
       }
       con.Close();

      }

      /// <summary>
      /// 將文章信息從庫中讀出,并將準備生成的HTML文件路徑寫入庫中
      /// </summary>
      /// <param name="inputid"></param>
      /// <param name="class2id"></param>
      public void ReadDataBase(string inputid,string class2id)
      {
       string filename_w = MakeFileName(class1id,class2id,newsid)+".htm";
       
       ReadPrevAndNext(inputid,class2id);       //讀取下一篇和上一篇的信息。


       OleDbConnection mycon  = new OleDbConnection(strcon);          //打開數據庫連接
       mycon.Open();

       int              id    = int.Parse(inputid);
       string       strSQL    = "select * from news where id="+id;
       OleDbDataReader  dr    = null;
       OleDbCommand mycommand = new OleDbCommand(strSQL,mycon);
       dr                     = mycommand.ExecuteReader();
       while(dr.Read())
       {
        newstitle   = dr["newstitle"].ToString();
        newscontent = dr["newscontent"].ToString();
        newsdate    = dr["newsdate"].ToString();
        newsip      = dr["newsip"].ToString();
       }
       dr.Close();
       mycommand.CommandText = "update news set url='"+ filename_w +"' where id="+int.Parse(inputid);   //將生成的文件路徑寫入庫中,以遍在生成分類頁中方便使用
       mycommand.ExecuteNonQuery();
       mycon.Close();
       
      }


      /// <summary>
      /// 生成目標目錄和文件,主要用來生成不同分類的目錄
      /// </summary>
      /// <param name="inputstr"></param>
      /// <returns></returns>
      public string MakeCatalogName(string class1,string class2)            //生成目標目錄文件
      {
       string namestr   = "Article";
       string rootstr   = Server.MapPath(".").ToString();
       string class1str  = rootstr + "\\" + namestr + "_" + class1 + "\\";
       string class2str  = rootstr + "\\" + namestr + "_" + class1 + "\\" + namestr + "_" + class2 + "\\";
       if(!Directory.Exists(class1str))
       {
        Directory.CreateDirectory(class1str);
       }
       if(!Directory.Exists(class2str))
       {
        Directory.CreateDirectory(class2str);
       }
                  //創建目標文件夾
       return class2str;
      }

      /// <summary>
      /// 根據文章分類和ID生成文件名
      /// </summary>
      /// <param name="class1id"></param>
      /// <param name="class2id"></param>
      /// <param name="nid"></param>
      /// <returns>返回文件名</returns>
      public string MakeFileName(string class1,string class2,string id)    //生成文件名,能夠生成上下篇
      {
       string myclass2id    = class2;
       string myclass1id    = class1;
       string s             = DateTime.Now.Year.ToString()
        +DateTime.Now.Month.ToString()
        +DateTime.Now.Day.ToString()
        +"_"
        +myclass1id 
        +"_"
        +myclass2id                         //父類ID
        +"_"
        +id;                               //新聞ID
       return s;
      }

      /// <summary>
      /// 生成HTML文件
      /// </summary>
      /// <param name="nid">文章ID號</param>
      public void MakeHtmlFile(string nid,string cla1id,string cla2id)                      //  MakeHtmlFile(string nid,string cla1id,string cla2id,string filetemp)  用于區分不同的摸班
      {
       string file_path            =   Server.MapPath ("template/news_mb.htm");
       string desfilename          =   MakeFileName(cla1id,cla2id,nid)+".htm";
       string desfile              =   MakeCatalogName(cla1id,cla2id)+MakeFileName(cla1id,cla2id,nid)+".htm";
       string prevurl              =   MakeFileName(cla1id,cla2id,previd)+".htm";                 //根據分類和ID生成上下篇的文件連接名
       string nexturl              =   MakeFileName(cla1id,cla2id,nextid)+".htm";                 //下篇
       System.Text.Encoding code   =   System.Text.Encoding.GetEncoding("gb2312");
      
       StreamReader srd            =   null;        //讀
       StreamWriter swr            =   null;        //寫
      
       string strFile              =   null ;       //字符串
      
       try
       {
        srd                     =   new StreamReader(file_path, code);
        strFile                 =   srd.ReadToEnd(); // 讀取文件
       }
       catch(Exception exp)
       {
        HttpContext.Current.Response.Write(exp.Message);
        HttpContext.Current.Response.End();
        srd.Close();
       }
      
       strFile = strFile.Replace("$title$",newstitle);
       strFile = strFile.Replace("$content$",newscontent);
       strFile = strFile.Replace("$date$",newsdate);
       strFile = strFile.Replace("$ip$",newsip);
       strFile = strFile.Replace("$prev$",prevtitle);
       strFile = strFile.Replace("$next$",nexttitle);
       strFile = strFile.Replace("$prevurl$",prevurl);
       strFile = strFile.Replace("$nexturl$",nexturl);
     
       try
       {
        swr = new StreamWriter(desfile,false,code);
        swr.Write(strFile);
        swr.Flush();
       }
       catch(Exception ex)
       {
        HttpContext.Current.Response.Write(ex.Message);
        HttpContext.Current.Response.End();
       }
       finally
       {
        swr.Close();
       }
       if(srd!=null)
       {
        srd.Close();
       }
       Response.Write(desfilename);

      }

      public void Open()
      {
       if(conn==null)
       {
        conn = new OleDbConnection(strcon);
        conn.Open();
       }
      }
      public void Close()
      {
       if(conn!=null)
       {
        conn.Close();
       }
      }

      #region Web 窗體設計器生成的代碼
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
      /// 此方法的內容。
      /// </summary>
      private void InitializeComponent()
      {   
       this.Load += new System.EventHandler(this.Page_Load);
      }
      #endregion
     }
    }

    posted on 2007-04-11 17:51 圣域飛俠 閱讀(322) 評論(0)  編輯  收藏 所屬分類: 轉載
    主站蜘蛛池模板: 一级免费黄色大片| 亚洲AV成人影视在线观看| 黄色a三级三级三级免费看| 日韩免费精品视频| 亚洲神级电影国语版| 一区二区免费在线观看| 99在线观看视频免费| 亚洲视频精品在线| 91香蕉国产线观看免费全集 | 性盈盈影院免费视频观看在线一区| 亚洲自偷自拍另类12p| 性xxxxx大片免费视频| 亚洲乱色熟女一区二区三区丝袜| 国产亚洲精品AAAA片APP| 久久久久国产精品免费免费搜索 | 日本不卡高清中文字幕免费| 亚洲男同gay片| vvvv99日韩精品亚洲| 又粗又长又爽又长黄免费视频| 亚洲精品无码久久不卡| av网站免费线看| 91免费国产在线观看| 国产成+人+综合+亚洲专| 免费毛片a在线观看67194| 亚洲日韩精品无码AV海量| 又粗又硬又黄又爽的免费视频 | 久久精品国产精品亚洲艾草网美妙 | 亚洲AV无码乱码在线观看代蜜桃| 成年人在线免费观看| 另类小说亚洲色图| 亚洲AV日韩AV高潮无码专区| 曰曰鲁夜夜免费播放视频| 天天综合亚洲色在线精品| 亚洲国产另类久久久精品黑人| 亚洲日本在线免费观看| 国产精品亚洲а∨天堂2021| 亚洲高清专区日韩精品| a级毛片无码免费真人| 黄 色一级 成 人网站免费| 亚洲噜噜噜噜噜影院在线播放| 免费人成无码大片在线观看|