diff --git a/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml b/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml index e95bfc8b..79257775 100644 --- a/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml +++ b/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml @@ -215,5 +215,4 @@ - \ No newline at end of file diff --git a/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml.cs b/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml.cs index 87cae49f..4ec57c70 100644 --- a/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml.cs +++ b/BPASmartClient.CustomResource/UserControls/DateTimeUI.xaml.cs @@ -21,6 +21,7 @@ namespace BPASmartClient.CustomResource.UserControls /// public partial class DateTimeUI : UserControl { + public DateTimeUI() { InitializeComponent(); diff --git a/BPASmartClient.Modbus/ModbusTcp.cs b/BPASmartClient.Modbus/ModbusTcp.cs index f8380822..504bc6d6 100644 --- a/BPASmartClient.Modbus/ModbusTcp.cs +++ b/BPASmartClient.Modbus/ModbusTcp.cs @@ -130,7 +130,7 @@ namespace BPASmartClient.Modbus } return -1; } - + private void ExceptionHandling(Exception ex) { if (ex.InnerException is SocketException) @@ -174,7 +174,78 @@ namespace BPASmartClient.Modbus } return default(object); } + #region 180项目调用 + public int GetAddress(string address, string target) + { + if (address == null) return -1; + if (address.Length > 0) + { + if (address.ToUpper().Contains("D") && address.Length == 5) + { + try + { + string head = (Convert.ToInt32(address.Substring(1, 1)) - 1).ToString(); + string tail = address.Substring(2, 3); + address = head + tail; + } + catch (Exception) + { + //打印日志 + return -1; + } + } + + } + return -1; + } + public object Read(string address, ushort len, string target, byte slaveAddress = 1) + { + if (address == null || tcpClient == null) return default(object); + ushort startAddress = (ushort)GetAddress(address, target); + CommandType commandType = CommandType.HoldingRegisters; + try + { + if (address.ToUpper().Contains("D")) + { + commandType = CommandType.HoldingRegisters; + return master.ReadHoldingRegisters(slaveAddress, startAddress, len); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx($"读取地址:【{address}:= {startAddress}】,读取类型:【{commandType.ToString()}】出错,{ex.ToString()}"); + ExceptionHandling(ex); + } + return default(object); + } + + public void Write(string address, T value, string target, byte slaveAddress = 1) + { + if (address == null || tcpClient == null) return; + ushort startAddress = (ushort)GetAddress(address,target); + CommandType commandType = CommandType.Coils; + try + { + + if (address.ToUpper().Contains("D")) + { + commandType = CommandType.HoldingRegisters; + if (value is ushort ushortValue) + { + master.WriteSingleRegister(slaveAddress, startAddress, ushortValue); + } + + } + + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}"); + ExceptionHandling(ex); + } + } + #endregion public void Write(string address, T value, byte slaveAddress = 1) { if (address == null || tcpClient == null) return; diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index 747e56e7..5467ea55 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -51,8 +51,6 @@ namespace DosingSystem.Model private void IpAddressLines() { - - for (int i = 1; i <= 255; i++) { if (!InvalidIP.Contains($"{IPSegment}{i}")) diff --git a/DosingSystem/View/MainWindow.xaml b/DosingSystem/View/MainWindow.xaml index 45e64487..996b100c 100644 --- a/DosingSystem/View/MainWindow.xaml +++ b/DosingSystem/View/MainWindow.xaml @@ -238,7 +238,7 @@ - diff --git a/DosingSystem/View/NewRecipeView.xaml b/DosingSystem/View/NewRecipeView.xaml index 58a502a5..be21477c 100644 --- a/DosingSystem/View/NewRecipeView.xaml +++ b/DosingSystem/View/NewRecipeView.xaml @@ -116,7 +116,7 @@ Height="30" Margin="0,0,7,0" Command="{Binding AddCommand}" - Content="添加原料" /> + Content="添加原料" Cursor="Hand" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FryPot_DosingSystem/View/DeviceListVIew.xaml.cs b/FryPot_DosingSystem/View/DeviceListVIew.xaml.cs new file mode 100644 index 00000000..2a26d676 --- /dev/null +++ b/FryPot_DosingSystem/View/DeviceListVIew.xaml.cs @@ -0,0 +1,28 @@ +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 FryPot_DosingSystem.View +{ + /// + /// DeviceListVIew.xaml 的交互逻辑 + /// + public partial class DeviceListVIew : UserControl + { + public DeviceListVIew() + { + InitializeComponent(); + } + } +} diff --git a/FryPot_DosingSystem/View/EditRecipeView.xaml b/FryPot_DosingSystem/View/EditRecipeView.xaml new file mode 100644 index 00000000..4c6c7640 --- /dev/null +++ b/FryPot_DosingSystem/View/EditRecipeView.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/FryPot_DosingSystem/View/EditRecipeView.xaml.cs b/FryPot_DosingSystem/View/EditRecipeView.xaml.cs new file mode 100644 index 00000000..fb3e0f1e --- /dev/null +++ b/FryPot_DosingSystem/View/EditRecipeView.xaml.cs @@ -0,0 +1,28 @@ +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 FryPot_DosingSystem.View +{ + /// + /// EditRecipeView.xaml 的交互逻辑 + /// + public partial class EditRecipeView : UserControl + { + public EditRecipeView() + { + InitializeComponent(); + } + } +} diff --git a/FryPot_DosingSystem/View/HardWareStatusView.xaml b/FryPot_DosingSystem/View/HardWareStatusView.xaml new file mode 100644 index 00000000..48b2fd23 --- /dev/null +++ b/FryPot_DosingSystem/View/HardWareStatusView.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/FryPot_DosingSystem/View/HardWareStatusView.xaml.cs b/FryPot_DosingSystem/View/HardWareStatusView.xaml.cs new file mode 100644 index 00000000..a90f2f7c --- /dev/null +++ b/FryPot_DosingSystem/View/HardWareStatusView.xaml.cs @@ -0,0 +1,28 @@ +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 FryPot_DosingSystem.View +{ + /// + /// HardWareStatusView.xaml 的交互逻辑 + /// + public partial class HardWareStatusView : UserControl + { + public HardWareStatusView() + { + InitializeComponent(); + } + } +} diff --git a/FryPot_DosingSystem/View/LogView.xaml b/FryPot_DosingSystem/View/LogView.xaml new file mode 100644 index 00000000..1c8e6c68 --- /dev/null +++ b/FryPot_DosingSystem/View/LogView.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FryPot_DosingSystem/View/LogView.xaml.cs b/FryPot_DosingSystem/View/LogView.xaml.cs new file mode 100644 index 00000000..5aa62b7c --- /dev/null +++ b/FryPot_DosingSystem/View/LogView.xaml.cs @@ -0,0 +1,30 @@ +using FryPot_DosingSystem.ViewModel; +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 FryPot_DosingSystem.View +{ + /// + /// LogView.xaml 的交互逻辑 + /// + public partial class LogView : UserControl + { + public LogView() + { + InitializeComponent(); + this.DataContext = LogViewModel.GetInstance; + } + } +} diff --git a/FryPot_DosingSystem/View/MainWindow.xaml b/FryPot_DosingSystem/View/MainWindow.xaml new file mode 100644 index 00000000..d6cc90ee --- /dev/null +++ b/FryPot_DosingSystem/View/MainWindow.xaml @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FryPot_DosingSystem/View/NewRecipeView.xaml.cs b/FryPot_DosingSystem/View/NewRecipeView.xaml.cs new file mode 100644 index 00000000..d9a62b9c --- /dev/null +++ b/FryPot_DosingSystem/View/NewRecipeView.xaml.cs @@ -0,0 +1,36 @@ +using BPASmartClient.Helper; +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.Shapes; + +namespace FryPot_DosingSystem.View +{ + /// + /// NewRecipeView.xaml 的交互逻辑 + /// + public partial class NewRecipeView : Window + { + public NewRecipeView() + { + InitializeComponent(); + this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); }; + ActionManage.GetInstance.CancelRegister("CloseNewRecipeView"); + ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "CloseNewRecipeView"); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + this.Close(); + } + } +} diff --git a/FryPot_DosingSystem/View/RecipeSendDownView.xaml b/FryPot_DosingSystem/View/RecipeSendDownView.xaml new file mode 100644 index 00000000..823edbd6 --- /dev/null +++ b/FryPot_DosingSystem/View/RecipeSendDownView.xaml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FryPot_DosingSystem/View/RecipeSendDownView.xaml.cs b/FryPot_DosingSystem/View/RecipeSendDownView.xaml.cs new file mode 100644 index 00000000..e8d7dc97 --- /dev/null +++ b/FryPot_DosingSystem/View/RecipeSendDownView.xaml.cs @@ -0,0 +1,28 @@ +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 FryPot_DosingSystem.View +{ + /// + /// RecipeSendDownView.xaml 的交互逻辑 + /// + public partial class RecipeSendDownView : UserControl + { + public RecipeSendDownView() + { + InitializeComponent(); + } + } +} diff --git a/FryPot_DosingSystem/View/RecipeSetView.xaml b/FryPot_DosingSystem/View/RecipeSetView.xaml new file mode 100644 index 00000000..14a9a6e3 --- /dev/null +++ b/FryPot_DosingSystem/View/RecipeSetView.xaml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FryPot_DosingSystem/View/RecipeSetView.xaml.cs b/FryPot_DosingSystem/View/RecipeSetView.xaml.cs new file mode 100644 index 00000000..d8a3a8ff --- /dev/null +++ b/FryPot_DosingSystem/View/RecipeSetView.xaml.cs @@ -0,0 +1,30 @@ +using FryPot_DosingSystem.ViewModel; +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 FryPot_DosingSystem.View +{ + /// + /// RecipeSetView.xaml 的交互逻辑 + /// + public partial class RecipeSetView : UserControl + { + public RecipeSetView() + { + InitializeComponent(); + + } + } +} diff --git a/FryPot_DosingSystem/ViewModel/AdministratorLoginViewModel.cs b/FryPot_DosingSystem/ViewModel/AdministratorLoginViewModel.cs new file mode 100644 index 00000000..deb6f065 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/AdministratorLoginViewModel.cs @@ -0,0 +1,172 @@ +using BPA.Message; +using BPASmartClient.Helper; +using FryPot_DosingSystem.Model; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using Newtonsoft.Json; +using System; +using System.Collections.ObjectModel; +using System.IO; +using System.Windows; + +namespace FryPot_DosingSystem.ViewModel +{ + public class AdministratorLoginViewModel : ObservableObject + { + /// + /// 按钮内容修改:注册/修改 + /// + private string _registOrChange; + public string RegistOrChange { get { return _registOrChange; } set { _registOrChange = value; OnPropertyChanged(); } } + public string Admin { get { return _admin; } set { _admin = value; OnPropertyChanged(); } } + private string _admin; + + public string Password { get { return _password; } set { _password = value; OnPropertyChanged(); } } + private string _password; + + public string ErrorMessage { get { return _errorMessage; } set { _errorMessage = value; OnPropertyChanged(); } } + private string _errorMessage; + + public string SelectText { get { return _mSelectText; } set { _mSelectText = value; OnPropertyChanged(); } } + private string _mSelectText; + + private UserInfo _userInfo; + public UserInfo UserInfo { get { return _userInfo; }set { _userInfo = value;OnPropertyChanged(); } } + + private string _account; + public string Account { get { return _account; } set { _account = value;OnPropertyChanged(); } } + + private string _txtpassword; + public string Txtpassword { get { return _txtpassword; } set { _txtpassword = value; OnPropertyChanged(); } } + + public RelayCommand AdminLoginCommand { get; set; } + public RelayCommand RegistCommand { get; set; } + + public ObservableCollection permission { get; set; } = new ObservableCollection(); + + public AdministratorLoginViewModel() + { + permission.Add("管理员"); + permission.Add("操作员"); + permission.Add("观察员"); + permission.Add("技术员"); + SelectText = permission[0]; + var content = ActionManage.GetInstance.SendResult("ContentUpdate"); + if (content != null && content is string strContent) + { + RegistOrChange = strContent; + } + var loginInfo = ActionManage.GetInstance.SendResult("LoginInfo"); + if (loginInfo != null && loginInfo is UserInfo LoginInfo) + { + UserInfo = LoginInfo; + if (UserInfo != null) + { + switch (UserInfo.Authority) + { + case Authority.管理员: SelectText = permission[0]; break; + case Authority.操作员: SelectText = permission[1]; break; + case Authority.观察员: SelectText = permission[2]; break; + case Authority.技术员: SelectText = permission[3]; break; + } + Account = UserInfo.UserName; + Txtpassword = UserInfo.Password; + } + } + RegistCommand = new RelayCommand(() => + { + if (RegistOrChange != null) + { + if (RegistOrChange == "注册") + { + if (Admin == null || Admin == string.Empty || Password == null || Password == string.Empty) + { + ErrorMessage = "注册信息不能为空!!!"; + } + else + { + ep: + string guid=Guid.NewGuid().ToString();//用户唯一ID + var resultManage = JsonConvert.DeserializeObject(File.ReadAllText("LoginUp.hbl").AESDecrypt()); + if (resultManage != null && resultManage is UserManage manage) + { + int a= manage.userInfos.FindIndex(p => p.UserId == guid); + if (a == -1) + { + switch (SelectText) + { + case "管理员": Global.userManager.userInfos.Add(new UserInfo() { Authority = Authority.管理员, UserName = Admin, Password = Password,UserId=guid }); break; + case "技术员": Global.userManager.userInfos.Add(new UserInfo() { Authority = Authority.技术员, UserName = Admin, Password = Password,UserId = guid }); break; + case "操作员": Global.userManager.userInfos.Add(new UserInfo() { Authority = Authority.操作员, UserName = Admin, Password = Password, UserId = guid }); break; + case "观察员": Global.userManager.userInfos.Add(new UserInfo() { Authority = Authority.观察员, UserName = Admin, Password = Password, UserId = guid }); break; + } + File.WriteAllText("LoginUp.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); + var result = JsonConvert.DeserializeObject(File.ReadAllText("LoginUp.hbl").AESDecrypt()); + Global.userManager = result; + ErrorMessage = "注册成功"; + } + else + { + goto ep; + + } + } + + } + } + if (RegistOrChange == "修改") + { + //执行密码修改操作 + try + { + if (UserInfo != null) + { + UserInfo info = Global.userManager.userInfos.Find(p => p.UserId == UserInfo.UserId); + if (info != null) + { + switch (SelectText) + { + case "管理员": info.Authority = Authority.管理员; info.UserName = Admin; info.Password = Password; break; + case "技术员": info.Authority = Authority.技术员; info.UserName = Admin; info.Password = Password; break; + case "操作员": info.Authority = Authority.操作员; info.UserName = Admin; info.Password = Password; break; + case "观察员": info.Authority = Authority.观察员; info.UserName = Admin; info.Password = Password; break; + } + File.WriteAllText("LoginUp.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); + var result = JsonConvert.DeserializeObject(File.ReadAllText("LoginUp.hbl").AESDecrypt()); + Global.userManager = result; + ErrorMessage = "修改成功"; + } + else + { + ErrorMessage = "修改失败"; + } + } + else + { + ErrorMessage = "修改失败"; + } + } + catch (Exception) + { + ErrorMessage = "修改失败"; + } + } + } + + }); + AdminLoginCommand = new RelayCommand(() => + { + var rest = ActionManage.GetInstance.SendResult("LoginDosingSystem", $"{Admin}-={Password}-={SelectText}"); + if (rest != null && rest is string str) + { + Account = String.Empty; + Txtpassword = String.Empty; + ErrorMessage = str; + + } + }); + + + } + } +} diff --git a/FryPot_DosingSystem/ViewModel/AdministratorPasswordChangeViewModel.cs b/FryPot_DosingSystem/ViewModel/AdministratorPasswordChangeViewModel.cs new file mode 100644 index 00000000..db3f9682 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/AdministratorPasswordChangeViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class AdministratorPasswordChangeViewModel + { + + } +} diff --git a/FryPot_DosingSystem/ViewModel/DeviceListViewModel.cs b/FryPot_DosingSystem/ViewModel/DeviceListViewModel.cs new file mode 100644 index 00000000..580908f4 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/DeviceListViewModel.cs @@ -0,0 +1,61 @@ +using BPASmartClient.Helper; +using FryPot_DosingSystem.Model; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class DeviceListViewModel : ObservableObject + { + public ObservableCollection DeviceName { get; set; } = new ObservableCollection(); + public ObservableCollection devices { get; set; } = new ObservableCollection(); + public RelayCommand AddDeviceCommand { get; set; } + public RelayCommand SaveDeviceConfig { get; set; } + public RelayCommand DeleteDevice { get; set; } + public DeviceListViewModel() + { + Json.Read(); + devices = Json.Data.Devices; + DeviceName.Add("滚筒输送线"); + DeviceName.Add("炒锅1"); + DeviceName.Add("炒锅2"); + DeviceName.Add("炒锅3"); + DeviceName.Add("炒锅4"); + DeviceName.Add("炒锅5"); + AddDeviceCommand = new RelayCommand(() => + { + erp: + string guid = Guid.NewGuid().ToString(); + DeviceInfo info = devices.FirstOrDefault(p => p.DeviceNum == guid); + if (info == null) + { + devices.Add(new DeviceInfo() { DeviceNum = guid }); + } + else + { + goto erp; + } + }); + DeleteDevice = new RelayCommand((str) => + { + DeviceInfo device = devices.FirstOrDefault(p => p.DeviceNum == str); + if (device != null) + { + devices.Remove(device); + } + }); + SaveDeviceConfig = new RelayCommand(() => + { + Json.Data.Devices = devices; + Json.Save(); + }); + } + + } +} diff --git a/FryPot_DosingSystem/ViewModel/LogViewModel.cs b/FryPot_DosingSystem/ViewModel/LogViewModel.cs new file mode 100644 index 00000000..15a23294 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/LogViewModel.cs @@ -0,0 +1,76 @@ +using BPASmartClient.Message; +using FryPot_DosingSystem.Model; +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; +using System.Windows.Media; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class LogViewModel:ObservableObject + { + public static LogViewModel _instance; + public static LogViewModel GetInstance=>_instance?? (_instance = new LogViewModel()); + private string _logTime; + public string LogTime { get { return _logTime; } set { _logTime = value; OnPropertyChanged(); } } + + private string _logType; + public string LogType { get { return _logType; } set { _logType = value; OnPropertyChanged(); } } + + private string _logMessage; + public string LogMessage { get { return _logMessage; } set { _logMessage = value; OnPropertyChanged(); } } + + private Brush _foreColor; + public Brush ForeColor { get { return _foreColor; } set { _foreColor = value; OnPropertyChanged(); } } + + public ObservableCollection LogDatas { get; set; } = new ObservableCollection(); + + public LogViewModel() + { + Inite(); + } + public void Inite() + { + //一般日志 MessageLog.GetInstance.Show(""); + MessageLog.GetInstance.InfoNotify = new Action((s) => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + LogModel logModel = new LogModel { LogMessage= s, LogType = "一般日志" }; + LogDatas.Add(logModel); + })); + }); + //设备日志 MessageLog.GetInstance.DeviceProcessLogShow(id,message) + MessageLog.GetInstance.DeviceProcessLogNotify = new Action((id, s) => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + LogModel logModel = new LogModel { LogMessage = s, LogType = "设备日志" }; + LogDatas.Add(logModel); + })); + }); + //设备告警日志 MessageLog.GetInstance.AddDeviceAlarmLogShow(id,message) + MessageLog.GetInstance.DeviceAlarmLogNotify = new Action((id, s) => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + LogModel logModel = new LogModel { LogMessage = id, LogType = "报警日志" }; + LogDatas.Add(logModel); + })); + }); + //错误日志MessageLog.GetInstance.ShowEx(message) + MessageLog.GetInstance.ExInfoNotify = new Action((s) => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + LogModel logModel = new LogModel { LogMessage = s, LogType = "错误日志" }; + LogDatas.Add(logModel); + })); + }); + } + } +} diff --git a/FryPot_DosingSystem/ViewModel/MainViewModel.cs b/FryPot_DosingSystem/ViewModel/MainViewModel.cs new file mode 100644 index 00000000..e8448cb7 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/MainViewModel.cs @@ -0,0 +1,151 @@ + +using BPASmartClient.Helper; +using FryPot_DosingSystem.Control; +using FryPot_DosingSystem.Model; +using FryPot_DosingSystem.View; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Forms; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class MainViewModel : ObservableObject + { + public ObservableCollection menus { get; set; } = new ObservableCollection(); + + public RelayCommand Login { get; set; } + public RelayCommand PasswordChange { get; set; } + + public RelayCommand ExitLogin { get; set; } + public RelayCommand TogglePag { get; set; } + public bool UserManagement { get { return _mUserManagement; } set { _mUserManagement = value; OnPropertyChanged(); } } + private bool _mUserManagement; + /// + /// 当前登陆信息 + /// + private UserInfo _currentLoginAccount; + public UserInfo CurrentLoginAccount { get { return _currentLoginAccount; } set { _currentLoginAccount = value;OnPropertyChanged(); } } + /// + /// 不同权限显示不同菜单 + /// + public ObservableCollection DisplayMenus { get; set; } = new ObservableCollection(); + public FrameworkElement MyWindow { get { return _mMyWindow; } set { _mMyWindow = value; OnPropertyChanged(); } } + private FrameworkElement _mMyWindow; + + public string WindowTitleName { get { return _mWindowTitleName; } set { _mWindowTitleName = value; OnPropertyChanged(); } } + private string _mWindowTitleName; + /// + /// 开机自启 + /// + public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } } + + private Authority authority; + public Authority Authority + { + get { return authority; } + set + { + var res = menus.Where(p => Array.FindIndex(p.Authority, au => au == value) >= 0).ToList(); + if (res != null && res.Count > 0) + { + DisplayMenus.Clear(); + res.ForEach(p => DisplayMenus.Add(p)); + DoNavChanged(res[0].CommandParameter); + } + authority = value; + } + } + public MainViewModel() + { + LogViewModel model= LogViewModel.GetInstance; + DeviceOperate deviceOperate=DeviceOperate.GetInstance;//开启实时PLC数据读取 + DosingLogicControl logigControl = DosingLogicControl.GetInstance;//开启逻辑控制任务程序 + TogglePag = new RelayCommand(DoNavChanged); + Login = new RelayCommand(() => + { + ActionManage.GetInstance.CancelRegister("ContentUpdate"); + ActionManage.GetInstance.Register(new Func(() => { return "注册"; }), "ContentUpdate"); + DoNavChanged("AdministratorLoginView.用户登陆"); + UserManagement = false; + }); + PasswordChange = new RelayCommand(() => + { + ActionManage.GetInstance.CancelRegister("ContentUpdate"); + ActionManage.GetInstance.Register(new Func(() => { return "修改"; }), "ContentUpdate"); + ActionManage.GetInstance.CancelRegister("LoginInfo"); + ActionManage.GetInstance.Register(new Func(() => { return CurrentLoginAccount; }), "LoginInfo"); + DoNavChanged("AdministratorLoginView.密码修改"); + UserManagement = false; + }); + ExitLogin = new RelayCommand(() => + { + //DoNavChanged("LoginView.退出登录"); + CurrentLoginAccount = null; + Authority = Authority.观察员; + UserManagement = false; + }); + LoginInfoConfig.GetInstance.Init();//用户数据初始化 + LoginRegister(); + MenusDefaultInit(); + Authority = Authority.管理员; + } + + private void MenusDefaultInit() + { + menus.Add(new ActionMenu() { MenuName = "配方设置", CommandParameter = "RecipeSetView.配方设置", Authority = new Authority[] { Authority.管理员, Authority.技术员 } }); + menus.Add(new ActionMenu() { MenuName = "配方下发", CommandParameter = "RecipeSendDownView.配方下发", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员 } }); + menus.Add(new ActionMenu() { MenuName = "设备列表", CommandParameter = "DeviceListVIew.设备列表", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } }); + menus.Add(new ActionMenu() { MenuName = "状态监测", CommandParameter = "HardWareStatusView.状态监测", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } }); + menus.Add(new ActionMenu() { MenuName = "日志信息", CommandParameter = "LogView.日志信息", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } }); + menus.Add(new ActionMenu() { MenuName = "报警记录", CommandParameter = "", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } }); + + } + + public void DoNavChanged(object obj) + { + if (obj != null && obj is string stobj) + { + var strs = stobj.Split('.'); + if (strs != null && strs.Length == 2) + { + Type type = Type.GetType($"FryPot_DosingSystem.View.{strs[0]}"); + var res = type?.GetConstructor(System.Type.EmptyTypes)?.Invoke(null); + if (res != null && res is FrameworkElement fe) MyWindow = fe; + WindowTitleName = strs[1]; + } + } + } + /// + /// 登陆验证 + /// + private void LoginRegister() + { + ActionManage.GetInstance.Register(new Func((o) => + { + if (o != null && o is string str) + { + var strs = str.Split("-="); + if (strs != null && strs.Length == 3) + { + var us = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == strs[0] && p.Password == strs[1]&& strs[2] == p.Authority.ToString()); + if (us != null) + { + Authority = us.Authority; + CurrentLoginAccount = us;//记录当前登陆信息 + return string.Empty; + } + } + } + return "用户名或密码错误"; + }), "LoginDosingSystem"); + } + } +} diff --git a/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs b/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs new file mode 100644 index 00000000..53440266 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/NewRecipeViewModel.cs @@ -0,0 +1,98 @@ +using BPASmartClient.Helper; +using FryPot_DosingSystem.Model; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class NewRecipeViewModel : ObservableObject + { + /// + /// 配方唯一编码,用于编辑配方 + /// + public string recipeId { get; set; } + /// + /// 配料名称 + /// + private string _recipeName; + public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } } + + public ObservableCollection materials { get; set; } = new ObservableCollection(); + + public ObservableCollection materialNames { get; set; } = new ObservableCollection() { "肉","葱","蒜"}; + + public RelayCommand AddRecipe { get; set; } + public RelayCommand RemoveRecipe { get; set; } + public RelayCommand Comfirm { get; set; } + public NewRecipeViewModel() + { + ActionManage.GetInstance.Register(new Action(Id => { + if (Id != null && Id is string strId) + { + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeId == strId); + if (res != null && res is NewRecipeModel rom) + { + RecipeName = rom.RecipeName; + foreach (var item in rom.materialCollection) + { + materials.Add(item); + } + recipeId = strId; + } + } + }),"EditRecipe"); + AddRecipe = new RelayCommand(() => + { + pr: + string materialCode = Guid.NewGuid().ToString();//原料唯一ID ,后期需要根据实际要求更改 + var res = materials.FirstOrDefault(p => p.MaterialCode == materialCode); + if (res == null) + { + materials.Add(new MaterialType() { MaterialCode = materialCode }); + } + else + { + goto pr; + } + }); + RemoveRecipe = new RelayCommand(code => + { + var res = materials.FirstOrDefault(m => m.MaterialCode == code); + if (res != null) + materials.Remove(res); + }); + Comfirm = new RelayCommand(() => + { + var bom = Json.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeId); + if (bom == null)//新配方 + { + prop: string recipeID = Guid.NewGuid().ToString();//配方唯一ID,后期根据实际要求更改 + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeID); + if (res == null) + { + Json.Data.Recipes.Add(new NewRecipeModel { RecipeId = recipeID, RecipeName = RecipeName, materialCollection = materials });//配方添加 + + } + else + { + goto prop; + } + ActionManage.GetInstance.Send("CloseNewRecipeView"); + } + else //已有配方,用于编辑 + { + bom.materialCollection= materials; + bom.RecipeName = RecipeName; + ActionManage.GetInstance.Send("CloseNewRecipeView"); + } + }); + + } + } +} diff --git a/FryPot_DosingSystem/ViewModel/RecipeSetDownViewModel.cs b/FryPot_DosingSystem/ViewModel/RecipeSetDownViewModel.cs new file mode 100644 index 00000000..7e1aacfa --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/RecipeSetDownViewModel.cs @@ -0,0 +1,62 @@ +using BPASmartClient.Helper; +using FryPot_DosingSystem.Model; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class RecipeSetDownViewModel : ObservableObject + { + + + /// + /// 配方下发 + /// + public RelayCommand RecipeSetDownCommand { get; set; } + /// + /// 配方一键下发 + /// + public RelayCommand AllRecipeSetDownCommand { get; set; } + public ObservableCollection Recipes { get; set; } = new ObservableCollection(); + public RecipeSetDownViewModel() + { + Json.Read(); + Recipes = Json.Data.Recipes; + RecipeSetDownCommand = new RelayCommand((Id) => + { + if (Id != null && Id is string strId) + { + var res = Recipes.FirstOrDefault(p => p.RecipeId == strId); + if (res != null) + { + RecipeSetDown(res); + } + } + }); + AllRecipeSetDownCommand = new RelayCommand(() => + { + if (Recipes!=null) + { + foreach (var recipeModel in Recipes) + { + RecipeSetDown(recipeModel); + } + } + + }); + } + /// + /// 数据下发方法 + /// + public void RecipeSetDown(NewRecipeModel recipeModel) + { + recipeModel.RecipeSetInfo = "下发成功"; + } + } +} diff --git a/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs b/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs new file mode 100644 index 00000000..be2f8d68 --- /dev/null +++ b/FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs @@ -0,0 +1,80 @@ +using BPASmartClient.Helper; +using BPASmartClient.Message; +using FryPot_DosingSystem.Model; +using FryPot_DosingSystem.View; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FryPot_DosingSystem.ViewModel +{ + internal class RecipeSetViewModel : ObservableObject + { + ///// + ///// 配方编号 + ///// + //private int _serialNumber; + //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } } + ///// + ///// 配方名称 + ///// + //private string _recipeName; + //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } } + + public ObservableCollection recipeModels { get; set; } = new ObservableCollection(); + + public Action NewRecipe { get; set; } + + public Action SaveRecipe { get; set; } + /// + /// 编辑配方 + /// + public RelayCommand EditRecipeCommand { get; set; } + /// + /// 删除配方 + /// + public RelayCommand DeleteRecipeCommand { get; set; } + + public RecipeSetViewModel() + { + Json.Read(); + recipeModels = Json.Data.Recipes; + NewRecipe = new Action(() => + { + NewRecipeView nrv = new NewRecipeView(); + nrv.ShowDialog(); + MessageLog.GetInstance.Show("新建配方"); + }); + SaveRecipe = new Action(() => { + Json.Save(); + }); + EditRecipeCommand = new RelayCommand((Id) => + { + if (Id != null) + { + ActionManage.GetInstance.CancelRegister("EditRecipe"); + NewRecipeView nrv = new NewRecipeView(); + ActionManage.GetInstance.Send("EditRecipe", Id); + nrv.ShowDialog(); + } + }); + DeleteRecipeCommand = new RelayCommand((Id) => + { + if (Id != null && Id is String strId) + { + var res= recipeModels.FirstOrDefault(p => p.RecipeId == strId); + if (res != null && res is NewRecipeModel nes) + { + recipeModels.Remove(res);//删除配方 + Json.Save();//保存配方 + } + } + }); + } + } +} diff --git a/FryPot_DosingSystem/hbl.ico b/FryPot_DosingSystem/hbl.ico new file mode 100644 index 00000000..cf89051a Binary files /dev/null and b/FryPot_DosingSystem/hbl.ico differ diff --git a/LoginUp.hbl b/LoginUp.hbl new file mode 100644 index 00000000..993e1cd1 --- /dev/null +++ b/LoginUp.hbl @@ -0,0 +1 @@ +deac37237d550f2bb590b1d004aab120f4401e4504fd380cf9afa150f1f019d624ce5842ec9c5a8b2120413b2d623477a5b1c93800f28232dfcce895649de806a90a33c6aa3e437981381bb5e28745b8c5a9df97b8b94372d1b9dcac16580901 \ No newline at end of file diff --git a/SmartClient.sln b/SmartClient.sln index 8856d1df..0b07ef7a 100644 --- a/SmartClient.sln +++ b/SmartClient.sln @@ -98,7 +98,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DosingSystem", "DosingSyste EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MorkTJuicer", "BPASmartClient.MorkTJuicer\BPASmartClient.MorkTJuicer.csproj", "{724087A3-E7E7-4494-B844-414FF5CD1D40}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.AGV", "BPASmartClient.AGV\BPASmartClient.AGV.csproj", "{507A30E2-246E-4AC9-82F4-BE8FBBC1C5B8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.AGV", "BPASmartClient.AGV\BPASmartClient.AGV.csproj", "{507A30E2-246E-4AC9-82F4-BE8FBBC1C5B8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FryPot_DosingSystem", "FryPot_DosingSystem\FryPot_DosingSystem.csproj", "{BF0BCA66-BAE3-4293-9C3A-51537AB8580E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -914,6 +916,26 @@ Global {507A30E2-246E-4AC9-82F4-BE8FBBC1C5B8}.Release|x64.Build.0 = Release|Any CPU {507A30E2-246E-4AC9-82F4-BE8FBBC1C5B8}.Release|x86.ActiveCfg = Release|Any CPU {507A30E2-246E-4AC9-82F4-BE8FBBC1C5B8}.Release|x86.Build.0 = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|ARM.ActiveCfg = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|ARM.Build.0 = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|ARM64.Build.0 = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|x64.ActiveCfg = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|x64.Build.0 = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|x86.ActiveCfg = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Debug|x86.Build.0 = Debug|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|Any CPU.Build.0 = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|ARM.ActiveCfg = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|ARM.Build.0 = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|ARM64.ActiveCfg = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|ARM64.Build.0 = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|x64.ActiveCfg = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|x64.Build.0 = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|x86.ActiveCfg = Release|Any CPU + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -959,6 +981,7 @@ Global {4E0B01AD-CFD0-4BD5-BBE6-AD2A4183B4DB} = {8712125E-14CD-4E1B-A1CE-4BDE03805942} {724087A3-E7E7-4494-B844-414FF5CD1D40} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F} {507A30E2-246E-4AC9-82F4-BE8FBBC1C5B8} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625} + {BF0BCA66-BAE3-4293-9C3A-51537AB8580E} = {8712125E-14CD-4E1B-A1CE-4BDE03805942} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC} diff --git a/up.hbl b/up.hbl new file mode 100644 index 00000000..304f1618 --- /dev/null +++ b/up.hbl @@ -0,0 +1 @@ +deac37237d550f2bb590b1d004aab120481999a41282f0d8eed6fa9049bb2b58cf766ac542f7a79f9082f942d0190d731890e60eebc260ec3b9e76773b3e4e83443ee7e834210c4de2f560a9b4a6dffbc2a95b696b61aa07653dc4afdd31b551dc9f238426fc95486e3cf08d9387518bf125481cbfd4003d593f7f0c83167badfca9e6b0e585bf724542d50252bd672d2650e1146dd47b395b9b5d22b4fba4e75f528e15f91b5eb98112d2b1a3d5b1e1305cd1a1086a71336213e2a7cf83b262e36d4f33428a80c089f2f1ed81695a6c2d431dd7aaf64d71262dd132539e26900ebb7a6d1cc5923550c6612fdfee2a0a \ No newline at end of file