|
|
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;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
/*--------------------------------------------------------------------
|
|
|
* 版权所有 (c) 2024 WenJY 保留所有权利。
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
* 机器名称:T14-GEN3-7895
|
|
|
* 命名空间:SlnMesnac.WPF.ViewModel
|
|
|
* 唯一标识:06dea146-4bed-4f74-9aac-01f8ea91d6bf
|
|
|
*
|
|
|
* 创建者:WenJY
|
|
|
* 电子邮箱:
|
|
|
* 创建时间:2024-10-09 8:50:06
|
|
|
* 版本:V1.0.0
|
|
|
* 描述:
|
|
|
*
|
|
|
*--------------------------------------------------------------------
|
|
|
* 修改人:
|
|
|
* 时间:
|
|
|
* 修改说明:
|
|
|
*
|
|
|
* 版本:V1.0.0
|
|
|
*--------------------------------------------------------------------*/
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
namespace SlnMesnac.WPF.ViewModel
|
|
|
{
|
|
|
public partial class LogInfoViewModel: ObservableObject
|
|
|
{
|
|
|
|
|
|
private readonly LogInfoBusiness logInfoBusiness;
|
|
|
|
|
|
public LogInfoViewModel()
|
|
|
{
|
|
|
logInfoBusiness = App.ServiceProvider.GetService<LogInfoBusiness>();
|
|
|
|
|
|
}
|
|
|
|
|
|
public ComboBoxItem _logType = null;
|
|
|
public ComboBoxItem LogType
|
|
|
{
|
|
|
get => _logType;
|
|
|
set => SetProperty(ref _logType, value);
|
|
|
}
|
|
|
|
|
|
public ComboBoxItem _logLevel = null;
|
|
|
public ComboBoxItem LogLevel
|
|
|
{
|
|
|
get => _logLevel;
|
|
|
set => SetProperty(ref _logLevel, value);
|
|
|
}
|
|
|
|
|
|
public DateTime _beginTime = DateTime.Now;
|
|
|
public DateTime BeginTime
|
|
|
{
|
|
|
get => _beginTime;
|
|
|
set => SetProperty(ref _beginTime, value);
|
|
|
}
|
|
|
|
|
|
public DateTime _endTime = DateTime.Now.AddDays(1);
|
|
|
public DateTime EndTime
|
|
|
{
|
|
|
get => _endTime;
|
|
|
set => SetProperty(ref _endTime, value);
|
|
|
}
|
|
|
|
|
|
private ObservableCollection<BaseLog> _scanItems = new ObservableCollection<BaseLog>();
|
|
|
public ObservableCollection<BaseLog> ScanItems
|
|
|
{
|
|
|
get => _scanItems;
|
|
|
set => SetProperty(ref _scanItems, value);
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
|
private void Query()
|
|
|
{
|
|
|
string logLevel = _logLevel == null ? string.Empty : _logLevel.Content.ToString();
|
|
|
string logType = _logType == null ? string.Empty : _logType.Content.ToString();
|
|
|
logInfoBusiness.QueryLogInfo(logType, logLevel, _beginTime, _endTime, out List<BaseLog> info);
|
|
|
|
|
|
ScanItems = new ObservableCollection<BaseLog>(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}");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|