diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index fcecf9cd..f5f6331d 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/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(() => diff --git a/BPASmartClient.Helper/logHelper.cs b/BPASmartClient.Helper/logHelper.cs index 60291612..6c181237 100644 --- a/BPASmartClient.Helper/logHelper.cs +++ b/BPASmartClient.Helper/logHelper.cs @@ -353,7 +353,53 @@ namespace BPASmartClient.Helper return LogConfig.GetLogConfigInstance().EnableThreadId; } - + /// + /// 打开指定路径下文件 + /// + 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 { } + } + } } /// diff --git a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs new file mode 100644 index 00000000..c95602fb --- /dev/null +++ b/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 +{ + /// + /// 告警/日志查询界面 + /// + public class LogOrAlarmViewModel : ObservableObject + { + #region 单一变量 + private volatile static LogOrAlarmViewModel _Instance; + public static LogOrAlarmViewModel GetInstance() => _Instance ?? (_Instance = new LogOrAlarmViewModel()); + private LogOrAlarmViewModel() + { + Init(); + } + #endregion + + #region 变量 + /// + /// 选中变量 + /// + 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 + + + + + + } +} diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index bb6522ff..17a11b4e 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -23,10 +23,10 @@ namespace BPASmartClient.ViewModel /// public class LogViewModel : ObservableObject { + #region 变量 public DispatcherTimer dispatcherTimer; public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); - private ObservableCollection _LogModels; - public ObservableCollection LogDataGrid + private ObservableCollection _LogModels;public ObservableCollection 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(); + Init(); + } + #endregion + #region 函数 + /// + /// 初始化 + /// + public void Init() + { + if (LogDataGrid == null) LogDataGrid = new ObservableCollection(); + logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); //一般日志 MessageLog.GetInstance.InfoNotify = new Action((s) => { @@ -56,17 +96,15 @@ namespace BPASmartClient.ViewModel logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s); })); }); - //设备日志 MessageLog.GetInstance.DeviceProcessLogNotify = new Action((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((id, s) => { @@ -76,7 +114,6 @@ namespace BPASmartClient.ViewModel logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); })); }); - //错误日志 MessageLog.GetInstance.ExInfoNotify = new Action((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(); } - /// /// 导出数据 /// @@ -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 - /// - /// 打开指定路径下文件,比如:Word、Excel、Dll、图片等都可以(前提是你已经安装打开程序的对应软件) - /// - /// eg:D:\Test\模版8.doc - /// eg:D:\Test\模版8.doc - 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 { diff --git a/BPASmartClient/Control/LogOrAlarmView.xaml b/BPASmartClient/Control/LogOrAlarmView.xaml index 960c4997..8bfc51c0 100644 --- a/BPASmartClient/Control/LogOrAlarmView.xaml +++ b/BPASmartClient/Control/LogOrAlarmView.xaml @@ -25,17 +25,16 @@ - - 一般日志 - 错误日志 - 告警信息 + + 一般日志 + 设备日志 + 错误日志 + 设备告警 - - - - 实时模式 - 定时清除 - + + + + diff --git a/BPASmartClient/Control/LogOrAlarmView.xaml.cs b/BPASmartClient/Control/LogOrAlarmView.xaml.cs index 1fa455ab..fb589b30 100644 --- a/BPASmartClient/Control/LogOrAlarmView.xaml.cs +++ b/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(); } } } diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index d147de7a..7509613d 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -114,13 +114,7 @@ - -