MainWindowModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using AGV_WPF.Commands;
  6. using System.Windows;
  7. using System.Collections.ObjectModel;
  8. using AGV_WPF_DisMember;
  9. using AGV_WPF.ExtraUI;
  10. using AGV_WPF_Global;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.IO;
  14. using System.Windows.Controls;
  15. using AGV_WPF.Forms;
  16. namespace AGV_WPF.Models
  17. {
  18. class MainWindowModel : NotificationObject
  19. {
  20. public MainWindowModel()
  21. {
  22. ShowSelCommand = new DelegateCommand();
  23. ShowSelCommand.ExecuteAction = new Action<object>(this.ShowSel);
  24. ShowNoSelCommand = new DelegateCommand();
  25. ShowNoSelCommand.ExecuteAction = new Action<object>(this.ShowNoSel);
  26. HideSelCommand = new DelegateCommand();
  27. HideSelCommand.ExecuteAction = new Action<object>(this.HideSel);
  28. HideNoSelCommand = new DelegateCommand();
  29. HideNoSelCommand.ExecuteAction = new Action<object>(this.HideNoSel);
  30. ShowAllCommand = new DelegateCommand();
  31. ShowAllCommand.ExecuteAction = new Action<object>(this.ShowAll);
  32. HideAllCommand = new DelegateCommand();
  33. HideAllCommand.ExecuteAction = new Action<object>(this.HideAll);
  34. SetAgvAliasCommand = new DelegateCommand();
  35. SetAgvAliasCommand.ExecuteAction = new Action<object>(this.SetAgvAlias);
  36. ReadCheckSetCommand = new DelegateCommand();
  37. ReadCheckSetCommand.ExecuteAction = new Action<object>(this.ReadCheckSet);
  38. RemoteRouteSetCommand = new DelegateCommand();
  39. RemoteRouteSetCommand.ExecuteAction = new Action<object>(this.RemoteRouteSet);
  40. ReadCheckRecordCommand = new DelegateCommand();
  41. ReadCheckRecordCommand.ExecuteAction = new Action<object>(this.ReadCheckRecord);
  42. ChangeDisplayCommand = new DelegateCommand();
  43. ChangeDisplayCommand.ExecuteAction = new Action<object>(this.ChangeDisplay);
  44. HideCurrentColumnCommand = new DelegateCommand();
  45. HideCurrentColumnCommand.ExecuteAction = new Action<object>(this.HideCurrentColumn);
  46. ShowAllColumnsCommand = new DelegateCommand();
  47. ShowAllColumnsCommand.ExecuteAction = new Action<object>(this.ShowAllColumns);
  48. ExtendModuleDisplayCommand = new DelegateCommand();
  49. ExtendModuleDisplayCommand.ExecuteAction = new Action<object>(this.ExtendModuleDisplay);
  50. ClientListDisplayCommand = new DelegateCommand();
  51. ClientListDisplayCommand.ExecuteAction = new Action<object>(this.ClientListDisplay);
  52. UseRateDisplayCommand = new DelegateCommand();
  53. UseRateDisplayCommand.ExecuteAction = new Action<object>(this.UseRateDisplay);
  54. OpenManagerWindowCommand = new DelegateCommand();
  55. OpenManagerWindowCommand.ExecuteAction = new Action<object>(this.OpenManagerWindow);
  56. }
  57. public bool IsManager
  58. {
  59. get
  60. {
  61. return GlobalPara.IsManager;
  62. }
  63. }
  64. //private bool isShowName;
  65. public ImageSource HeaderImage
  66. {
  67. get
  68. {
  69. if (File.Exists(@"Image\header.png"))
  70. {
  71. return MainWindow.GetImageFromFile(@"Image\header.png");
  72. }
  73. else
  74. {
  75. return new BitmapImage(new Uri(@"Image\Header1.jpg", UriKind.RelativeOrAbsolute));
  76. }
  77. }
  78. }
  79. public DelegateCommand ShowSelCommand { get; set; }
  80. public DelegateCommand ShowNoSelCommand { get; set; }
  81. public DelegateCommand HideSelCommand { get; set; }
  82. public DelegateCommand HideNoSelCommand { get; set; }
  83. public DelegateCommand ShowAllCommand { get; set; }
  84. public DelegateCommand HideAllCommand { get; set; }
  85. public DelegateCommand ReadCheckSetCommand { get; set; }
  86. public DelegateCommand SetAgvAliasCommand { get; set; }
  87. public DelegateCommand RemoteRouteSetCommand { get; set; }
  88. public DelegateCommand ReadCheckRecordCommand { get; set; }
  89. public DelegateCommand ChangeDisplayCommand { get; set; }
  90. public DelegateCommand HideCurrentColumnCommand { get; set; }
  91. public DelegateCommand ShowAllColumnsCommand { get; set; }
  92. public DelegateCommand ExtendModuleDisplayCommand { get; set; }
  93. public DelegateCommand ClientListDisplayCommand { get; set; }
  94. public DelegateCommand UseRateDisplayCommand { get; set; }
  95. public DelegateCommand OpenManagerWindowCommand { get; set; }
  96. public void UseRateDisplay(object parameter)
  97. {
  98. Form1 form = new Form1();
  99. form.Show();
  100. }
  101. public void ClientListDisplay(object parameter)
  102. {
  103. ClientListWindow window = new ClientListWindow();
  104. window.Show();
  105. }
  106. public void ExtendModuleDisplay(object parameter)
  107. {
  108. ExtendModuleWindow window = new ExtendModuleWindow();
  109. window.Show();
  110. }
  111. public void ReadCheckRecord(object parameter)
  112. {
  113. ReadCheckRecordWindow window = new ReadCheckRecordWindow();
  114. window.Show();
  115. }
  116. public void RemoteRouteSet(object parameter)
  117. {
  118. RemoteRouteSetWindow window = new RemoteRouteSetWindow();
  119. window.Show();
  120. }
  121. public void ReadCheckSet(object parameter)
  122. {
  123. CardCheckSetWindow window = new CardCheckSetWindow();
  124. window.Show();
  125. }
  126. public void SetAgvAlias(object parameter)
  127. {
  128. AgvAliasWindow aliasWindow = new AgvAliasWindow();
  129. aliasWindow.Show();
  130. }
  131. public void ShowSel(object parameter)
  132. {
  133. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems)
  134. {
  135. agv.AgvLabel.Visibility = Visibility.Visible;
  136. }
  137. }
  138. public void ShowNoSel(object parameter)
  139. {
  140. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items)
  141. {
  142. agv.AgvLabel.Visibility = Visibility.Visible;
  143. }
  144. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems)
  145. {
  146. agv.AgvLabel.Visibility = Visibility.Hidden;
  147. }
  148. }
  149. public void HideSel(object parameter)
  150. {
  151. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems)
  152. {
  153. agv.AgvLabel.Visibility = Visibility.Hidden;
  154. }
  155. }
  156. public void HideNoSel(object parameter)
  157. {
  158. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items)
  159. {
  160. agv.AgvLabel.Visibility = Visibility.Hidden;
  161. }
  162. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems)
  163. {
  164. agv.AgvLabel.Visibility = Visibility.Visible;
  165. }
  166. }
  167. public void ShowAll(object parameter)
  168. {
  169. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items)
  170. {
  171. agv.AgvLabel.Visibility = Visibility.Visible;
  172. }
  173. }
  174. public void HideAll(object parameter)
  175. {
  176. foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items)
  177. {
  178. agv.AgvLabel.Visibility = Visibility.Hidden;
  179. }
  180. }
  181. public void ChangeDisplay(object parameter)
  182. {
  183. if (MainWindow.mainWindow.contextMenuChangeDisplay.IsChecked)
  184. {
  185. UpdateText("AGV名称");
  186. }
  187. else
  188. {
  189. UpdateText("AGV编号");
  190. }
  191. }
  192. void UpdateText(string type)
  193. {
  194. if (type == "AGV名称")
  195. {
  196. foreach (AGV_DisMember agv in MainWindow.mainWindow.memberData)
  197. {
  198. if (agv.txtStatus == "运行")
  199. {
  200. agv.AgvLabel.Content = agv.txtAgvAlias;
  201. }
  202. else if (agv.txtStatus == "暂停")
  203. {
  204. agv.AgvLabel.Content = agv.txtAgvAlias + agv.txtStatus.Trim();
  205. }
  206. else if (agv.txtStatus == "结束地标停止")
  207. {
  208. agv.AgvLabel.Content = agv.txtAgvAlias;
  209. }
  210. else
  211. {
  212. agv.AgvLabel.Content = agv.txtAgvAlias + agv.txtStatus.Trim();
  213. }
  214. }
  215. }
  216. else if (type == "AGV编号")
  217. {
  218. foreach (AGV_DisMember agv in MainWindow.mainWindow.memberData)
  219. {
  220. if (agv.txtStatus == "运行")
  221. {
  222. agv.AgvLabel.Content = agv.txtAGVNum;
  223. }
  224. else if (agv.txtStatus == "暂停")
  225. {
  226. agv.AgvLabel.Content = agv.txtAGVNum.Remove(0, 3) + agv.txtStatus.Trim();
  227. }
  228. else if (agv.txtStatus == "结束地标停止")
  229. {
  230. agv.AgvLabel.Content = agv.txtAGVNum.Remove(0, 3);
  231. }
  232. else
  233. {
  234. agv.AgvLabel.Content = agv.txtAGVNum.Remove(0, 3) + agv.txtStatus.Trim();
  235. }
  236. }
  237. }
  238. }
  239. int GetColumnIndex(string columnName)
  240. {
  241. int index = MainWindow.mainWindow.dataGrid.Columns.IndexOf(MainWindow.mainWindow.dataGrid.Columns.First(c => c.Header.ToString() == columnName));
  242. return index;
  243. }
  244. public void HideCurrentColumn(object parameter)
  245. {
  246. MainWindow.mainWindow.dataGrid.Columns[MainWindow.mainWindow.dataGrid.CurrentColumn.DisplayIndex].Visibility = Visibility.Hidden;
  247. }
  248. public void ShowAllColumns(object parameter)
  249. {
  250. for (int i = 0; i < MainWindow.mainWindow.dataGrid.Columns.Count; i++)
  251. {
  252. MainWindow.mainWindow.dataGrid.Columns[i].Visibility = Visibility.Visible;
  253. }
  254. }
  255. public void OpenManagerWindow(object parameter)
  256. {
  257. ManagerWindow window = new ManagerWindow();
  258. window.Show();
  259. }
  260. }
  261. }