AuditTrailPage.xaml.cs 37 KB

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