|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using BPASmartClient.SmallBatchingSystem.Views;
- using BPA.Helper;
-
-
- namespace BPASmartClient.SmallBatchingSystem.ViewModels
- {
- public class NewOutletViewModel : BaseModel
- {
- public NewOutletViewModel()
- {
- Json<ConfigInfoModel>.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add($"{item.SiloName}"); });
- 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<ConfigInfoModel>.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<ConfigInfoModel>.Data.OutletInfoModels.Count)
- {
- var array = Json<ConfigInfoModel>.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<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).OutletName = OutletName;
- Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).OutletLoc = OutletLoc;
- Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos.Clear();
- Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos = SileNames;
- Control.GetInstance.OperationLog($"{OutletName} 编辑完成");
- }
- else
- {
- var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletName == OutletName);
- if (res != null)
- {
- ErrorInfo = "出料口名称已经存在!";
- return;
- }
-
- var temp = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletLoc == OutletLoc);
- if (temp != null)
- {
- ErrorInfo = "出料口位置已存在!";
- return;
- }
- Json<ConfigInfoModel>.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;
-
- }
- }
|