界面:
代码:
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Data.SqlClient;
namespace wyyNavigator
{
public partial class wyyNavigator : UserControl
{
#region 变量定义
private int totalCount = 0;//总数据个数
private int pageCount = 0;//总页数
private int currentPageIndex = 1;//当前页索引
private int pageSize = 10;//每页分页大小
private int remainder = 0;//最后一页剩余个数
private bool isAutoUpdateLabelTip = true;//获取或设置是否自动更新分页标签内容提示,默认为true
private string sqlAddress = "";//"Data Source=192.168.100.144;Initial Catalog=test;User ID=sa;Password=123456;";//DataGridViewd要绑定的表名
private string tableName = "";//"DataSource";//DataGridViewd要绑定的表名
private string strWhere = "";
private DataSet dsAll = null;//总数据源
#endregion
#region 传入参数
#region 通过数据[库]查询
/// <summary>
/// 链接数据库地址
/// </summary>
public string SqlAddress
{
get { return this.sqlAddress; }
set { this.sqlAddress = value; base.Refresh(); }
}
/// <summary>
/// 查询表
/// </summary>
public string TableName
{
get { return this.tableName; }
set { this.tableName = value; base.Refresh(); }
}
/// <summary>
/// 添加自定义条件
/// </summary>
public string StrWhere
{
get { return this.strWhere; }
set { this.strWhere = value; base.Refresh(); }
}
#endregion
#region 通过数据[源]查询
/// <summary>
/// 传递dataset数据源
/// </summary>
public DataSet DsAll
{
get { return this.dsAll; }
set { this.dsAll = value; base.Refresh(); }
}
#endregion
#region 外调函数
/// <summary>
/// 绑定数据
/// </summary>
public void dataBand()
{
comboBoxNum();
showDataGirdView();
}
/// <summary>
/// 返回当前页面数据
/// </summary>
/// <returns></returns>
public DataGridView outputDGV()
{
return dataGridView_show;
}
#endregion
#endregion
#region 加载
//定义委托
public delegate void BindHandle(object sender, EventArgs e);
/// <summary>
/// 绑定数据源事件
/// </summary>
//public event BindHandle BindSource;
public wyyNavigator()
{
InitializeComponent();
}
#endregion
//加载事件
private void wyyNavigator_Load(object sender, EventArgs e)
{
comboBoxNum();
showDataGirdView();
}
#region 分页操作
//首页
private void label_first_Click(object sender, EventArgs e)
{
currentPageIndex = 1;
showDataGirdView();
}
//末页
private void label_end_Click(object sender, EventArgs e)
{
currentPageIndex = pageCount;
showDataGirdView();
}
//上一页
private void label_up_Click(object sender, EventArgs e)
{
if (currentPageIndex <= pageCount && currentPageIndex != 1)
{
currentPageIndex--;
showDataGirdView();
}
if (isAutoUpdateLabelTip)
{
updateSplitPageLabelTip();
}
}
//下一页
private void label_down_Click(object sender, EventArgs e)
{
if (currentPageIndex < pageCount && currentPageIndex != pageCount)
{
currentPageIndex++;
showDataGirdView();
}
if (isAutoUpdateLabelTip)
{
updateSplitPageLabelTip();
}
}
//第几页
private voi