首页 - C#.NET

生成静态文件的新闻系统核心代码(.net C#)(一)

发布时间: 2007-04-19 02:48    作者: 未知    来源: 未知    浏览:    评论

 

在网上看了许多能生成静态页的新闻系统,但基于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
 }
}


TAG

Smile Big Smile Surprise Stick out tongue Wink Sad Tongue Tied Indifferent Crying Embarrassed Cool Angry Angel Devil [8-|] [:#] [:-*] [:^)] [<:o)] [|-)] Yes Beer Left Hug Music Star Time Snail Pizza Automobile Umbrella Computer Storm [mo] [8o|] [^o)] [+o(] [*-)] [8-)] Coffee No Drinks [Z] Right Hug Cake Broken Heart Gift Wilted Flower Movie Dog Idea Sleep Email Travel Paradise
呢称:

加粗 斜体 下划线 链接 图片 代码 邮件地址 引用 列表

最多只能输入100个字符

Tags

SQL 数据库 asp.net C# XML 控件 .NET教程 程序 事件 数据 安全 代码 Server 客户端 验证 数据库专栏 接口 文件 Oracle DataSet 函数 DataGrid 问题 .net return C#语言 JavaScript 服务 IIS 对象 语句 windows 继承 时间 web.config 设计 开发 参数 变量 解决 字符 ADO.net 环境 VB.Net语言 web 异常 工具 服务器 计算 实例 OLEDB Application VB Word WebService insert asp net 安装 记录

精华推荐

更多

精品下载

更多