|
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using BPA.Helper;
-
-
- namespace BPASmartClient.DosingSystemSingle.ViewModel
- {
- public class NewOutletViewModel : ViewModelBase
- {
- public NewOutletViewModel()
- {
- DeviceInquire.GetInstance.devices.ToList()?.ForEach(item => { SileName.Add($"{item.DeviceName}"); });
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is OutletInfoModel tempOutletInfo)
- {
- OutletName = tempOutletInfo.OutletName;
- OutletLoc = tempOutletInfo.OutletLoc;
- tempOutletInfo.SiloInfos?.ToList()?.ForEach((item =>
- {
- int tempIndex = Array.FindIndex(SileName.ToArray(), p => p == item);
- SiloInfos.Add(new RawMaterialInfo() { RawMaterialName = item, SelectIndex = tempIndex });
- }));
- Index = Array.FindIndex(Json<DevicePar>.Data.OutletInfoModels.ToArray(), p => p.OutletName == tempOutletInfo.OutletName);
- }
- }), "OpenNewOutlet", true);
- AddCommand = new BPARelayCommand(() => { SiloInfos.Add(new RawMaterialInfo()); });
- CancelCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("NewOutletViewClose"); });
- SaveCommand = new BPARelayCommand(() =>
- {
- ObservableCollection<string> SileNames = new ObservableCollection<string>();
- SiloInfos.ToList()?.ForEach(item => { SileNames.Add(item.RawMaterialName); });
- if (Index >= 0 && Index < Json<DevicePar>.Data.OutletInfoModels.Count)
- {
- var array = Json<DevicePar>.Data.OutletInfoModels.ToArray();
- var res = Array.FindIndex(array, p => p.OutletName == OutletName);
- if (res >= 0 && res != Index)
- {
- ErrorInfo = "出料口名称已经存在!";
- return;
- }
-
- var temp = Array.FindIndex(array, p => p.OutletLoc == OutletLoc);
- if (temp >= 0 && temp != Index)
- {
- ErrorInfo = "出料口位置已存在!";
- return;
- }
- Json<DevicePar>.Data.OutletInfoModels.ElementAt(Index).OutletName = OutletName;
- Json<DevicePar>.Data.OutletInfoModels.ElementAt(Index).OutletLoc = OutletLoc;
- Json<DevicePar>.Data.OutletInfoModels.ElementAt(Index).SiloInfos.Clear();
- Json<DevicePar>.Data.OutletInfoModels.ElementAt(Index).SiloInfos = SileNames;
- //Control.GetInstance.OperationLog($"{OutletName} 编辑完成");
- }
- else
- {
- var res = Json<DevicePar>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletName == OutletName);
- if (res != null)
- {
- ErrorInfo = "出料口名称已经存在!";
- return;
- }
-
- var temp = Json<DevicePar>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletLoc == OutletLoc);
- if (temp != null)
- {
- ErrorInfo = "出料口位置已存在!";
- return;
- }
- Json<DevicePar>.Data.OutletInfoModels.Add(new OutletInfoModel()
- {
- OutletLoc = OutletLoc,
- OutletName = OutletName,
- SiloInfos = SileNames
- });
- //Control.GetInstance.OperationLog($"{OutletName} 添加成功");
- }
- ActionManage.GetInstance.Send("NewOutletViewClose");
- });
- RemoveCommand = new BPARelayCommand<object>((o) =>
- {
- if (!string.IsNullOrEmpty(o?.ToString()))
- {
- var res = SiloInfos.FirstOrDefault(p => p.RawMaterialName == o.ToString());
- if (res != null) SiloInfos.Remove(res);
- }
-
- });
- }
-
- public string OutletName { get { return _mOutletName; } set { _mOutletName = value; OnPropertyChanged(); } }
- private string _mOutletName;
-
- public int OutletLoc { get { return _mOutletLoc; } set { _mOutletLoc = value; OnPropertyChanged(); } }
- private int _mOutletLoc;
-
- public ObservableCollection<RawMaterialInfo> SiloInfos { get; set; } = new ObservableCollection<RawMaterialInfo>();
-
- public ObservableCollection<string> SileName { get; set; } = new ObservableCollection<string>();
- }
-
-
- public class RawMaterialInfo : NotifyBase
- {
-
- public string RawMaterialName { get { return _mRawMaterialName; } set { _mRawMaterialName = value; OnPropertyChanged(); } }
- private string _mRawMaterialName;
-
- public int SelectIndex { get { return _mSelectIndex; } set { _mSelectIndex = value; OnPropertyChanged(); } }
- private int _mSelectIndex;
-
- }
-
- }
|