From d54eb8816ecb8e6ed46ede1c81f455bc3eaa8e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Mon, 16 May 2022 09:47:49 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecDictionarys/GlobalStyle.xaml | 12 +- BPASmartClient/App.config | 14 +- BPASmartClient/App.xaml | 2 + .../Control/ShopDeviceConfigView.xaml | 1399 ++++++++--------- BPASmartClient/DeviceInfo.xml | 2 +- BPASmartClient/MainWindow.xaml | 2 +- 6 files changed, 686 insertions(+), 745 deletions(-) diff --git a/BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml b/BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml index 2426ffba..8b6a4b0d 100644 --- a/BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml +++ b/BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml @@ -4,5 +4,15 @@ xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters"> - + + + + + + + + + + + \ No newline at end of file diff --git a/BPASmartClient/App.config b/BPASmartClient/App.config index 2fb2713f..1caea14f 100644 --- a/BPASmartClient/App.config +++ b/BPASmartClient/App.config @@ -3,7 +3,7 @@ - + @@ -16,8 +16,10 @@ - - --> + --> + + + @@ -37,10 +39,10 @@ - - + + - + diff --git a/BPASmartClient/App.xaml b/BPASmartClient/App.xaml index 29cb2e65..a85b3559 100644 --- a/BPASmartClient/App.xaml +++ b/BPASmartClient/App.xaml @@ -13,6 +13,8 @@ + + diff --git a/BPASmartClient/Control/ShopDeviceConfigView.xaml b/BPASmartClient/Control/ShopDeviceConfigView.xaml index 358590c6..a242d89d 100644 --- a/BPASmartClient/Control/ShopDeviceConfigView.xaml +++ b/BPASmartClient/Control/ShopDeviceConfigView.xaml @@ -7,8 +7,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pry="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource" xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel" - d:DesignHeight="450" - d:DesignWidth="800" + d:DesignHeight="900" + d:DesignWidth="1200" mc:Ignorable="d"> @@ -19,6 +19,7 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -72,193 +323,204 @@ - - + - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + + + + + + + + + + - - - + FontSize="20" + Foreground="#ff23caca" + IsEditable="False" + ItemsSource="{Binding ClientDevices}" + SelectedIndex="0" + Style="{StaticResource ComboBoxStyle}" + Text="{Binding ClientDeviceType}" /> - + - - + - - - - - + - - - - + - + - - + + + + 客户端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 06/14] =?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 07/14] 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 08/14] =?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 @@ + + + + + --> + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - @@ -511,6 +513,20 @@ + + + + + + Text="{Binding deviceConfig[0].ShopName}" /> + Text="{Binding deviceConfig[0].ShopId}" /> - + @@ -584,7 +600,7 @@ Margin="0" HorizontalAlignment="Left" Style="{StaticResource TextBoxStyle}" - Text="255.255.255.255" /> + Text="{Binding SelectedValue.DeviceName, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.DeviceId, ElementName=tv, Mode=TwoWay}" /> - + @@ -623,7 +639,7 @@ Width="170" HorizontalAlignment="Left" Style="{StaticResource TextBoxStyle}" - Text="{Binding Path=Device.IP}" /> + Text="{Binding SelectedValue.communicationPar.IPAddress, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.IPPort, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.StationNo, ElementName=tv, Mode=TwoWay}" /> @@ -657,7 +673,7 @@ + Visibility="{Binding SelectedValue.communicationPar.CommunicationType, ElementName=tv, Mode=TwoWay, Converter={StaticResource VisibleTypeConverter}, ConverterParameter=SerialPort}"> @@ -694,7 +710,7 @@ ItemsSource="{Binding Path=Device.Ports}" SelectedIndex="0" Style="{StaticResource ComboBoxStyle}" - Text="{Binding Path=Device.ComSerialPort}" /> + Text="{Binding SelectedValue.communicationPar.SerialPort, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.BaudRate, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.Parity, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.DataBits, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.StopBits, ElementName=tv, Mode=TwoWay}" /> + Text="{Binding SelectedValue.communicationPar.StationNo, ElementName=tv, Mode=TwoWay}" /> diff --git a/BPASmartClient/Control/ShopDeviceConfigView.xaml.cs b/BPASmartClient/Control/ShopDeviceConfigView.xaml.cs index 2cb92a67..c30ebd46 100644 --- a/BPASmartClient/Control/ShopDeviceConfigView.xaml.cs +++ b/BPASmartClient/Control/ShopDeviceConfigView.xaml.cs @@ -13,6 +13,8 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using BPASmartClient.DialogWindow; +using BPASmartClient.ViewModel; +using BPASmartClient.ViewModel.Model; namespace BPASmartClient.Control { @@ -31,5 +33,67 @@ namespace BPASmartClient.Control NewShopWindow newShopWindow = new NewShopWindow(); newShopWindow.ShowDialog(); } + + private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) + { + + Refresh(); + } + + private void tv_MouseRightButtonDown(object sender, MouseButtonEventArgs e) + { + //if (e.ButtonState == MouseButtonState.Pressed) + //{ + // Refresh(); + //} + } + + private void Refresh() + { + if (this.tv.SelectedValue is DeviceConfigModel deviceConfigModel) + { + //ShopDeviceConfigViewModel.ShopName = deviceConfigModel.ShopName; + } + else if (this.tv.SelectedValue is DeviceModel deviceModel) + { + ShopDeviceConfigViewModel.DeviceParVisibility = Visibility.Visible; + ShopDeviceConfigViewModel.CommunicationVisibility = Visibility.Hidden; + //ShopDeviceConfigViewModel.DeviceName = deviceModel.DeviceName; + } + else if (this.tv.SelectedValue is CommunicationModel communicationModel) + { + ShopDeviceConfigViewModel.CommunicationVisibility = Visibility.Visible; + ShopDeviceConfigViewModel.DeviceParVisibility = Visibility.Hidden; + //ShopDeviceConfigViewModel.CommunicationName = communicationModel.CommunicationName; + //ShopDeviceConfigViewModel.DeviceModelId = communicationModel.DeviceModelId; + } + } + + private void tv_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) + { + + } + + private void DeviceInfo(object sender, MouseButtonEventArgs e) + { + var tb = sender as TextBlock; + if (tb != null) + { + //ShopDeviceConfigViewModel.DeviceName = tb.Text.Trim(); + //tb.Background = Brushes.Blue; + } + } + private void CommunicationInfo(object sender, MouseButtonEventArgs e) + { + //var tb = sender as TextBlock; + //if (tb != null) + //{ + // ShopDeviceConfigViewModel.CommunicationName = tb.Text.Trim(); + // ShopDeviceConfigViewModel.DeviceModelId = tb.Tag.ToString(); + // tb.Focus(); + // //tb.Background = Brushes.Blue; + + //} + } } } diff --git a/BPASmartClient/DeviceInfo.xml b/BPASmartClient/DeviceInfo.xml index 48d28f7c..89e636c8 100644 --- a/BPASmartClient/DeviceInfo.xml +++ b/BPASmartClient/DeviceInfo.xml @@ -38,7 +38,7 @@ --> - + diff --git a/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj b/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj index e444219e..0dcf2236 100644 --- a/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj +++ b/HBLConsole.MORKIC/BPASmartClient.MORKIC.csproj @@ -5,7 +5,7 @@ - + From 338de893cdcd5f8a590f0803cd11ecc9cdaac598 Mon Sep 17 00:00:00 2001 From: fyf Date: Wed, 18 May 2022 13:48:32 +0800 Subject: [PATCH 11/14] 6 --- BPASmartClient/Control/DataVView.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BPASmartClient/Control/DataVView.xaml.cs b/BPASmartClient/Control/DataVView.xaml.cs index 3ffd3018..d0067c42 100644 --- a/BPASmartClient/Control/DataVView.xaml.cs +++ b/BPASmartClient/Control/DataVView.xaml.cs @@ -44,7 +44,7 @@ namespace BPASmartClient.Control dispatcherTimer.Stop(); })); }; - dispatcherTimer.Interval = TimeSpan.FromSeconds(20); + dispatcherTimer.Interval = TimeSpan.FromSeconds(120); } From b27c0a2b45049024016bcafa5d3fc1a46dd2baf0 Mon Sep 17 00:00:00 2001 From: fyf Date: Wed, 18 May 2022 16:07:19 +0800 Subject: [PATCH 12/14] 3232 --- .../Themes/MyStyle.xaml | 64 ++++++++++++++++++- BPASmartClient/Control/DataVView.xaml | 12 ++-- BPASmartClient/MainWindow.xaml | 16 ++--- 3 files changed, 74 insertions(+), 18 deletions(-) diff --git a/BPASmartClient.CustomResource/Themes/MyStyle.xaml b/BPASmartClient.CustomResource/Themes/MyStyle.xaml index 5a02829c..eee7a413 100644 --- a/BPASmartClient.CustomResource/Themes/MyStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/MyStyle.xaml @@ -957,7 +957,67 @@ - + + + - - - - + + + @@ -584,7 +592,7 @@ - + diff --git a/BPASmartClient.Device/BPASmartClient.Device.csproj b/BPASmartClient.Device/BPASmartClient.Device.csproj index 3164a1d8..3f4f0b9f 100644 --- a/BPASmartClient.Device/BPASmartClient.Device.csproj +++ b/BPASmartClient.Device/BPASmartClient.Device.csproj @@ -2,6 +2,8 @@ net6.0 + bin\ + portable diff --git a/BPASmartClient.Helper/ActionManage.cs b/BPASmartClient.Helper/ActionManage.cs index ba2f19c6..e9a8a7dd 100644 --- a/BPASmartClient.Helper/ActionManage.cs +++ b/BPASmartClient.Helper/ActionManage.cs @@ -72,13 +72,13 @@ namespace BPASmartClient.Helper if (actions.ContainsKey(key)) if (par == null) { - if (actions[key].FuncObj != null) - return actions[key].FuncObj; + //if (actions[key].FuncObj != null) + return actions[key].FuncObj?.Invoke(); } else { - if (actions[key].FuncPar != null) - return actions[key].FuncPar(par); + //if (actions[key].FuncPar != null) + return actions[key].FuncPar?.Invoke(par); } return default; } diff --git a/BPASmartClient.Helper/ExpandMethod.cs b/BPASmartClient.Helper/ExpandMethod.cs index f0d1ccac..97336f6e 100644 --- a/BPASmartClient.Helper/ExpandMethod.cs +++ b/BPASmartClient.Helper/ExpandMethod.cs @@ -41,11 +41,13 @@ namespace BPASmartClient.Helper /// 委托回调 public static void Invoke(this Action action, Action callback) { - if (action != null) - { - action(); - if (callback != null) callback(); - } + action?.Invoke(); + callback?.Invoke(); + //if (action != null) + //{ + // action(); + // if (callback != null) callback(); + //} } /// @@ -56,20 +58,24 @@ namespace BPASmartClient.Helper /// 委托回调 public static void Invoke(this Action action, object par, Action callback) { - if (action != null) - { - action(par); - if (callback != null) callback(); - } + action?.Invoke(par); + callback?.Invoke(); + //if (action != null) + //{ + // action(par); + // if (callback != null) callback(); + //} } public static void Invokes(this Action action, object[] par, Action callback) { - if (action != null) - { - action(par); - if (callback != null) callback(); - } + action?.Invoke(par); + callback?.Invoke(); + //if (action != null) + //{ + // action(par); + // if (callback != null) callback(); + //} } diff --git a/BPASmartClient.Helper/LocaPath.cs b/BPASmartClient.Helper/LocaPath.cs index afc71e39..ccd14562 100644 --- a/BPASmartClient.Helper/LocaPath.cs +++ b/BPASmartClient.Helper/LocaPath.cs @@ -7,10 +7,8 @@ using System.Threading.Tasks; namespace BPASmartClient.Helper { - public class LocaPath:Singleton + public class LocaPath : Singleton { - - public string FilePath { get; set; } = string.Empty; public string Getpath(string name) @@ -19,5 +17,14 @@ namespace BPASmartClient.Helper return $"{AppDomain.CurrentDomain.BaseDirectory}{FilePath}JSON\\{name}.json"; } + public string GetDeviceConfigPath + { + get + { + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DeviceConfig")); + return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceConfig\\"; + } + } + } } diff --git a/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj b/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj index 69f50a3d..04bceac9 100644 --- a/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj +++ b/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj @@ -5,7 +5,7 @@ - + diff --git a/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj b/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj index dbc15171..b4b46ffa 100644 --- a/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj +++ b/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj @@ -2,6 +2,8 @@ net6.0 + bin\ + portable diff --git a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj index e39ff09d..09946d55 100644 --- a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj +++ b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj @@ -4,6 +4,8 @@ net6.0 enable enable + bin\ + portable diff --git a/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj b/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj index ce6a7f77..11f083b1 100644 --- a/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj +++ b/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj @@ -2,6 +2,8 @@ net6.0 + bin\ + portable diff --git a/BPASmartClient.MorkS/Control.cs b/BPASmartClient.MorkS/Control_Morks.cs similarity index 92% rename from BPASmartClient.MorkS/Control.cs rename to BPASmartClient.MorkS/Control_Morks.cs index b788434d..ae2ac5b7 100644 --- a/BPASmartClient.MorkS/Control.cs +++ b/BPASmartClient.MorkS/Control_Morks.cs @@ -17,7 +17,7 @@ using System.Reflection; namespace BPASmartClient.MorkS { - public class Control : BaseDevice + public class Control_Morks : BaseDevice { public override DeviceClientType DeviceType => DeviceClientType.MORKS; GVL_MORKS mORKS = new GVL_MORKS(); @@ -223,16 +223,19 @@ namespace BPASmartClient.MorkS mORKS.AllowRun = mORKS.InitComplete; //IsHealth = mORKS.Error && mORKS.InitComplete; IsHealth = true; - TakeBowlTask(); - TakeNoodleTask(); + if (mORKS.AllowRun) + { + TakeBowlTask(); - OutNoodleTask(); + TakeNoodleTask(); - SingleDetect(); + OutNoodleTask(); - TurntableControl(); + SingleDetect(); + TurntableControl(); + } } @@ -245,11 +248,39 @@ namespace BPASmartClient.MorkS { if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) { - mORKS.TakeBowlId = orderLocInfo.SuborderId; - TakeBowlControl(orderLocInfo.Loc); - SetRecipeNumber(orderLocInfo.RecipeNumber); - OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING); - DeviceProcessLogShow($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]"); + ushort BowLoc = 0; + var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == orderLocInfo.BatchingId).ToList(); + if (res != null) + { + foreach (var item in res) + { + if (ushort.TryParse(item.BatchingLoc, out ushort loc)) + { + if (loc == 10 && alarm.Supply1_LossBowl) + { + BowLoc = loc; + break; + } + else if (loc == 11 && alarm.Supply2_LossBowl) + { + BowLoc = loc; + break; + } + } + + } + } + + if (BowLoc >= 10 && BowLoc <= 11) + { + mORKS.TakeBowlId = orderLocInfo.SuborderId; + //TakeBowlControl(orderLocInfo.Loc); + TakeBowlControl(BowLoc); + SetRecipeNumber(orderLocInfo.RecipeNumber); + OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING); + DeviceProcessLogShow($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]"); + } + } mORKS.TakeBowlInterlock = true; } diff --git a/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj b/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj index 288c5e34..efbf696e 100644 --- a/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj +++ b/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj @@ -2,6 +2,7 @@ net6.0 + D:\HBL\Porgram\BPASmartClient\BPASmartClient\bin\Debug\net6.0-windows\Devices diff --git a/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj b/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj index b99aa4f8..69df2f85 100644 --- a/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj +++ b/BPASmartClient.ViewModel/BPASmartClient.ViewModel.csproj @@ -8,6 +8,8 @@ + + diff --git a/BPASmartClient.ViewModel/MainViewModel.cs b/BPASmartClient.ViewModel/MainViewModel.cs index 60990cc7..bef488e8 100644 --- a/BPASmartClient.ViewModel/MainViewModel.cs +++ b/BPASmartClient.ViewModel/MainViewModel.cs @@ -52,7 +52,7 @@ namespace BPASmartClient.ViewModel public MainViewModel() { - IsAlarm =new AlarmModel(); + IsAlarm = new AlarmModel(); OrderStatusViewModel.Init(); //设备告警日志 MessageLog.GetInstance.AlarmLogNotify = new Action(() => @@ -75,6 +75,12 @@ namespace BPASmartClient.ViewModel dispatcherTimer.Interval = TimeSpan.FromSeconds(1); dispatcherTimer.Start(); } + + + public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } } + + + } public class AlarmModel : ObservableObject @@ -118,7 +124,7 @@ namespace BPASmartClient.ViewModel public AlarmModel() { - + } } } diff --git a/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs b/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs index f6f699f3..cf5977b8 100644 --- a/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs +++ b/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using System.Collections.ObjectModel; using Microsoft.Toolkit.Mvvm.Input; +using System.Windows; namespace BPASmartClient.ViewModel.Model { @@ -96,12 +97,29 @@ namespace BPASmartClient.ViewModel.Model /// public class CommunicationPar : ObservableObject { + ///// + ///// 通讯类型,false:串口,true:网口 + ///// + //public bool CommunicationType { get { return _mCommunicationType; } set { _mCommunicationType = value; OnPropertyChanged(); } } + //private bool _mCommunicationType; + + /// + /// 选择网口通讯 + /// + public bool IsNetworkPort { get { return _mIsNetworkPort; } set { _mIsNetworkPort = value; OnPropertyChanged(); } } + private bool _mIsNetworkPort = false; + /// - /// 通讯类型,false:串口,true:网口 + /// 选择串口通讯 /// - public bool CommunicationType { get { return _mCommunicationType; } set { _mCommunicationType = value; OnPropertyChanged(); } } - private bool _mCommunicationType; + public bool IsSerialPort { get { return _mIsSerialPort; } set { _mIsSerialPort = value; OnPropertyChanged(); } } + private bool _mIsSerialPort = true; + //public Visibility NetworkVisibility { get { return _mNetworkVisibility; } set { _mNetworkVisibility = value; OnPropertyChanged(); } } + //private Visibility _mNetworkVisibility = Visibility.Collapsed; + + //public Visibility SerialVisibility { get { return _mSerialVisibility; } set { _mSerialVisibility = value; OnPropertyChanged(); } } + //private Visibility _mSerialVisibility = Visibility.Visible; /// /// IP地址 @@ -138,13 +156,13 @@ namespace BPASmartClient.ViewModel.Model /// 数据位 /// public int DataBits { get { return _mDataBits; } set { _mDataBits = value; OnPropertyChanged(); } } - private int _mDataBits; + private int _mDataBits = 8; /// /// 停止位 /// public string StopBits { get { return _mStopBits; } set { _mStopBits = value; OnPropertyChanged(); } } - private string _mStopBits; + private string _mStopBits = "1"; /// /// 校验位 @@ -152,37 +170,22 @@ namespace BPASmartClient.ViewModel.Model public string Parity { get { return _mParity; } set { _mParity = value; OnPropertyChanged(); } } private string _mParity; + public ObservableCollection variables { get; set; } = new ObservableCollection(); } - //public enum CommunicationParType - //{ - // /// - // /// IP地址 - // /// - // IPAddress, - // /// - // /// 端口号 - // /// - // Port, - // /// - // /// 串口端口号 - // /// - // SerialPort, - // /// - // /// 波特率 - // /// - // BaudRate, - // /// - // /// 数据位 - // /// - // DataBits, - // /// - // /// 停止位 - // /// - // StopBits, - // /// - // /// 校验位 - // /// - // Parity, - //} + public class Variable : ObservableObject + { + public int Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } } + private int _mId; + + + public string Address { get { return _mAddress; } set { _mAddress = value; OnPropertyChanged(); } } + private string _mAddress; + + + public int ReadLeng { get { return _mReadLeng; } set { _mReadLeng = value; OnPropertyChanged(); } } + private int _mReadLeng; + + + } } diff --git a/BPASmartClient.ViewModel/NewShopWindowModel.cs b/BPASmartClient.ViewModel/NewShopWindowModel.cs index cef93844..49787d3b 100644 --- a/BPASmartClient.ViewModel/NewShopWindowModel.cs +++ b/BPASmartClient.ViewModel/NewShopWindowModel.cs @@ -7,23 +7,32 @@ using BPASmartClient.Helper; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using Microsoft.Toolkit.Mvvm.Messaging; +using System.Windows; +using System.IO; namespace BPASmartClient.ViewModel { public class NewShopWindowModel : ObservableObject { + public NewShopWindowModel() { - CloseWindowCommand = new RelayCommand(() => { WeakReferenceMessenger.Default.Send("", "CloseWindow"); }); - CancelCommand = new RelayCommand(() => { WeakReferenceMessenger.Default.Send("", "CloseWindow"); }); + CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("CloseWindow"); }); DefineCommand = new RelayCommand(() => { + DirectoryInfo directoryInfo = new DirectoryInfo(LocaPath.GetInstance().GetDeviceConfigPath); + var files = directoryInfo.GetFiles(); + if (files != null && files.FirstOrDefault(p => p.FullName.Contains(ShopName)) != null) + { + ErrorInfo = "已存在该店铺,请重新输入!"; + return; + } ActionManage.GetInstance.Send("ShopPar", new string[] { ShopName, ShopId }); - WeakReferenceMessenger.Default.Send("", "CloseWindow"); + ActionManage.GetInstance.Send("OkCloseWindow"); }); } - public RelayCommand CloseWindowCommand { get; set; } + //public RelayCommand CloseWindowCommand { get; set; } public RelayCommand CancelCommand { get; set; } @@ -35,6 +44,10 @@ namespace BPASmartClient.ViewModel public string ShopId { get { return _mShopId; } set { _mShopId = value; OnPropertyChanged(); } } private string _mShopId; + public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } } + private string _mErrorInfo; + + } diff --git a/BPASmartClient.ViewModel/ShopDeviceConfigViewModel.cs b/BPASmartClient.ViewModel/ShopDeviceConfigViewModel.cs index a919b862..b5041e8b 100644 --- a/BPASmartClient.ViewModel/ShopDeviceConfigViewModel.cs +++ b/BPASmartClient.ViewModel/ShopDeviceConfigViewModel.cs @@ -11,12 +11,16 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; +using System.IO.Ports; +using System.IO; +using Newtonsoft.Json; namespace BPASmartClient.ViewModel { public class ShopDeviceConfigViewModel : ObservableObject { private DeviceConfigModel configModel = new DeviceConfigModel(); + string FileName => deviceConfig.Count > 0 ? deviceConfig[0].ShopName : string.Empty; public ShopDeviceConfigViewModel() { @@ -28,6 +32,7 @@ namespace BPASmartClient.ViewModel { configModel.ShopName = par[0]; configModel.ShopId = par[1]; + deviceConfig.Clear(); deviceConfig.Add(configModel); } } @@ -37,8 +42,19 @@ namespace BPASmartClient.ViewModel RemoveDeviceCommand = new RelayCommand(RemoveDevice); NewCommunicationCommand = new RelayCommand(NewCommunication); RemoveCommunicationCommand = new RelayCommand(RemoveCommunication); + + DataListInit(); + + SaveData = new Action(() => + { + if (deviceConfig.Count > 0) + { + File.WriteAllText($"{LocaPath.GetInstance().GetDeviceConfigPath}{FileName}.json", JsonConvert.SerializeObject(deviceConfig)); + } + }); } + #region 右键菜单按钮操作 private void RemoveCommunication(object? obj) { if (obj != null && obj is CommunicationModel com) @@ -78,7 +94,7 @@ namespace BPASmartClient.ViewModel { CommunicationName = $"Communication_{num}", DeviceModelId = deviceConfig.ElementAt(0).deviceModels.FirstOrDefault(p => p.DeviceName == dm.DeviceName)?.Id, - communicationPar = new CommunicationPar() { CommunicationType = false } + communicationPar = new CommunicationPar() { IsNetworkPort = false } }); break; @@ -120,97 +136,9 @@ namespace BPASmartClient.ViewModel } } } + #endregion - - public static event EventHandler StaticPropertyChanged; - private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "") - { - StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName)); - } - - - //public static string DeviceNamePar - //{ - // get { return _mDeviceNamePar; } - // set - // { - // _mDeviceNamePar = value; - // if (deviceConfig.Count == 1) - // { - // int index = Array.FindIndex(deviceConfig.ElementAt(0).deviceModels.ToArray(), p => p.DeviceName == DeviceName); - // if (index >= 0 && index < deviceConfig.ElementAt(0).deviceModels.Count) - // { - // deviceConfig.ElementAt(0).deviceModels.ElementAt(index).DeviceName = value; - // } - // } - // OnStaticPropertyChanged(); - // } - //} - //private static string _mDeviceNamePar; - - //public static string DeviceIdPar - //{ - // get { return _mDeviceIdPar; } - // set - // { - // _mDeviceIdPar = value; - // if (deviceConfig.Count == 1) - // { - // int index = Array.FindIndex(deviceConfig.ElementAt(0).deviceModels.ToArray(), p => p.DeviceName == DeviceName); - // if (index >= 0 && index < deviceConfig.ElementAt(0).deviceModels.Count) - // { - // deviceConfig.ElementAt(0).deviceModels.ElementAt(index).DeviceId = value; - // } - // } - // OnStaticPropertyChanged(); - // } - //} - //private static string _mDeviceIdPar; - - public static Visibility DeviceParVisibility { get { return _mDeviceParVisibility; } set { _mDeviceParVisibility = value; OnStaticPropertyChanged(); } } - private static Visibility _mDeviceParVisibility = Visibility.Hidden; - public static Visibility CommunicationVisibility { get { return _mCommunicationVisibility; } set { _mCommunicationVisibility = value; OnStaticPropertyChanged(); } } - private static Visibility _mCommunicationVisibility = Visibility.Hidden; - - - - - //public static string DeviceModelId - //{ - // get { return _mDeviceModelId; } - // set - // { - // _mDeviceModelId = value; - - // } - //} - //private static string _mDeviceModelId; - - - //public static string DeviceName - //{ - // get { return _mDeviceName; } - // set - // { - // _mDeviceName = value; - // if (deviceConfig.Count == 1) - // { - // var res = deviceConfig.ElementAt(0).deviceModels.FirstOrDefault(p => p.DeviceName == value); - // if (res != null) - // { - // DeviceIdPar = res.DeviceId; - // DeviceNamePar = res.DeviceName; - // } - // } - // } - //} - //private static string _mDeviceName; - - - //public static string CommunicationName { get; set; } - - - + #region Command /// /// 新建设备 /// @@ -231,8 +159,81 @@ namespace BPASmartClient.ViewModel /// public RelayCommand RemoveCommunicationCommand { get; set; } + public Action SaveData { get; set; } + #endregion + + #region 列表集合 + /// + /// 设备信息列表 + /// public static ObservableCollection deviceConfig { get; set; } = new ObservableCollection(); + /// + /// 端口号列表 + /// + public static ObservableCollection Ports { get; set; } = new ObservableCollection(); + + /// + /// 波特率列表 + /// + public static ObservableCollection BaudRates { get; set; } = new ObservableCollection(); + + /// + /// 奇偶校验列表 + /// + public static ObservableCollection Paritys { get; set; } = new ObservableCollection(); + + /// + /// 设备模块 + /// + public static ObservableCollection DeviceModels { get; set; } = new ObservableCollection(); + + /// + /// 通讯模块 + /// + public static ObservableCollection CommunicationModel { get; set; } = new ObservableCollection(); + + /// + /// 店铺集合 + /// + public static ObservableCollection Shops { get; set; } = new ObservableCollection(); + + private void DataListInit() + { + Ports.Clear(); + SerialPort.GetPortNames().ToList().ForEach((item) => { Ports.Add(item); }); + + BaudRates.Clear(); + int[] rb = new int[] { 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 43000, 57600, 76800, 115200 }; + rb.ToList().ForEach((item) => { BaudRates.Add(item); }); + + Paritys.Clear(); + Enum.GetNames(typeof(Parity)).ToList().ForEach((item) => { Paritys.Add(item); }); + + DeviceModels.Clear(); + DeviceModels.Add("Morks"); + DeviceModels.Add("Morkt"); + DeviceModels.Add("Morkic"); + DeviceModels.Add("Morkjc"); + + CommunicationModel.Clear(); + CommunicationModel.Add("乐百"); + CommunicationModel.Add("节卡"); + CommunicationModel.Add("单片机"); + CommunicationModel.Add("咖啡机"); + CommunicationModel.Add("冰淇淋机"); + + Shops.Clear(); + DirectoryInfo directoryInfo = new DirectoryInfo(LocaPath.GetInstance().GetDeviceConfigPath); + var files = directoryInfo.GetFiles(); + foreach (var item in files) + { + var res = Path.GetFileNameWithoutExtension(item.FullName); + if (res != null && res.Length > 0 && item.FullName.Contains("json")) Shops.Add(res); + } + } + #endregion + } diff --git a/BPASmartClient/App.config b/BPASmartClient/App.config index fd222222..0b7359ac 100644 --- a/BPASmartClient/App.config +++ b/BPASmartClient/App.config @@ -3,7 +3,7 @@ - + @@ -12,16 +12,19 @@ - + + + + - - - - + + + + @@ -48,10 +54,10 @@ - + - + diff --git a/BPASmartClient/Control/ShopDeviceConfigView.xaml b/BPASmartClient/Control/ShopDeviceConfigView.xaml index 11d18b8a..b114f896 100644 --- a/BPASmartClient/Control/ShopDeviceConfigView.xaml +++ b/BPASmartClient/Control/ShopDeviceConfigView.xaml @@ -27,6 +27,16 @@ + + - --> - @@ -473,36 +472,25 @@ Header="删除通讯" /> - - - + - - - - + + + + - + @@ -514,17 +502,26 @@ + Columns="2" + Visibility="Collapsed"> + Foreground="{StaticResource TextBlockForeground}" + IsChecked="{Binding SelectedValue.communicationPar.IsNetworkPort, ElementName=tv, Mode=TwoWay}" /> + + Foreground="{StaticResource TextBlockForeground}" + IsChecked="{Binding SelectedValue.communicationPar.IsSerialPort, ElementName=tv, Mode=TwoWay}" /> + - - - + + @@ -584,9 +584,9 @@ FontSize="20" Foreground="#ff23caca" IsEditable="False" - ItemsSource="{Binding Path=Device.PlcTypes}" + ItemsSource="{Binding DeviceModels}" Style="{StaticResource ComboBoxStyle}" - Text="{Binding Path=Device.PlcType}" /> + Text="{Binding SelectedValue.DeviceModule, ElementName=tv, Mode=TwoWay}" /> + - + @@ -671,9 +675,10 @@ + Visibility="Collapsed"> @@ -707,7 +712,7 @@ FontSize="20" Foreground="#ff23caca" IsEditable="False" - ItemsSource="{Binding Path=Device.Ports}" + ItemsSource="{Binding Ports}" SelectedIndex="0" Style="{StaticResource ComboBoxStyle}" Text="{Binding SelectedValue.communicationPar.SerialPort, ElementName=tv, Mode=TwoWay}" /> @@ -730,7 +735,7 @@ FontSize="20" Foreground="#ff23caca" IsEditable="False" - ItemsSource="{Binding Path=Device.BaudRates}" + ItemsSource="{Binding BaudRates}" SelectedIndex="0" Style="{StaticResource ComboBoxStyle}" Text="{Binding SelectedValue.communicationPar.BaudRate, ElementName=tv, Mode=TwoWay}" /> @@ -753,7 +758,7 @@ FontSize="20" Foreground="#ff23caca" IsEditable="False" - ItemsSource="{Binding Path=Device.Paritys}" + ItemsSource="{Binding Paritys}" SelectedIndex="0" Style="{StaticResource ComboBoxStyle}" Text="{Binding SelectedValue.communicationPar.Parity, ElementName=tv, Mode=TwoWay}" /> @@ -802,8 +807,77 @@ + + + + + + + + + + + + + + + + + + + + - + @@ -850,7 +924,7 @@ Grid.Row="1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> - + @@ -860,28 +934,35 @@ + - - - - - + HorizontalAlignment="Center" + VerticalAlignment="Center" + Background="Transparent" + FontSize="14" + Foreground="{StaticResource TitleBorderColor}" + Text="{Binding Id}" /> + + + - + Width="400" + HorizontalAlignment="Left" + Style="{StaticResource InputTextboxStyle}" + Text="{Binding ReadLeng}" /> e) @@ -40,60 +49,120 @@ namespace BPASmartClient.Control Refresh(); } - private void tv_MouseRightButtonDown(object sender, MouseButtonEventArgs e) - { - //if (e.ButtonState == MouseButtonState.Pressed) - //{ - // Refresh(); - //} - } - private void Refresh() { if (this.tv.SelectedValue is DeviceConfigModel deviceConfigModel) { - //ShopDeviceConfigViewModel.ShopName = deviceConfigModel.ShopName; } else if (this.tv.SelectedValue is DeviceModel deviceModel) { - ShopDeviceConfigViewModel.DeviceParVisibility = Visibility.Visible; - ShopDeviceConfigViewModel.CommunicationVisibility = Visibility.Hidden; - //ShopDeviceConfigViewModel.DeviceName = deviceModel.DeviceName; + this.Device.Visibility = Visibility.Visible; + this.CommType.Visibility = Visibility.Collapsed; + this.VarTab.Visibility = Visibility.Collapsed; + this.Serial.Visibility = Visibility.Collapsed; + this.Network.Visibility = Visibility.Collapsed; + this.GridCommunication.Visibility = Visibility.Collapsed; } else if (this.tv.SelectedValue is CommunicationModel communicationModel) { - ShopDeviceConfigViewModel.CommunicationVisibility = Visibility.Visible; - ShopDeviceConfigViewModel.DeviceParVisibility = Visibility.Hidden; - //ShopDeviceConfigViewModel.CommunicationName = communicationModel.CommunicationName; - //ShopDeviceConfigViewModel.DeviceModelId = communicationModel.DeviceModelId; + this.Device.Visibility = Visibility.Collapsed; + this.CommType.Visibility = Visibility.Visible; + this.VarTab.Visibility = Visibility.Visible; + this.GridCommunication.Visibility = Visibility.Visible; + this.Serial.Visibility = (bool)this.rbSerial.IsChecked ? Visibility.Visible : Visibility.Collapsed; + this.Network.Visibility = (bool)this.rbNetwork.IsChecked ? Visibility.Visible : Visibility.Collapsed; + + + if (ShopDeviceConfigViewModel.deviceConfig.Count > 0) + { + int index = Array.FindIndex(ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.ToArray(), p => p.Id == communicationModel.DeviceModelId); + if (index >= 0 && index < ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.Count) + { + int commIndex = Array.FindIndex(ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.ElementAt(index).communicationDevcies.ToArray(), p => p.DeviceModelId == communicationModel.DeviceModelId); + if (commIndex >= 0 && commIndex < ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.ElementAt(index).communicationDevcies.Count) + { + if (ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.ElementAt(index).communicationDevcies.ElementAt(commIndex).communicationPar.variables.Count <= 0) + { + for (int i = 0; i < 20; i++) + { + ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.ElementAt(index).communicationDevcies.ElementAt(commIndex).communicationPar.variables.Add(new Variable() + { + Id = ShopDeviceConfigViewModel.deviceConfig.ElementAt(0).deviceModels.ElementAt(index).communicationDevcies.ElementAt(commIndex).communicationPar.variables.Count, + Address = string.Empty, + ReadLeng = 0 + }); + } + } + } + } + } + } } - private void tv_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) + private void rbNetwork_Checked(object sender, RoutedEventArgs e) { + rbVisibility(); + } + private void rbSerial_Checked(object sender, RoutedEventArgs e) + { + rbVisibility(); } - private void DeviceInfo(object sender, MouseButtonEventArgs e) + private void rbVisibility() { - var tb = sender as TextBlock; - if (tb != null) + this.Network.Visibility = (bool)this.rbNetwork.IsChecked ? Visibility.Visible : Visibility.Collapsed; + this.Serial.Visibility = (bool)this.rbSerial.IsChecked ? Visibility.Visible : Visibility.Collapsed; + } + + private void ComboBox_DropDownOpened(object sender, EventArgs e) + { + ShopDeviceConfigViewModel.Shops.Clear(); + DirectoryInfo directoryInfo = new DirectoryInfo(LocaPath.GetInstance().GetDeviceConfigPath); + var files = directoryInfo.GetFiles(); + foreach (var item in files) { - //ShopDeviceConfigViewModel.DeviceName = tb.Text.Trim(); - //tb.Background = Brushes.Blue; + var res = System.IO.Path.GetFileNameWithoutExtension(item.FullName); + if (res != null && res.Length > 0 && item.FullName.Contains("json")) ShopDeviceConfigViewModel.Shops.Add(res); } } - private void CommunicationInfo(object sender, MouseButtonEventArgs e) + + private void shop_SelectionChanged(object sender, SelectionChangedEventArgs e) { - //var tb = sender as TextBlock; - //if (tb != null) - //{ - // ShopDeviceConfigViewModel.CommunicationName = tb.Text.Trim(); - // ShopDeviceConfigViewModel.DeviceModelId = tb.Tag.ToString(); - // tb.Focus(); - // //tb.Background = Brushes.Blue; + var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig"); + if (this.shop.Items.Contains(text)) this.shop.SelectedValue = text; + DirectoryInfo directoryInfo = new DirectoryInfo(LocaPath.GetInstance().GetDeviceConfigPath); + var files = directoryInfo.GetFiles(); + if (files != null && this.shop.SelectedValue != null && this.shop.SelectedValue.ToString().Length > 0) + { + var file = files.FirstOrDefault(p => p.FullName.Contains(this.shop.SelectedValue.ToString())); + if (file != null && File.Exists(file.FullName)) + { + string JsonString = File.ReadAllText(file.FullName); + var result = JsonConvert.DeserializeObject>(JsonString); + if (result != null) + { + ShopDeviceConfigViewModel.deviceConfig.Clear(); + foreach (var item in result) + { + ShopDeviceConfigViewModel.deviceConfig.Add(item); + } + VisibilityControl(); + } + } + } + TextHelper.GetInstance.WriteTextInfo(this.shop.SelectedValue?.ToString(), "StartShop", "DeviceConfig"); + } - //} + private void VisibilityControl() + { + if (this.Device != null) this.Device.Visibility = Visibility.Collapsed; + if (this.CommType != null) this.CommType.Visibility = Visibility.Collapsed; + if (this.VarTab != null) this.VarTab.Visibility = Visibility.Collapsed; + if (this.Serial != null) this.Serial.Visibility = Visibility.Collapsed; + if (this.Network != null) this.Network.Visibility = Visibility.Collapsed; + if (this.GridCommunication != null) this.GridCommunication.Visibility = Visibility.Collapsed; } } } diff --git a/BPASmartClient/DeviceInfo.xml b/BPASmartClient/DeviceInfo.xml index 89e636c8..95e5a89b 100644 --- a/BPASmartClient/DeviceInfo.xml +++ b/BPASmartClient/DeviceInfo.xml @@ -38,7 +38,7 @@ --> - + diff --git a/BPASmartClient/DialogWindow/NewShopWindow.xaml b/BPASmartClient/DialogWindow/NewShopWindow.xaml index 838849c1..e2cdd252 100644 --- a/BPASmartClient/DialogWindow/NewShopWindow.xaml +++ b/BPASmartClient/DialogWindow/NewShopWindow.xaml @@ -125,7 +125,7 @@ Visibility="Hidden" />