diff --git a/BPASmartClient.Business/Plugin/OrderProxy.cs b/BPASmartClient.Business/Plugin/OrderProxy.cs index 5f8969ef..720a2698 100644 --- a/BPASmartClient.Business/Plugin/OrderProxy.cs +++ b/BPASmartClient.Business/Plugin/OrderProxy.cs @@ -122,7 +122,12 @@ namespace BPASmartClient.Business { OrderStatusChangedEvent orderStatusChangedEvent = @event as OrderStatusChangedEvent; string result = string.Empty; - OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = orderStatusChangedEvent.Status, SuborderId = orderStatusChangedEvent.SubOrderId }; + OrderStatusChange orderStatusChange = new OrderStatusChange() + { + CookingStatus = orderStatusChangedEvent.Status, + SuborderId = orderStatusChangedEvent.SubOrderId, + GoodName = orderStatusChangedEvent.GoodName + }; #region API 订单状态修改 try diff --git a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml index f82209c3..e15e3c81 100644 --- a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml @@ -123,37 +123,45 @@ - - - + + + @@ -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" />