|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using BPA.Helper;
-
- namespace BPASmartClient.SmallBatchingSystem.ViewModels
- {
- public class NewSiloViewModel : BaseModel
- {
- public NewSiloViewModel()
- {
- CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("SiloClose"); });
- SaveCommand = new RelayCommand(() =>
- {
- if (Index >= 0 && Index < Json<ConfigInfoModel>.Data.SiloInfoModels.Count)
- {
- var array = Json<ConfigInfoModel>.Data.SiloInfoModels.ToArray();
- var res = Array.FindIndex(array, p => p.SiloName == SiloInfoModelObj.SiloName);
- if (res >= 0 && res != Index)
- {
- ErrorInfo = "料仓名称已经存在!";
- return;
- }
-
- var temp = Array.FindIndex(array, p => p.SiloLoc == SiloInfoModelObj.SiloLoc);
- if (temp >= 0 && temp != Index)
- {
- ErrorInfo = "料仓位置已存在!";
- return;
- }
-
- Json<ConfigInfoModel>.Data.SiloInfoModels.ElementAt(Index).SiloName = SiloInfoModelObj.SiloName;
- Json<ConfigInfoModel>.Data.SiloInfoModels.ElementAt(Index).SiloLoc = SiloInfoModelObj.SiloLoc;
- Control.GetInstance.OperationLog($"{SiloInfoModelObj.SiloName} 编辑完成");
- }
- else
- {
- var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == SiloInfoModelObj.SiloName);
- if (res != null)
- {
- ErrorInfo = "料仓名称已经存在!";
- return;
- }
-
- var temp = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloLoc == SiloInfoModelObj.SiloLoc);
- if (temp != null)
- {
- ErrorInfo = "料仓位置已存在!";
- return;
- }
-
- Json<ConfigInfoModel>.Data.SiloInfoModels.Add(new SiloInfoModel()
- {
- SiloLoc = SiloInfoModelObj.SiloLoc,
- SiloName = SiloInfoModelObj.SiloName,
- });
- Control.GetInstance.OperationLog($"{SiloInfoModelObj.SiloName} 添加成功");
- }
- ActionManage.GetInstance.Send("SiloClose");
- });
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is SiloInfoModel tempSilo)
- {
- SiloInfoModelObj.SiloLoc = tempSilo.SiloLoc;
- SiloInfoModelObj.SiloName = tempSilo.SiloName;
- Index = Array.FindIndex(Json<ConfigInfoModel>.Data.SiloInfoModels.ToArray(), p => p.SiloName == tempSilo.SiloName);
- }
- }), "OpenNewSilo", true);
- }
-
-
- public SiloInfoModel SiloInfoModelObj { get { return _mSiloInfoModelObj; } set { _mSiloInfoModelObj = value; OnPropertyChanged(); } }
- private SiloInfoModel _mSiloInfoModelObj = new SiloInfoModel();
-
- }
- }
|