| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943 |
- using CCDCount.DLL.AuditTrail;
- using CCDCount.DLL.SqlDataClass;
- using CCDCount.DLL.Tools;
- using CCDCount.MODEL.AuditTrailModel;
- using CCDCount.MODEL.ConfigModel;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- namespace CCDCountWpf.WpfPage
- {
- /// <summary>
- /// AuditTrailPage.xaml 的交互逻辑
- /// </summary>
- public partial class AuditTrailPage : Page
- {
- #region 实例
- /// <summary>
- /// 批次信息数据类
- /// </summary>
- BatchMessSqliteDataClass batchMessSqliteData = null;
- ErrorMesSqliteDataClass errorMesSqliteData = null;
- // <summary>
- /// 批次记录类(数据转PDF)
- /// </summary>
- BatchRecordClass batchRecord = new BatchRecordClass();
- FormulationRecordClass formulationRecordClass = new FormulationRecordClass();
- ValueChangeRecordClass ValueChangeRecordClass = new ValueChangeRecordClass();
- ErrorMessageRecordClass errorMessageRecordClass = new ErrorMessageRecordClass();
- #endregion
- #region 变量
- /// <summary>
- /// 时间间隔
- /// </summary>
- int TimeInterval = 0;
- string FormulationfolderPath = "";
- #endregion
- #region 窗口事件
- /// <summary>
- /// 构建方法
- /// </summary>
- public AuditTrailPage()
- {
- InitializeComponent();
- this.Height = Double.NaN;
- this.Width = Double.NaN;
- DataContext = ShowMessageBus.ShowBinding;
- InitBatchItems();
- InitTimeIntervalComBox();
- InitFormationItems();
- InitValueChangeItems();
- InitErrorMessage();
- }
- /// <summary>
- /// 批号时间筛选选择时间-最小时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BatchMinTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (BatchMinTime.SelectedDate == null)
- {
- return;
- }
- else
- {
- if (BatchMaxTime.SelectedDate == null)
- {
- InitBatchItemsByMinTime((DateTime)BatchMinTime.SelectedDate);
- }
- else
- {
- InitBatchItems((DateTime)BatchMinTime.SelectedDate, (DateTime)BatchMaxTime.SelectedDate);
- }
- }
- }
- /// <summary>
- /// 批号时间筛选选择时间-最大时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BatchMaxTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (BatchMaxTime.SelectedDate == null)
- {
- return;
- }
- else
- {
- if (BatchMinTime.SelectedDate == null)
- {
- InitBatchItemsByMaxTime((DateTime)BatchMaxTime.SelectedDate);
- }
- else
- {
- InitBatchItems((DateTime)BatchMinTime.SelectedDate, (DateTime)BatchMaxTime.SelectedDate);
- }
- }
- }
- /// <summary>
- /// 批号选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BatchNumComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (BatchNumComBox.SelectedItem == null || BatchNumComBox.SelectedItem.ToString() == "")
- {
- return;
- }
- if (TimeInterval == 0) return;
- string LoadPath = GenerateBatchPDF();
- BatchLoadPdf(LoadPath);
- }
- /// <summary>
- /// 时间间隔选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TimeIntervalComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (TimeIntervalComBox.SelectedItem != null)
- {
- // 获取显示的文本
- var selectedText = TimeIntervalComBox.Text;
- // 获取选中的值
- var selectedValue = Convert.ToInt32(TimeIntervalComBox.SelectedValue?.ToString());
- TimeInterval = selectedValue;
- if (BatchNumComBox.SelectedItem == null || BatchNumComBox.SelectedItem.ToString() == "")
- {
- return;
- }
- if (TimeInterval == 0) return;
- string LoadPath = GenerateBatchPDF();
- BatchLoadPdf(LoadPath);
- }
- }
- /// <summary>
- /// 批号记录按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BatchRecordBtn_Click(object sender, System.Windows.RoutedEventArgs e)
- {
- BatchRecordGrid.Visibility = System.Windows.Visibility.Visible;
- FormulationRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- ErrorRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- }
- /// <summary>
- /// 配方记录按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FormulationRecordBtn_Click(object sender, System.Windows.RoutedEventArgs e)
- {
- BatchRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- FormulationRecordGrid.Visibility = System.Windows.Visibility.Visible;
- ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- ErrorRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- }
- /// <summary>
- /// 值改变记录按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ValueChangeRecordBtd_Click(object sender, System.Windows.RoutedEventArgs e)
- {
- BatchRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- FormulationRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Visible;
- ErrorRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- }
- /// <summary>
- /// 错误记录按钮点击事件
- /// </summary>
- private void ErrorRecordBtn_Click(object sender, System.Windows.RoutedEventArgs e)
- {
- BatchRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- FormulationRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- ValueChangeRecordGrid.Visibility = System.Windows.Visibility.Collapsed;
- ErrorRecordGrid.Visibility = System.Windows.Visibility.Visible;
- }
- /// <summary>
- /// 配方选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FormulationRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (FormulationRecordComBox.SelectedItem == null || FormulationRecordComBox.SelectedItem.ToString() == "")
- {
- return;
- }
- FormulationfolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations\\{FormulationRecordComBox.SelectedItem.ToString()}.xml";
- string pdfFilePath = GenerateFormulationPDF();
- FormulationLoadPdf(pdfFilePath);
- }
- /// <summary>
- /// 值改变记录最小时间选择框选择事件
- /// </summary>
- private void ValueChangeRecordMinTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ValueChangeRecordMinTime.SelectedDate == null)
- {
- return;
- }
- else
- {
- if (ValueChangeRecordMaxTime.SelectedDate == null)
- {
- InitValueChangeItemsByMinTime((DateTime)ValueChangeRecordMinTime.SelectedDate);
- }
- else
- {
- InitValueChangeItems((DateTime)ValueChangeRecordMinTime.SelectedDate, (DateTime)ValueChangeRecordMaxTime.SelectedDate);
- }
- }
- }
- /// <summary>
- /// 值改变记录最大时间选择框选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ValueChangeRecordMaxTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ValueChangeRecordMaxTime.SelectedDate == null)
- {
- return;
- }
- else
- {
- if (ValueChangeRecordMinTime.SelectedDate == null)
- {
- InitValueChangeItemsByMaxTime((DateTime)ValueChangeRecordMaxTime.SelectedDate);
- }
- else
- {
- InitValueChangeItems((DateTime)ValueChangeRecordMinTime.SelectedDate, (DateTime)ValueChangeRecordMaxTime.SelectedDate);
- }
- }
- }
- /// <summary>
- /// 值改变记录选择框选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ValueChangeRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ValueChangeDateComBox.SelectedItem == null || ValueChangeDateComBox.SelectedItem.ToString() == "")
- {
- return;
- }
- string LoadPath = GenerateValueChangePDF();
- ValueChangeLoadPdf(LoadPath);
- }
- /// <summary>
- /// 异常信息选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ErrorMessageRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ErrorMessageDateComBox.SelectedItem == null || ErrorMessageDateComBox.SelectedItem.ToString() == "")
- {
- return;
- }
- string LoadPath = GenerateErrorMessagePDF();
- ErrorMessageLoadPdf(LoadPath);
- }
- /// <summary>
- /// 异常信息时间选择事件-最小时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ErrorMessageRecordMinTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ErrorMessageRecordMinTime.SelectedDate == null)
- {
- return;
- }
- else
- {
- if (ErrorMessageRecordMaxTime.SelectedDate == null)
- {
- InitErrorMessageByMinTime((DateTime)ErrorMessageRecordMinTime.SelectedDate);
- }
- else
- {
- InitErrorMessage((DateTime)ErrorMessageRecordMinTime.SelectedDate, (DateTime)ErrorMessageRecordMaxTime.SelectedDate);
- }
- }
- }
- /// <summary>
- /// 异常信息时间选择事件-最大时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ErrorMessageRecordMaxTime_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (ErrorMessageRecordMaxTime.SelectedDate == null)
- {
- return;
- }
- else
- {
- if (ErrorMessageRecordMinTime.SelectedDate == null)
- {
- InitErrorMessageByMaxTime((DateTime)ErrorMessageRecordMaxTime.SelectedDate);
- }
- else
- {
- InitErrorMessage((DateTime)ErrorMessageRecordMinTime.SelectedDate, (DateTime)ErrorMessageRecordMaxTime.SelectedDate);
- }
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 初始化批次列表
- /// </summary>
- private void InitBatchItems()
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.BatchItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- BatchNumComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化批号列表
- /// </summary>
- private void InitBatchItems(DateTime Mintime, DateTime MaxTime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.BatchItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- BatchNumComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化批号列表
- /// </summary>
- private void InitBatchItemsByMinTime(DateTime Mintime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.BatchItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- BatchNumComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化批号列表
- /// </summary>
- private void InitBatchItemsByMaxTime(DateTime MaxTime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.BatchItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.BatchItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- BatchNumComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化时间间隔下拉框
- /// </summary>
- private void InitTimeIntervalComBox()
- {
- // 数据源
- var items = new List<KeyValuePair<string, int>>
- {
- new KeyValuePair<string, int>("1秒", 1),
- new KeyValuePair<string, int>("5秒", 5),
- new KeyValuePair<string, int>("10秒", 10),
- new KeyValuePair<string, int>("30秒",30),
- new KeyValuePair<string, int>("1分", 60),
- new KeyValuePair<string, int>("5分", 300),
- };
- TimeIntervalComBox.ItemsSource = items;
- TimeIntervalComBox.DisplayMemberPath = "Key";
- TimeIntervalComBox.SelectedValuePath = "Value";
- TimeIntervalComBox.SelectedIndex = 0;
- }
- /// <summary>
- /// 初始化配方列表
- /// </summary>
- private void InitFormationItems()
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 获取文件列表(包含子目录)
- string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
- ShowMessageBus.ShowBinding.FormulationItems.Clear();
- foreach (string file in files)
- {
- ShowMessageBus.ShowBinding.FormulationItems.Add(Path.GetFileNameWithoutExtension(file));
- }
- if (ShowMessageBus.ShowBinding.FormulationName != null && ShowMessageBus.ShowBinding.FormulationName != string.Empty)
- {
- try
- {
- FormulationRecordComBox.SelectedItem = ShowMessageBus.ShowBinding.FormulationName;
- }
- catch { }
- }
- }
- catch
- { }
- }
- /// <summary>
- /// 生成批记录PDF
- /// </summary>
- /// <returns></returns>
- private string GenerateBatchPDF()
- {
- string BatchNumber = BatchNumComBox.SelectedItem.ToString();
- //string LoadPath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\BatchData.PDF";
- batchMessSqliteData = new BatchMessSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData\\BatchData_{BatchNumber}.db");
- var batchMess = batchMessSqliteData.GetAllBatchMessage();
- var ShowtableMessage = batchMess.Where((item, index) => index % TimeInterval == 0).ToList();
- List<string> ColSpan = new List<string>()
- {
- "批次号",
- "料筒震盘速度",
- "过滤震台速度",
- "计数震台速度",
- "装瓶数量",
- "装瓶速度",
- "记录时间"
- };
- batchRecord.GetRecordLogo(Properties.Resources.Logo);
- return batchRecord.BatchRecordToPDFReColspan(ShowtableMessage, ColSpan);
- }
- /// <summary>
- /// 生成配方PDF
- /// </summary>
- /// <returns></returns>
- private string GenerateFormulationPDF()
- {
- string BatchNumber = BatchNumComBox.SelectedItem.ToString();
- FormulationConfigClass formulationConfigClass = null;
- formulationConfigClass = XmlStorage.DeserializeFromXml<FormulationConfigClass>(FormulationfolderPath);
- formulationRecordClass.GetRecordLogo(Properties.Resources.Logo);
- List<string> RowSpanNames = new List<string>()
- {
- "配方名称",
- "二值化阈值",
- "允许物体中断的最大连续行数",
- "合格物体的最长长度",
- "合格物体的最短长度",
- "判定标准识别码",
- "合格物体的最大面积",
- "合格物体的最小面积",
- "噪声过滤阈值",
- "通道数量",
- "曝光时间",
- "采集行频",
- "设备名称",
- "速度模式运行速度",
- "点动速度",
- "瓶装设定值",
- "中转阀打开速度",
- "中转阀打开时间",
- "罐装减速值",
- "缓存减速值",
- "缓存计数延迟时间",
- "缓存停机值",
- "罐装料筒震台高速值",
- "罐装过滤震台高速值",
- "罐装计数震台高速值",
- "罐装料筒震台减速值",
- "罐装过滤震台减速值",
- "罐装计数震台减速值",
- "缓存料筒震台高速值",
- "缓存过滤震台高速值",
- "缓存计数震台高速值",
- "缓存料筒震台减速值",
- "缓存过滤震台减速值",
- "缓存计数震台减速值",
- "阀门打开延迟",
- "回零偏移值",
- "回零偏移速度",
- "中转阀关闭速度",
- "中转阀打开位置",
- "中转阀关闭位置",
- "气阀打开延迟",
- "装瓶停机值",
- "装瓶停机时间",
- "送瓶轮运行速度",
- "送瓶轮点动速度",
- "送瓶轮回零偏移值",
- "送瓶轮回零速度",
- "送瓶轮位置长度",
- "送瓶轮暂停时间",
- "下料延时"
- };
- return formulationRecordClass.FormulationRecordToPDFReRowspan(formulationConfigClass, RowSpanNames);
- }
- /// <summary>
- /// 加载PDF
- /// </summary>
- /// <param name="pdfFilePath"></param>
- private async void BatchLoadPdf(string pdfFilePath)
- {
- // 加载 PDF 文件
- await BatchRecordWebBrowser.EnsureCoreWebView2Async(null);
- BatchRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
- }
- /// <summary>
- /// 加载PDF
- /// </summary>
- /// <param name="pdfFilePath"></param>
- private async void FormulationLoadPdf(string pdfFilePath)
- {
- // 加载 PDF 文件
- await FormulationRecordWebBrowser.EnsureCoreWebView2Async(null);
- FormulationRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
- }
- /// <summary>
- /// 加载PDF
- /// </summary>
- /// <param name="pdfFilePath"></param>
- private async void ValueChangeLoadPdf(string pdfFilePath)
- {
- // 加载 PDF 文件
- await ValueChangeRecordWebBrowser.EnsureCoreWebView2Async(null);
- ValueChangeRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
- }
- /// <summary>
- /// 加载PDF
- /// </summary>
- /// <param name="pdfFilePath"></param>
- private async void ErrorMessageLoadPdf(string pdfFilePath)
- {
- // 加载 PDF 文件
- await ErrorMessageRecordWebBrowser.EnsureCoreWebView2Async(null);
- ErrorMessageRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitValueChangeItems()
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ValueChangeDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitValueChangeItems(DateTime Mintime, DateTime MaxTime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ValueChangeDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitValueChangeItemsByMinTime(DateTime Mintime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ValueChangeDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitValueChangeItemsByMaxTime(DateTime MaxTime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ValueChangeItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ValueChangeItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ValueChangeDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 生成值更改记录PDF
- /// </summary>
- /// <returns></returns>
- private string GenerateValueChangePDF()
- {
- string ValueChangeValue = ValueChangeDateComBox.SelectedItem.ToString();
- errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
- var ValueChangeMess = errorMesSqliteData.GetValueChangeMessage();
- List<string> ColSpan = new List<string>()
- {
- "信息类别",
- "信息类型",
- "错误信息",
- "记录时间",
- "操作员ID",
- };
- ValueChangeRecordClass.GetRecordLogo(Properties.Resources.Logo);
- return ValueChangeRecordClass.ValueChangeRecordToPDFReColspan(ValueChangeMess, ColSpan);
- //return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitErrorMessage()
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ErrorMessageDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitErrorMessage(DateTime Mintime, DateTime MaxTime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime > Mintime && f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ErrorMessageDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitErrorMessageByMinTime(DateTime Mintime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime > Mintime).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ErrorMessageDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 初始化异常数据列表
- /// </summary>
- private void InitErrorMessageByMaxTime(DateTime MaxTime)
- {
- string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage";
- if (!Directory.Exists(folderPath))
- {
- // 创建文件夹
- Directory.CreateDirectory(folderPath);
- }
- try
- {
- // 使用 DirectoryInfo 获取文件并按修改时间排序
- DirectoryInfo dirInfo = new DirectoryInfo(folderPath);
- FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
- // 按照修改时间排序(最新的在前)
- var sortedFiles = files.Where(f => f.CreationTime < MaxTime.AddDays(1)).OrderByDescending(f => f.LastWriteTime).ToArray();
- ShowMessageBus.ShowBinding.ErrorMessItems.Clear();
- foreach (FileInfo file in sortedFiles)
- {
- ShowMessageBus.ShowBinding.ErrorMessItems.Add(Path.GetFileNameWithoutExtension(file.Name).Split('_')[1]);
- }
- ErrorMessageDateComBox.SelectedIndex = 0;
- }
- catch
- { }
- }
- /// <summary>
- /// 生成值更改记录PDF
- /// </summary>
- /// <returns></returns>
- private string GenerateErrorMessagePDF()
- {
- string ValueChangeValue = ErrorMessageDateComBox.SelectedItem.ToString();
- errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
- var ValueChangeMess = errorMesSqliteData.GetErrorMessage();
- List<string> ColSpan = new List<string>()
- {
- "信息类别",
- "信息类型",
- "错误信息",
- "信息路径",
- "记录时间",
- "操作员ID",
- };
- errorMessageRecordClass.GetRecordLogo(Properties.Resources.Logo);
- return errorMessageRecordClass.ErrorMessageRecordToPDFReColspan(ValueChangeMess, ColSpan);
- //return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
- }
- #endregion
- }
- }
|