MainWindowViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. using System.Data.SqlClient;
  17. using Prism.Ioc;
  18. using System.ComponentModel;
  19. using DryIoc;
  20. using System.Linq;
  21. namespace LogoForceTestApp.ViewModels
  22. {
  23. public class MainWindowViewModel : BindableBase
  24. {
  25. private string _title = "浙江德盾智能科技有限公司";
  26. private readonly IRegionManager _regionManager;
  27. private readonly IEventAggregator _eventAggregator;
  28. private readonly IRepository _repository;
  29. private readonly IWritableOptions<AppSettings> _appSettings;
  30. private readonly IContainerProvider _container;
  31. private MulProductModel _Products;
  32. public MulProductModel Products
  33. {
  34. get { return _Products; }
  35. set { SetProperty(ref _Products, value); }
  36. }
  37. public string Title
  38. {
  39. get { return _title; }
  40. set { SetProperty(ref _title, value); }
  41. }
  42. private RunResultState _runResultState;
  43. public RunResultState Jugement
  44. {
  45. get { return _runResultState; }
  46. set { SetProperty(ref _runResultState, value); }
  47. }
  48. private ProductModel _CurrentProduct;
  49. public ProductModel CurrentProduct
  50. {
  51. get { return _CurrentProduct; }
  52. set { SetProperty(ref _CurrentProduct, value); }
  53. }
  54. public string LoginMessage { get; set; }
  55. public DelegateCommand LogCommand { get; set; }
  56. public DelegateCommand DataCommand { get; set; }
  57. public DelegateCommand GoMainPageCommand { get; set; }
  58. public DelegateCommand LoginCommand { get; set; }
  59. public DelegateCommand SettingCommand { get; set; }
  60. public DelegateCommand OperationLogPageCommand { get; set; }
  61. public DelegateCommand Tracing { get; set; }
  62. public DelegateCommand SopCommand { get; set; }
  63. public DelegateCommand AccountCommand { get; set; }
  64. public DelegateCommand StatementPageCommand { get; set; }
  65. public Brush LoinBrush { get; set; }
  66. public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,
  67. IRepository repository,IWritableOptions<AppSettings> appSettings,IContainerProvider container)
  68. {
  69. _container= container;
  70. var version=Assembly.GetExecutingAssembly().GetName().Version;
  71. Title = Title+"-" + version.ToString();
  72. DataCommand = new DelegateCommand(GoDataPage);
  73. GoMainPageCommand = new DelegateCommand(GoMainPage);
  74. LogCommand = new DelegateCommand(GoLogPage);
  75. LoginCommand = new DelegateCommand(Login);
  76. SettingCommand = new DelegateCommand(GoSettingPage);
  77. OperationLogPageCommand = new DelegateCommand(GoOperationLogPage);
  78. Tracing = new DelegateCommand(GoQualityTracing);
  79. SopCommand = new DelegateCommand(GoSopPage);
  80. AccountCommand = new DelegateCommand(GoAccountPage);
  81. StatementPageCommand= new DelegateCommand(GoStatementPage);
  82. _regionManager = regionManager;
  83. _eventAggregator = eventAggregator;
  84. _repository = repository;
  85. _appSettings = appSettings;
  86. if (string.IsNullOrWhiteSpace(_appSettings.Value.Process))
  87. {
  88. _appSettings.Update(c =>
  89. {
  90. c.Process = "FI_PP";
  91. });
  92. }
  93. if (string.IsNullOrWhiteSpace(_appSettings.Value.Builds))
  94. {
  95. _appSettings.Update(c =>
  96. {
  97. c.Builds = "RAMP";
  98. });
  99. }
  100. if (string.IsNullOrWhiteSpace(_appSettings.Value.Project))
  101. {
  102. _appSettings.Update(c =>
  103. {
  104. c.Project = "X1930";
  105. });
  106. }
  107. if (string.IsNullOrWhiteSpace(_appSettings.Value.Part))
  108. {
  109. _appSettings.Update(c =>
  110. {
  111. c.Part = "TC";
  112. });
  113. }
  114. if (string.IsNullOrWhiteSpace(_appSettings.Value.INSPECTION_PROGRAM_NAME))
  115. {
  116. _appSettings.Update(c =>
  117. {
  118. c.INSPECTION_PROGRAM_NAME = "FS_Color_Gloss";
  119. });
  120. }
  121. if (string.IsNullOrWhiteSpace(_appSettings.Value.AIM_UNIQUE))
  122. {
  123. _appSettings.Update(c =>
  124. {
  125. c.AIM_UNIQUE = "V1.0";
  126. });
  127. }
  128. if (string.IsNullOrWhiteSpace(_appSettings.Value.AimName))
  129. {
  130. _appSettings.Update(c =>
  131. {
  132. c.AimName = "L1-1";
  133. });
  134. }
  135. _eventAggregator.GetEvent<ResultEvent>().Subscribe(c =>
  136. {
  137. Jugement = c;
  138. });
  139. UpdateLoginMessage();
  140. _eventAggregator.GetEvent<LoginSuccessEvent>().Subscribe(result =>
  141. {
  142. UpdateLoginMessage();
  143. });
  144. //Products = _container.Resolve<MulProductModel>();
  145. //if (Products==null)
  146. //{
  147. // Products = new MulProductModel();
  148. //}
  149. //Products.LoadParame();
  150. //CurrentProduct = Products.ProductCollection.FirstOrDefault(p=>p.Name=="123");
  151. //Products.ProductCollection.Add(new ProductModel() { Name="123"});
  152. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题1");
  153. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题2");
  154. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题3");
  155. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题4");
  156. //Products.ProductCollection.Add(new ProductModel() { Name = "321" });
  157. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题1");
  158. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题2");
  159. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题3");
  160. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题4");
  161. //Products.ProductCollection.Add(new ProductModel() { Name = "234" });
  162. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题1");
  163. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题2");
  164. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题3");
  165. //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题4");
  166. }
  167. private async void GoAccountPage()
  168. {
  169. var paramLog = new ParamLog
  170. {
  171. Id = Guid.NewGuid(),
  172. OperateAction = OperateAction.Navigate,
  173. Occured = DateTime.UtcNow,
  174. OperateObject = nameof(LoginPage),
  175. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  176. CurrentUser.CurrentUserName
  177. };
  178. try
  179. {
  180. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  181. {
  182. paramLog.Content = "权限不足失败";
  183. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  184. return;
  185. }
  186. paramLog.Content = "导航成功";
  187. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(AccountPage));
  188. }
  189. finally
  190. {
  191. await _repository.AddAsync(paramLog);
  192. }
  193. }
  194. private async void GoSopPage()
  195. {
  196. var paramLog = new ParamLog
  197. {
  198. Id = Guid.NewGuid(),
  199. OperateAction = OperateAction.Navigate,
  200. Occured = DateTime.UtcNow,
  201. OperateObject = nameof(LoginPage),
  202. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  203. CurrentUser.CurrentUserName
  204. };
  205. try
  206. {
  207. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  208. {
  209. paramLog.Content = "权限不足失败";
  210. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  211. return;
  212. }
  213. paramLog.Content = "导航成功";
  214. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(SopPage));
  215. }
  216. finally
  217. {
  218. await _repository.AddAsync(paramLog);
  219. }
  220. }
  221. private async void GoQualityTracing()
  222. {
  223. var paramLog = new ParamLog
  224. {
  225. Id = Guid.NewGuid(),
  226. OperateAction = OperateAction.Navigate,
  227. Occured = DateTime.UtcNow,
  228. OperateObject = nameof(LoginPage),
  229. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  230. CurrentUser.CurrentUserName
  231. };
  232. try
  233. {
  234. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  235. {
  236. paramLog.Content = "权限不足失败";
  237. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  238. return;
  239. }
  240. paramLog.Content = "导航成功";
  241. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(QualityTracing));
  242. }
  243. finally
  244. {
  245. await _repository.AddAsync(paramLog);
  246. }
  247. }
  248. private async void GoStatementPage()
  249. {
  250. var paramLog = new ParamLog
  251. {
  252. Id = Guid.NewGuid(),
  253. OperateAction = OperateAction.Navigate,
  254. Occured = DateTime.UtcNow,
  255. OperateObject = nameof(StatementPage),
  256. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  257. CurrentUser.CurrentUserName
  258. };
  259. try
  260. {
  261. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  262. {
  263. paramLog.Content = "权限不足失败";
  264. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  265. return;
  266. }
  267. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(StatementPage));
  268. paramLog.Content = "导航成功";
  269. }
  270. finally
  271. {
  272. await _repository.AddAsync(paramLog);
  273. }
  274. }
  275. private async void GoOperationLogPage()
  276. {
  277. var paramLog = new ParamLog
  278. {
  279. Id = Guid.NewGuid(),
  280. OperateAction = OperateAction.Navigate,
  281. Occured = DateTime.UtcNow,
  282. OperateObject = nameof(OperationLogPage),
  283. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  284. CurrentUser.CurrentUserName
  285. };
  286. try
  287. {
  288. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  289. {
  290. paramLog.Content = "权限不足失败";
  291. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  292. return;
  293. }
  294. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(OperationLogPage));
  295. paramLog.Content = "导航成功";
  296. }
  297. finally
  298. {
  299. await _repository.AddAsync(paramLog);
  300. }
  301. }
  302. private async void GoSettingPage()
  303. {
  304. var paramLog = new ParamLog
  305. {
  306. Id = Guid.NewGuid(),
  307. OperateAction = OperateAction.Navigate,
  308. Occured = DateTime.UtcNow,
  309. OperateObject = "SettingPage",
  310. UserName=string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName)?"游客":
  311. CurrentUser.CurrentUserName
  312. };
  313. try
  314. {
  315. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  316. {
  317. paramLog.Content = "无权限,跳转登录界面";
  318. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  319. return;
  320. }
  321. //if (CurrentUser.CurrentUserName == Role.Operator.ToString())
  322. //{
  323. // paramLog.Content = "权限不足";
  324. // Growl.Info($"权限不足,请切换工程师权限");
  325. // return;
  326. //}
  327. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(ParamPage));
  328. paramLog.Content = "导航成功";
  329. }
  330. finally
  331. {
  332. await _repository.AddAsync(paramLog);
  333. }
  334. }
  335. private void UpdateLoginMessage()
  336. {
  337. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  338. {
  339. LoginMessage = "未登录";
  340. LoinBrush = Brushes.Red;
  341. }
  342. else
  343. {
  344. LoginMessage = $"{CurrentUser.CurrentUserName}";
  345. LoinBrush = Brushes.Black;
  346. }
  347. }
  348. private void Login()
  349. {
  350. var paramLog = new ParamLog
  351. {
  352. Id = Guid.NewGuid(),
  353. OperateAction = OperateAction.Navigate,
  354. Occured = DateTime.UtcNow,
  355. OperateObject = "LoginPage",
  356. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  357. CurrentUser.CurrentUserName
  358. };
  359. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  360. paramLog.Content = "导航成功";
  361. _repository.Add(paramLog);
  362. }
  363. private async void GoLogPage()
  364. {
  365. var paramLog = new ParamLog
  366. {
  367. Id = Guid.NewGuid(),
  368. OperateAction = OperateAction.Navigate,
  369. Occured = DateTime.UtcNow,
  370. OperateObject = "LoginPage",
  371. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  372. CurrentUser.CurrentUserName
  373. };
  374. try
  375. {
  376. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  377. {
  378. paramLog.Content = "权限不足失败";
  379. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  380. return;
  381. }
  382. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LogPage));
  383. paramLog.Content = "导航成功";
  384. }
  385. finally
  386. {
  387. await _repository.AddAsync(paramLog);
  388. }
  389. }
  390. private void GoMainPage()
  391. {
  392. var paramLog = new ParamLog
  393. {
  394. Id = Guid.NewGuid(),
  395. OperateAction = OperateAction.Navigate,
  396. Occured = DateTime.UtcNow,
  397. OperateObject = "MainPage",
  398. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  399. CurrentUser.CurrentUserName
  400. };
  401. _regionManager.RequestNavigate(RegionNames.ContentRegion, "MainPage");
  402. paramLog.Content = "导航成功";
  403. _repository.Add(paramLog);
  404. }
  405. private async void GoDataPage()
  406. {
  407. var paramLog = new ParamLog
  408. {
  409. Id = Guid.NewGuid(),
  410. OperateAction = OperateAction.Navigate,
  411. Occured = DateTime.UtcNow,
  412. OperateObject = nameof(LoginPage),
  413. UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
  414. CurrentUser.CurrentUserName
  415. };
  416. try
  417. {
  418. if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
  419. {
  420. paramLog.Content = "权限不足失败";
  421. _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
  422. return;
  423. }
  424. paramLog.Content = "导航成功";
  425. _regionManager.RequestNavigate(RegionNames.ContentRegion, "DataPage");
  426. }
  427. finally
  428. {
  429. await _repository.AddAsync(paramLog);
  430. }
  431. }
  432. }
  433. }