| | |
| | | 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 Gs.DevApp.ToolBox; |
| | | using System; |
| | | using System.Windows.Forms; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraGrid; |
| | | using Gs.DevApp.ToolBox; |
| | | |
| | | namespace UserControls.Data |
| | | { |
| | | public partial class UcPageBar : UserControl |
| | | { |
| | | public delegate void GetPageDataEvents(int curPage, int pageSize);//定义委托 |
| | | public event GetPageDataEvents PagerEvent;//定义事件 |
| | | public delegate void |
| | | GetPageDataEvents(int curPage, int pageSize); //定义委托 |
| | | |
| | | public UcPageBar() |
| | | { |
| | | InitializeComponent(); |
| | | // UtilityHelper.SetFont(layoutControl1); |
| | | this.cbxRowCount.Text = "50"; |
| | | this.cbxRowCount.SelectedIndexChanged += new System.EventHandler(this.cbxRowCount_SelectedIndexChanged); |
| | | } |
| | | |
| | | #region 定义属性 |
| | | |
| | | |
| | | int _TotalPages; |
| | | /// <summary> |
| | | /// 总页数 |
| | | /// </summary> |
| | | public int TotalPages |
| | | { |
| | | get { return _TotalPages; } |
| | | set |
| | | { |
| | | _TotalPages = value; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 当前页 |
| | | /// </summary> |
| | | public int CurrentPage |
| | | { |
| | | get; set; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 每页条数 |
| | | /// </summary> |
| | | public int RowsCount |
| | | { |
| | | get; set; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 总记录数 |
| | | /// </summary> |
| | | public int RecordCount |
| | | { |
| | | get; set; |
| | | } |
| | | #endregion |
| | | public event GetPageDataEvents PagerEvent; //定义事件 |
| | | |
| | | //选择每页显示条数 |
| | | private void cbxRowCount_SelectedIndexChanged(object sender, EventArgs e) |
| | | private void cbxRowCount_SelectedIndexChanged(object sender, |
| | | EventArgs e) |
| | | { |
| | | RowsCount = Convert.ToInt32(cbxRowCount.Text); |
| | | int _RowsCount = Convert.ToInt32(cbxRowCount.Text); |
| | | CurrentPage = 1; |
| | | if (PagerEvent != null) |
| | | BtnEvents(sender, e); |
| | | if (_RowsCount > 0 && _RowsCount > 0) |
| | | BtnEvents(sender, e); |
| | | } |
| | | |
| | | //手动输入显示页面编号 |
| | |
| | | { |
| | | if (e.KeyCode == Keys.Enter) |
| | | { |
| | | int page = Convert.ToInt32(tbxCurrentPage.Text); |
| | | var page = Convert.ToInt32(tbxCurrentPage.Text); |
| | | if (page < 1) |
| | | { |
| | | CurrentPage = 1; |
| | | } |
| | | else if (page > TotalPages) |
| | | { |
| | | CurrentPage = TotalPages; |
| | | } |
| | | else |
| | | { |
| | | CurrentPage = page; |
| | | } |
| | | if (PagerEvent != null) |
| | | BtnEvents(sender, e); |
| | | } |
| | |
| | | { |
| | | if (CurrentPage == 1) |
| | | return; |
| | | if (CurrentPage <= TotalPages) |
| | | { |
| | | CurrentPage -= 1; |
| | | } |
| | | if (CurrentPage <= TotalPages) CurrentPage -= 1; |
| | | if (PagerEvent != null) |
| | | BtnEvents(sender, e); |
| | | } |
| | |
| | | { |
| | | if (CurrentPage == TotalPages) |
| | | return; |
| | | if (CurrentPage < TotalPages) |
| | | { |
| | | CurrentPage += 1; |
| | | } |
| | | if (CurrentPage < TotalPages) CurrentPage += 1; |
| | | if (PagerEvent != null) |
| | | BtnEvents(sender, e); |
| | | } |
| | |
| | | |
| | | private void BtnEvents(object sender, EventArgs e) |
| | | { |
| | | //setTxt(); |
| | | PagerEvent(CurrentPage, RowsCount); |
| | | } |
| | | |
| | | public void setTxt() |
| | | { |
| | | tbxCurrentPage.Text = CurrentPage.ToString(); |
| | | lbTotalPages.Text = "共 " + TotalPages.ToString() + "页"; |
| | | lbTotalRows.Text = "共 " + RecordCount.ToString() + " 条记录"; |
| | | this.cbxRowCount.Text = this.RowsCount.ToString(); |
| | | lbTotalPages.Text = "共 " + TotalPages + "页"; |
| | | lbTotalRows.Text = "共 " + RecordCount + " 条记录"; |
| | | if (RowsCount > 0) |
| | | cbxRowCount.Text = RowsCount.ToString(); |
| | | if (CurrentPage == 1) |
| | | lbFirstPage.Enabled = false; |
| | | else |
| | |
| | | else |
| | | lbNextPage.Enabled = true; |
| | | } |
| | | |
| | | #region 定义属性 |
| | | |
| | | /// <summary> |
| | | /// 总页数 |
| | | /// </summary> |
| | | public int TotalPages { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 当前页 |
| | | /// </summary> |
| | | public int CurrentPage { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 每页条数 |
| | | /// </summary> |
| | | public int RowsCount { get { return int.Parse(this.cbxRowCount.Text); } } |
| | | |
| | | |
| | | int _RecordCount; |
| | | /// <summary> |
| | | /// 总记录数 |
| | | /// </summary> |
| | | public int RecordCount |
| | | { |
| | | get { return _RecordCount; } |
| | | set |
| | | { |
| | | _RecordCount = value; |
| | | setTxt(); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | } |