Преглед изворни кода

增加日志查询界面

样式分支
fyf пре 2 година
родитељ
комит
75b0e78f82
7 измењених фајлова са 193 додато и 126 уклоњено
  1. +1
    -4
      BPASmartClient.Device/BaseDevice.cs
  2. +47
    -1
      BPASmartClient.Helper/logHelper.cs
  3. +74
    -0
      BPASmartClient.ViewModel/LogOrAlarmViewModel.cs
  4. +58
    -103
      BPASmartClient.ViewModel/LogViewModel.cs
  5. +9
    -10
      BPASmartClient/Control/LogOrAlarmView.xaml
  6. +3
    -1
      BPASmartClient/Control/LogOrAlarmView.xaml.cs
  7. +1
    -7
      BPASmartClient/MainWindow.xaml

+ 1
- 4
BPASmartClient.Device/BaseDevice.cs Прегледај датотеку

@@ -112,6 +112,7 @@ namespace BPASmartClient.Device
{
Log.Insert(0,new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = "流程", Text = info });
MessageLog.GetInstance.DeviceProcessLogShow(DeviceId.ToString(), info);
if (Log.Count > 100) { Log.RemoveAt(Log.Count - 1);}
}

public void Initliaze()
@@ -132,10 +133,6 @@ namespace BPASmartClient.Device
public virtual void StartMain()
{
#region 测试添加几个日志与告警
Error.Add(new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = "落碗", Text = "落碗异常" });
Error.Add(new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = "煮面机", Text = "煮面机温度异常" });
Log.Add(new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = "初始化", Text = "初始化已完成" });
Log.Add(new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = "启动中", Text = "已完成外设启动" });
#endregion

ThreadManage.GetInstance().StartLong(new Action(() =>


+ 47
- 1
BPASmartClient.Helper/logHelper.cs Прегледај датотеку

@@ -353,7 +353,53 @@ namespace BPASmartClient.Helper
return LogConfig.GetLogConfigInstance().EnableThreadId;
}


/// <summary>
/// 打开指定路径下文件
/// </summary>
public void OpenFile(string NewFileName)
{
Process process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo(NewFileName);
process.StartInfo = processStartInfo;
#region 下面这段被注释掉代码(可以用来全屏打开代码)
//建立新的系统进程
////System.Diagnostics.Process process = new System.Diagnostics.Process();
//设置文件名,此处为图片的真实路径 + 文件名(需要有后缀)
////process.StartInfo.FileName = NewFileName;
//此为关键部分。设置进程运行参数,此时为最大化窗口显示图片。
////process.StartInfo.Arguments = "rundll32.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen";
// 此项为是否使用Shell执行程序,因系统默认为true,此项也可不设,但若设置必须为true
process.StartInfo.UseShellExecute = true;
#endregion
try
{
process.Start();
try
{
// process.WaitForExit();
}
catch (Exception ex)
{
throw ex;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
try
{
if (process != null)
{
process.Close();
process = null;
}
}
catch { }
}
}
}

/// <summary>


+ 74
- 0
BPASmartClient.ViewModel/LogOrAlarmViewModel.cs Прегледај датотеку

@@ -0,0 +1,74 @@
using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.ViewModel
{
/// <summary>
/// 告警/日志查询界面
/// </summary>
public class LogOrAlarmViewModel : ObservableObject
{
#region 单一变量
private volatile static LogOrAlarmViewModel _Instance;
public static LogOrAlarmViewModel GetInstance() => _Instance ?? (_Instance = new LogOrAlarmViewModel());
private LogOrAlarmViewModel()
{
Init();
}
#endregion

#region 变量
/// <summary>
/// 选中变量
/// </summary>
private bool _selectCombox = true;
public bool SelectCombox
{
get
{
return _selectCombox;
}
set
{
if (_selectCombox == value)
return;
_selectCombox = value;
OnPropertyChanged("SelectCombox");
}
}
#endregion

#region Command
public RelayCommand QueryCommand { get; set; }
public RelayCommand OpenCommand { get; set; }
#endregion

#region 函数
public void Init()
{
QueryCommand = new RelayCommand(() =>
{

});

OpenCommand = new RelayCommand(() =>
{
System.Diagnostics.Process.Start("Explorer", "/select," + logHelper.GetLogConfigInstance().directRollfileAppender.File);
//logHelper.GetLogConfigInstance().OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File);
});
}

#endregion





}
}

+ 58
- 103
BPASmartClient.ViewModel/LogViewModel.cs Прегледај датотеку

@@ -23,10 +23,10 @@ namespace BPASmartClient.ViewModel
/// </summary>
public class LogViewModel : ObservableObject
{
#region 变量
public DispatcherTimer dispatcherTimer;
public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
private ObservableCollection<LogModel> _LogModels;
public ObservableCollection<LogModel> LogDataGrid
private ObservableCollection<LogModel> _LogModels;public ObservableCollection<LogModel> LogDataGrid
{
get
{
@@ -40,13 +40,53 @@ namespace BPASmartClient.ViewModel
OnPropertyChanged("LogDataGrid");
}
}
private bool _RealTimeModel = true;public bool RealTimeModel
{
get
{
return _RealTimeModel;
}
set
{
if (_RealTimeModel == value)
return;
_RealTimeModel = value;
OnPropertyChanged("RealTimeModel");
}
}
private bool _TimedClear = true;public bool TimedClear
{
get
{
return _TimedClear;
}
set
{
if (_TimedClear == value)
return;
_TimedClear = value;
OnPropertyChanged("TimedClear");
}
}
#endregion

#region 单一
private volatile static LogViewModel _Instance;
public static LogViewModel GetInstance() => _Instance ?? (_Instance = new LogViewModel());
private LogViewModel()
{
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory);
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>();
Init();
}
#endregion

#region 函数
/// <summary>
/// 初始化
/// </summary>
public void Init()
{
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>();
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory);
//一般日志
MessageLog.GetInstance.InfoNotify = new Action<string>((s) =>
{
@@ -56,17 +96,15 @@ namespace BPASmartClient.ViewModel
logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s);
}));
});

//设备日志
MessageLog.GetInstance.DeviceProcessLogNotify = new Action<string, string>((id, s) =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" });
logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s);
}));
});

{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" });
logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s);
}));
});
//设备告警日志
MessageLog.GetInstance.DeviceAlarmLogNotify = new Action<string, string>((id, s) =>
{
@@ -76,7 +114,6 @@ namespace BPASmartClient.ViewModel
logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id);
}));
});

//错误日志
MessageLog.GetInstance.ExInfoNotify = new Action<string>((s) =>
{
@@ -106,10 +143,10 @@ namespace BPASmartClient.ViewModel
if (System.Windows.MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
System.Diagnostics.Process.Start("Explorer", "/select," + logHelper.GetLogConfigInstance().directRollfileAppender.File);
OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File);
}else
logHelper.GetLogConfigInstance().OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File);
}
else
System.Diagnostics.Process.Start("Explorer", "/select," + logHelper.GetLogConfigInstance().directRollfileAppender.File);

});

dispatcherTimer = new DispatcherTimer();
@@ -127,7 +164,6 @@ namespace BPASmartClient.ViewModel
dispatcherTimer.Interval = TimeSpan.FromSeconds(10);
dispatcherTimer.Start();
}

/// <summary>
/// 导出数据
/// </summary>
@@ -167,104 +203,24 @@ namespace BPASmartClient.ViewModel
string msg = string.Format("记录导出完成,共导出记录{0}条,是否打开!", LogDataGrid.Count);
if (System.Windows.MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
OpenFile(openfile.FileName);
logHelper.GetLogConfigInstance().OpenFile(openfile.FileName);
}
}
else
System.Windows.MessageBox.Show("无数据!");

}
#endregion

/// <summary>
/// 打开指定路径下文件,比如:Word、Excel、Dll、图片等都可以(前提是你已经安装打开程序的对应软件)
/// </summary>
/// <param name="NewFileName">eg:D:\Test\模版8.doc</param>
/// <param name="NewFileName">eg:D:\Test\模版8.doc</param>
private void OpenFile(string NewFileName)
{
Process process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo(NewFileName);
process.StartInfo = processStartInfo;
#region 下面这段被注释掉代码(可以用来全屏打开代码)
//建立新的系统进程
////System.Diagnostics.Process process = new System.Diagnostics.Process();
//设置文件名,此处为图片的真实路径 + 文件名(需要有后缀)
////process.StartInfo.FileName = NewFileName;
//此为关键部分。设置进程运行参数,此时为最大化窗口显示图片。
////process.StartInfo.Arguments = "rundll32.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen";
// 此项为是否使用Shell执行程序,因系统默认为true,此项也可不设,但若设置必须为true
process.StartInfo.UseShellExecute = true;
#endregion
try
{
process.Start();
try
{
// process.WaitForExit();
}
catch (Exception ex)
{
throw ex;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
try
{
if (process != null)
{
process.Close();
process = null;
}
}
catch { }
}
}

private bool _RealTimeModel = true;
public bool RealTimeModel
{
get
{
return _RealTimeModel;
}
set
{
if (_RealTimeModel == value)
return;
_RealTimeModel = value;
OnPropertyChanged("RealTimeModel");
}
}

private bool _TimedClear = true;
public bool TimedClear
{
get
{
return _TimedClear;
}
set
{
if (_TimedClear == value)
return;
_TimedClear = value;
OnPropertyChanged("TimedClear");
}
}

#region Command
public RelayCommand ExcelCommand { get; set; }
public RelayCommand OpenCommand { get; set; }
#endregion
}

public class LogModel : ObservableObject
{
public string time { get; set; }

private string _type;
public string type
{
@@ -283,7 +239,6 @@ namespace BPASmartClient.ViewModel
}
}
public string message { get; set; }

private Brush _foreground;
public Brush foreground
{


+ 9
- 10
BPASmartClient/Control/LogOrAlarmView.xaml Прегледај датотеку

@@ -25,17 +25,16 @@

<!-- 查询按钮栏 -->
<StackPanel Margin="10,0,10,0" Orientation="Horizontal">
<ComboBox Width="80" SelectedIndex="0">
<ComboBoxItem>一般日志</ComboBoxItem>
<ComboBoxItem>错误日志</ComboBoxItem>
<ComboBoxItem>告警信息</ComboBoxItem>
<ComboBox Width="80" SelectedIndex="0" SelectedItem="{Binding SelectCombox}">
<ComboBoxItem Tag="Info">一般日志</ComboBoxItem>
<ComboBoxItem Tag="DeviceLog">设备日志</ComboBoxItem>
<ComboBoxItem Tag="Error">错误日志</ComboBoxItem>
<ComboBoxItem Tag="DeviceAlarm">设备告警</ComboBoxItem>
</ComboBox>
<Button Margin="10,0,0,0">查询</Button>
<Button Margin="10,0,0,0">导出</Button>

<CheckBox Margin="10,0,0,0" IsChecked="True">实时模式</CheckBox>
<CheckBox Margin="10,0,0,0" IsChecked="True">定时清除</CheckBox>

<TextBox Width="100"></TextBox>
<DatePicker HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,10,0"></DatePicker>
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding QueryCommand}">查询</Button>
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding OpenCommand}">源文件</Button>
</StackPanel>

<!-- 表格栏 -->


+ 3
- 1
BPASmartClient/Control/LogOrAlarmView.xaml.cs Прегледај датотеку

@@ -1,4 +1,5 @@
using System;
using BPASmartClient.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -23,6 +24,7 @@ namespace BPASmartClient.Control
public LogOrAlarmView()
{
InitializeComponent();
this.DataContext = LogOrAlarmViewModel.GetInstance();
}
}
}

+ 1
- 7
BPASmartClient/MainWindow.xaml Прегледај датотеку

@@ -114,13 +114,7 @@
<MenuItem
Click="MenuItem_Click"
FontSize="12"
Header="告警查询"
Tag="LogOrAlarmView" />
<Separator />
<MenuItem
Click="MenuItem_Click"
FontSize="12"
Header="日志查询"
Header="日志/告警查询"
Tag="LogOrAlarmView" />
<Separator />
<MenuItem


Loading…
Откажи
Сачувај