程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#簡略的通用基本字典完成辦法

C#簡略的通用基本字典完成辦法

編輯:C#入門知識

C#簡略的通用基本字典完成辦法。本站提示廣大學習愛好者:(C#簡略的通用基本字典完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#簡略的通用基本字典完成辦法正文


本文實例講述了C#簡略的通用基本字典完成辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Alif.Alif_WSAPI;
using System.Data;
using System.Windows.Forms;

namespace Alif.AlifForm.CommClass
{
    /// <summary>
    ///
    /// </summary>
    public class PagingCtrl
    {
        /// <summary>
        /// 頁年夜小
        /// </summary>
        private int _PageSize = 50;

        /// <summary>
        /// 頁索引
        /// </summary>
        private int _PageIndex = 1;

        /// <summary>
        /// 記載數
        /// </summary>
        private int _RecodeCount = 0;

        /// <summary>
        /// 頁數
        /// </summary>
        private int _PageCount = 0;

        /// <summary>
        /// 回調函數獲得要查詢數據的XML數據參數
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public delegate string LoadXML(int PageIndex, int PageSize);

        /// <summary>
        /// 在讀取數據後產生的事宜,用於告訴客戶
        /// </summary>
        public delegate void afterDataLoadDelegate();

        /// <summary>
        /// 在讀取數據前產生的事宜,提醒客戶期待
        /// </summary>
        public delegate void beforeDataLoadDelegate();

        /// <summary>
        /// 在讀取數據產生毛病時產生,用於毛病處置
        /// </summary>
        public delegate void errorDataLoadDelegate(string ErrMSG);

        /// <summary>
        /// 首頁按鈕
        /// </summary>
        System.Windows.Forms.Button _btFirst;

        /// <summary>
        /// 前頁按鈕
        /// </summary>
        System.Windows.Forms.Button _btPreview;

        /// <summary>
        /// 下一頁按鈕
        /// </summary>
        System.Windows.Forms.Button _btNext;

        /// <summary>
        /// 末頁按鈕
        /// </summary>
        System.Windows.Forms.Button _btLast;

        /// <summary>
        /// 刷新按鈕
        /// </summary>
        System.Windows.Forms.Button _btreflesh;

        /// <summary>
        /// 記載數提醒Label
        /// </summary>
        System.Windows.Forms.Label _msg;

        /// <summary>
        /// 每頁記載數combo
        /// </summary>
        System.Windows.Forms.ComboBox _comPageSize;

        /// <summary>
        /// 以後頁索引combo
        /// </summary>
        System.Windows.Forms.ComboBox _comToPageIndex;

        /// <summary>
        /// 顯示數據的datagridview
        /// </summary>
        C1.Win.C1FlexGrid.C1FlexGrid _dv;

        LoadXML _loadxml;
        afterDataLoadDelegate _afterDataLoad;
        beforeDataLoadDelegate _beferDataLoad;
        errorDataLoadDelegate _errorDataLoad;

        public string _webseiviceComm = "";

        /// <summary>
        /// 結構函數
        /// </summary>
        /// <param name="btFirst">首頁</param>
        /// <param name="btPreview">上一頁</param>
        /// <param name="btNext">下一頁</param>
        /// <param name="btLast">末頁</param>
        /// <param name="btreflesh">刷新</param>
        /// <param name="msg">共x頁,記載數:x</param>
        /// <param name="PageSize">頁年夜小</param>
        /// <param name="PageIndex">頁索引</param>
        /// <param name="dv">顯示數據的datagridview</param>
        /// <param name="webseiviceComm">敕令編號</param>
        /// <param name="loadxmlCallBack">參數</param>
        /// <param name="beferfireCallBack">加載之前處置的回調函數</param>
        /// <param name="afterfireCallBack">加載以後處置的回調函數</param>
        /// <param name="errorfireCallBack">毛病處置的回調函數</param>
        public PagingCtrl(System.Windows.Forms.Button btFirst,
                                    System.Windows.Forms.Button btPreview,
                                    System.Windows.Forms.Button btNext,
                                    System.Windows.Forms.Button btLast,
                                    System.Windows.Forms.Button btreflesh,
                                    System.Windows.Forms.Label msg,
                                    System.Windows.Forms.ComboBox PageSize,
                                    System.Windows.Forms.ComboBox PageIndex,
                                    C1.Win.C1FlexGrid.C1FlexGrid dv,
                                    string webseiviceComm,
                                    LoadXML loadxmlCallBack,
                                    beforeDataLoadDelegate beferfireCallBack,
                                    afterDataLoadDelegate afterfireCallBack,
                                    errorDataLoadDelegate errorfireCallBack)
        {
            _btFirst = btFirst;
            _btPreview = btPreview;
            _btNext = btNext;
            _btLast = btLast;
            _msg = msg;
            _dv = (C1.Win.C1FlexGrid.C1FlexGrid)dv;
            _loadxml = loadxmlCallBack;
            _webseiviceComm = webseiviceComm;
            _comPageSize = PageSize;
            _comToPageIndex = PageIndex;
            _btreflesh = btreflesh;
            _beferDataLoad = beferfireCallBack;
            _afterDataLoad = afterfireCallBack;
            _errorDataLoad = errorfireCallBack;

            if (_btFirst != null)
            {
                _btFirst.Click += new System.EventHandler(this.btFirst_Click);
            }
            if (_btPreview != null)
            {
                _btPreview.Click += new System.EventHandler(this.btUp_Click);
            }
            if (_btNext != null)
            {
                _btNext.Click += new System.EventHandler(this.btNext_Click);
            }
            if (_btLast != null)
            {
                _btLast.Click += new System.EventHandler(this.btLast_Click);
            }

            if (_comPageSize != null)
            {
                _comPageSize.SelectedIndexChanged += new System.EventHandler(comPageSize_SelectedIndexChanged);
            }
            if (_comToPageIndex != null)
            {
                _comToPageIndex.SelectedIndexChanged += new EventHandler(comToPageIndex_SelectedIndexChanged);
                _comToPageIndex.Tag = "";
            }
            if (_btreflesh != null)
            {
                _btreflesh.Click += new System.EventHandler(this.btReflesh_Click);
            }
        }

        /// <summary>
        /// 挪用webservice 辦法獲得數據
        /// </summary>
        /// <param name="webservicecomm"></param>
        /// <param name="Xmlcommand"></param>
        public void LoadData(string webservicecomm, string Xmlcommand)
        {
            if (_comToPageIndex != null)
            {
                //避免法式重入
                if (_comToPageIndex.Tag == null || _comToPageIndex.Tag.ToString() == "1")
                {
                    return;
                }
                _comToPageIndex.Tag = "1";
            }

            //動身beforefire事宜
            if (_beferDataLoad != null)
            {
                _beferDataLoad();
            }

            System.Data.DataSet ds;

            try
            {
                ds = LoadWebServiceData(webservicecomm, Xmlcommand);

                if (!ds.Tables.Contains("table0"))
                {
                    if(_dv.DataSource!=null)
                    {
                        ((DataTable)_dv.DataSource).Clear();
                    }
                }
                else
                {

                    _dv.DataSource = ds.Tables["table0"];


                }

                this._PageSize = Int32.Parse(ds.Tables["TabScript"].Rows[0]["PageSize"].ToString());
                this._PageIndex = Int32.Parse(ds.Tables["TabScript"].Rows[0]["PageIndex"].ToString());
                this._RecodeCount = Int32.Parse(ds.Tables["TabScript"].Rows[0]["Rows"].ToString());
                this._PageCount = this._RecodeCount / this._PageSize + 1;

                if (_comToPageIndex != null)
                {
                    _comToPageIndex.Items.Clear();
                    for (int i = 1; i <= this._PageCount; ++i)
                    {
                        _comToPageIndex.Items.Add(i.ToString());

                    }
                    _comToPageIndex.Text = this._PageIndex.ToString();
                }

                if (_msg != null)
                {
                    _msg.Text = "以後第" + this._PageIndex + "頁," + "共" + this._PageCount.ToString() + "頁,記載數:" + this._RecodeCount.ToString();
                }

                if (_btFirst != null)
                {
                    _btFirst.Enabled = this._PageIndex <= 1 ? false : true;
                }
                if (_btPreview != null)
                {
                    _btPreview.Enabled = _btFirst.Enabled;
                }
                if (_btLast != null)
                {
                    _btLast.Enabled = this._PageIndex >= this._PageCount ? false : true;
                }

                if (_btLast != null)
                {
                    _btLast.Enabled = _btLast.Enabled;
                }
            }
            catch (Exception ex)
            {
                //產生webservice毛病
                if (_errorDataLoad != null)
                {
                    _errorDataLoad("銜接WebService辦事器掉敗(001)!\n\r毛病緣由:" + ex.Message);
                }
                if (_comToPageIndex != null)
                {
                    _comToPageIndex.Tag = "";
                }
            }

            if (_afterDataLoad != null)
            {
                _afterDataLoad();
            }

            if (_comToPageIndex != null)
            {
                _comToPageIndex.Tag = "";
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="XmlComm"></param>
        public void LoadData(string XmlComm)
        {
            LoadData(_webseiviceComm, XmlComm);

        }

        /// <summary>
        ///
        /// </summary>
        public void LoadData()
        {
            LoadData(_webseiviceComm, _loadxml(this._PageIndex, this._PageSize));
        }

        /// <summary>
        /// 加載web辦事數據
        /// </summary>
        /// <param name="cmdID">敕令編號</param>
        /// <param name="para">參數</param>
        /// <returns>數據集</returns>
        private DataSet LoadWebServiceData(string cmdID, string para)
        {
            int tt;
            string errmsg = "";
            System.Data.DataSet ds = new DataSet();
            try
            {
                tt = WebService.GetInstance(CommonInfo.LoginInfo.userParameters).Execute("DataServices", cmdID, "1", para, out errmsg, out  ds);
            }
            catch (Exception ex)
            {
                //產生webservice毛病
                throw new Exception("銜接WebService辦事器掉敗(001)!\n\r毛病緣由:" + ex.Message);
            }

            if (tt == 1)
            {
                //獲得數據勝利
                return ds;
            }
            else
            {
                //獲得keystring毛病
                throw new Exception("辦事器前往掉敗信息(002)!\n\r毛病緣由:" + errmsg);
            }
        }

        /// <summary>
        /// 刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btReflesh_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        /// <summary>
        /// 下一頁
        /// </summary>
        public void NextPage()
        {
            this._btNext.PerformClick();
        }

        /// <summary>
        /// 下一頁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btNext_Click(object sender, EventArgs e)
        {
            _PageIndex++;
            LoadData();
        }

        /// <summary>
        /// 上一頁
        /// </summary>
        public void UpPage()
        {
            this._btPreview.PerformClick();
        }

        /// <summary>
        /// 上一頁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btUp_Click(object sender, EventArgs e)
        {
            --_PageIndex;
            LoadData();
        }

        /// <summary>
        /// 首頁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btFirst_Click(object sender, EventArgs e)
        {
            _PageIndex = 1;
            LoadData();
        }

        /// <summary>
        /// 首頁
        /// </summary>
        public void FirstPage()
        {
            this._btFirst.PerformClick();
        }

        /// <summary>
        /// 最初一頁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btLast_Click(object sender, EventArgs e)
        {
            _PageIndex = _PageCount;
            LoadData();
        }

        /// <summary>
        /// 最初一頁
        /// </summary>
        public void LastPage()
        {
            this._btLast.PerformClick();
        }

        /// <summary>
        /// combobox選擇轉變頁號
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this._PageSize = Int32.Parse(_comPageSize.Text);
            LoadData();
        }

        /// <summary>
        /// 翻到第幾頁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comToPageIndex_SelectedIndexChanged(object sender, EventArgs e)
        {
            this._PageIndex = Int32.Parse(_comToPageIndex.Text);
            LoadData();
        }
    }
}

願望本文所述對年夜家的C#法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved