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 = ; /// <summary>
/// 页索引
/// </summary>
private int _PageIndex = ; /// <summary>
/// 记录数
/// </summary>
private int _RecodeCount = ; /// <summary>
/// 页数
/// </summary>
private int _PageCount = ; /// <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() == "")
{
return;
}
_comToPageIndex.Tag = "";
} //出发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[]["PageSize"].ToString());
this._PageIndex = Int32.Parse(ds.Tables["TabScript"].Rows[]["PageIndex"].ToString());
this._RecodeCount = Int32.Parse(ds.Tables["TabScript"].Rows[]["Rows"].ToString());
this._PageCount = this._RecodeCount / this._PageSize + ; if (_comToPageIndex != null)
{
_comToPageIndex.Items.Clear();
for (int i = ; 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 <= ? 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, "", para, out errmsg, out ds);
}
catch (Exception ex)
{
//发生webservice错误
throw new Exception("连接WebService服务器失败(001)!\n\r错误原因:" + ex.Message);
} if (tt == )
{
//获取数据成功
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 = ;
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# 简单的通用基础字典的更多相关文章
- python基础—字典
阅读文本需要3分钟,不建议跳读 节目清单 字典是python中最重要的数据类型,字典由“键-值”对组成的集合,字典中的“值”通过“键”来引用.这里将介绍字典的定义.访问.排序等功能. 字典的创建 字典 ...
- 一个简单的通用Makefile实现
一个简单的通用Makefile实现 Makefile是Linux下程序开发的自动化编译工具,一个好的Makefile应该准确的识别编译目标与源文件的依赖关系,并且有着高效的编译效率,即每次重新ma ...
- 【RL-TCPnet网络教程】第38章 TFTP简单文件传输基础知识
第38章 TFTP简单文件传输基础知识 本章节为大家讲解TFTP(Trivial File Transfer Protocol,简单文件传输协议)的基础知识,方便后面章节的实战操作. (本章 ...
- python基础--字典
Python基础--字典 字典的常用函数: dict.clear( )--->无任何返回值 说明: 清除字典内的所有的元素 语法: In [5]: dict.clear? Type: metho ...
- C#中使用泛型对照使用通用基础类型效率减少近一倍
C#中使用泛型对照使用通用基础类型效率减少近一倍 以下是測试结果: CSharp class and generic TotalMilliseconds: 270772.9229CSharp g ...
- Master-Slave通用基础框架
一.设计目的 设计出一个通用的Master-Slave基础框架,然后可以基于这个框架来实现特定的业务需求,比如实现多节点并行计算.分布式处理等. 二.设计理念 基于经典的命令模式,Master和Sla ...
- 简单的通用TreeView(WPF)
工作中要为很多类创建TreeView, 很多时候仅仅是因为要显示字段不同, 就得Ctrl+C.Ctrl+V复制一份几乎相同的代码, 这难免让人生厌, 于是希望像泛型集合的扩展方法那样, 可以在使用的时 ...
- git的简单理解及基础操作命令
前端小白一枚,最近开始使用git,于是花了2天看了廖雪峰的git教程(偏实践,对于学习git的基础操作很有帮助哦),也在看<git版本控制管理>这本书(偏理论,内容完善,很不错),针对所学 ...
- css简单的一些基础知识
css层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.CSS不仅可 ...
随机推荐
- Git Cmd
http://my.oschina.net/sunboy2050/blog/55749
- Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心
B. OR in Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/probl ...
- HDU 1863 畅通工程
畅通工程 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- Android传感器编程带实例
看了程序人生 网站的 编程高手的编程感悟 深有感触,好像也是一个android 程序员写的,推荐大家也看看.话不多说,还是言归正传吧. 一.前言 我很喜欢电脑,可是笔记本还是太大,笔记本电脑再小还是要 ...
- class、classLoader的getResourceAsStream的区别
1.class.getResourceAsStream() 从源码中可以看出他也是调用ClassLoader的getResourceAsStream() public InputStream getR ...
- xtrabackup原理0
- 高级I/O之非阻塞I/O
http://www.cnblogs.com/nufangrensheng/p/3515035.html中曾将系统调用分成“低速”系统调用和其他系统调用两类.低速系统调用是可能会使进程永远阻塞的一类系 ...
- (转)Windows7 64位系统搭建Cocos2d-x 2.2.1最新版以及Android交叉编译环境(详细教程) .
声明:本教程在参考了以下博文,并经过自己的摸索后实际操作得出,本教程系本人原创,由于升级后的cocos2d-x有了一些变化,目前的博文还没有关于Cocos2d-x 2.2.1最新版搭建Android交 ...
- Computer skills one can learn within one day
Computer related technical skills are usually thought as complicated and difficult to understand. It ...
- Android(java)学习笔记85:案例拨号程序
手机拨号程序:(只有程序代码) package cn.itcast.phone; import android.app.Activity; import android.content.Intent; ...