using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

namespace mdEngergy
{
    public partial class index : System.Web.UI.Page
    {
        public string strConnection = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            strConnection = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("DB_51aspx\\Data.mdb");
            notesBind();
            newsBind();
            rybBind();
        }

        //绑定公告
        private void notesBind()
        {

            //创建数据库连接对象
            OleDbConnection myconn = new OleDbConnection(strConnection);
            //打开数据库连接(edit by 51aspx.com)
            myconn.Open();
            //创建查询语句
            string sql = "select top 5 * from News where BigClassId=4 order by AddTime desc";

            //创建数据库命令
            OleDbCommand mycmd = new OleDbCommand(sql, myconn);
            OleDbDataReader result = mycmd.ExecuteReader();
            rpNotes.DataSource = result;
            rpNotes.DataBind();
            myconn.Close();
        }

        //绑定新闻
        private void newsBind()
        { 
        
            //创建数据库连接对象
            OleDbConnection myconn = new OleDbConnection(strConnection);
            //打开数据库连接(edit by 51aspx.com)
            myconn.Open();
            //创建查询语句
            string sql = "select top 4 * from News where BigClassId=7 order by AddTime desc";

            //创建数据库命令
            OleDbCommand mycmd = new OleDbCommand(sql, myconn);
            OleDbDataReader result = mycmd.ExecuteReader();
            rpNews.DataSource = result;
            rpNews.DataBind();
            myconn.Close();
        }    
        
        
        //绑定荣誉榜
        private void rybBind()
        { 
        
            //创建数据库连接对象
            OleDbConnection myconn = new OleDbConnection(strConnection);
            //打开数据库连接(edit by 51aspx.com)
            myconn.Open();
            //创建查询语句
            string sql = "select top 6 * from News where BigClassId=10 order by AddTime desc";

            //创建数据库命令
            OleDbCommand mycmd = new OleDbCommand(sql, myconn);
            OleDbDataReader result = mycmd.ExecuteReader();
            rpRyb.DataSource = result;
            rpRyb.DataBind();
            myconn.Close();
        }
    }
}
