InfoBar.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace NEIntelligentControl2.Views.Basic
  16. {
  17. /// <summary>
  18. /// 状态栏
  19. /// </summary>
  20. public partial class InfoBar : UserControl
  21. {
  22. public static readonly DependencyProperty IsPaginationProperty = DependencyProperty.Register("IsPagination", typeof(bool), typeof(InfoBar));
  23. public static readonly DependencyProperty PageCountProperty = DependencyProperty.Register("PageCount", typeof(int), typeof(InfoBar));
  24. public static readonly DependencyProperty PageIndexProperty = DependencyProperty.Register("PageIndex", typeof(int), typeof(InfoBar));
  25. public static readonly DependencyProperty EachPageCountProperty = DependencyProperty.Register("EachPageCount", typeof(int), typeof(InfoBar));
  26. /// <summary>
  27. /// 是否分页
  28. /// </summary>
  29. public bool IsPagination { get => (bool)GetValue(IsPaginationProperty); set => SetValue(IsPaginationProperty, value); }
  30. /// <summary>
  31. /// 总页数
  32. /// </summary>
  33. public int PageCount { get=>(int)GetValue(PageCountProperty); set => SetValue(PageCountProperty, value); }
  34. /// <summary>
  35. /// 当前页码
  36. /// </summary>
  37. public int PageIndex { get => (int)GetValue(PageIndexProperty); set => SetValue(PageIndexProperty, value); }
  38. /// <summary>
  39. /// 每页条数
  40. /// </summary>
  41. public int EachPageCount { get => (int)GetValue(EachPageCountProperty); set => SetValue(EachPageCountProperty, value); }
  42. /// <summary>
  43. /// 分页动作 每页数据,第几页
  44. /// </summary>
  45. public Action<int,int> OnPagination { get; set; }
  46. public InfoBar()
  47. {
  48. InitializeComponent();
  49. IsPagination = true;
  50. PageCount = 1;
  51. PageIndex = 1;
  52. EachPageCount = 100;
  53. }
  54. internal void Inof(string v)
  55. {
  56. // FFCA5100 FF006CBE
  57. Dispatcher.Invoke(() =>
  58. {
  59. this.Visibility = Visibility.Visible;
  60. _SBMain.Background = new SolidColorBrush(Color.FromRgb(0x00, 0x6C, 0xBE));
  61. _TBStatus.Text = v;
  62. _tbEachCountTitle.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
  63. });
  64. }
  65. internal void Warning(string v)
  66. {
  67. Dispatcher.Invoke(() =>
  68. {
  69. this.Visibility = Visibility.Visible;
  70. _SBMain.Background = new SolidColorBrush(Color.FromRgb(0xCA, 0x51, 0x00));
  71. _TBStatus.Text = v;
  72. _tbEachCountTitle.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
  73. });
  74. }
  75. internal void Success()
  76. {
  77. Dispatcher.Invoke(() =>
  78. {
  79. this._TBStatus.Text = "就绪";
  80. _SBMain.Background = new SolidColorBrush(Colors.WhiteSmoke);
  81. _tbEachCountTitle.Foreground = new SolidColorBrush(Colors.Black);
  82. if (!IsPagination)
  83. {
  84. this.Visibility = Visibility.Collapsed;
  85. }
  86. });
  87. }
  88. private void Button_Click(object sender, RoutedEventArgs e)
  89. {
  90. var tag = ((Control)sender).Tag as string;
  91. if (tag == null) return;
  92. switch (tag)
  93. {
  94. case "first":// 第一页
  95. PageIndex = 1;
  96. break;
  97. case "previous":// 上一页
  98. if (PageIndex <= 1) return;
  99. --PageIndex;
  100. break;
  101. case "last":// 下一页
  102. if (PageIndex >= PageCount) return;
  103. ++PageIndex;
  104. break;
  105. case "latest":// 最后一页
  106. PageIndex = PageCount;
  107. break;
  108. default:return;
  109. }
  110. this.OnPagination?.Invoke(EachPageCount, PageIndex);
  111. }
  112. }
  113. }