diff --git a/SlnMesnac.Model/domain/BaseCode.cs b/SlnMesnac.Model/domain/BaseCode.cs index aaf2c29..6a77de2 100644 --- a/SlnMesnac.Model/domain/BaseCode.cs +++ b/SlnMesnac.Model/domain/BaseCode.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using MiniExcelLibs.Attributes; using SqlSugar; namespace SlnMesnac.Model.domain @@ -48,22 +49,28 @@ namespace SlnMesnac.Model.domain this.CreateTime = DateTime.Now; } + + [ExcelColumnName("标识"), ExcelColumnWidth(15)] [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)] public int Id { get; set; } + [ExcelColumnName("记录时间"), ExcelColumnWidth(15)] [SugarColumn(ColumnName = "createtime")] public DateTime CreateTime { get; set; } + [ExcelColumnName("日志类型"), ExcelColumnWidth(15)] [SugarColumn(ColumnName = "log_type")] public string LogType { get; set; } + [ExcelColumnName("日志级别"), ExcelColumnWidth(15)] [SugarColumn(ColumnName = "log_level")] public string LogLevel { get; set; } + [ExcelColumnName("日志内容"), ExcelColumnWidth(60)] [SugarColumn(ColumnName = "content")] public string Content { get; set; } - + [ExcelColumnName("异常信息"), ExcelColumnWidth(50)] [SugarColumn(ColumnName = "err_msg")] public string ErrMsg { get; set; } diff --git a/SlnMesnac.WPF/Page/History/HistoryControl.xaml b/SlnMesnac.WPF/Page/History/HistoryControl.xaml index 543f928..0d542db 100644 --- a/SlnMesnac.WPF/Page/History/HistoryControl.xaml +++ b/SlnMesnac.WPF/Page/History/HistoryControl.xaml @@ -38,12 +38,12 @@ - + diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml b/SlnMesnac.WPF/Page/IndexControl.xaml index 8158a46..857b61a 100644 --- a/SlnMesnac.WPF/Page/IndexControl.xaml +++ b/SlnMesnac.WPF/Page/IndexControl.xaml @@ -46,9 +46,8 @@ - - - + + @@ -63,7 +62,7 @@ - + + + + diff --git a/SlnMesnac.WPF/Page/LogInfo/LogInfoControl.xaml b/SlnMesnac.WPF/Page/LogInfo/LogInfoControl.xaml index b903fae..4a8b58c 100644 --- a/SlnMesnac.WPF/Page/LogInfo/LogInfoControl.xaml +++ b/SlnMesnac.WPF/Page/LogInfo/LogInfoControl.xaml @@ -12,9 +12,10 @@ + - + 包裹数据 设备监控 @@ -22,7 +23,7 @@ 所有 - + Info Warn @@ -30,7 +31,7 @@ 所有 - + @@ -44,29 +45,29 @@ - + - + - + diff --git a/SlnMesnac.WPF/ViewModel/HistoryViewModel.cs b/SlnMesnac.WPF/ViewModel/HistoryViewModel.cs index 51d0cd2..ae000a4 100644 --- a/SlnMesnac.WPF/ViewModel/HistoryViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/HistoryViewModel.cs @@ -96,7 +96,7 @@ namespace SlnMesnac.WPF.ViewModel SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*"; saveFileDialog.Title = "保存文件"; - saveFileDialog.FileName = $"扫描记录{DateTime.Now.Date:yyyy-MM-dd}.xlsx"; + saveFileDialog.FileName = $"扫描记录{System.Guid.NewGuid().ToString()}.xlsx"; if (saveFileDialog.ShowDialog() == true) { diff --git a/SlnMesnac.WPF/ViewModel/LogInfoViewModel.cs b/SlnMesnac.WPF/ViewModel/LogInfoViewModel.cs index 2295236..ce70efa 100644 --- a/SlnMesnac.WPF/ViewModel/LogInfoViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/LogInfoViewModel.cs @@ -1,6 +1,8 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Win32; +using MiniExcelLibs; using SlnMesnac.Business; using SlnMesnac.Model.domain; using System; @@ -9,6 +11,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Controls; #region << 版 本 注 释 >> @@ -90,5 +93,32 @@ namespace SlnMesnac.WPF.ViewModel ScanItems = new ObservableCollection(info); } + + [RelayCommand] + private void Export() + { + try + { + var info = _scanItems; + + // 创建 SaveFileDialog 对象 + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*"; + saveFileDialog.Title = "保存文件"; + saveFileDialog.FileName = $"日志信息{System.Guid.NewGuid().ToString()}.xlsx"; + + if (saveFileDialog.ShowDialog() == true) + { + string filePath = saveFileDialog.FileName; + MiniExcel.SaveAs(filePath, info); + MessageBox.Show($"日志信息导出成功:{filePath}"); + + } + } + catch (Exception ex) + { + MessageBox.Show($"日志信息导出异常:{ex.Message}"); + } + } } }