AuditTrailPage.xaml.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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>("1s", 1),
  454. new KeyValuePair<string, int>("5s", 5),
  455. new KeyValuePair<string, int>("10s", 10),
  456. new KeyValuePair<string, int>("30s",30),
  457. new KeyValuePair<string, int>("1min", 60),
  458. new KeyValuePair<string, int>("5min", 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. List<string> ColSpan = new List<string>()
  519. {
  520. "BatchNunber",
  521. "MaterialCylinderVibrationTableSpeed",
  522. "FilterVibrationTableSpeed",
  523. "CountVibrationTableSpeed",
  524. "BottingCount",
  525. "BottingSpeed",
  526. "RecordTime"
  527. };
  528. batchRecord.GetRecordLogo(Properties.Resources.Logo);
  529. return batchRecord.BatchRecordToPDFReColspan(ShowtableMessage, ColSpan);
  530. }
  531. /// <summary>
  532. /// 生成配方PDF
  533. /// </summary>
  534. /// <returns></returns>
  535. private string GenerateFormulationPDF()
  536. {
  537. string BatchNumber = BatchNumComBox.SelectedItem.ToString();
  538. FormulationConfigClass formulationConfigClass = null;
  539. formulationConfigClass = XmlStorage.DeserializeFromXml<FormulationConfigClass>(FormulationfolderPath);
  540. formulationRecordClass.GetRecordLogo(Properties.Resources.Logo);
  541. //List<string> RowSpanNames = new List<string>()
  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. // "装瓶停机值",
  585. // "装瓶停机时间",
  586. // "送瓶轮运行速度",
  587. // "送瓶轮点动速度",
  588. // "送瓶轮回零偏移值",
  589. // "送瓶轮回零速度",
  590. // "送瓶轮位置长度",
  591. // "送瓶轮暂停时间",
  592. // "下料延时"
  593. //};
  594. return formulationRecordClass.FormulationRecordToPDF(formulationConfigClass);
  595. //return formulationRecordClass.FormulationRecordToPDFReRowspan(formulationConfigClass, RowSpanNames);
  596. }
  597. /// <summary>
  598. /// 加载PDF
  599. /// </summary>
  600. /// <param name="pdfFilePath"></param>
  601. private async void BatchLoadPdf(string pdfFilePath)
  602. {
  603. // 加载 PDF 文件
  604. await BatchRecordWebBrowser.EnsureCoreWebView2Async(null);
  605. BatchRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  606. }
  607. /// <summary>
  608. /// 加载PDF
  609. /// </summary>
  610. /// <param name="pdfFilePath"></param>
  611. private async void FormulationLoadPdf(string pdfFilePath)
  612. {
  613. // 加载 PDF 文件
  614. await FormulationRecordWebBrowser.EnsureCoreWebView2Async(null);
  615. FormulationRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  616. }
  617. /// <summary>
  618. /// 加载PDF
  619. /// </summary>
  620. /// <param name="pdfFilePath"></param>
  621. private async void ValueChangeLoadPdf(string pdfFilePath)
  622. {
  623. // 加载 PDF 文件
  624. await ValueChangeRecordWebBrowser.EnsureCoreWebView2Async(null);
  625. ValueChangeRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  626. }
  627. /// <summary>
  628. /// 加载PDF
  629. /// </summary>
  630. /// <param name="pdfFilePath"></param>
  631. private async void ErrorMessageLoadPdf(string pdfFilePath)
  632. {
  633. // 加载 PDF 文件
  634. await ErrorMessageRecordWebBrowser.EnsureCoreWebView2Async(null);
  635. ErrorMessageRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
  636. }
  637. /// <summary>
  638. /// 初始化值更改列表
  639. /// </summary>
  640. private void InitValueChangeItems()
  641. {
  642. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  643. if (!Directory.Exists(folderPath))
  644. {
  645. // 创建文件夹
  646. Directory.CreateDirectory(folderPath);
  647. }
  648. try
  649. {
  650. // 使用 DirectoryInfo 获取文件并按修改时间排序
  651. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  652. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  653. // 按照修改时间排序(最新的在前)
  654. var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
  655. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  656. foreach (FileInfo file in sortedFiles)
  657. {
  658. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  659. }
  660. ValueChangeDateComBox.SelectedIndex = 0;
  661. }
  662. catch
  663. { }
  664. }
  665. /// <summary>
  666. /// 初始化异常数据列表
  667. /// </summary>
  668. private void InitValueChangeItems(DateTime Mintime, DateTime MaxTime)
  669. {
  670. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  671. if (!Directory.Exists(folderPath))
  672. {
  673. // 创建文件夹
  674. Directory.CreateDirectory(folderPath);
  675. }
  676. try
  677. {
  678. // 使用 DirectoryInfo 获取文件并按修改时间排序
  679. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  680. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  681. // 按照修改时间排序(最新的在前)
  682. var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  683. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  684. foreach (FileInfo file in sortedFiles)
  685. {
  686. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  687. }
  688. ValueChangeDateComBox.SelectedIndex = 0;
  689. }
  690. catch
  691. { }
  692. }
  693. /// <summary>
  694. /// 初始化异常数据列表
  695. /// </summary>
  696. private void InitValueChangeItemsByMinTime(DateTime Mintime)
  697. {
  698. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  699. if (!Directory.Exists(folderPath))
  700. {
  701. // 创建文件夹
  702. Directory.CreateDirectory(folderPath);
  703. }
  704. try
  705. {
  706. // 使用 DirectoryInfo 获取文件并按修改时间排序
  707. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  708. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  709. // 按照修改时间排序(最新的在前)
  710. var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
  711. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  712. foreach (FileInfo file in sortedFiles)
  713. {
  714. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  715. }
  716. ValueChangeDateComBox.SelectedIndex = 0;
  717. }
  718. catch
  719. { }
  720. }
  721. /// <summary>
  722. /// 初始化异常数据列表
  723. /// </summary>
  724. private void InitValueChangeItemsByMaxTime(DateTime MaxTime)
  725. {
  726. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  727. if (!Directory.Exists(folderPath))
  728. {
  729. // 创建文件夹
  730. Directory.CreateDirectory(folderPath);
  731. }
  732. try
  733. {
  734. // 使用 DirectoryInfo 获取文件并按修改时间排序
  735. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  736. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  737. // 按照修改时间排序(最新的在前)
  738. var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  739. ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
  740. foreach (FileInfo file in sortedFiles)
  741. {
  742. ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  743. }
  744. ValueChangeDateComBox.SelectedIndex = 0;
  745. }
  746. catch
  747. { }
  748. }
  749. /// <summary>
  750. /// 生成值更改记录PDF
  751. /// </summary>
  752. /// <returns></returns>
  753. private string GenerateValueChangePDF()
  754. {
  755. string ValueChangeValue = ValueChangeDateComBox.SelectedItem.ToString();
  756. errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
  757. var ValueChangeMess = errorMesSqliteData.GetValueChangeMessage();
  758. List<string> ColSpan = new List<string>()
  759. {
  760. "信息类别",
  761. "信息类型",
  762. "错误信息",
  763. "记录时间",
  764. "操作员ID",
  765. };
  766. ValueChangeRecordClass.GetRecordLogo(Properties.Resources.Logo);
  767. return ValueChangeRecordClass.ValueChangeRecordToPDFReColspan(ValueChangeMess, ColSpan);
  768. //return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
  769. }
  770. /// <summary>
  771. /// 初始化异常数据列表
  772. /// </summary>
  773. private void InitErrorMessage()
  774. {
  775. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  776. if (!Directory.Exists(folderPath))
  777. {
  778. // 创建文件夹
  779. Directory.CreateDirectory(folderPath);
  780. }
  781. try
  782. {
  783. // 使用 DirectoryInfo 获取文件并按修改时间排序
  784. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  785. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  786. // 按照修改时间排序(最新的在前)
  787. var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
  788. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  789. foreach (FileInfo file in sortedFiles)
  790. {
  791. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  792. }
  793. ErrorMessageDateComBox.SelectedIndex = 0;
  794. }
  795. catch
  796. { }
  797. }
  798. /// <summary>
  799. /// 初始化异常数据列表
  800. /// </summary>
  801. private void InitErrorMessage(DateTime Mintime, DateTime MaxTime)
  802. {
  803. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  804. if (!Directory.Exists(folderPath))
  805. {
  806. // 创建文件夹
  807. Directory.CreateDirectory(folderPath);
  808. }
  809. try
  810. {
  811. // 使用 DirectoryInfo 获取文件并按修改时间排序
  812. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  813. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  814. // 按照修改时间排序(最新的在前)
  815. var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  816. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  817. foreach (FileInfo file in sortedFiles)
  818. {
  819. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  820. }
  821. ErrorMessageDateComBox.SelectedIndex = 0;
  822. }
  823. catch
  824. { }
  825. }
  826. /// <summary>
  827. /// 初始化异常数据列表
  828. /// </summary>
  829. private void InitErrorMessageByMinTime(DateTime Mintime)
  830. {
  831. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  832. if (!Directory.Exists(folderPath))
  833. {
  834. // 创建文件夹
  835. Directory.CreateDirectory(folderPath);
  836. }
  837. try
  838. {
  839. // 使用 DirectoryInfo 获取文件并按修改时间排序
  840. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  841. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  842. // 按照修改时间排序(最新的在前)
  843. var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
  844. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  845. foreach (FileInfo file in sortedFiles)
  846. {
  847. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  848. }
  849. ErrorMessageDateComBox.SelectedIndex = 0;
  850. }
  851. catch
  852. { }
  853. }
  854. /// <summary>
  855. /// 初始化异常数据列表
  856. /// </summary>
  857. private void InitErrorMessageByMaxTime(DateTime MaxTime)
  858. {
  859. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
  860. if (!Directory.Exists(folderPath))
  861. {
  862. // 创建文件夹
  863. Directory.CreateDirectory(folderPath);
  864. }
  865. try
  866. {
  867. // 使用 DirectoryInfo 获取文件并按修改时间排序
  868. DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
  869. FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
  870. // 按照修改时间排序(最新的在前)
  871. var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
  872. ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
  873. foreach (FileInfo file in sortedFiles)
  874. {
  875. ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
  876. }
  877. ErrorMessageDateComBox.SelectedIndex = 0;
  878. }
  879. catch
  880. { }
  881. }
  882. /// <summary>
  883. /// 生成值更改记录PDF
  884. /// </summary>
  885. /// <returns></returns>
  886. private string GenerateErrorMessagePDF()
  887. {
  888. string ValueChangeValue = ErrorMessageDateComBox.SelectedItem.ToString();
  889. errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
  890. var ValueChangeMess = errorMesSqliteData.GetErrorMessage();
  891. List<string> ColSpan = new List<string>()
  892. {
  893. "信息类别",
  894. "信息类型",
  895. "错误信息",
  896. "信息路径",
  897. "记录时间",
  898. "操作员ID",
  899. };
  900. errorMessageRecordClass.GetRecordLogo(Properties.Resources.Logo);
  901. return errorMessageRecordClass.ErrorMessageRecordToPDFReColspan(ValueChangeMess, ColSpan);
  902. //return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
  903. }
  904. #endregion
  905. private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
  906. {
  907. BatchMinTime.SelectedDate = DateTime.Today;
  908. BatchMaxTime.SelectedDate = DateTime.Today;
  909. ValueChangeRecordMinTime.SelectedDate = DateTime.Today;
  910. ValueChangeRecordMaxTime.SelectedDate = DateTime.Today;
  911. ErrorMessageRecordMinTime.SelectedDate = DateTime.Today;
  912. ErrorMessageRecordMaxTime.SelectedDate = DateTime.Today;
  913. }
  914. }
  915. }