SettingPageView.xaml.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. using ivf_tl_Entity.DebugEntitys;
  2. using ivf_tl_Operate.Converts;
  3. using ivf_tl_Operate.ViewModel;
  4. using ivf_tl_Operate.Windows;
  5. using ivf_tl_Services;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Animation;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace ivf_tl_Operate.View
  23. {
  24. /// <summary>
  25. /// SettingPageView.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class SettingPageView : UserControl
  28. {
  29. string guanbi;
  30. public TLSettingCommon tLSettingCommon = null;
  31. public SettingPageView()
  32. {
  33. InitializeComponent();
  34. List<int> autoTimeList = new List<int>();
  35. for (int i = 0; i < 24; i++) autoTimeList.Add(i);
  36. List<int> zhenList = new List<int>();
  37. for (int i = 1; i <= 30; i++) zhenList.Add(i);
  38. guanbi = KeyToStringConvert.GetLanguageStringByKey("C0305");
  39. List<string> cropList = new List<string>() { guanbi, "1", "3", "5", "7", "9", "11", "13", "15", "17", "19", "21", "23", "25" };
  40. //for (int i = 1; i <= 11; i++) cropList.Add(i);
  41. this._timingAutoFocus_ComboBox.ItemsSource = autoTimeList;
  42. this._videoFps_ComboBox.ItemsSource = zhenList;
  43. this._cropNum_ComboBox.ItemsSource = cropList;
  44. Loaded += SettingPageView_Loaded;
  45. }
  46. private void SettingPageView_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. if (AppData.Instance.TLSettingCommon != null && AppData.Instance.TLSettingCommon.id == 0)
  49. {
  50. AppData.Instance.TLSettingCommon = AppData.Instance.HttpHelper.SettingCommonApi(AppData.Instance.TLSettingCommon.tlSn);
  51. if (AppData.Instance.TLSettingCommon != null && AppData.Instance.TLSettingCommon.id == 0)
  52. {
  53. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "获取设置失败");
  54. }
  55. }
  56. tLSettingCommon = AppData.Instance.TLSettingCommon;
  57. SetPageInfo();
  58. }
  59. private string GetDataTime()
  60. {
  61. try
  62. {
  63. AppData.Instance.MainWindow.Mark(true);
  64. GetDateWindow getDate = new GetDateWindow(AppData.Instance.MainWindow);
  65. //getDate._dateControl.SetNYR(false);
  66. getDate.SetSelectWeiLai();
  67. getDate.isClos = true;
  68. var result = getDate.ShowDialog();
  69. if (result.Value == true)
  70. {
  71. return $"{getDate.Date} 00:00:00";
  72. }
  73. return null;
  74. }
  75. catch (Exception ex)
  76. {
  77. return null;
  78. }
  79. finally
  80. {
  81. AppData.Instance.MainWindow.Mark(false);
  82. }
  83. }
  84. private void SetPageInfo()
  85. {
  86. //this._timingAutoFocus_TextBlock.Text = $"{tLSettingCommon.autoFocusTime} >";
  87. //this._videoFps_TextBlock.Text = $"{tLSettingCommon.videoFps} >";
  88. //this._hepaTime_TextBlock.Text = $"{tLSettingCommon.heapDate} >";
  89. //this._keepTime_TextBlock.Text = $"{tLSettingCommon.keepDate} >";
  90. this._timingAutoFocus_ComboBox.SelectedItem = tLSettingCommon.autoFocusTime;
  91. this._videoFps_ComboBox.SelectedItem = tLSettingCommon.videoFps;
  92. if (tLSettingCommon.cropNum == -1)
  93. {
  94. this._cropNum_ComboBox.SelectedItem = guanbi;
  95. }
  96. else
  97. {
  98. this._cropNum_ComboBox.SelectedItem = tLSettingCommon.cropNum.ToString();
  99. }
  100. }
  101. private bool MiMa(PasswordBox textBox)
  102. {
  103. bool rs = false;
  104. // M5-02-3:工程师口令改读加密存储的 engineerPwd(首次无值回退默认 tl13579,迁移已在 App_Startup 加密回写)。
  105. // 方法签名与 7 处调用点不变(00-需求总览.md §8),仅换口令来源。[D8] 权限分级(普通运维 vs 工程师)待确认。
  106. string engineerPwd = ivf_tl_Operate.Helpers.AppConfigHelper.GetEngineerPwd();
  107. if (textBox.Password.Trim() == engineerPwd) rs = true;
  108. textBox.Password = "";
  109. return rs;
  110. }
  111. private bool UpdataTlSetting()
  112. {
  113. if (AppData.Instance.HttpHelper.CommonUpdateApi(tLSettingCommon))
  114. {
  115. new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0232"));
  116. return true;
  117. }
  118. else
  119. {
  120. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "更新失败");
  121. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0233"));
  122. return false;
  123. }
  124. }
  125. private void Return_Click(object sender, RoutedEventArgs e)
  126. {
  127. AppData.Instance.BackMainPage();
  128. }
  129. private void TimingAutoFocus_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  130. {
  131. if (this._timingAutoFocus_ComboBox.SelectedItem is int newValue)
  132. {
  133. if (newValue != tLSettingCommon.autoFocusTime)
  134. {
  135. int oldValue = tLSettingCommon.autoFocusTime;
  136. tLSettingCommon.autoFocusTime = newValue;
  137. if (!UpdataTlSetting()) tLSettingCommon.autoFocusTime = oldValue;
  138. }
  139. }
  140. }
  141. private void VideoFps_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  142. {
  143. if (this._videoFps_ComboBox.SelectedItem is int newValue)
  144. {
  145. if (newValue != tLSettingCommon.videoFps)
  146. {
  147. int oldValue = tLSettingCommon.videoFps;
  148. tLSettingCommon.videoFps = newValue;
  149. if (!UpdataTlSetting()) tLSettingCommon.videoFps = oldValue;
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// HEPA下次更换时间
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. private void HepaTime_MouseUp(object sender, MouseButtonEventArgs e)
  159. {
  160. if (!MiMa(this._hepaTime_PasswordBox))
  161. {
  162. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  163. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  164. return;
  165. }
  166. string newTime = GetDataTime();
  167. if (string.IsNullOrEmpty(newTime))
  168. {
  169. return;
  170. }
  171. string oldValue = tLSettingCommon.heapDate;
  172. tLSettingCommon.heapDate = newTime;
  173. if (!UpdataTlSetting()) tLSettingCommon.heapDate = oldValue;
  174. }
  175. /// <summary>
  176. /// 设备下次保养时间
  177. /// </summary>
  178. /// <param name="sender"></param>
  179. /// <param name="e"></param>
  180. private void KeepTime_MouseUp(object sender, MouseButtonEventArgs e)
  181. {
  182. if (!MiMa(this.KeepTime_PasswordBox))
  183. {
  184. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  185. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  186. return;
  187. }
  188. string newTime = GetDataTime();
  189. if (string.IsNullOrEmpty(newTime))
  190. {
  191. return;
  192. }
  193. string oldValue = tLSettingCommon.keepDate;
  194. tLSettingCommon.keepDate = newTime;
  195. if (!UpdataTlSetting()) tLSettingCommon.keepDate = oldValue;
  196. }
  197. /// <summary>
  198. /// 系统参数设置
  199. /// </summary>
  200. /// <param name="sender"></param>
  201. /// <param name="e"></param>
  202. private void HouseSetting_MouseUp(object sender, MouseButtonEventArgs e)
  203. {
  204. if (!MiMa(this.HouseSetting_PasswordBox))
  205. {
  206. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  207. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  208. return;
  209. }
  210. HouseSettingPageViewModel houseSettingPageViewModel = new HouseSettingPageViewModel();
  211. HouseSettingPageView houseSettingPageView = new HouseSettingPageView()
  212. {
  213. DataContext = houseSettingPageViewModel,
  214. };
  215. //houseSettingPageView.TestData();
  216. AppData.Instance.MainWindow.LoadPage(houseSettingPageView);
  217. }
  218. /// <summary>
  219. /// 对焦参数设置
  220. /// </summary>
  221. /// <param name="sender"></param>
  222. /// <param name="e"></param>
  223. private void AutoFocusSetting_MouseUp(object sender, MouseButtonEventArgs e)
  224. {
  225. if (!MiMa(this.AutoFocusSetting_PasswordBox))
  226. {
  227. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  228. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  229. return;
  230. }
  231. AutoFocusSettingViewModel autoFocusSettingViewModel = new AutoFocusSettingViewModel();
  232. AutoFocusSettingView autoFocusSettingView = new AutoFocusSettingView(autoFocusSettingViewModel);
  233. AppData.Instance.MainWindow.LoadPage(autoFocusSettingView);
  234. }
  235. /// <summary>
  236. /// 舱室调试
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void HouseDebug_MouseUp(object sender, MouseButtonEventArgs e)
  241. {
  242. if (!MiMa(this.HouseDebug_PasswordBox))
  243. {
  244. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  245. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  246. return;
  247. }
  248. if (!IsClose())
  249. {
  250. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "请先关闭下位机控制软件");
  251. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0235"));
  252. return;
  253. }
  254. HouseDebugPageViewModel houseDebugPageViewModel = new HouseDebugPageViewModel();
  255. string err = null;
  256. houseDebugPageViewModel.Start(ref err);
  257. if (!string.IsNullOrEmpty(err))
  258. {
  259. if (err == "结束") return;
  260. MessageBox.Show(err);
  261. return;
  262. }
  263. HouseDebugPageView houseDebugPageView = new HouseDebugPageView(houseDebugPageViewModel);
  264. AppData.Instance.MainWindow.LoadPage(houseDebugPageView);
  265. }
  266. /// <summary>
  267. /// 缓冲瓶调试
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void BufferDebug_MouseUp(object sender, MouseButtonEventArgs e)
  272. {
  273. if (!MiMa(this.BufferDebug_PasswordBox))
  274. {
  275. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  276. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  277. return;
  278. }
  279. if (!IsClose())
  280. {
  281. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "请先关闭下位机控制软件");
  282. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0235"));
  283. return;
  284. }
  285. BufferDebugViewModel bufferDebugViewModel = new BufferDebugViewModel();
  286. string err = null;
  287. bufferDebugViewModel.Start(ref err);
  288. if (!string.IsNullOrEmpty(err))
  289. {
  290. if (err == "结束") return;
  291. MessageBox.Show(err);
  292. return;
  293. }
  294. BufferDebugView houseDebugPageView = new BufferDebugView(bufferDebugViewModel);
  295. AppData.Instance.MainWindow.LoadPage(houseDebugPageView);
  296. }
  297. /// <summary>
  298. /// 退出系统
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void Exit_MouseUp(object sender, MouseButtonEventArgs e)
  303. {
  304. if (!MiMa(this.Exit_PasswordBox))
  305. {
  306. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误");
  307. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  308. return;
  309. }
  310. App.Current.Shutdown();
  311. }
  312. /// <summary>
  313. /// 关于我们
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void About_MouseUp(object sender, MouseButtonEventArgs e)
  318. {
  319. AboutView houseDebugPageView = new AboutView();
  320. AppData.Instance.MainWindow.LoadPage(houseDebugPageView);
  321. }
  322. /// <summary>
  323. /// M5-02-4:统一配置(本地层配置界面化)。工程师口令保护,仿 HouseSetting_MouseUp。既有入口不变。
  324. /// </summary>
  325. private void UnifiedConfig_MouseUp(object sender, MouseButtonEventArgs e)
  326. {
  327. if (!MiMa(this.UnifiedConfig_PasswordBox))
  328. {
  329. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234"));
  330. return;
  331. }
  332. UnifiedConfigView unifiedConfigView = new UnifiedConfigView();
  333. AppData.Instance.MainWindow.LoadPage(unifiedConfigView);
  334. }
  335. /// <summary>
  336. /// M5-03-5:服务监控(只读)。仿 About_MouseUp(无口令、直接进入)。
  337. /// 监控页纯只读、无任何控制/写控件。[D8] 是否需口令/权限分级待确认。既有入口不变。
  338. /// </summary>
  339. private void ServiceMonitor_MouseUp(object sender, MouseButtonEventArgs e)
  340. {
  341. ServiceMonitorView serviceMonitorView = new ServiceMonitorView();
  342. AppData.Instance.MainWindow.LoadPage(serviceMonitorView);
  343. }
  344. private void _exitPass_PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
  345. {
  346. PasswordBox passwordBox = sender as PasswordBox;
  347. if (passwordBox == null) return;
  348. string ss = passwordBox.Password.Trim();
  349. if (string.IsNullOrEmpty(ss))
  350. {
  351. passwordBox.Background = (VisualBrush)this.FindResource("HelpBrush");
  352. }
  353. else
  354. {
  355. passwordBox.Background = new SolidColorBrush(Colors.White);
  356. }
  357. }
  358. private void Min_MouseUp(object sender, MouseButtonEventArgs e)
  359. {
  360. AppData.Instance.MainWindow.WindowState = WindowState.Minimized;
  361. }
  362. private bool IsClose()
  363. {
  364. Process[] processes = Process.GetProcessesByName("ivf_tl_ControlMain");
  365. if (processes.Length == 0) return true;
  366. return false;
  367. }
  368. private void CropNum_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  369. {
  370. if (this._cropNum_ComboBox.SelectedItem is string newValue)
  371. {
  372. int newValueInt;
  373. if (!int.TryParse(newValue, out newValueInt) && newValue == guanbi) newValueInt = -1;
  374. if (newValueInt != tLSettingCommon.cropNum)
  375. {
  376. int oldValue = tLSettingCommon.cropNum;
  377. tLSettingCommon.cropNum = newValueInt;
  378. if (!UpdataTlSetting())
  379. {
  380. tLSettingCommon.cropNum = oldValue;
  381. if (tLSettingCommon.cropNum == -1)
  382. {
  383. this._cropNum_ComboBox.SelectedItem = guanbi;
  384. }
  385. else
  386. {
  387. this._cropNum_ComboBox.SelectedItem = tLSettingCommon.cropNum.ToString();
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }