修改分页工具栏
This commit is contained in:
1 parent
d370a58554
commit
8c2cd6b83d
3 files changed
+172
-139
No files matched your search
+160
-128
@@ -11,141 +11,173 @@ using System.Windows.Forms;
|
||||
|
||||
namespace TemuKJD.UserControls
|
||||
{
|
||||
public partial class UcSplitPage : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否显示每页条数(启用每页条数功能)
|
||||
/// </summary>
|
||||
[Description("显示每页条数"), Category("UserProperty")]
|
||||
public bool IsShowPageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cmbPageSize.Visible;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (cmbPageSize.Visible != value)
|
||||
{
|
||||
this.lblPageSize.Visible = this.cmbPageSize.Visible = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
public partial class UcSplitPage : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否显示每页条数(启用每页条数功能)
|
||||
/// </summary>
|
||||
[Description("显示每页条数"), Category("UserProperty")]
|
||||
public bool IsShowPageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cmbPageSize.Visible;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (cmbPageSize.Visible != value)
|
||||
{
|
||||
this.lblPageSize.Visible = this.cmbPageSize.Visible = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
long totalCount = 0;
|
||||
/// <summary>
|
||||
/// 总数量
|
||||
/// </summary>
|
||||
[Description("总数量"), Category("UserProperty")]
|
||||
public long TotalCount
|
||||
{
|
||||
get { return totalCount; }
|
||||
set
|
||||
{
|
||||
if (totalCount != value && value >= 0)
|
||||
{
|
||||
totalCount = value;
|
||||
// 根据总数量和每页条数计算总页数
|
||||
int pageSize = this.PageSize;
|
||||
if (pageSize > 0)
|
||||
{
|
||||
this.TotalPage = (int)Math.Ceiling((double)totalCount / pageSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.TotalPage = 1;
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int totalPage = 1;
|
||||
public int TotalPage
|
||||
{
|
||||
get { return totalPage; }
|
||||
set
|
||||
{
|
||||
if (TotalPage != value && value > 0)
|
||||
{
|
||||
totalPage = value;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.lblTotal.Text = "共 " + totalPage + " 页";
|
||||
}));
|
||||
}
|
||||
else
|
||||
this.lblTotal.Text = "共 " + totalPage + " 页";
|
||||
}
|
||||
}
|
||||
}
|
||||
int totalPage = 1;
|
||||
public int TotalPage
|
||||
{
|
||||
get { return totalPage; }
|
||||
set
|
||||
{
|
||||
if (totalPage != value && value > 0)
|
||||
{
|
||||
totalPage = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int currentPage = 1;
|
||||
public int CurrentPage
|
||||
{
|
||||
get { return currentPage; }
|
||||
set
|
||||
{
|
||||
if (currentPage != value)
|
||||
{
|
||||
currentPage = value;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.lblPage.Text = "" + currentPage;
|
||||
}));
|
||||
}
|
||||
else
|
||||
this.lblPage.Text = "" + currentPage;
|
||||
}
|
||||
OnPageChange(this);
|
||||
}
|
||||
}
|
||||
int currentPage = 1;
|
||||
public int CurrentPage
|
||||
{
|
||||
get { return currentPage; }
|
||||
set
|
||||
{
|
||||
// 确保当前页不超过总页数
|
||||
int newPage = Math.Max(1, Math.Min(totalPage, value));
|
||||
if (currentPage != newPage)
|
||||
{
|
||||
currentPage = newPage;
|
||||
Refresh();
|
||||
}
|
||||
OnPageChange(this);
|
||||
}
|
||||
}
|
||||
|
||||
[Description("每页条数"), Category("UserProperty")]
|
||||
public int PageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
int pageSize = 50;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
|
||||
}));
|
||||
}
|
||||
else
|
||||
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
|
||||
return pageSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (this.cmbPageSize.Text.ParseToInt() != value)
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
else
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.cmbPageSize.Text.ParseToInt() != value)
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
else
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
}
|
||||
//OnPageChange(this);
|
||||
}
|
||||
}
|
||||
[Description("每页条数"), Category("UserProperty")]
|
||||
public int PageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
int pageSize = 50;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
|
||||
}));
|
||||
}
|
||||
else
|
||||
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
|
||||
return pageSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (this.cmbPageSize.Text.ParseToInt() != value)
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
else
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.cmbPageSize.Text.ParseToInt() != value)
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
else
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
}
|
||||
// 当每页条数变化时,重新计算总页数
|
||||
if (totalCount > 0)
|
||||
{
|
||||
this.TotalPage = (int)Math.Ceiling((double)totalCount / value);
|
||||
// 确保当前页不超过新的总页数
|
||||
if (this.CurrentPage > this.TotalPage)
|
||||
{
|
||||
this.CurrentPage = this.TotalPage;
|
||||
}
|
||||
}
|
||||
//OnPageChange(this);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<object> PageChange;
|
||||
protected virtual void OnPageChange(object sender)
|
||||
{
|
||||
this.PageChange?.Invoke(sender);
|
||||
}
|
||||
public event Action<object> PageChange;
|
||||
protected virtual void OnPageChange(object sender)
|
||||
{
|
||||
this.PageChange?.Invoke(sender);
|
||||
}
|
||||
|
||||
public UcSplitPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public UcSplitPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void pnlJump_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.txtJumpPage.Text.ParseToInt();
|
||||
this.CurrentPage = Math.Max(1, page);
|
||||
|
||||
}
|
||||
private void pnlJump_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.txtJumpPage.Text.ParseToInt();
|
||||
this.CurrentPage = Math.Max(1, page);
|
||||
|
||||
private void btnPrev_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.CurrentPage - 1;
|
||||
this.CurrentPage = Math.Max(1, page);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnNext_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.CurrentPage + 1;
|
||||
this.CurrentPage = Math.Min(totalPage, page);
|
||||
private void btnPrev_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.CurrentPage - 1;
|
||||
this.CurrentPage = Math.Max(1, page);
|
||||
}
|
||||
|
||||
private void btnNext_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.CurrentPage + 1;
|
||||
this.CurrentPage = Math.Min(totalPage, page);
|
||||
}
|
||||
private void Refresh()
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
lblPage.Text = $"{currentPage}/{TotalPage}页";
|
||||
lblTotal.Text = $"共{TotalCount}条";
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user