AuditTrailPage.xaml.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. using CCDCount.DLL.AuditTrail;
  2. using CCDCount.DLL.SqlDataClass;
  3. using CCDCount.DLL.Tools;
  4. using CCDCount.MODEL.AuditTrailModel;
  5. using CCDCount.MODEL.ConfigModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using System.Windows.Controls;
  12. namespace CCDCountWpf.WpfPage
  13. {
  14. /// <summary>
  15. /// AuditTrailPage.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class AuditTrailPage : Page
  18. {
  19. #region 实例
  20. /// <summary>
  21. /// 批次信息数据类
  22. /// </summary>
  23. BatchMessSqliteDataClass batchMessSqliteData = null;
  24. ErrorMesSqliteDataClass errorMesSqliteData = null;
  25. // <summary>
  26. /// 批次记录类(数据转PDF)
  27. /// </summary>
  28. BatchRecordClass batchRecord = new BatchRecordClass();
  29. FormulationRecordClass formulationRecordClass = new FormulationRecordClass();
  30. ValueChangeRecordClass ValueChangeRecordClass = new ValueChangeRecordClass();
  31. ErrorMessageRecordClass errorMessageRecordClass = new ErrorMessageRecordClass();
  32. #endregion
  33. #region 变量
  34. /// <summary>
  35. /// 时间间隔
  36. /// </summary>
  37. int TimeInterval = 0;
  38. string FormulationfolderPath = "";
  39. #endregion
  40. #region 窗口事件
  41. /// <summary>
  42. /// 构建方法
  43. /// </summary>
  44. public AuditTrailPage()
  45. {
  46. InitializeComponent();
  47. this.Height = Double.NaN;
  48. this.Width = Double.NaN;
  49. DataContext = ShowMessageBus.ShowBinding;
  50. InitBatchItems();
  51. InitTimeIntervalComBox();
  52. InitFormationItems();
  53. InitValueChangeItems();
  54. InitErrorMessage();
  55. }
  56. /// <summary>
  57. /// 批号时间筛选选择时间-最小时间
  58. /// </summary>
  59. /// <param name="sender"></param>
  60. /// <param name="e"></param>
  61. private void BatchMinTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  62. {
  63. if (BatchMinTime.SelectedDate == null)
  64. {
  65. return;
  66. }
  67. else
  68. {
  69. if (BatchMaxTime.SelectedDate == null)
  70. {
  71. InitBatchItemsByMinTime((DateTime)BatchMinTime.SelectedDate);
  72. }
  73. else
  74. {
  75. InitBatchItems((DateTime)BatchMinTime.SelectedDate, (DateTime)BatchMaxTime.SelectedDate);
  76. }
  77. }
  78. }
  79. /// <summary>
  80. /// 批号时间筛选选择时间-最大时间
  81. /// </summary>
  82. /// <param name="sender"></param>
  83. /// <param name="e"></param>
  84. private void BatchMaxTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  85. {
  86. if (BatchMaxTime.SelectedDate == null)
  87. {
  88. return;
  89. }
  90. else
  91. {
  92. if (BatchMinTime.SelectedDate == null)
  93. {
  94. InitBatchItemsByMaxTime((DateTime)BatchMaxTime.SelectedDate);
  95. }
  96. else
  97. {
  98. InitBatchItems((DateTime)BatchMinTime.SelectedDate, (DateTime)BatchMaxTime.SelectedDate);
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 批号选择事件
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void BatchNumComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  108. {
  109. if (BatchNumComBox.SelectedItem == null || BatchNumComBox.SelectedItem.ToString() == "")
  110. {
  111. return;
  112. }
  113. if (TimeInterval == 0) return;
  114. string LoadPath = GenerateBatchPDF();
  115. BatchLoadPdf(LoadPath);
  116. }
  117. /// <summary>
  118. /// 时间间隔选择事件
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void TimeIntervalComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  123. {
  124. if (TimeIntervalComBox.SelectedItem != null)
  125. {
  126. // 获取显示的文本
  127. var selectedText = TimeIntervalComBox.Text;
  128. // 获取选中的值
  129. var selectedValue = Convert.ToInt32(TimeIntervalComBox.SelectedValue?.ToString());
  130. TimeInterval = selectedValue;
  131. if (BatchNumComBox.SelectedItem == null || BatchNumComBox.SelectedItem.ToString() == "")
  132. {
  133. return;
  134. }
  135. if (TimeInterval == 0) return;
  136. string LoadPath = GenerateBatchPDF();
  137. BatchLoadPdf(LoadPath);
  138. }
  139. }
  140. /// <summary>
  141. /// 批号记录按钮点击事件
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void BatchRecordBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  146. {
  147. BatchRecordGrid.Visibility = System.Windows.Visibility.Visible;
  148. FormulationRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  149. ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  150. ErrorRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  151. }
  152. /// <summary>
  153. /// 配方记录按钮点击事件
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. private void FormulationRecordBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  158. {
  159. BatchRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  160. FormulationRecordGrid.Visibility = System.Windows.Visibility.Visible;
  161. ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  162. ErrorRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  163. }
  164. /// <summary>
  165. /// 值改变记录按钮点击事件
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void ValueChangeRecordBtd_Click(object sender, System.Windows.RoutedEventArgs e)
  170. {
  171. BatchRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  172. FormulationRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  173. ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Visible;
  174. ErrorRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  175. }
  176. /// <summary>
  177. /// 错误记录按钮点击事件
  178. /// </summary>
  179. private void ErrorRecordBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  180. {
  181. BatchRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  182. FormulationRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  183. ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
  184. ErrorRecordGrid.Visibility = System.Windows.Visibility.Visible;
  185. }
  186. /// <summary>
  187. /// 配方选择事件
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. private void FormulationRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  192. {
  193. if (FormulationRecordComBox.SelectedItem == null || FormulationRecordComBox.SelectedItem.ToString() == "")
  194. {
  195. return;
  196. }
  197. FormulationfolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations\\{FormulationRecordComBox.SelectedItem.ToString()}.xml";
  198. string pdfFilePath = GenerateFormulationPDF();
  199. FormulationLoadPdf(pdfFilePath);
  200. }
  201. /// <summary>
  202. /// 值改变记录最小时间选择框选择事件
  203. /// </summary>
  204. private void ValueChangeRecordMinTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  205. {
  206. if (ValueChangeRecordMinTime.SelectedDate == null)
  207. {
  208. return;
  209. }
  210. else
  211. {
  212. if (ValueChangeRecordMaxTime.SelectedDate == null)
  213. {
  214. InitValueChangeItemsByMinTime((DateTime)ValueChangeRecordMinTime.SelectedDate);
  215. }
  216. else
  217. {
  218. InitValueChangeItems((DateTime)ValueChangeRecordMinTime.SelectedDate, (DateTime)ValueChangeRecordMaxTime.SelectedDate);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 值改变记录最大时间选择框选择事件
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. private void ValueChangeRecordMaxTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  228. {
  229. if (ValueChangeRecordMaxTime.SelectedDate == null)
  230. {
  231. return;
  232. }
  233. else
  234. {
  235. if (ValueChangeRecordMinTime.SelectedDate == null)
  236. {
  237. InitValueChangeItemsByMaxTime((DateTime)ValueChangeRecordMaxTime.SelectedDate);
  238. }
  239. else
  240. {
  241. InitValueChangeItems((DateTime)ValueChangeRecordMinTime.SelectedDate, (DateTime)ValueChangeRecordMaxTime.SelectedDate);
  242. }
  243. }
  244. }
  245. /// <summary>
  246. /// 值改变记录选择框选择事件
  247. /// </summary>
  248. /// <param name="sender"></param>
  249. /// <param name="e"></param>
  250. private void ValueChangeRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  251. {
  252. if (ValueChangeDateComBox.SelectedItem == null || ValueChangeDateComBox.SelectedItem.ToString() == "")
  253. {
  254. return;
  255. }
  256. string LoadPath = GenerateValueChangePDF();
  257. ValueChangeLoadPdf(LoadPath);
  258. }
  259. /// <summary>
  260. /// 异常信息选择事件
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void ErrorMessageRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  265. {
  266. if (ErrorMessageDateComBox.SelectedItem == null || ErrorMessageDateComBox.SelectedItem.ToString() == "")
  267. {
  268. return;
  269. }
  270. string LoadPath = GenerateErrorMessagePDF();
  271. ErrorMessageLoadPdf(LoadPath);
  272. }
  273. /// <summary>
  274. /// 异常信息时间选择事件-最小时间
  275. /// </summary>
  276. /// <param name="sender"></param>
  277. /// <param name="e"></param>
  278. private void ErrorMessageRecordMinTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  279. {
  280. if (ErrorMessageRecordMinTime.SelectedDate == null)
  281. {
  282. return;
  283. }
  284. else
  285. {
  286. if (ErrorMessageRecordMaxTime.SelectedDate == null)
  287. {
  288. InitErrorMessageByMinTime((DateTime)ErrorMessageRecordMinTime.SelectedDate);
  289. }
  290. else
  291. {
  292. InitErrorMessage((DateTime)ErrorMessageRecordMinTime.SelectedDate, (DateTime)ErrorMessageRecordMaxTime.SelectedDate);
  293. }
  294. }
  295. }
  296. /// <summary>
  297. /// 异常信息时间选择事件-最大时间
  298. /// </summary>
  299. /// <param name="sender"></param>
  300. /// <param name="e"></param>
  301. private void ErrorMessageRecordMaxTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  302. {
  303. if (ErrorMessageRecordMaxTime.SelectedDate == null)
  304. {
  305. return;
  306. }
  307. else
  308. {
  309. if (ErrorMessageRecordMinTime.SelectedDate == null)
  310. {
  311. InitErrorMessageByMaxTime((DateTime)ErrorMessageRecordMaxTime.SelectedDate);
  312. }
  313. else
  314. {
  315. InitErrorMessage((DateTime)ErrorMessageRecordMinTime.SelectedDate, (DateTime)ErrorMessageRecordMaxTime.SelectedDate);
  316. }
  317. }
  318. }
  319. #endregion
  320. #region 私有方法
  321. /// <summary>
  322. /// 初始化批次列表
  323. /// </summary>
  324. private void InitBatchItems()
  325. {
  326. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
  327. if (!Directory.Exists(folderPath))
  328. {
  329. // 创建文件夹
  330. Directory.CreateDirectory(folderPath);
  331. }
  332. try
  333. {
  334. // 使用 DirectoryInfo 获取文件并按修改时间排序
  335. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  336. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  337. // 按照修改时间排序(最新的在前)
  338. var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
  339. ShowMessageBus.ShowBinding.BatchItems.Clear();
  340. foreach (FileInfo file in sortedFiles)
  341. {
  342. ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  343. }
  344. BatchNumComBox.SelectedIndex = 0;
  345. }
  346. catch
  347. { }
  348. }
  349. /// <summary>
  350. /// 初始化批号列表
  351. /// </summary>
  352. private void InitBatchItems(DateTime Mintime, DateTime MaxTime)
  353. {
  354. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
  355. if (!Directory.Exists(folderPath))
  356. {
  357. // 创建文件夹
  358. Directory.CreateDirectory(folderPath);
  359. }
  360. try
  361. {
  362. // 使用 DirectoryInfo 获取文件并按修改时间排序
  363. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  364. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  365. // 按照修改时间排序(最新的在前)
  366. var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  367. ShowMessageBus.ShowBinding.BatchItems.Clear();
  368. foreach (FileInfo file in sortedFiles)
  369. {
  370. ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  371. }
  372. BatchNumComBox.SelectedIndex = 0;
  373. }
  374. catch
  375. { }
  376. }
  377. /// <summary>
  378. /// 初始化批号列表
  379. /// </summary>
  380. private void InitBatchItemsByMinTime(DateTime Mintime)
  381. {
  382. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
  383. if (!Directory.Exists(folderPath))
  384. {
  385. // 创建文件夹
  386. Directory.CreateDirectory(folderPath);
  387. }
  388. try
  389. {
  390. // 使用 DirectoryInfo 获取文件并按修改时间排序
  391. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  392. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  393. // 按照修改时间排序(最新的在前)
  394. var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
  395. ShowMessageBus.ShowBinding.BatchItems.Clear();
  396. foreach (FileInfo file in sortedFiles)
  397. {
  398. ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  399. }
  400. BatchNumComBox.SelectedIndex = 0;
  401. }
  402. catch
  403. { }
  404. }
  405. /// <summary>
  406. /// 初始化批号列表
  407. /// </summary>
  408. private void InitBatchItemsByMaxTime(DateTime MaxTime)
  409. {
  410. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
  411. if (!Directory.Exists(folderPath))
  412. {
  413. // 创建文件夹
  414. Directory.CreateDirectory(folderPath);
  415. }
  416. try
  417. {
  418. // 使用 DirectoryInfo 获取文件并按修改时间排序
  419. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  420. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  421. // 按照修改时间排序(最新的在前)
  422. var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  423. ShowMessageBus.ShowBinding.BatchItems.Clear();
  424. foreach (FileInfo file in sortedFiles)
  425. {
  426. ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  427. }
  428. BatchNumComBox.SelectedIndex = 0;
  429. }
  430. catch
  431. { }
  432. }
  433. /// <summary>
  434. /// 初始化时间间隔下拉框
  435. /// </summary>
  436. private void InitTimeIntervalComBox()
  437. {
  438. // 数据源
  439. var items = new List<KeyValuePair<string, int>>
  440. {
  441. new KeyValuePair<string, int>("1秒", 1),
  442. new KeyValuePair<string, int>("5秒", 5),
  443. new KeyValuePair<string, int>("10秒", 10),
  444. new KeyValuePair<string, int>("30秒",30),
  445. new KeyValuePair<string, int>("1分", 60),
  446. new KeyValuePair<string, int>("5分", 300),
  447. };
  448. TimeIntervalComBox.ItemsSource = items;
  449. TimeIntervalComBox.DisplayMemberPath = "Key";
  450. TimeIntervalComBox.SelectedValuePath = "Value";
  451. TimeIntervalComBox.SelectedIndex = 0;
  452. }
  453. /// <summary>
  454. /// 初始化配方列表
  455. /// </summary>
  456. private void InitFormationItems()
  457. {
  458. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations";
  459. if (!Directory.Exists(folderPath))
  460. {
  461. // 创建文件夹
  462. Directory.CreateDirectory(folderPath);
  463. }
  464. try
  465. {
  466. // 获取文件列表(包含子目录)
  467. string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
  468. ShowMessageBus.ShowBinding.FormulationItems.Clear();
  469. foreach (string file in files)
  470. {
  471. ShowMessageBus.ShowBinding.FormulationItems.Add(Path.GetFileNameWithoutExtension(file));
  472. }
  473. if (ShowMessageBus.ShowBinding.FormulationName != null && ShowMessageBus.ShowBinding.FormulationName != string.Empty)
  474. {
  475. try
  476. {
  477. FormulationRecordComBox.SelectedItem = ShowMessageBus.ShowBinding.FormulationName;
  478. }
  479. catch { }
  480. }
  481. }
  482. catch
  483. { }
  484. }
  485. /// <summary>
  486. /// 生成批记录PDF
  487. /// </summary>
  488. /// <returns></returns>
  489. private string GenerateBatchPDF()
  490. {
  491. string BatchNumber = BatchNumComBox.SelectedItem.ToString();
  492. //string LoadPath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\BatchData.PDF";
  493. batchMessSqliteData = new BatchMessSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData\\BatchData_{BatchNumber}.db");
  494. var batchMess = batchMessSqliteData.GetAllBatchMessage();
  495. var ShowtableMessage = batchMess.Where((item, index) => index % TimeInterval == 0).ToList();
  496. List<string> ColSpan = new List<string>()
  497. {
  498. "批次号",
  499. "料筒震盘速度",
  500. "过滤震台速度",
  501. "计数震台速度",
  502. "装瓶数量",
  503. "装瓶速度",
  504. "记录时间"
  505. };
  506. batchRecord.GetRecordLogo(Properties.Resources.Logo);
  507. return batchRecord.BatchRecordToPDFReColspan(ShowtableMessage, ColSpan);
  508. }
  509. /// <summary>
  510. /// 生成配方PDF
  511. /// </summary>
  512. /// <returns></returns>
  513. private string GenerateFormulationPDF()
  514. {
  515. string BatchNumber = BatchNumComBox.SelectedItem.ToString();
  516. FormulationConfigClass formulationConfigClass = null;
  517. formulationConfigClass = XmlStorage.DeserializeFromXml<FormulationConfigClass>(FormulationfolderPath);
  518. formulationRecordClass.GetRecordLogo(Properties.Resources.Logo);
  519. List<string> RowSpanNames = new List<string>()
  520. {
  521. "配方名称",
  522. "二值化阈值",
  523. "允许物体中断的最大连续行数",
  524. "合格物体的最长长度",
  525. "合格物体的最短长度",
  526. "判定标准识别码",
  527. "合格物体的最大面积",
  528. "合格物体的最小面积",
  529. "噪声过滤阈值",
  530. "通道数量",
  531. "曝光时间",
  532. "采集行频",
  533. "设备名称",
  534. "速度模式运行速度",
  535. "点动速度",
  536. "瓶装设定值",
  537. "中转阀打开速度",
  538. "中转阀打开时间",
  539. "罐装减速值",
  540. "缓存减速值",
  541. "缓存计数延迟时间",
  542. "缓存停机值",
  543. "罐装料筒震台高速值",
  544. "罐装过滤震台高速值",
  545. "罐装计数震台高速值",
  546. "罐装料筒震台减速值",
  547. "罐装过滤震台减速值",
  548. "罐装计数震台减速值",
  549. "缓存料筒震台高速值",
  550. "缓存过滤震台高速值",
  551. "缓存计数震台高速值",
  552. "缓存料筒震台减速值",
  553. "缓存过滤震台减速值",
  554. "缓存计数震台减速值",
  555. "阀门打开延迟",
  556. "回零偏移值",
  557. "回零偏移速度",
  558. "中转阀关闭速度",
  559. "中转阀打开位置",
  560. "中转阀关闭位置",
  561. "气阀打开延迟",
  562. "装瓶停机值",
  563. "装瓶停机时间",
  564. "送瓶轮运行速度",
  565. "送瓶轮点动速度",
  566. "送瓶轮回零偏移值",
  567. "送瓶轮回零速度",
  568. "送瓶轮位置长度",
  569. "送瓶轮暂停时间",
  570. "下料延时"
  571. };
  572. return formulationRecordClass.FormulationRecordToPDFReRowspan(formulationConfigClass, RowSpanNames);
  573. }
  574. /// <summary>
  575. /// 加载PDF
  576. /// </summary>
  577. /// <param name="pdfFilePath"></param>
  578. private async void BatchLoadPdf(string pdfFilePath)
  579. {
  580. // 加载 PDF 文件
  581. await BatchRecordWebBrowser.EnsureCoreWebView2Async(null);
  582. BatchRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  583. }
  584. /// <summary>
  585. /// 加载PDF
  586. /// </summary>
  587. /// <param name="pdfFilePath"></param>
  588. private async void FormulationLoadPdf(string pdfFilePath)
  589. {
  590. // 加载 PDF 文件
  591. await FormulationRecordWebBrowser.EnsureCoreWebView2Async(null);
  592. FormulationRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  593. }
  594. /// <summary>
  595. /// 加载PDF
  596. /// </summary>
  597. /// <param name="pdfFilePath"></param>
  598. private async void ValueChangeLoadPdf(string pdfFilePath)
  599. {
  600. // 加载 PDF 文件
  601. await ValueChangeRecordWebBrowser.EnsureCoreWebView2Async(null);
  602. ValueChangeRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  603. }
  604. /// <summary>
  605. /// 加载PDF
  606. /// </summary>
  607. /// <param name="pdfFilePath"></param>
  608. private async void ErrorMessageLoadPdf(string pdfFilePath)
  609. {
  610. // 加载 PDF 文件
  611. await ErrorMessageRecordWebBrowser.EnsureCoreWebView2Async(null);
  612. ErrorMessageRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  613. }
  614. /// <summary>
  615. /// 初始化异常数据列表
  616. /// </summary>
  617. private void InitValueChangeItems()
  618. {
  619. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  620. if (!Directory.Exists(folderPath))
  621. {
  622. // 创建文件夹
  623. Directory.CreateDirectory(folderPath);
  624. }
  625. try
  626. {
  627. // 使用 DirectoryInfo 获取文件并按修改时间排序
  628. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  629. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  630. // 按照修改时间排序(最新的在前)
  631. var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
  632. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  633. foreach (FileInfo file in sortedFiles)
  634. {
  635. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  636. }
  637. ValueChangeDateComBox.SelectedIndex = 0;
  638. }
  639. catch
  640. { }
  641. }
  642. /// <summary>
  643. /// 初始化异常数据列表
  644. /// </summary>
  645. private void InitValueChangeItems(DateTime Mintime, DateTime MaxTime)
  646. {
  647. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  648. if (!Directory.Exists(folderPath))
  649. {
  650. // 创建文件夹
  651. Directory.CreateDirectory(folderPath);
  652. }
  653. try
  654. {
  655. // 使用 DirectoryInfo 获取文件并按修改时间排序
  656. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  657. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  658. // 按照修改时间排序(最新的在前)
  659. var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  660. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  661. foreach (FileInfo file in sortedFiles)
  662. {
  663. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  664. }
  665. ValueChangeDateComBox.SelectedIndex = 0;
  666. }
  667. catch
  668. { }
  669. }
  670. /// <summary>
  671. /// 初始化异常数据列表
  672. /// </summary>
  673. private void InitValueChangeItemsByMinTime(DateTime Mintime)
  674. {
  675. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  676. if (!Directory.Exists(folderPath))
  677. {
  678. // 创建文件夹
  679. Directory.CreateDirectory(folderPath);
  680. }
  681. try
  682. {
  683. // 使用 DirectoryInfo 获取文件并按修改时间排序
  684. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  685. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  686. // 按照修改时间排序(最新的在前)
  687. var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
  688. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  689. foreach (FileInfo file in sortedFiles)
  690. {
  691. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  692. }
  693. ValueChangeDateComBox.SelectedIndex = 0;
  694. }
  695. catch
  696. { }
  697. }
  698. /// <summary>
  699. /// 初始化异常数据列表
  700. /// </summary>
  701. private void InitValueChangeItemsByMaxTime(DateTime MaxTime)
  702. {
  703. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  704. if (!Directory.Exists(folderPath))
  705. {
  706. // 创建文件夹
  707. Directory.CreateDirectory(folderPath);
  708. }
  709. try
  710. {
  711. // 使用 DirectoryInfo 获取文件并按修改时间排序
  712. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  713. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  714. // 按照修改时间排序(最新的在前)
  715. var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  716. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  717. foreach (FileInfo file in sortedFiles)
  718. {
  719. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  720. }
  721. ValueChangeDateComBox.SelectedIndex = 0;
  722. }
  723. catch
  724. { }
  725. }
  726. /// <summary>
  727. /// 生成值更改记录PDF
  728. /// </summary>
  729. /// <returns></returns>
  730. private string GenerateValueChangePDF()
  731. {
  732. string ValueChangeValue = ValueChangeDateComBox.SelectedItem.ToString();
  733. errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
  734. var ValueChangeMess = errorMesSqliteData.GetValueChangeMessage();
  735. List<string> ColSpan = new List<string>()
  736. {
  737. "信息类别",
  738. "信息类型",
  739. "错误信息",
  740. "记录时间",
  741. "操作员ID",
  742. };
  743. ValueChangeRecordClass.GetRecordLogo(Properties.Resources.Logo);
  744. return ValueChangeRecordClass.ValueChangeRecordToPDFReColspan(ValueChangeMess, ColSpan);
  745. //return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
  746. }
  747. /// <summary>
  748. /// 初始化异常数据列表
  749. /// </summary>
  750. private void InitErrorMessage()
  751. {
  752. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  753. if (!Directory.Exists(folderPath))
  754. {
  755. // 创建文件夹
  756. Directory.CreateDirectory(folderPath);
  757. }
  758. try
  759. {
  760. // 使用 DirectoryInfo 获取文件并按修改时间排序
  761. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  762. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  763. // 按照修改时间排序(最新的在前)
  764. var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
  765. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  766. foreach (FileInfo file in sortedFiles)
  767. {
  768. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  769. }
  770. ErrorMessageDateComBox.SelectedIndex = 0;
  771. }
  772. catch
  773. { }
  774. }
  775. /// <summary>
  776. /// 初始化异常数据列表
  777. /// </summary>
  778. private void InitErrorMessage(DateTime Mintime, DateTime MaxTime)
  779. {
  780. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  781. if (!Directory.Exists(folderPath))
  782. {
  783. // 创建文件夹
  784. Directory.CreateDirectory(folderPath);
  785. }
  786. try
  787. {
  788. // 使用 DirectoryInfo 获取文件并按修改时间排序
  789. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  790. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  791. // 按照修改时间排序(最新的在前)
  792. var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  793. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  794. foreach (FileInfo file in sortedFiles)
  795. {
  796. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  797. }
  798. ErrorMessageDateComBox.SelectedIndex = 0;
  799. }
  800. catch
  801. { }
  802. }
  803. /// <summary>
  804. /// 初始化异常数据列表
  805. /// </summary>
  806. private void InitErrorMessageByMinTime(DateTime Mintime)
  807. {
  808. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  809. if (!Directory.Exists(folderPath))
  810. {
  811. // 创建文件夹
  812. Directory.CreateDirectory(folderPath);
  813. }
  814. try
  815. {
  816. // 使用 DirectoryInfo 获取文件并按修改时间排序
  817. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  818. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  819. // 按照修改时间排序(最新的在前)
  820. var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
  821. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  822. foreach (FileInfo file in sortedFiles)
  823. {
  824. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  825. }
  826. ErrorMessageDateComBox.SelectedIndex = 0;
  827. }
  828. catch
  829. { }
  830. }
  831. /// <summary>
  832. /// 初始化异常数据列表
  833. /// </summary>
  834. private void InitErrorMessageByMaxTime(DateTime MaxTime)
  835. {
  836. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  837. if (!Directory.Exists(folderPath))
  838. {
  839. // 创建文件夹
  840. Directory.CreateDirectory(folderPath);
  841. }
  842. try
  843. {
  844. // 使用 DirectoryInfo 获取文件并按修改时间排序
  845. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  846. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  847. // 按照修改时间排序(最新的在前)
  848. var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  849. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  850. foreach (FileInfo file in sortedFiles)
  851. {
  852. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  853. }
  854. ErrorMessageDateComBox.SelectedIndex = 0;
  855. }
  856. catch
  857. { }
  858. }
  859. /// <summary>
  860. /// 生成值更改记录PDF
  861. /// </summary>
  862. /// <returns></returns>
  863. private string GenerateErrorMessagePDF()
  864. {
  865. string ValueChangeValue = ErrorMessageDateComBox.SelectedItem.ToString();
  866. errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
  867. var ValueChangeMess = errorMesSqliteData.GetErrorMessage();
  868. List<string> ColSpan = new List<string>()
  869. {
  870. "信息类别",
  871. "信息类型",
  872. "错误信息",
  873. "信息路径",
  874. "记录时间",
  875. "操作员ID",
  876. };
  877. errorMessageRecordClass.GetRecordLogo(Properties.Resources.Logo);
  878. return errorMessageRecordClass.ErrorMessageRecordToPDFReColspan(ValueChangeMess, ColSpan);
  879. //return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
  880. }
  881. #endregion
  882. }
  883. }