国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

生成靜態文件的新聞系統核心代碼(.net C#)(一)

2024-07-10 13:12:59
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

 

在網上看了許多能生成靜態頁的新聞系統,但基于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
 }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永寿县| 霍州市| 灵山县| 古交市| 额济纳旗| 商南县| 湛江市| 灵丘县| 临朐县| 永胜县| 隆德县| 秦安县| 乌什县| 鄯善县| 务川| 大新县| 财经| 贡觉县| 彝良县| 隆化县| 宁蒗| 扬州市| 雅江县| 彩票| 平罗县| 山阴县| 芒康县| 保德县| 昔阳县| 祁连县| 旬阳县| 中宁县| 丽江市| 浦城县| 绥棱县| 临夏市| 井研县| 哈密市| 贡觉县| 渝中区| 白朗县|