From 69b82f6fb569cbd4625e18bf6ccc151fe6129bb4 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Thu, 21 Apr 2022 18:05:14 +0800 Subject: [PATCH] 1 --- .../Themes/MyStyle.xaml | 2 +- BPASmartClient.ViewModel/LogViewModel.cs | 146 +++++++++++++++++- BPASmartClient/App.xaml | 4 +- BPASmartClient/Control/LogOrAlarmView.xaml | 8 + BPASmartClient/Control/LogView.xaml | 16 +- BPASmartClient/MainWindow.xaml | 15 +- 6 files changed, 179 insertions(+), 12 deletions(-) diff --git a/BPASmartClient.CustomResource/Themes/MyStyle.xaml b/BPASmartClient.CustomResource/Themes/MyStyle.xaml index dc58cc01..e19e617e 100644 --- a/BPASmartClient.CustomResource/Themes/MyStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/MyStyle.xaml @@ -699,7 +699,7 @@ - + diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 1f05e3c2..ad19c9f2 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -1,13 +1,18 @@ using BPASmartClient.Message; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Media; +using System.Windows.Threading; namespace BPASmartClient.ViewModel { @@ -16,6 +21,7 @@ namespace BPASmartClient.ViewModel /// public class LogViewModel :ObservableObject { + public DispatcherTimer dispatcherTimer; private ObservableCollection _LogModels; public ObservableCollection LogDataGrid @@ -52,10 +58,148 @@ namespace BPASmartClient.ViewModel }); ExcelCommand = new RelayCommand(() => { - + ExcellOrder(); }); + + //dispatcherTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };//1秒一流转 + //dispatcherTimer.Tick += delegate + //{ + // if (TimedClear) + // { + + // } + //}; + //dispatcherTimer.Start(); } + private string[] colums = new string[] { "订单编号","商品名称","排序号","订单状态","开始时间","取餐时间","结束时间" }; + /// + /// 导出数据 + /// + public void ExcellOrder() + { + if (LogDataGrid.Count > 0) + { + string text = "时间 类型 日志内容\n"; + LogDataGrid?.ToList().ForEach(temp => + { + text = text + temp.time + " " + temp.type + " " + temp.message+ "\n"; + }); + SaveFileDialog openfile = new SaveFileDialog(); + openfile.Filter = "Txt文件(*.txt)|*.txt"; + if (openfile.ShowDialog() == null) + { + return; + } + string path = openfile.FileName; + if (!System.IO.File.Exists(path)) + { + //没有则创建这个文件 + FileStream fs1 = new FileStream(path,FileMode.Create,FileAccess.Write);//创建写入文件 + StreamWriter sw = new StreamWriter(fs1); + sw.WriteLine(text);//开始写入值 + sw.Close(); + fs1.Close(); + } + else + { + FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Write); + StreamWriter sr = new StreamWriter(fs); + sr.WriteLine(text);//开始写入值 + sr.Close(); + fs.Close(); + } + string msg = string.Format("记录导出完成,共导出记录{0}条,是否打开!",LogDataGrid.Count); + if (System.Windows.MessageBox.Show(msg,"提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK) + { + OpenFile(openfile.FileName); + } + } + else + System.Windows.MessageBox.Show("无数据!"); + + } + /// + /// 打开指定路径下文件,比如: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"); + } + } public RelayCommand ExcelCommand { get; set; } diff --git a/BPASmartClient/App.xaml b/BPASmartClient/App.xaml index e4f09b8f..bb21ce47 100644 --- a/BPASmartClient/App.xaml +++ b/BPASmartClient/App.xaml @@ -10,8 +10,8 @@ - - + diff --git a/BPASmartClient/Control/LogOrAlarmView.xaml b/BPASmartClient/Control/LogOrAlarmView.xaml index 5443bcbe..2d3a6dbb 100644 --- a/BPASmartClient/Control/LogOrAlarmView.xaml +++ b/BPASmartClient/Control/LogOrAlarmView.xaml @@ -6,6 +6,14 @@ xmlns:local="clr-namespace:BPASmartClient.Control" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> + + + + + + + + diff --git a/BPASmartClient/Control/LogView.xaml b/BPASmartClient/Control/LogView.xaml index 9f960653..08bec324 100644 --- a/BPASmartClient/Control/LogView.xaml +++ b/BPASmartClient/Control/LogView.xaml @@ -7,6 +7,14 @@ xmlns:local="clr-namespace:BPASmartClient.Control" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> + + + + + + + + @@ -19,8 +27,8 @@ - 实时模式 - 定时清除 + 实时模式 + 定时清除 @@ -36,14 +44,14 @@ - + - + diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index ff6acea5..51bbfe4e 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -14,7 +14,14 @@ WindowStartupLocation="CenterScreen" WindowStyle="None" mc:Ignorable="d"> - + + + + + + + + @@ -34,7 +41,7 @@ - + @@ -100,7 +107,7 @@ -