MainWindowViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. using LogoForceTestApp.Modules.MainModule.Enums;
  2. using LogoForceTestApp.Modules.MainModule.Models;
  3. using LogoForceTestApp.Core;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System.Windows.Media;
  9. using LogoForceTestApp.Modules.MainModule.Views;
  10. using System;
  11. using HandyControl.Controls;
  12. using Repository.Entiies;
  13. using Repository;
  14. using Team.Utility;
  15. using System.Reflection;
  16. namespace LogoForceTestApp.ViewModels
  17. {
  18. public class MainWindowViewModel : BindableBase
  19. {
  20. private string _title = "LogoForceTestApp";
  21. private readonly IRegionManager _regionManager;
  22. private readonly IEventAggregator _eventAggregator;
  23. private readonly IRepository _repository;
  24. private readonly IWritableOptions<AppSettings> _appSettings;
  25. public string Title
  26. {
  27. get { return _title; }
  28. set { SetProperty(ref _title, value); }
  29. }
  30. private RunResultState _runResultState;
  31. public RunResultState Jugement
  32. {
  33. get { return _runResultState; }
  34. set { SetProperty(ref _runResultState, value); }
  35. }
  36. public string LoginMessage { get; set; }
  37. public DelegateCommand LogCommand { get; set; }
  38. public DelegateCommand DataCommand { get; set; }
  39. public DelegateCommand GoMainPageCommand { get; set; }
  40. public DelegateCommand LoginCommand { get; set; }
  41. public DelegateCommand SettingCommand { get; set; }
  42. public DelegateCommand OperationLogPageCommand { get; set; }
  43. public DelegateCommand Tracing { get; set; }
  44. public DelegateCommand SignInCommand { get; set; }
  45. public Brush LoinBrush { get; set; }
  46. public string LineName { get; set; }
  47. public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,
  48. IRepository repository,IWritableOptions<AppSettings> appSettings)
  49. {
  50. var version=Assembly.GetExecutingAssembly().GetName().Version;
  51. Title = Title+"-" + version.ToString();
  52. DataCommand = new DelegateCommand(GoDataPage);
  53. GoMainPageCommand = new DelegateCommand(GoMainPage);
  54. LogCommand = new DelegateCommand(GoLogPage);
  55. LoginCommand = new DelegateCommand(Login);
  56. SettingCommand = new DelegateCommand(GoSettingPage);
  57. OperationLogPageCommand = new DelegateCommand(GoOperationLogPage);
  58. Tracing = new DelegateCommand(GoQualityTracing);
  59. SignInCommand = new DelegateCommand(GoSignInPage);
  60. _regionManager = regionManager;
  61. _eventAggregator = eventAggregator;
  62. _repository = repository;
  63. _appSettings = appSettings;
  64. LineName = _appSettings.Value.MachineName;
  65. if (string.IsNullOrWhiteSpace(_appSettings.Value.Process))
  66. {
  67. _appSettings.Update(c =>
  68. {
  69. c.Process = "FI_PP";
  70. });
  71. }
  72. if (string.IsNullOrWhiteSpace(_appSettings.Value.Builds))
  73. {
  74. _appSettings.Update(c =>
  75. {
  76. c.Builds = "RAMP";
  77. });
  78. }
  79. if (string.IsNullOrWhiteSpace(_appSettings.Value.Project))
  80. {
  81. _appSettings.Update(c =>
  82. {
  83. c.Project = "X1930";
  84. });
  85. }
  86. if (string.IsNullOrWhiteSpace(_appSettings.Value.Part))
  87. {
  88. _appSettings.Update(c =>
  89. {
  90. c.Part = "TC";
  91. });
  92. }
  93. if (string.IsNullOrWhiteSpace(_appSettings.Value.INSPECTION_PROGRAM_NAME))
  94. {
  95. _appSettings.Update(c =>
  96. {
  97. c.INSPECTION_PROGRAM_NAME = "FS_Color_Gloss";
  98. });
  99. }
  100. if (string.IsNullOrWhiteSpace(_appSettings.Value.AIM_UNIQUE))
  101. {
  102. _appSettings.Update(c =>
  103. {
  104. c.AIM_UNIQUE = "V1.0";
  105. });
  106. }
  107. if (string.IsNullOrWhiteSpace(_appSettings.Value.AimName))
  108. {
  109. _appSettings.Update(c =>
  110. {
  111. c.AimName = "L1-1";
  112. });
  113. }
  114. _eventAggregator.GetEvent<ResultEvent>().Subscribe(c =>
  115. {
  116. Jugement = c;
  117. });
  118. UpdateLoginMessage();
  119. _eventAggregator.GetEvent<LoginSuccessEvent>().Subscribe(result =>
  120. {
  121. UpdateLoginMessage();
  122. });
  123. }
  124. private void GoSignInPage()
  125. {
  126. var paramLog = new ParamLog
  127. {
  128. Id = Guid.NewGuid(),
  129. OperateAction = OperateAction.Navigate,
  130. Occured = DateTime.UtcNow,
  131. OperateObject = nameof(SignInPage),
  132. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  133. CurrentUser.CurrentUserName
  134. };
  135. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(SignInPage));
  136. paramLog.Content = "导航成功";
  137. _repository.Add(paramLog);
  138. }
  139. private async void GoQualityTracing()
  140. {
  141. var paramLog = new ParamLog
  142. {
  143. Id = Guid.NewGuid(),
  144. OperateAction = OperateAction.Navigate,
  145. Occured = DateTime.UtcNow,
  146. OperateObject = nameof(LoginPage),
  147. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  148. CurrentUser.CurrentUserName
  149. };
  150. try
  151. {
  152. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  153. {
  154. paramLog.Content = "权限不足失败";
  155. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  156. return;
  157. }
  158. paramLog.Content = "导航成功";
  159. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(QualityTracing));
  160. }
  161. finally
  162. {
  163. await _repository.AddAsync(paramLog);
  164. }
  165. }
  166. private async void GoOperationLogPage()
  167. {
  168. var paramLog = new ParamLog
  169. {
  170. Id = Guid.NewGuid(),
  171. OperateAction = OperateAction.Navigate,
  172. Occured = DateTime.UtcNow,
  173. OperateObject = nameof(OperationLogPage),
  174. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  175. CurrentUser.CurrentUserName
  176. };
  177. try
  178. {
  179. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  180. {
  181. paramLog.Content = "权限不足失败";
  182. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  183. return;
  184. }
  185. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(OperationLogPage));
  186. paramLog.Content = "导航成功";
  187. }
  188. finally
  189. {
  190. await _repository.AddAsync(paramLog);
  191. }
  192. }
  193. private async void GoSettingPage()
  194. {
  195. var paramLog = new ParamLog
  196. {
  197. Id = Guid.NewGuid(),
  198. OperateAction = OperateAction.Navigate,
  199. Occured = DateTime.UtcNow,
  200. OperateObject = "SettingPage",
  201. UserName=string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName)?"游客":
  202. CurrentUser.CurrentUserName
  203. };
  204. try
  205. {
  206. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  207. {
  208. paramLog.Content = "无权限,跳转登录界面";
  209. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  210. return;
  211. }
  212. if (CurrentUser.CurrentUserName == Role.Operator.ToString())
  213. {
  214. paramLog.Content = "权限不足";
  215. Growl.Info($"权限不足,请切换工程师权限");
  216. return;
  217. }
  218. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(ParamPage));
  219. paramLog.Content = "导航成功";
  220. }
  221. finally
  222. {
  223. await _repository.AddAsync(paramLog);
  224. }
  225. }
  226. private void UpdateLoginMessage()
  227. {
  228. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  229. {
  230. LoginMessage = "未登录";
  231. LoinBrush = Brushes.Red;
  232. }
  233. else
  234. {
  235. LoginMessage = $"{CurrentUser.CurrentUserName}";
  236. LoinBrush = Brushes.Blue;
  237. }
  238. }
  239. private void Login()
  240. {
  241. var paramLog = new ParamLog
  242. {
  243. Id = Guid.NewGuid(),
  244. OperateAction = OperateAction.Navigate,
  245. Occured = DateTime.UtcNow,
  246. OperateObject = "LoginPage",
  247. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  248. CurrentUser.CurrentUserName
  249. };
  250. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  251. paramLog.Content = "导航成功";
  252. _repository.Add(paramLog);
  253. }
  254. private async void GoLogPage()
  255. {
  256. var paramLog = new ParamLog
  257. {
  258. Id = Guid.NewGuid(),
  259. OperateAction = OperateAction.Navigate,
  260. Occured = DateTime.UtcNow,
  261. OperateObject = "LoginPage",
  262. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  263. CurrentUser.CurrentUserName
  264. };
  265. try
  266. {
  267. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  268. {
  269. paramLog.Content = "权限不足失败";
  270. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  271. return;
  272. }
  273. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LogPage));
  274. paramLog.Content = "导航成功";
  275. }
  276. finally
  277. {
  278. await _repository.AddAsync(paramLog);
  279. }
  280. }
  281. private async void GoMainPage()
  282. {
  283. var paramLog = new ParamLog
  284. {
  285. Id = Guid.NewGuid(),
  286. OperateAction = OperateAction.Navigate,
  287. Occured = DateTime.UtcNow,
  288. OperateObject = "MainPage",
  289. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  290. CurrentUser.CurrentUserName
  291. };
  292. try
  293. {
  294. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  295. {
  296. paramLog.Content = "权限不足失败";
  297. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  298. return;
  299. }
  300. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(MainPage));
  301. paramLog.Content = "导航成功";
  302. }
  303. finally
  304. {
  305. await _repository.AddAsync(paramLog);
  306. }
  307. }
  308. private async void GoDataPage()
  309. {
  310. var paramLog = new ParamLog
  311. {
  312. Id = Guid.NewGuid(),
  313. OperateAction = OperateAction.Navigate,
  314. Occured = DateTime.UtcNow,
  315. OperateObject = nameof(LoginPage),
  316. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  317. CurrentUser.CurrentUserName
  318. };
  319. try
  320. {
  321. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  322. {
  323. paramLog.Content = "权限不足失败";
  324. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  325. return;
  326. }
  327. paramLog.Content = "导航成功";
  328. _regionManager.RequestNavigate(RegionNames.ContentRegion, "DataPage");
  329. }
  330. finally
  331. {
  332. await _repository.AddAsync(paramLog);
  333. }
  334. }
  335. }
  336. }