熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET項目開發指南:經營狀況統計(2)[1]

2022-06-13   來源: .NET編程 

    經營狀況統計(

  ST_TurnOverStatModuleascxcs的主要代碼及其解釋

  本頁面與客戶信息查詢頁面類似當頁面加載時會執行Page_Load中的代碼這裡執行的是一個自定義的方法Show_TurnOverList()其後台代碼如程序所示

  程序  ST_TurnOverStatModuleascxcs

    public partial class ST_TurnOverStatModule : ST_ModuleBase

    {

        private void Page_Load(object sender SystemEventArgs e)

        {

            if(!IsPostBack)

            {

                //

                //綁定按房間類型下拉列表框

                //

                //從文件WebConfig中讀取連接字符串

                string ST_sqldb=

                ConfigurationSettingsAppSettings[ConnectionString];

                //連接ST_GinShopManage數據庫

                SqlConnection ST_Conn= new SqlConnection (ST_sqldb)

                ST_ConnOpen ()

                //定義SQL語句

                string ST_mysql=select ST_RCategoryIdST_Name from

                    ST_RoomCategory ;

                SqlCommand ST_cm=new SqlCommand  (ST_mysqlST_Conn)

                  //執行SQL語句並讀出數據

                SqlDataReader dr=ST_cmExecuteReader ()

                while(drRead ())

                {

                    ListItem li=new ListItem(dr[ST_Name]ToString()

                        dr[ST_RCategoryId]ToString())

                    RCategoryNameListItemsAdd (li)

                }

                //關閉連接

                ST_ConnClose ()

                Show_TurnOverList()

            }

        }

        protected void  Show_TurnOverList()

        {

            //從文件WebConfig中讀取連接字符串

            string ST_sqldb =

            ConfigurationSettingsAppSettings[ConnectionString];

            //連接ST_GinShopManage數據庫

            SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

            //定義sql

            string ST_selsql=select hST_BeginTimehST_EndTime

                hST_RoomIdcST_NamehST_CNamehST_CIdentityId

                hST_CPhonehST_TotalPrice+

            from ST_History hST_RoomsInfo rST_RoomCategory c where

    rST_RoomId=hST_RoomId and rST_RCategoryId=cST_RCategoryId;

            //創建SqlDataAdapter對象調用存儲過程ST_ShowRoomsInfo

            SqlDataAdapter ST_myadapter=new SqlDataAdapter

                (ST_selsqlST_Conn)

            //創建並填充DataSet

            DataSet ds = new DataSet()

            ST_myadapterFill (ds)

                dg_TurnOverListDataSource =ds;

            dg_TurnOverListDataBind()

            ST_ConnClose()

        }

        protected void GridView_Page(Object sender

            GridViewPageEventArgs E)

        {

            dg_TurnOverList PageIndex =ENewPageIndex ;

            Show_TurnOverList()

        }

    …

  【代碼說明】這裡的實現代碼和大多數的頁面一樣也是從數據庫中讀取數據並綁定到網格控件dg_TurnOverList代碼第~行是GridView控件的翻頁事件其中第行是指定新頁面行是重新綁定數據

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15961.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.