using CCDCount.DLL.AuditTrail;
using CCDCount.DLL.SqlDataClass;
using CCDCount.DLL.Tools;
using CCDCount.MODEL.AuditTrailModel;
using CCDCount.MODEL.ConfigModel;
using LogClass;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace CCDCountWpf.WpfPage
{
///
/// AuditTrailPage.xaml 的交互逻辑
///
public partial class AuditTrailPage : Page
{
#region 实例
///
/// 批次信息数据类
///
BatchMessSqliteDataClass batchMessSqliteData = null;
ErrorMesSqliteDataClass errorMesSqliteData = null;
//
/// 批次记录类(数据转PDF)
///
BatchRecordClass batchRecord = new BatchRecordClass();
FormulationRecordClass formulationRecordClass = new FormulationRecordClass();
ValueChangeRecordClass ValueChangeRecordClass = new ValueChangeRecordClass();
ErrorMessageRecordClass errorMessageRecordClass = new ErrorMessageRecordClass();
#endregion
#region 变量
///
/// 时间间隔
///
int TimeInterval = 0;
string FormulationfolderPath = "";
#endregion
#region 窗口事件
///
/// 构建方法
///
public AuditTrailPage()
{
InitializeComponent();
this.Height = Double.NaN;
this.Width = Double.NaN;
DataContext = ShowMessageBus.ShowBinding;
try
{
LOG.log("初始化批次列表", 6);
InitBatchItems();
InitTimeIntervalComBox();
LOG.log("初始化配方列表", 6);
InitFormationItems();
LOG.log("初始化值更改列表", 6);
InitValueChangeItems();
LOG.log("初始化异常数据列表", 6);
InitErrorMessage();
}
catch(Exception ex)
{
LOG.error(ex.Message);
}
}
///
/// 批号时间筛选选择时间-最小时间
///
///
///
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);
}
}
}
///
/// 批号时间筛选选择时间-最大时间
///
///
///
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);
}
}
}
///
/// 批号选择事件
///
///
///
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);
}
///
/// 时间间隔选择事件
///
///
///
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);
}
}
///
/// 批号记录按钮点击事件
///
///
///
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;
}
///
/// 配方记录按钮点击事件
///
///
///
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;
}
///
/// 值改变记录按钮点击事件
///
///
///
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;
}
///
/// 错误记录按钮点击事件
///
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;
}
///
/// 配方选择事件
///
///
///
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);
}
///
/// 值改变记录最小时间选择框选择事件
///
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);
}
}
}
///
/// 值改变记录最大时间选择框选择事件
///
///
///
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);
}
}
}
///
/// 值改变记录选择框选择事件
///
///
///
private void ValueChangeRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ValueChangeDateComBox.SelectedItem == null || ValueChangeDateComBox.SelectedItem.ToString() == "")
{
return;
}
string LoadPath = GenerateValueChangePDF();
ValueChangeLoadPdf(LoadPath);
}
///
/// 异常信息选择事件
///
///
///
private void ErrorMessageRecordComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ErrorMessageDateComBox.SelectedItem == null || ErrorMessageDateComBox.SelectedItem.ToString() == "")
{
return;
}
string LoadPath = GenerateErrorMessagePDF();
ErrorMessageLoadPdf(LoadPath);
}
///
/// 异常信息时间选择事件-最小时间
///
///
///
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);
}
}
}
///
/// 异常信息时间选择事件-最大时间
///
///
///
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 私有方法
///
/// 初始化批次列表
///
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
{ }
}
///
/// 初始化批号列表
///
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
{ }
}
///
/// 初始化批号列表
///
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
{ }
}
///
/// 初始化批号列表
///
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
{ }
}
///
/// 初始化时间间隔下拉框
///
private void InitTimeIntervalComBox()
{
// 数据源
var items = new List>
{
new KeyValuePair("1s", 1),
new KeyValuePair("5s", 5),
new KeyValuePair("10s", 10),
new KeyValuePair("30s",30),
new KeyValuePair("1min", 60),
new KeyValuePair("5min", 300),
};
TimeIntervalComBox.ItemsSource = items;
TimeIntervalComBox.DisplayMemberPath = "Key";
TimeIntervalComBox.SelectedValuePath = "Value";
TimeIntervalComBox.SelectedIndex = 0;
}
///
/// 初始化配方列表
///
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
{ }
}
///
/// 生成批记录PDF
///
///
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 ColSpan = new List()
//{
// "批次号",
// "料筒震盘速度",
// "过滤震台速度",
// "计数震台速度",
// "装瓶数量",
// "装瓶速度",
// "记录时间"
//};
List ColSpan = new List()
{
"BatchNunber",
"MaterialCylinderVibrationTableSpeed",
"FilterVibrationTableSpeed",
"CountVibrationTableSpeed",
"BottingCount",
"BottingSpeed",
"RecordTime"
};
batchRecord.GetRecordLogo(Properties.Resources.Logo);
return batchRecord.BatchRecordToPDFReColspan(ShowtableMessage, ColSpan);
}
///
/// 生成配方PDF
///
///
private string GenerateFormulationPDF()
{
string BatchNumber = BatchNumComBox.SelectedItem.ToString();
FormulationConfigClass formulationConfigClass = null;
formulationConfigClass = XmlStorage.DeserializeFromXml(FormulationfolderPath);
formulationRecordClass.GetRecordLogo(Properties.Resources.Logo);
//List RowSpanNames = new List()
//{
// "配方名称",
// "二值化阈值",
// "允许物体中断的最大连续行数",
// "合格物体的最长长度",
// "合格物体的最短长度",
// "判定标准识别码",
// "合格物体的最大面积",
// "合格物体的最小面积",
// "噪声过滤阈值",
// "通道数量",
// "曝光时间",
// "采集行频",
// "设备名称",
// "速度模式运行速度",
// "点动速度",
// "瓶装设定值",
// "中转阀打开速度",
// "中转阀打开时间",
// "罐装减速值",
// "缓存减速值",
// "缓存计数延迟时间",
// "缓存停机值",
// "罐装料筒震台高速值",
// "罐装过滤震台高速值",
// "罐装计数震台高速值",
// "罐装料筒震台减速值",
// "罐装过滤震台减速值",
// "罐装计数震台减速值",
// "缓存料筒震台高速值",
// "缓存过滤震台高速值",
// "缓存计数震台高速值",
// "缓存料筒震台减速值",
// "缓存过滤震台减速值",
// "缓存计数震台减速值",
// "阀门打开延迟",
// "回零偏移值",
// "回零偏移速度",
// "中转阀关闭速度",
// "中转阀打开位置",
// "中转阀关闭位置",
// "气阀打开延迟",
// "装瓶停机值",
// "装瓶停机时间",
// "送瓶轮运行速度",
// "送瓶轮点动速度",
// "送瓶轮回零偏移值",
// "送瓶轮回零速度",
// "送瓶轮位置长度",
// "送瓶轮暂停时间",
// "下料延时"
//};
return formulationRecordClass.FormulationRecordToPDF(formulationConfigClass);
//return formulationRecordClass.FormulationRecordToPDFReRowspan(formulationConfigClass, RowSpanNames);
}
///
/// 加载PDF
///
///
private async void BatchLoadPdf(string pdfFilePath)
{
// 加载 PDF 文件
await BatchRecordWebBrowser.EnsureCoreWebView2Async(null);
BatchRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
}
///
/// 加载PDF
///
///
private async void FormulationLoadPdf(string pdfFilePath)
{
// 加载 PDF 文件
await FormulationRecordWebBrowser.EnsureCoreWebView2Async(null);
FormulationRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
}
///
/// 加载PDF
///
///
private async void ValueChangeLoadPdf(string pdfFilePath)
{
// 加载 PDF 文件
await ValueChangeRecordWebBrowser.EnsureCoreWebView2Async(null);
ValueChangeRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
}
///
/// 加载PDF
///
///
private async void ErrorMessageLoadPdf(string pdfFilePath)
{
// 加载 PDF 文件
await ErrorMessageRecordWebBrowser.EnsureCoreWebView2Async(null);
ErrorMessageRecordWebBrowser.CoreWebView2.Navigate(pdfFilePath);
}
///
/// 初始化值更改列表
///
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
{ }
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 生成值更改记录PDF
///
///
private string GenerateValueChangePDF()
{
string ValueChangeValue = ValueChangeDateComBox.SelectedItem.ToString();
errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
var ValueChangeMess = errorMesSqliteData.GetValueChangeMessage();
List ColSpan = new List()
{
"信息类别",
"信息类型",
"错误信息",
"记录时间",
"操作员ID",
};
ValueChangeRecordClass.GetRecordLogo(Properties.Resources.Logo);
return ValueChangeRecordClass.ValueChangeRecordToPDFReColspan(ValueChangeMess, ColSpan);
//return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 初始化异常数据列表
///
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
{ }
}
///
/// 生成值更改记录PDF
///
///
private string GenerateErrorMessagePDF()
{
string ValueChangeValue = ErrorMessageDateComBox.SelectedItem.ToString();
errorMesSqliteData = new ErrorMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\FaultMessage\\FaultMessage_{ValueChangeValue}.db");
var ValueChangeMess = errorMesSqliteData.GetErrorMessage();
List ColSpan = new List()
{
"信息类别",
"信息类型",
"错误信息",
"信息路径",
"记录时间",
"操作员ID",
};
errorMessageRecordClass.GetRecordLogo(Properties.Resources.Logo);
return errorMessageRecordClass.ErrorMessageRecordToPDFReColspan(ValueChangeMess, ColSpan);
//return ValueChangeRecordClass.ValueChangeRecordToPDF(ValueChangeMess);
}
#endregion
private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
BatchMinTime.SelectedDate = DateTime.Today;
BatchMaxTime.SelectedDate = DateTime.Today;
ValueChangeRecordMinTime.SelectedDate = DateTime.Today;
ValueChangeRecordMaxTime.SelectedDate = DateTime.Today;
ErrorMessageRecordMinTime.SelectedDate = DateTime.Today;
ErrorMessageRecordMaxTime.SelectedDate = DateTime.Today;
}
}
}