修改分页工具栏

This commit is contained in:
chfei committed 2026-09-07 14:32:54 +08:00
1 parent d370a58554
commit 8c2cd6b83d
3 files changed
+172 -139

No files matched your search

@@ -55,7 +55,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms
num_minprice.Value = 0; num_minprice.Value = 0;
num_maxprice.Value = 999; num_maxprice.Value = 999;
cb_Platform.SelectedIndex = 0; cb_Platform.SelectedIndex = 0;
//ucSplitPage1.TotalPage ucSplitPage1.TotalCount = 0;
} }
@@ -358,6 +358,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms
{ {
ret.List.ForEach(a => dataList.Add(a)); ret.List.ForEach(a => dataList.Add(a));
ucSplitPage1.TotalPage = Math.Max(1, ret.TotalPages); ucSplitPage1.TotalPage = Math.Max(1, ret.TotalPages);
ucSplitPage1.TotalCount = ret.Total;
this.pbLoading.Visible = false; this.pbLoading.Visible = false;
// 异步加载商品缩略图(Column1 绑定 ThumbUrl) // 异步加载商品缩略图(Column1 绑定 ThumbUrl)
ShowDgvImg(); ShowDgvImg();
+9 -9
View File
@@ -52,7 +52,7 @@ namespace TemuKJD.UserControls
this.btnPrev.Cursor = System.Windows.Forms.Cursors.Hand; this.btnPrev.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnPrev.DisabledBackColor = System.Drawing.Color.Empty; this.btnPrev.DisabledBackColor = System.Drawing.Color.Empty;
this.btnPrev.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnPrev.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnPrev.Location = new System.Drawing.Point(259, 0); this.btnPrev.Location = new System.Drawing.Point(235, 0);
this.btnPrev.Margin = new System.Windows.Forms.Padding(0); this.btnPrev.Margin = new System.Windows.Forms.Padding(0);
this.btnPrev.Name = "btnPrev"; this.btnPrev.Name = "btnPrev";
this.btnPrev.Size = new System.Drawing.Size(31, 20); this.btnPrev.Size = new System.Drawing.Size(31, 20);
@@ -102,11 +102,11 @@ namespace TemuKJD.UserControls
// //
this.lblPage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); this.lblPage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.lblPage.AutoSize = true; this.lblPage.AutoSize = true;
this.lblPage.Location = new System.Drawing.Point(293, 0); this.lblPage.Location = new System.Drawing.Point(269, 0);
this.lblPage.Name = "lblPage"; this.lblPage.Name = "lblPage";
this.lblPage.Size = new System.Drawing.Size(15, 20); this.lblPage.Size = new System.Drawing.Size(39, 20);
this.lblPage.TabIndex = 436; this.lblPage.TabIndex = 436;
this.lblPage.Text = "1"; this.lblPage.Text = "1/1页";
this.lblPage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblPage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// flowLayoutPanel1 // flowLayoutPanel1
@@ -216,19 +216,19 @@ namespace TemuKJD.UserControls
// //
this.lblTotal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); this.lblTotal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.lblTotal.AutoSize = true; this.lblTotal.AutoSize = true;
this.lblTotal.Location = new System.Drawing.Point(220, 0); this.lblTotal.Location = new System.Drawing.Point(196, 0);
this.lblTotal.Margin = new System.Windows.Forms.Padding(0); this.lblTotal.Margin = new System.Windows.Forms.Padding(0);
this.lblTotal.Name = "lblTotal"; this.lblTotal.Name = "lblTotal";
this.lblTotal.Size = new System.Drawing.Size(39, 20); this.lblTotal.Size = new System.Drawing.Size(39, 20);
this.lblTotal.TabIndex = 446; this.lblTotal.TabIndex = 446;
this.lblTotal.Text = "共1页"; this.lblTotal.Text = "共1条";
this.lblTotal.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblTotal.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// lblPageSize // lblPageSize
// //
this.lblPageSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); this.lblPageSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.lblPageSize.AutoSize = true; this.lblPageSize.AutoSize = true;
this.lblPageSize.Location = new System.Drawing.Point(177, 0); this.lblPageSize.Location = new System.Drawing.Point(153, 0);
this.lblPageSize.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0); this.lblPageSize.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
this.lblPageSize.Name = "lblPageSize"; this.lblPageSize.Name = "lblPageSize";
this.lblPageSize.Size = new System.Drawing.Size(37, 20); this.lblPageSize.Size = new System.Drawing.Size(37, 20);
@@ -250,7 +250,7 @@ namespace TemuKJD.UserControls
"1000", "1000",
"2000", "2000",
"5000"}); "5000"});
this.cmbPageSize.Location = new System.Drawing.Point(132, 0); this.cmbPageSize.Location = new System.Drawing.Point(108, 0);
this.cmbPageSize.Margin = new System.Windows.Forms.Padding(0); this.cmbPageSize.Margin = new System.Windows.Forms.Padding(0);
this.cmbPageSize.Name = "cmbPageSize"; this.cmbPageSize.Name = "cmbPageSize";
this.cmbPageSize.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmbPageSize.RightToLeft = System.Windows.Forms.RightToLeft.No;
@@ -287,5 +287,5 @@ namespace TemuKJD.UserControls
private System.Windows.Forms.Label lblPageSize; private System.Windows.Forms.Label lblPageSize;
public System.Windows.Forms.ComboBox cmbPageSize; public System.Windows.Forms.ComboBox cmbPageSize;
public System.Windows.Forms.Label lblTotal; public System.Windows.Forms.Label lblTotal;
} }
} }
+161 -129
View File
@@ -11,141 +11,173 @@ using System.Windows.Forms;
namespace TemuKJD.UserControls namespace TemuKJD.UserControls
{ {
public partial class UcSplitPage : UserControl public partial class UcSplitPage : UserControl
{ {
/// <summary> /// <summary>
/// 是否显示每页条数(启用每页条数功能) /// 是否显示每页条数(启用每页条数功能)
/// </summary> /// </summary>
[Description("显示每页条数"), Category("UserProperty")] [Description("显示每页条数"), Category("UserProperty")]
public bool IsShowPageSize public bool IsShowPageSize
{ {
get get
{ {
return this.cmbPageSize.Visible; return this.cmbPageSize.Visible;
} }
set set
{ {
if (cmbPageSize.Visible != value) if (cmbPageSize.Visible != value)
{ {
this.lblPageSize.Visible = this.cmbPageSize.Visible = value; this.lblPageSize.Visible = this.cmbPageSize.Visible = value;
this.Invalidate(); 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; int totalPage = 1;
public int TotalPage public int TotalPage
{ {
get { return totalPage; } get { return totalPage; }
set set
{ {
if (TotalPage != value && value > 0) if (totalPage != value && value > 0)
{ {
totalPage = value; totalPage = value;
if (InvokeRequired) Refresh();
{ }
Invoke(new Action(() => }
{ }
this.lblTotal.Text = "共 " + totalPage + " 页";
}));
}
else
this.lblTotal.Text = "共 " + totalPage + " 页";
}
}
}
int currentPage = 1; int currentPage = 1;
public int CurrentPage public int CurrentPage
{ {
get { return currentPage; } get { return currentPage; }
set set
{ {
if (currentPage != value) // 确保当前页不超过总页数
{ int newPage = Math.Max(1, Math.Min(totalPage, value));
currentPage = value; if (currentPage != newPage)
if (InvokeRequired) {
{ currentPage = newPage;
Invoke(new Action(() => Refresh();
{ }
this.lblPage.Text = "" + currentPage; OnPageChange(this);
})); }
} }
else
this.lblPage.Text = "" + currentPage;
}
OnPageChange(this);
}
}
[Description("每页条数"), Category("UserProperty")] [Description("每页条数"), Category("UserProperty")]
public int PageSize public int PageSize
{ {
get get
{ {
int pageSize = 50; int pageSize = 50;
if (InvokeRequired) if (InvokeRequired)
{ {
Invoke(new Action(() => Invoke(new Action(() =>
{ {
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1); pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
})); }));
} }
else else
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1); pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
return pageSize; return pageSize;
} }
set set
{ {
if (InvokeRequired) if (InvokeRequired)
{ {
Invoke(new Action(() => Invoke(new Action(() =>
{ {
if (this.cmbPageSize.Text.ParseToInt() != value) if (this.cmbPageSize.Text.ParseToInt() != value)
this.cmbPageSize.Text = value.ParseToString(); this.cmbPageSize.Text = value.ParseToString();
else else
this.cmbPageSize.Text = value.ParseToString(); this.cmbPageSize.Text = value.ParseToString();
})); }));
} }
else else
{ {
if (this.cmbPageSize.Text.ParseToInt() != value) if (this.cmbPageSize.Text.ParseToInt() != value)
this.cmbPageSize.Text = value.ParseToString(); this.cmbPageSize.Text = value.ParseToString();
else else
this.cmbPageSize.Text = value.ParseToString(); this.cmbPageSize.Text = value.ParseToString();
} }
//OnPageChange(this); // 当每页条数变化时,重新计算总页数
} 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; public event Action<object> PageChange;
protected virtual void OnPageChange(object sender) protected virtual void OnPageChange(object sender)
{ {
this.PageChange?.Invoke(sender); this.PageChange?.Invoke(sender);
} }
public UcSplitPage() public UcSplitPage()
{ {
InitializeComponent(); InitializeComponent();
} }
private void pnlJump_Click(object sender, EventArgs e) private void pnlJump_Click(object sender, EventArgs e)
{ {
int page = this.txtJumpPage.Text.ParseToInt(); int page = this.txtJumpPage.Text.ParseToInt();
this.CurrentPage = Math.Max(1, page); 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 Refresh()
{
Invoke(new Action(() =>
{
lblPage.Text = $"{currentPage}/{TotalPage}页";
lblTotal.Text = $"共{TotalCount}条";
}));
} }
}
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);
}
}
} }