版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

111 wiersze
2.9 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace ProductionControl.UI
  11. {
  12. public partial class UIPagination : UserControl
  13. {
  14. /// <summary>
  15. /// 1-n
  16. /// </summary>
  17. public int CurrentPage { get; private set; } = 1;
  18. /// <summary>
  19. /// 每页条数
  20. /// </summary>
  21. public int PageSize { get; set; } = 20;
  22. /// <summary>
  23. /// 总条数
  24. /// </summary>
  25. public int TotalCount { get; set; } = 0;
  26. /// <summary>
  27. ///
  28. /// </summary>
  29. public Action refresh;
  30. /// <summary>
  31. /// 总页数
  32. /// </summary>
  33. private int TotalPages
  34. {
  35. get { return (int)(TotalCount * 1.0f / PageSize + 0.5); }
  36. }
  37. public UIPagination()
  38. {
  39. InitializeComponent();
  40. }
  41. private void UIPagination_Load(object sender, EventArgs e)
  42. {
  43. this.cobPageNum.Items.Add(1);
  44. }
  45. private void freshUI()
  46. {
  47. this.btnFirst.Enabled = this.btnPre.Enabled = (CurrentPage > 1);
  48. this.btnLast.Enabled = this.btnNext.Enabled = (CurrentPage < TotalPages);
  49. if (CurrentPage > TotalPages)
  50. CurrentPage = TotalPages;
  51. this.lblPagesCount.Text = $"/{TotalPages}页";
  52. int liTotalPages = TotalPages;
  53. while (this.cobPageNum.Items.Count != liTotalPages)
  54. {
  55. if (this.cobPageNum.Items.Count > liTotalPages)
  56. this.cobPageNum.Items.RemoveAt(this.cobPageNum.Items.Count - 1);
  57. else
  58. this.cobPageNum.Items.Add(this.cobPageNum.Items.Count + 1);
  59. }
  60. }
  61. private void numPageSize_ValueChanged(object sender, EventArgs e)
  62. {
  63. PageSize = (int)numPageSize.Value;
  64. freshUI();
  65. refresh?.Invoke();
  66. }
  67. private void btnPre_Click(object sender, EventArgs e)
  68. {
  69. CurrentPage--;
  70. freshUI();
  71. refresh?.Invoke();
  72. }
  73. private void btnNext_Click(object sender, EventArgs e)
  74. {
  75. CurrentPage++;
  76. freshUI();
  77. refresh?.Invoke();
  78. }
  79. private void btnFirst_Click(object sender, EventArgs e)
  80. {
  81. CurrentPage = 1;
  82. freshUI();
  83. refresh?.Invoke();
  84. }
  85. private void btnLast_Click(object sender, EventArgs e)
  86. {
  87. CurrentPage = TotalPages;
  88. freshUI();
  89. refresh?.Invoke();
  90. }
  91. private void cobPageNum_SelectedIndexChanged(object sender, EventArgs e)
  92. {
  93. CurrentPage = cobPageNum.SelectedIndex + 1;
  94. freshUI();
  95. refresh?.Invoke();
  96. }
  97. }
  98. }