TitleBar.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using NEIntelligentControl2.Models.Pages;
  2. using NEIntelligentControl2.Models.Station;
  3. using NEIntelligentControl2.Models.User;
  4. using NEIntelligentControl2.Service.User;
  5. using NEIntelligentControl2.Windows;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace NEIntelligentControl2.Views.MainWindow
  21. {
  22. /// <summary>
  23. /// 标题栏
  24. /// </summary>
  25. public partial class TitleBar : UserControl
  26. {
  27. private List<StationInfo> itemsSource;
  28. /// <summary>
  29. /// 标题数据
  30. /// </summary>
  31. public List<StationInfo> ItemsSource { get=> itemsSource; set { itemsSource = value; _LBMain.ItemsSource = value; _LBMain.SelectedIndex = 0; } }
  32. private UserManager _UserManager;
  33. private TagManager _TagManager;
  34. public TitleBar()
  35. {
  36. InitializeComponent();
  37. _UserManager = App.ServiceProvider.GetService(typeof(UserManager)) as UserManager;
  38. _TagManager = App.ServiceProvider.GetService(typeof(TagManager)) as TagManager;
  39. _TagManager.TagChanged = TagChanged;
  40. _TagManager.ChangeTag = ChangeTag;
  41. }
  42. private void ChangeTag(string obj)
  43. {
  44. var v = ItemsSource.Where(i => i.Id == obj).FirstOrDefault();
  45. if (v == null) return;
  46. _LBMain.SelectedItem = v;
  47. _TagManager.TagSwitched?.Invoke(v);
  48. }
  49. /// <summary>
  50. /// 标签内容改变
  51. /// </summary>
  52. /// <param name="obj"></param>
  53. private void TagChanged(List<StationInfo> obj)
  54. {
  55. this.ItemsSource = obj;
  56. }
  57. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  58. {
  59. _PUser.IsOpen = false;
  60. switch (((FrameworkElement)sender).Tag)
  61. {
  62. case "close":// 关闭应用程序
  63. CloseApp();
  64. break;
  65. case "user":
  66. UserClick();
  67. break;
  68. case "useradd":
  69. _UserManager.UserAdd();
  70. break;
  71. case "useredit":
  72. _UserManager.UserEdit();
  73. break;
  74. case "logout":
  75. Logout();
  76. break;
  77. default: return;
  78. }
  79. }
  80. /// <summary>
  81. /// 注销用户
  82. /// </summary>
  83. private void Logout()
  84. {
  85. _UserManager.Logout();
  86. _TBUser.Text = "未登录";
  87. }
  88. private void UserClick()
  89. {
  90. if (_UserManager.IsLogined)
  91. {
  92. _PUser.IsOpen = !_PUser.IsOpen;
  93. }
  94. else
  95. {
  96. UserWindow uw = App.ServiceProvider.GetService(typeof(UserWindow)) as UserWindow;
  97. bool b = uw.Show("User.PageFingerprint");
  98. if (b)
  99. {
  100. _TBUser.Text = _UserManager.User.Name;
  101. }
  102. }
  103. }
  104. /// <summary>
  105. /// 关闭程序
  106. /// </summary>
  107. private void CloseApp()
  108. {
  109. var v = MessageWindow.ShowMessage("是否退出系统?");
  110. if (!v) return;
  111. Application.Current.Shutdown();
  112. }
  113. private void Grid_MouseLeave(object sender, MouseEventArgs e)
  114. {
  115. _PUser.IsOpen = false;
  116. }
  117. private void _LBMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
  118. {
  119. if (e.AddedItems.Count <= 0) return;
  120. var si = e.AddedItems[0] as StationInfo;
  121. if (si == null) return;
  122. _TagManager.TagSwitched?.Invoke(si);
  123. }
  124. }
  125. }