PaginationConfig.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. namespace GDNXFD.Alert.Config.Model
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. /// <summary>
  9. /// Pagination Manager class.
  10. /// </summary>
  11. public class PaginationConfig
  12. {
  13. private PageItem pageSelected;
  14. private int itemsCounted;
  15. private int pageSize;
  16. /// <summary>
  17. /// Constructor
  18. /// </summary>
  19. /// <param name="itemsCounted">Items counted.</param>
  20. /// <param name="pageSize">Size of the page.</param>
  21. public PaginationConfig(int itemsCounted, int pageSize)
  22. {
  23. this.itemsCounted = itemsCounted;
  24. this.pageSize = pageSize;
  25. this.pageSelected = new PageItem((1).ToString(), true, true);
  26. }
  27. /// <summary>
  28. /// Number of pages.
  29. /// </summary>
  30. public int NumberOfPages
  31. {
  32. get { return (int)Math.Ceiling((double)this.itemsCounted / this.pageSize); }
  33. }
  34. /// <summary>
  35. /// Page size.
  36. /// </summary>
  37. public int PageSize
  38. {
  39. get { return this.pageSize; }
  40. set { this.pageSize = value; }
  41. }
  42. /// <summary>
  43. /// Page selected.
  44. /// </summary>
  45. public PageItem PageSelected
  46. {
  47. get { return this.pageSelected; }
  48. set { this.pageSelected = value; }
  49. }
  50. /// <summary>
  51. /// Number of page selected.
  52. /// </summary>
  53. public int NumberOfPageSelected
  54. {
  55. get { return int.Parse(this.pageSelected.Page); }
  56. set { this.pageSelected.Page = value.ToString(); }
  57. }
  58. /// <summary>
  59. /// Items counted.
  60. /// </summary>
  61. public int ItemsCounted
  62. {
  63. get { return this.itemsCounted; }
  64. set
  65. {
  66. this.itemsCounted = value;
  67. }
  68. }
  69. /// <summary>
  70. /// This property is true if user can go to the next page.
  71. /// </summary>
  72. public bool CanGoNext
  73. {
  74. get { return NumberOfPageSelected < NumberOfPages; }
  75. }
  76. /// <summary>
  77. /// This property is true if user can go to the previous page.
  78. /// </summary>
  79. public bool CanGoPrevious
  80. {
  81. get { return 1 < NumberOfPageSelected; }
  82. }
  83. }
  84. }