C#简单的通用基础字典实现方法
本文实例讲述了C#简单的通用基础字典实现方法。分享给大家供大家参考。具体实现方法如下:
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingAlif.Alif_WSAPI; usingSystem.Data; usingSystem.Windows.Forms;
namespaceAlif.AlifForm.CommClass { ///<summary> /// ///</summary> publicclassPagingCtrl { ///<summary> ///页大小 ///</summary> privateint_PageSize=50;
///<summary> ///页索引 ///</summary> privateint_PageIndex=1;
///<summary> ///记录数 ///</summary> privateint_RecodeCount=0;
///<summary> ///页数 ///</summary> privateint_PageCount=0;
///<summary> ///回调函数获取要查询数据的XML数据参数 ///</summary> ///<paramname="PageIndex"></param> ///<paramname="PageSize"></param> ///<returns></returns> publicdelegatestringLoadXML(intPageIndex,intPageSize);
///<summary> ///在读取数据后发生的事件,用于通知客户 ///</summary> publicdelegatevoidafterDataLoadDelegate();
///<summary> ///在读取数据前发生的事件,提示客户等待 ///</summary> publicdelegatevoidbeforeDataLoadDelegate();
///<summary> ///在读取数据发生错误时发生,用于错误处理 ///</summary> publicdelegatevoiderrorDataLoadDelegate(stringErrMSG);
///<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;
publicstring_webseiviceComm="";
///<summary> ///构造函数 ///</summary> ///<paramname="btFirst">首页</param> ///<paramname="btPreview">上一页</param> ///<paramname="btNext">下一页</param> ///<paramname="btLast">末页</param> ///<paramname="btreflesh">刷新</param> ///<paramname="msg">共x页,记录数:x</param> ///<paramname="PageSize">页大小</param> ///<paramname="PageIndex">页索引</param> ///<paramname="dv">显示数据的datagridview</param> ///<paramname="webseiviceComm">命令编号</param> ///<paramname="loadxmlCallBack">参数</param> ///<paramname="beferfireCallBack">加载之前处理的回调函数</param> ///<paramname="afterfireCallBack">加载之后处理的回调函数</param> ///<paramname="errorfireCallBack">错误处理的回调函数</param> publicPagingCtrl(System.Windows.Forms.ButtonbtFirst, System.Windows.Forms.ButtonbtPreview, System.Windows.Forms.ButtonbtNext, System.Windows.Forms.ButtonbtLast, System.Windows.Forms.Buttonbtreflesh, System.Windows.Forms.Labelmsg, System.Windows.Forms.ComboBoxPageSize, System.Windows.Forms.ComboBoxPageIndex, C1.Win.C1FlexGrid.C1FlexGriddv, stringwebseiviceComm, LoadXMLloadxmlCallBack, beforeDataLoadDelegatebeferfireCallBack, afterDataLoadDelegateafterfireCallBack, errorDataLoadDelegateerrorfireCallBack) { _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+=newSystem.EventHandler(this.btFirst_Click); } if(_btPreview!=null) { _btPreview.Click+=newSystem.EventHandler(this.btUp_Click); } if(_btNext!=null) { _btNext.Click+=newSystem.EventHandler(this.btNext_Click); } if(_btLast!=null) { _btLast.Click+=newSystem.EventHandler(this.btLast_Click); }
if(_comPageSize!=null) { _comPageSize.SelectedIndexChanged+=newSystem.EventHandler(comPageSize_SelectedIndexChanged); } if(_comToPageIndex!=null) { _comToPageIndex.SelectedIndexChanged+=newEventHandler(comToPageIndex_SelectedIndexChanged); _comToPageIndex.Tag=""; } if(_btreflesh!=null) { _btreflesh.Click+=newSystem.EventHandler(this.btReflesh_Click); } }
///<summary> ///调用webservice方法获取数据 ///</summary> ///<paramname="webservicecomm"></param> ///<paramname="Xmlcommand"></param> publicvoidLoadData(stringwebservicecomm,stringXmlcommand) { if(_comToPageIndex!=null) { //防止程序重入 if(_comToPageIndex.Tag==null||_comToPageIndex.Tag.ToString()=="1") { return; } _comToPageIndex.Tag="1"; }
//出发beforefire事件 if(_beferDataLoad!=null) { _beferDataLoad(); }
System.Data.DataSetds;
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(inti=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(Exceptionex) { //发生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> ///<paramname="XmlComm"></param> publicvoidLoadData(stringXmlComm) { LoadData(_webseiviceComm,XmlComm);
}
///<summary> /// ///</summary> publicvoidLoadData() { LoadData(_webseiviceComm,_loadxml(this._PageIndex,this._PageSize)); }
///<summary> ///加载web服务数据 ///</summary> ///<paramname="cmdID">命令编号</param> ///<paramname="para">参数</param> ///<returns>数据集</returns> privateDataSetLoadWebServiceData(stringcmdID,stringpara) { inttt; stringerrmsg=""; System.Data.DataSetds=newDataSet(); try { tt=WebService.GetInstance(CommonInfo.LoginInfo.userParameters).Execute("DataServices",cmdID,"1",para,outerrmsg,out ds); } catch(Exceptionex) { //发生webservice错误 thrownewException("连接WebService服务器失败(001)!\n\r错误原因:"+ex.Message); }
if(tt==1) { //获取数据成功 returnds; } else { //获取keystring错误 thrownewException("服务器返回失败信息(002)!\n\r错误原因:"+errmsg); } }
///<summary> ///刷新 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidbtReflesh_Click(objectsender,EventArgse) { LoadData(); }
///<summary> ///下一页 ///</summary> publicvoidNextPage() { this._btNext.PerformClick(); }
///<summary> ///下一页 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidbtNext_Click(objectsender,EventArgse) { _PageIndex++; LoadData(); }
///<summary> ///上一页 ///</summary> publicvoidUpPage() { this._btPreview.PerformClick(); }
///<summary> ///上一页 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidbtUp_Click(objectsender,EventArgse) { --_PageIndex; LoadData(); }
///<summary> ///首页 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidbtFirst_Click(objectsender,EventArgse) { _PageIndex=1; LoadData(); }
///<summary> ///首页 ///</summary> publicvoidFirstPage() { this._btFirst.PerformClick(); }
///<summary> ///最后一页 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidbtLast_Click(objectsender,EventArgse) { _PageIndex=_PageCount; LoadData(); }
///<summary> ///最后一页 ///</summary> publicvoidLastPage() { this._btLast.PerformClick(); }
///<summary> ///combobox选择改变页号 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidcomPageSize_SelectedIndexChanged(objectsender,EventArgse) { this._PageSize=Int32.Parse(_comPageSize.Text); LoadData(); }
///<summary> ///翻到第几页 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> privatevoidcomToPageIndex_SelectedIndexChanged(objectsender,EventArgse) { this._PageIndex=Int32.Parse(_comToPageIndex.Text); LoadData(); } } }