From 8f083f9acd079ff8e791e416a5f3813d90151229 Mon Sep 17 00:00:00 2001 From: fyf Date: Mon, 16 May 2022 13:54:13 +0800 Subject: [PATCH 1/7] 77777 --- BPASmartClient.ViewModel/LogOrAlarmViewModel.cs | 8 ++++---- BPASmartClient.ViewModel/LogViewModel.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs index 4e097ed9..39c1c7e4 100644 --- a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs +++ b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs @@ -158,8 +158,8 @@ namespace BPASmartClient.ViewModel LogDataGrid.Clear(); //2.根据选中查询日志 DataTable dataTable = ReadFile(path); - DataRow[] datas = dataTable.Select(sql); - if (datas.Count() <= 0) + List datas = dataTable.Select($"({sql})").OrderByDescending(o => o["TIME"])?.ToList(); + if (datas==null || datas.Count() <= 0) { NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"查询结果为空!"); return; @@ -170,8 +170,8 @@ namespace BPASmartClient.ViewModel { time = item["TIME"].ToString(), type = item["LOGGER"].ToString(), - message = item["MESSAGE"].ToString(), - foreground = (item["LOGGER"].ToString() == "Error" || item["LOGGER"].ToString() == "DeviceAlarm") ? new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ed0032")) : new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#21bb2e")) + message = item["MESSAGE"].ToString() + // foreground = (item["LOGGER"].ToString() == "ERROR" || item["LOGGER"].ToString() == "DEVICEALARM") ? new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ed0032")) : new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#21bb2e")) }); } } diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 0088abaa..5c5e2bb8 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -233,7 +233,7 @@ namespace BPASmartClient.ViewModel if (_type == value) return; _type = value; - if (_type == "Error") foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ed0032")); + if (_type == "Error" || _type == "Error".ToUpper() || _type == "DeviceAlarm".ToUpper() || _type == "DeviceAlarm") foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ed0032")); OnPropertyChanged("type"); OnPropertyChanged("foreground"); From 418a6d8b3d3e4e76a7c06d3c7d023a66763f54ea Mon Sep 17 00:00:00 2001 From: fyf Date: Mon, 16 May 2022 14:07:55 +0800 Subject: [PATCH 2/7] 898 --- BPASmartClient.ViewModel/LogOrAlarmViewModel.cs | 10 ++++------ BPASmartClient/Control/LogOrAlarmView.xaml | 6 ++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs index 39c1c7e4..7cff7fb1 100644 --- a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs +++ b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs @@ -128,13 +128,11 @@ namespace BPASmartClient.ViewModel LogDataGrid = new ObservableCollection(); DateTimeStr = DateTime.Now; BookExs.Add(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true }); - BookExs.Add(new BookEx(new Book() { Name = "设备日志条件", Tag = "DeviceLog" })); - BookExs.Add(new BookEx(new Book() { Name = "错误日志条件", Tag = "Error" })); - BookExs.Add(new BookEx(new Book() { Name = "设备告警条件", Tag = "DeviceAlarm" })); - SelectedText = "一般日志条件"; + BookExs.Add(new BookEx(new Book() { Name = "设备日志条件", Tag = "DeviceLog" }) { IsChecked = true }); + BookExs.Add(new BookEx(new Book() { Name = "错误日志条件", Tag = "Error" }) { IsChecked = true }); + BookExs.Add(new BookEx(new Book() { Name = "设备告警条件", Tag = "DeviceAlarm" }) { IsChecked = true }); SelectBookExs = new ObservableCollection(); - SelectBookExs.Add(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true }); - + ItemPropertyChanged(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true },new PropertyChangedEventArgs("IsChecked")); //查询 QueryCommand = new RelayCommand(() => { diff --git a/BPASmartClient/Control/LogOrAlarmView.xaml b/BPASmartClient/Control/LogOrAlarmView.xaml index 4a690f85..23770892 100644 --- a/BPASmartClient/Control/LogOrAlarmView.xaml +++ b/BPASmartClient/Control/LogOrAlarmView.xaml @@ -26,12 +26,10 @@ - + - - - + From 79403b96f8b1b1248d2b0c3c7586b9f5f4adb02a Mon Sep 17 00:00:00 2001 From: fyf Date: Mon, 16 May 2022 14:40:09 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0dataV=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.ViewModel/DataVViewModel.cs | 189 +++++++++++++++++++++ BPASmartClient/Control/DataVView.xaml | 153 +++++++++++++++++ BPASmartClient/Control/DataVView.xaml.cs | 122 +++++++++++++ BPASmartClient/MainWindow.xaml | 7 + 4 files changed, 471 insertions(+) create mode 100644 BPASmartClient.ViewModel/DataVViewModel.cs create mode 100644 BPASmartClient/Control/DataVView.xaml create mode 100644 BPASmartClient/Control/DataVView.xaml.cs diff --git a/BPASmartClient.ViewModel/DataVViewModel.cs b/BPASmartClient.ViewModel/DataVViewModel.cs new file mode 100644 index 00000000..ea988f98 --- /dev/null +++ b/BPASmartClient.ViewModel/DataVViewModel.cs @@ -0,0 +1,189 @@ + +using BPASmartClient.Helper; +using BPASmartClient.IoT; +using DataVAPI.Tool.IOT; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.ViewModel +{ + public class DataVViewModel : ObservableObject + { + #region 单一变量 + private volatile static DataVViewModel _Instance; + public static DataVViewModel GetInstance() => _Instance ?? (_Instance = new DataVViewModel()); + private DataVViewModel() + { + deviceTable = new ObservableCollection(); + device = new DeviceTable(); + deviceTableSelectedItem = new DeviceTable(); + ApiURL = System.Configuration.ConfigurationManager.AppSettings["DataVServiceUri"].ToString(); + Refresh(); + } + #endregion + + #region 公有变量 + /// + /// 设备表 + /// + public ObservableCollection deviceTable { get; set; } + /// + /// 选中行 + /// + private DeviceTable _deviceTableSelectedItem; + + public DeviceTable deviceTableSelectedItem + { + get { return _deviceTableSelectedItem; } + set + { + if (_deviceTableSelectedItem == value) + return; + _deviceTableSelectedItem = value; + OnPropertyChanged("deviceTableSelectedItem"); + } + } + /// + /// 当前设备 + /// + private DeviceTable _device; + + public DeviceTable device + { + get { return _device; } + set + { + if (_device == value) + return; + _device = value; + OnPropertyChanged("device"); + } + } + /// + /// API 地址 + /// + public string ApiURL { get; set; } + #endregion + + #region 公有函数 + + + /// + /// 刷新 + /// + public void Refresh() + { + deviceTable.Clear(); + Inquire()?.OrderBy(o => int.Parse(o.ClientId)).ToList().ForEach(d => + { + if (int.Parse(d.ClientId) > 0) + { + deviceTable.Add(d); + } + }); + } + + /// + /// 根据客户端iD查询 + /// + /// + public List Inquire(string clientId = "") + { + try + { + string url = ApiURL + "/api/Device/Query"; + if (!string.IsNullOrEmpty(clientId)) url = ApiURL + "/api/Device/Query?clientId=" + clientId; + string json = HttpRequestHelper.HttpGetRequest(url); + JsonMsg> jsonMsg = Tools.JsonToObjectTools>>(json); + return jsonMsg.obj.data; + } + catch (Exception ex) + { + return null; + } + + } + + /// + /// 修改 + /// + /// + public bool Update() + { + try + { + string url = ApiURL + "/api/Device/Modify"; + string json = HttpRequestHelper.HttpPostRequest(url, Tools.JsonConvertTools(device)); + Refresh(); + return true; + } + catch (Exception ex) + { + return false; + } + + } + + /// + /// 增加 + /// + /// + public bool Add() + { + try + { + string url = ApiURL + "/api/Device/Create"; + string json = HttpRequestHelper.HttpPostRequest(url, Tools.JsonConvertTools(device)); + Refresh(); + return true; + } + catch (Exception ex) + { + return false; + } + + } + + public bool Add(DeviceTable deviceTable) + { + try + { + string url = ApiURL + "/api/Device/Create"; + string json = HttpRequestHelper.HttpPostRequest(url, Tools.JsonConvertTools(deviceTable)); + Refresh(); + return true; + } + catch (Exception ex) + { + return false; + } + + } + + /// + /// 删除 + /// + /// + public bool Delete() + { + try + { + string url = ApiURL + "/api/Device/DeleteDate?id=" + device.Id; + string json = HttpRequestHelper.HttpGetRequest(url); + Refresh(); + return true; + } + catch (Exception ex) + { + return false; + } + + } + #endregion + } +} diff --git a/BPASmartClient/Control/DataVView.xaml b/BPASmartClient/Control/DataVView.xaml new file mode 100644 index 00000000..12d0d2e0 --- /dev/null +++ b/BPASmartClient/Control/DataVView.xaml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + API查询地址: + + + + + + 客户端ID: + 1 + + + + + 客户端ID: + + + + + devicename: + + + + + productkey: + + + + + devicesecret: + + + + + 设备类型: + + + + + 经度: + + + + + 纬度: + + + + + 备注: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient/Control/DataVView.xaml.cs b/BPASmartClient/Control/DataVView.xaml.cs new file mode 100644 index 00000000..83c04c4f --- /dev/null +++ b/BPASmartClient/Control/DataVView.xaml.cs @@ -0,0 +1,122 @@ +using BPASmartClient.CustomResource.UserControls; +using BPASmartClient.CustomResource.UserControls.MessageShow; +using BPASmartClient.IoT; +using BPASmartClient.ViewModel; +using DataVAPI.Tool.IOT; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.Control +{ + /// + /// DataVView.xaml 的交互逻辑 + /// + public partial class DataVView : UserControl + { + public DataVView() + { + InitializeComponent(); + this.DataContext = DataVViewModel.GetInstance(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + if (sender is Button) + { + bool istrue = false; + Button button = sender as Button; + if (button.Tag != null) + { + switch (button.Tag.ToString()) + { + case "Add": + istrue = DataVViewModel.GetInstance().Add(); + if (istrue) NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, MainViewModel.GetInstance().window, "提示", $"增加成功!"); + else NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"增加失败!"); + break; + case "Update": + if (string.IsNullOrEmpty(DataVViewModel.GetInstance().device.Id)) + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"请先“查询”或者“双击右侧表格行”,修改之后在点击“修改”!"); + return; + } + istrue = DataVViewModel.GetInstance().Update(); + if (istrue) NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, MainViewModel.GetInstance().window, "提示", $"修改成功!"); + else NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"修改失败!"); + break; + case "Delete": + if (string.IsNullOrEmpty(DataVViewModel.GetInstance().device.Id)) + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"请先“查询”或者“双击右侧表格行”,修改之后在点击“删除”!"); + return; + } + istrue = DataVViewModel.GetInstance().Delete(); + if (istrue) NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, MainViewModel.GetInstance().window, "提示", $"删除成功!"); + else NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"删除失败!"); + break; + case "SetUrl": + DataVViewModel.GetInstance().ApiURL = apiurl.Text; + DataVViewModel.GetInstance().Refresh(); + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, MainViewModel.GetInstance().window, "提示", $"设置成功!"); + //MessageBox.Show("设置成功"); + break; + case "Inquire": + DataVViewModel.GetInstance().device = DataVViewModel.GetInstance().Inquire(chen.Text)?.FirstOrDefault(); + break; + case "Save": + System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + saveFileDialog.Filter = "txt文件(*.txt)|*.txt"; + if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + StreamWriter sw = File.CreateText(saveFileDialog.FileName); + sw.Write(Tools.JsonConvertTools(DataVViewModel.GetInstance().deviceTable)); //写入文件中 + sw.Flush();//清理缓冲区 + sw.Close();//关闭文件 + } + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, MainViewModel.GetInstance().window, "提示", $"导出设备成功,条数: {DataVViewModel.GetInstance().deviceTable.Count}!"); + break; + case "Insert": + System.Windows.Forms.OpenFileDialog file = new System.Windows.Forms.OpenFileDialog();//定义新的文件打开位置控件 + file.Filter = "txt文件(*.txt)|*.txt";//设置文件后缀的过滤 + if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)//如果有选择打开文件 + { + DeviceTable device = null; + FileStream fs = new FileStream(file.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8); //选择编码方式 + string str = sr.ReadToEnd(); + if (!string.IsNullOrEmpty(str)) + { + Tools.JsonToObjectTools>(str)?.ForEach(par => + { + DataVViewModel.GetInstance().Add(par); + }); + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, MainViewModel.GetInstance().window, "提示", $"插入设备成功,条数: {Tools.JsonToObjectTools>(str)?.Count}!"); + DataVViewModel.GetInstance().Refresh(); + } + } + + break; + } + } + } + } + + private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + DataVViewModel.GetInstance().device = DataVViewModel.GetInstance().deviceTableSelectedItem; + } + } +} diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index 79af5cea..52bd20cc 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -76,6 +76,12 @@ FontSize="12" Header="店铺设备配置" Tag="ShopDeviceConfigView" /> + + + Date: Mon, 16 May 2022 15:45:41 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LogOrAlarmViewModel.cs | 2 +- BPASmartClient.ViewModel/LogViewModel.cs | 146 +++++++++++++++++- BPASmartClient/Control/IOTView.xaml | 16 ++ BPASmartClient/Control/IOTView.xaml.cs | 29 ++++ BPASmartClient/Control/LogView.xaml | 12 +- BPASmartClient/MainWindow.xaml | 8 +- 6 files changed, 195 insertions(+), 18 deletions(-) create mode 100644 BPASmartClient/Control/IOTView.xaml create mode 100644 BPASmartClient/Control/IOTView.xaml.cs diff --git a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs index 7cff7fb1..6ed1ed0a 100644 --- a/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs +++ b/BPASmartClient.ViewModel/LogOrAlarmViewModel.cs @@ -132,7 +132,7 @@ namespace BPASmartClient.ViewModel BookExs.Add(new BookEx(new Book() { Name = "错误日志条件", Tag = "Error" }) { IsChecked = true }); BookExs.Add(new BookEx(new Book() { Name = "设备告警条件", Tag = "DeviceAlarm" }) { IsChecked = true }); SelectBookExs = new ObservableCollection(); - ItemPropertyChanged(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true },new PropertyChangedEventArgs("IsChecked")); + ItemPropertyChanged(new BookEx(new Book()) { IsChecked = true },new PropertyChangedEventArgs("IsChecked")); //查询 QueryCommand = new RelayCommand(() => { diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 5c5e2bb8..09088d00 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -1,12 +1,14 @@ using BPASmartClient.Helper; using BPASmartClient.IoT; using BPASmartClient.Message; +using BPASmartClient.Model; 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.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; @@ -26,6 +28,7 @@ namespace BPASmartClient.ViewModel #region 变量 public DispatcherTimer dispatcherTimer; public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); + public ObservableCollection LogDataGridData { get; set; } private ObservableCollection _LogModels;public ObservableCollection LogDataGrid { get @@ -68,6 +71,54 @@ namespace BPASmartClient.ViewModel OnPropertyChanged("TimedClear"); } } + private string _SelectedText = ""; + public string SelectedText + { + get + { + return _SelectedText; + } + set + { + if (_SelectedText == value) + return; + _SelectedText = value; + OnPropertyChanged("SelectedText"); + } + } + public ObservableCollection SelectBookExs { set; get; } + private ObservableCollection _books; + public ObservableCollection BookExs + { + get + { + if (_books == null) + { + _books = new ObservableCollection(); + + _books.CollectionChanged += (sender, e) => + { + if (e.OldItems != null) + { + foreach (BookEx bookEx in e.OldItems) + { + bookEx.PropertyChanged -= ItemPropertyChanged; + } + } + + if (e.NewItems != null) + { + foreach (BookEx bookEx in e.NewItems) + { + bookEx.PropertyChanged += ItemPropertyChanged; + } + } + }; + } + + return _books; + } + } #endregion #region 单一 @@ -85,14 +136,23 @@ namespace BPASmartClient.ViewModel /// public void Init() { - if (LogDataGrid == null) LogDataGrid = new ObservableCollection(); logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); + if (LogDataGrid == null) LogDataGrid = new ObservableCollection(); + if (LogDataGridData == null) LogDataGridData = new ObservableCollection(); + BookExs.Add(new BookEx(new Book() { Name = "一般日志", Tag = "Info" }) { IsChecked = true }); + BookExs.Add(new BookEx(new Book() { Name = "设备日志", Tag = "DeviceLog" }) { IsChecked = true }); + BookExs.Add(new BookEx(new Book() { Name = "错误日志", Tag = "Error" }) { IsChecked = true }); + BookExs.Add(new BookEx(new Book() { Name = "设备告警", Tag = "DeviceAlarm" }) { IsChecked = true }); + SelectBookExs = new ObservableCollection(); + ItemPropertyChanged(new BookEx(new Book()) { IsChecked = true }, new PropertyChangedEventArgs("IsChecked")); //一般日志 MessageLog.GetInstance.InfoNotify = new Action((s) => { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - LogDataGrid.Insert(0, new LogModel { message = s, type = "Info" }); + LogModel logModel = new LogModel { message = s, type = "Info" }; + LogDataGridData.Insert(0, logModel); + AddLog(logModel); logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s); })); }); @@ -101,7 +161,9 @@ namespace BPASmartClient.ViewModel { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" }); + LogModel logModel = new LogModel { message = s, type = "DeviceLog" }; + LogDataGridData.Insert(0, logModel); + AddLog(logModel); logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s); })); }); @@ -110,7 +172,9 @@ namespace BPASmartClient.ViewModel { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - LogDataGrid.Insert(0, new LogModel { message = id, type = "DeviceAlarm" }); + LogModel logModel = new LogModel { message = id, type = "DeviceAlarm" }; + LogDataGridData.Insert(0, logModel); + AddLog(logModel); logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); })); }); @@ -119,7 +183,9 @@ namespace BPASmartClient.ViewModel { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - LogDataGrid.Insert(0, new LogModel { message = s, type = "Error" }); + LogModel logModel = new LogModel { message = s, type = "Error" }; + LogDataGridData.Insert(0, logModel); + AddLog(logModel); logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s); DataVClient.GetInstance().HttpAddLog(new LogTable { @@ -154,9 +220,11 @@ namespace BPASmartClient.ViewModel { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - if (LogDataGrid.Count > 100) + if (LogDataGridData.Count > 200) { - LogDataGrid.RemoveAt(LogDataGrid.Count - 1); + LogModel logModel= LogDataGridData.Last(); + DeleteLog(logModel); + LogDataGridData.Remove(logModel); } })); @@ -164,6 +232,43 @@ namespace BPASmartClient.ViewModel dispatcherTimer.Interval = TimeSpan.FromSeconds(10); dispatcherTimer.Start(); } + /// + /// 增加日志 + /// + public void AddLog(LogModel logModel) + { + BookEx book= SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == logModel.type); + if (book != null) + { + LogDataGrid.Insert(0, logModel); + } + } + /// + /// 刷新日志 + /// + /// + public void RefreshLog() + { + LogDataGrid.Clear(); + LogDataGridData?.ToList().ForEach(b => { + + BookEx book = SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == b.type); + if (book != null) + { + LogDataGrid.Add(b); + } + }); + + } + /// + /// 删除日志 + /// + public void DeleteLog(LogModel logModel) + { + LogModel log= LogDataGrid?.ToList().Find(par => par == logModel); + if(log!=null) LogDataGrid.Remove(log); + } + /// /// 导出数据 /// @@ -210,6 +315,33 @@ namespace BPASmartClient.ViewModel System.Windows.MessageBox.Show("无数据!"); } + /// + /// 选中改变 + /// + /// + /// + private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "IsChecked") + { + BookEx bookEx = sender as BookEx; + + if (bookEx != null) + { + IEnumerable bookExs = BookExs.Where(b => b.IsChecked == true); + + StringBuilder builder = new StringBuilder(); + SelectBookExs.Clear(); + foreach (BookEx item in bookExs) + { + builder.Append(item.BookN.Name + ","); + SelectBookExs.Add((BookEx)item); + } + SelectedText = builder == null ? string.Empty : builder.ToString(); + RefreshLog(); + } + } + } #endregion #region Command diff --git a/BPASmartClient/Control/IOTView.xaml b/BPASmartClient/Control/IOTView.xaml new file mode 100644 index 00000000..a5c067cc --- /dev/null +++ b/BPASmartClient/Control/IOTView.xaml @@ -0,0 +1,16 @@ + + + + + diff --git a/BPASmartClient/Control/IOTView.xaml.cs b/BPASmartClient/Control/IOTView.xaml.cs new file mode 100644 index 00000000..96e3e884 --- /dev/null +++ b/BPASmartClient/Control/IOTView.xaml.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.Control +{ + /// + /// IOTView.xaml 的交互逻辑 + /// + public partial class IOTView : UserControl + { + public IOTView() + { + InitializeComponent(); + webView.Source = new Uri("http://iot.black-pa.com"); + } + } +} diff --git a/BPASmartClient/Control/LogView.xaml b/BPASmartClient/Control/LogView.xaml index dfa3fc63..28b1a173 100644 --- a/BPASmartClient/Control/LogView.xaml +++ b/BPASmartClient/Control/LogView.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:k="clr-namespace:BPASmartClient.Model;assembly=BPASmartClient.Model" xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel" xmlns:local="clr-namespace:BPASmartClient.Control" mc:Ignorable="d" @@ -25,8 +26,13 @@ - + + + + + + + @@ -54,7 +60,7 @@ - + diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index 52bd20cc..91442a31 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -102,17 +102,11 @@ Header="设备监视" Tag="DeviceMonitorView" /> - - + Tag="IOTView" /> From d3c53106717d7e63a1c65c4eb18d206f25cba2a5 Mon Sep 17 00:00:00 2001 From: fyf Date: Mon, 16 May 2022 15:50:16 +0800 Subject: [PATCH 5/7] 232 --- BPASmartClient.ViewModel/LogViewModel.cs | 4 ++-- BPASmartClient/Control/LogView.xaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 09088d00..0d137903 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -142,7 +142,7 @@ namespace BPASmartClient.ViewModel BookExs.Add(new BookEx(new Book() { Name = "一般日志", Tag = "Info" }) { IsChecked = true }); BookExs.Add(new BookEx(new Book() { Name = "设备日志", Tag = "DeviceLog" }) { IsChecked = true }); BookExs.Add(new BookEx(new Book() { Name = "错误日志", Tag = "Error" }) { IsChecked = true }); - BookExs.Add(new BookEx(new Book() { Name = "设备告警", Tag = "DeviceAlarm" }) { IsChecked = true }); + BookExs.Add(new BookEx(new Book() { Name = "告警日志", Tag = "DeviceAlarm" }) { IsChecked = true }); SelectBookExs = new ObservableCollection(); ItemPropertyChanged(new BookEx(new Book()) { IsChecked = true }, new PropertyChangedEventArgs("IsChecked")); //一般日志 @@ -334,7 +334,7 @@ namespace BPASmartClient.ViewModel SelectBookExs.Clear(); foreach (BookEx item in bookExs) { - builder.Append(item.BookN.Name + ","); + builder.Append(item.BookN.Name.Replace("日志","") + ","); SelectBookExs.Add((BookEx)item); } SelectedText = builder == null ? string.Empty : builder.ToString(); diff --git a/BPASmartClient/Control/LogView.xaml b/BPASmartClient/Control/LogView.xaml index 28b1a173..b32fd271 100644 --- a/BPASmartClient/Control/LogView.xaml +++ b/BPASmartClient/Control/LogView.xaml @@ -26,10 +26,10 @@ - + - + From 1f4f46061efecc9b1567531729de39989d595b91 Mon Sep 17 00:00:00 2001 From: fyf Date: Tue, 17 May 2022 10:13:39 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Themes/GenricStyle.xaml | 46 +++++++++++ BPASmartClient.Helper/AESHelper.cs | 80 +++++++++++++++++++ BPASmartClient/App.config | 5 +- BPASmartClient/Control/DataVView.xaml | 12 ++- BPASmartClient/Control/DataVView.xaml.cs | 27 ++++++- 5 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 BPASmartClient.Helper/AESHelper.cs diff --git a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml index 8561efb6..f82209c3 100644 --- a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml @@ -123,6 +123,52 @@ + + + +