|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.FoodStationTest.Model;
- using BPA.Helper;
- using BPA.Helper;
-
- using System;
- using System.Linq;
-
- namespace BPASmartClient.FoodStationTest.ViewModel
- {
- public class ChangeDeviceNameViewModel : NotifyBase
- {
- public ChangeDeviceNameViewModel()
- {
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is string str)
- IpAddress = str;
- }), "ChangeDeviceNameViewOpen");
-
- CancleCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("ChangeDeviceNameViewClose"); });
- ConfirmCommand = new BPARelayCommand(() =>
- {
- if (string.IsNullOrEmpty(DeviceName))
- {
- ErrorInfo = "设备名称不能为空";
- return;
- }
- int index = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.IpAddress == IpAddress);
- if (index >= 0 && index < DeviceInquire.GetInstance.devices.Count)
- {
- if (DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == DeviceName) != null)
- ErrorInfo = "设备名称已存在";
- else
- {
- var res = Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(index).DeviceName);
- if (res != null)
- {
- res.RawMaterialName = DeviceName;
- DeviceInquire.GetInstance.devices.ElementAt(index).DeviceName = DeviceName;
- DeviceInquire.GetInstance.GetDevice(IpAddress).SetDeviceName(DeviceName);//设置PLC名称
- for (int i = 0; i < Json<LocalPar>.Data.Recipes.Count; i++)
- {
- for (int m = 0; m < Json<LocalPar>.Data.Recipes.ElementAt(i).RawMaterials.Count; m++)
- {
- Json<LocalPar>.Data.Recipes.ElementAt(i).RawMaterials.ElementAt(m).RawMaterialName = DeviceName;
- }
- }
- ActionManage.GetInstance.Send("ChangeDeviceNameViewClose");
- }
- }
- }
-
- });
- }
-
- private static string IpAddress = string.Empty;
-
- public BPARelayCommand ConfirmCommand { get; set; }
-
- public BPARelayCommand CancleCommand { get; set; }
-
-
- public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
- private string _mErrorInfo;
-
-
- public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } }
- private string _mDeviceName;
-
- }
- }
|