123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using DevExpress.XtraEditors;
- using DevExpress.XtraPrinting.Native;
- using DW5S.DTO;
- using DW5S.Entity;
- using DW5S.Repostory;
- using ExtensionsDev;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace DW5S.App.UserControl
- {
- public partial class CtrlPage : DevExpress.XtraEditors.XtraUserControl
- {
- private event Func<PageQueryDto, Task<DTO.PageData>> OnQueryAsync;
- public void SetOnQuery(Func<PageQueryDto, Task<DTO.PageData>> onQueryAsync)
- {
- this.OnQueryAsync += onQueryAsync;
- RefreshData();
- }
- private bool comPact = false;
- /// <summary>
- /// 紧凑模式(默认false)
- /// </summary>
- [ToolboxItem(false)]
- [DefaultValue(false)]
- [Category("Style"), Description("紧凑模式")]
- public bool Compact
- {
- get
- {
- return comPact;
- }
- set
- {
- comPact = value;
- if (comPact)
- {
- foreach (Control item in this.stackPanel1.Controls)
- {
- item.Margin = new Padding(2);
- if (item.GetType() == typeof(Button))
- item.Width = 14;
- }
- txtCountPerPage.Width = 60;
- txtGoPage.Width = 60;
- }
- else
- {
- foreach (Control item in this.stackPanel1.Controls)
- {
- item.Margin = new Padding(2);
- if (item.GetType() == typeof(Button))
- item.Width = 20;
- }
- btnFirst.Margin = new System.Windows.Forms.Padding(20, 3, 3, 3);
- txtPageInfo.Margin = new System.Windows.Forms.Padding(10, 3, 10, 3);
- txtGoPage.Margin = new System.Windows.Forms.Padding(20, 3, 3, 3);
- this.txtCountPerPage.Width = 76;
- txtGoPage.Width = 76;
- }
- }
- }
- public bool showGoto = true;
- /// <summary>
- /// 是否显示跳转(模式true)
- /// </summary>
- [ToolboxItem(true)]
- [Category("Style"), Description("是否显示跳转")]
- [DefaultValue(true)]
- public bool ShowGoto
- {
- get
- {
- return showGoto;
- }
- set
- {
- showGoto = value;
- this.txtGoPage.Visible = value;
- this.btnGo.Visible = value;
- }
- }
- /// <summary>
- /// 当前页数
- /// </summary>
- private int CurrentPage { get; set; } = 1;
- public CtrlPage()
- {
- InitializeComponent();
- this.MinimumSize = new System.Drawing.Size(100, 26);
- }
- /// <summary>
- /// 刷新数据(当前页会变为1)
- /// </summary>
- public void RefreshData()
- {
- btn_Click(btnFirst, null);
- }
- private void txtCountPerPage_EditValueChanged(object sender, EventArgs e)
- {
- btn_Click(btnFirst, null);
- }
- private async void btn_Click(object sender, EventArgs e)
- {
- try
- {
- if (OnQueryAsync == null) return;
- if (sender == btnFirst)
- {
- this.CurrentPage = 1;
- }
- else if (sender == btnPrev)
- {
- if (this.CurrentPage > 1)
- this.CurrentPage--;
- }
- else if (sender == btnNext)
- {
- this.CurrentPage++;
- }
- else if (sender == btnLast)
- {
- this.CurrentPage = int.MaxValue;
- }
- else
- {
- int.TryParse(txtGoPage.Text, out int currentPage);
- if (currentPage <= 0) return;
- this.CurrentPage = currentPage;
- }
- int.TryParse(txtCountPerPage.Text, out int countPerPage);
- if (countPerPage <= 0)
- {
- countPerPage = (int)txtCountPerPage.Properties.Items[0];
- }
- this.Enabled = false;
- var pageData = await this.OnQueryAsync(new PageQueryDto()
- {
- CountPerPage = countPerPage,
- Page = CurrentPage,
- });
- this.CurrentPage = pageData.Page;
- txtPageInfo.Text = $"第{pageData.Page}页/共{pageData.TotalPage}页";
- }
- catch (Exception ex)
- {
- IocContainer.Logger.Error(ex, $"分页查询异常");
- }
- finally
- {
- this.Enabled = true;
- }
- }
- }
- }
|