diff --git a/BPASmartClient.SmallBatchingSystem/App.xaml.cs b/BPASmartClient.SmallBatchingSystem/App.xaml.cs index 395b45c8..b0e2fc31 100644 --- a/BPASmartClient.SmallBatchingSystem/App.xaml.cs +++ b/BPASmartClient.SmallBatchingSystem/App.xaml.cs @@ -10,8 +10,6 @@ using BPA.Helper; using BPASmartClient.CustomResource.Pages.Enums; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.Pages.View; -using BPASmartClient.SmallBatchingSystem.Models; -using BPASmartClient.SmallBatchingSystem.Services; namespace BPASmartClient.SmallBatchingSystem { diff --git a/BPASmartClient.SmallBatchingSystem/Models/BaseModel.cs b/BPASmartClient.SmallBatchingSystem/Models/BaseModel.cs new file mode 100644 index 00000000..b4ebc6d9 --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/Models/BaseModel.cs @@ -0,0 +1,20 @@ +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; + +namespace BPASmartClient.SmallBatchingSystem +{ + public class BaseModel : ObservableObject + { + public int Index { get; set; } = -1; + public RelayCommand AddCommand { get; set; } + public RelayCommand CancelCommand { get; set; } + public RelayCommand SaveCommand { get; set; } + public RelayCommand RemoveCommand { get; set; } + public RelayCommand DetailsCommand { get; set; } + } +} diff --git a/BPASmartClient.SmallBatchingSystem/Models/CommunicationPar.cs b/BPASmartClient.SmallBatchingSystem/Models/CommunicationPar.cs index 6e70d6a0..fc808c7e 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/CommunicationPar.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/CommunicationPar.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { public class CommunicationPar { diff --git a/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs b/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs index 5bc0dbf1..d5395b95 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Collections.ObjectModel; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { public class ConfigInfoModel { diff --git a/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs b/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs index 4a3ab337..8fa1213d 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using System.Collections.ObjectModel; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { /// /// 出料口信息 diff --git a/BPASmartClient.SmallBatchingSystem/Models/PLCModel.cs b/BPASmartClient.SmallBatchingSystem/Models/PLCModel.cs index 4b455e31..7a9aa9d5 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/PLCModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/PLCModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { public class PLCModel { diff --git a/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs b/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs index a891a24f..d170f2a1 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { public class PlcDataModel { diff --git a/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs b/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs index b3ee08f4..ee51e6e4 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using System.Collections.ObjectModel; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { public class RecipeInfo : ObservableObject { diff --git a/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs b/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs index 7e30ce52..2e054f80 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { public class RecipeRawMaterialInfo : ObservableObject { @@ -20,5 +20,12 @@ namespace BPASmartClient.SmallBatchingSystem.Models /// public int SiloWeight { get { return _mSiloWeight; } set { _mSiloWeight = value; OnPropertyChanged(); } } private int _mSiloWeight; + + /// + /// 选中索引 + /// + public int SelectIndex { get { return _mSelectIndex; } set { _mSelectIndex = value; OnPropertyChanged(); } } + private int _mSelectIndex; + } } diff --git a/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs b/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs index ab822258..d2efedb7 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; -namespace BPASmartClient.SmallBatchingSystem.Models +namespace BPASmartClient.SmallBatchingSystem { /// /// 原料仓信息 diff --git a/BPASmartClient.SmallBatchingSystem/Services/Control.cs b/BPASmartClient.SmallBatchingSystem/Services/Control.cs index 07556efd..acd3e6c8 100644 --- a/BPASmartClient.SmallBatchingSystem/Services/Control.cs +++ b/BPASmartClient.SmallBatchingSystem/Services/Control.cs @@ -1,5 +1,5 @@ using BPA.Helper; -using BPASmartClient.SmallBatchingSystem.Models; +using BPASmartClient.SmallBatchingSystem; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -9,7 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace BPASmartClient.SmallBatchingSystem.Services +namespace BPASmartClient.SmallBatchingSystem { public class Control { diff --git a/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs b/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs index 9b03eba5..813be047 100644 --- a/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs +++ b/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs @@ -6,9 +6,9 @@ using System.Threading; using System.Threading.Tasks; using BPA.Helper; using BPASmartClient.Modbus; -using BPASmartClient.SmallBatchingSystem.Models; +using BPASmartClient.SmallBatchingSystem; -namespace BPASmartClient.SmallBatchingSystem.Services +namespace BPASmartClient.SmallBatchingSystem { public class PlcServer { diff --git a/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs b/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs index ff653560..570b460e 100644 --- a/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs +++ b/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs @@ -9,7 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace BPASmartClient.SmallBatchingSystem.Services +namespace BPASmartClient.SmallBatchingSystem { /// /// 料仓服务线程 diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs index 9e2b4b9c..fd743e37 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs @@ -5,18 +5,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; -using BPASmartClient.SmallBatchingSystem.Models; using BPASmartClient.SmallBatchingSystem.Views; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.SmallBatchingSystem.ViewModels { - public class NewOutletViewModel : ObservableObject + public class NewOutletViewModel : BaseModel { - int index = -1; public NewOutletViewModel() { + Json.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); ActionManage.GetInstance.Register(new Action((o) => { if (o != null && o is OutletInfoModel tempOutletInfo) @@ -25,22 +24,23 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels OutletLoc = tempOutletInfo.OutletLoc; tempOutletInfo.SiloInfos?.ToList()?.ForEach((item => { - SiloInfos.Add(new RawMaterialInfo() { RawMaterialName = item }); + int tempIndex = Array.FindIndex(SileName.ToArray(), p => p.Contains(item)); + SiloInfos.Add(new RawMaterialInfo() { RawMaterialName = item, SelectIndex = tempIndex }); })); - index = Array.FindIndex(Json.Data.OutletInfoModels.ToArray(), p => p.OutletName == tempOutletInfo.OutletName); + Index = Array.FindIndex(Json.Data.OutletInfoModels.ToArray(), p => p.OutletName == tempOutletInfo.OutletName); } }), "OpenNewOutlet", true); - AddRawMaterialCommand = new RelayCommand(() => { SiloInfos.Add(new RawMaterialInfo()); }); + AddCommand = new RelayCommand(() => { SiloInfos.Add(new RawMaterialInfo()); }); CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("NewOutletViewClose"); }); SaveCommand = new RelayCommand(() => { ObservableCollection SileNames = new ObservableCollection(); SiloInfos.ToList()?.ForEach(item => { SileNames.Add(item.RawMaterialName); }); - if (index >= 0 && index < Json.Data.OutletInfoModels.Count) + if (Index >= 0 && Index < Json.Data.OutletInfoModels.Count) { - Json.Data.OutletInfoModels.ElementAt(index).OutletName = OutletName; - Json.Data.OutletInfoModels.ElementAt(index).OutletLoc = OutletLoc; - Json.Data.OutletInfoModels.ElementAt(index).SiloInfos = SileNames; + Json.Data.OutletInfoModels.ElementAt(Index).OutletName = OutletName; + Json.Data.OutletInfoModels.ElementAt(Index).OutletLoc = OutletLoc; + Json.Data.OutletInfoModels.ElementAt(Index).SiloInfos = SileNames; } else { @@ -62,18 +62,8 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels } }); - Json.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); } - - - - public RelayCommand AddRawMaterialCommand { get; set; } - public RelayCommand CancelCommand { get; set; } - public RelayCommand SaveCommand { get; set; } - - public RelayCommand RemoveCommand { get; set; } - public string OutletName { get { return _mOutletName; } set { _mOutletName = value; OnPropertyChanged(); } } private string _mOutletName; @@ -91,5 +81,8 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels 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; + } } diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs index 67f7ae69..6520cfb4 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs @@ -7,25 +7,49 @@ using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System.Collections.ObjectModel; using BPA.Helper; -using BPASmartClient.SmallBatchingSystem.Models; namespace BPASmartClient.SmallBatchingSystem.ViewModels { - public class NewRecipeViewModel : ObservableObject + public class NewRecipeViewModel : BaseModel { + //int Index = -1; public NewRecipeViewModel() { - AddRawMaterialCommand = new RelayCommand(() => { SiloInfos.Add(new RecipeRawMaterialInfo()); }); - CnacelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("NewRecipeViewModelClose"); }); + Json.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is RecipeInfo tempRecipeInfo) + { + RecipeName = tempRecipeInfo.RecipeName; + tempRecipeInfo.SiloInfoModels.ToList()?.ForEach(item => + { + int tempIndex = Array.FindIndex(SileName.ToArray(), p => p.Contains(item.SiloName)); + SiloInfos.Add(new RecipeRawMaterialInfo() { SiloName = item.SiloName, SiloWeight = item.SiloWeight, SelectIndex = tempIndex }); + }); + Index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == tempRecipeInfo.RecipeName); + } + }), "OpenNewRecipe", true); + AddCommand = new RelayCommand(() => { SiloInfos.Add(new RecipeRawMaterialInfo()); }); + CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("NewRecipeViewModelClose"); }); SaveCommand = new RelayCommand(() => { - //ObservableCollection SileNames = new ObservableCollection(); - //SiloInfos.ToList()?.ForEach(item => { SileNames.Add(item.RawMaterialName); }); - Json.Data.Recipes.Add(new RecipeInfo() + if (Index >= 0 && Index < Json.Data.OutletInfoModels.Count) { - RecipeName = RecipeName, - SiloInfoModels = SiloInfos - }); + Json.Data.Recipes.ElementAt(Index).RecipeName = RecipeName; + Json.Data.Recipes.ElementAt(Index).SiloInfoModels.Clear(); + SiloInfos.ToList()?.ForEach(item => + { + Json.Data.Recipes.ElementAt(Index).SiloInfoModels.Add(item); + }); + } + else + { + Json.Data.Recipes.Add(new RecipeInfo() + { + RecipeName = RecipeName, + SiloInfoModels = SiloInfos + }); + } ActionManage.GetInstance.Send("NewRecipeViewModelClose"); }); @@ -37,20 +61,18 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels if (res != null) SiloInfos.Remove(res); } }); - - Json.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); } public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } } private string _mRecipeName; - public RelayCommand AddRawMaterialCommand { get; set; } + //public RelayCommand AddCommand { get; set; } - public RelayCommand CnacelCommand { get; set; } + //public RelayCommand CnacelCommand { get; set; } - public RelayCommand SaveCommand { get; set; } + //public RelayCommand SaveCommand { get; set; } - public RelayCommand RemoveCommand { get; set; } + //public RelayCommand RemoveCommand { get; set; } public ObservableCollection SiloInfos { get; set; } = new ObservableCollection(); diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/NewSiloViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/NewSiloViewModel.cs index a697b87d..fcea4495 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/NewSiloViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/NewSiloViewModel.cs @@ -4,31 +4,51 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; -using BPASmartClient.SmallBatchingSystem.Models; using Microsoft.Toolkit.Mvvm.Input; using BPA.Helper; namespace BPASmartClient.SmallBatchingSystem.ViewModels { - public class NewSiloViewModel : ObservableObject + public class NewSiloViewModel : BaseModel { public NewSiloViewModel() { - CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("Cancel"); }); - OkCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("OK"); }); + CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("SiloClose"); }); + SaveCommand = new RelayCommand(() => + { + if (Index >= 0 && Index < Json.Data.SiloInfoModels.Count) + { + Json.Data.SiloInfoModels.ElementAt(Index).SiloName = SiloInfoModelObj.SiloName; + Json.Data.SiloInfoModels.ElementAt(Index).SiloLoc = SiloInfoModelObj.SiloLoc; + } + else + { + Json.Data.SiloInfoModels.Add(new SiloInfoModel() + { + SiloLoc = SiloInfoModelObj.SiloLoc, + SiloName = SiloInfoModelObj.SiloName, + }); + } + ActionManage.GetInstance.Send("SiloClose"); + }); + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is SiloInfoModel tempSilo) + { + SiloInfoModelObj.SiloLoc = tempSilo.SiloLoc; + SiloInfoModelObj.SiloName = tempSilo.SiloName; + Index = Array.FindIndex(Json.Data.SiloInfoModels.ToArray(), p => p.SiloName == tempSilo.SiloName); + } + }), "OpenNewSilo", true); } public SiloInfoModel SiloInfoModelObj { get { return _mSiloInfoModelObj; } set { _mSiloInfoModelObj = value; OnPropertyChanged(); } } - private SiloInfoModel _mSiloInfoModelObj; + private SiloInfoModel _mSiloInfoModelObj = new SiloInfoModel(); public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } } private string _mErrorInfo; - - public RelayCommand CancelCommand { get; set; } - public RelayCommand OkCommand { get; set; } - } } diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs index b6b10491..5079f8f5 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs @@ -5,18 +5,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; -using BPASmartClient.SmallBatchingSystem.Models; using BPASmartClient.SmallBatchingSystem.Views; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.SmallBatchingSystem.ViewModels { - public class OutletManagementViewModel : ObservableObject + public class OutletManagementViewModel : BaseModel { public OutletManagementViewModel() { - AddSiloCommand = new RelayCommand(() => + AddCommand = new RelayCommand(() => { NewOutletView newOutletView = new NewOutletView(); newOutletView.ShowDialog(); @@ -47,14 +46,6 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels }); } - public RelayCommand AddSiloCommand { get; set; } - - public RelayCommand SaveCommand { get; set; } - - public RelayCommand RemoveCommand { get; set; } - - public RelayCommand DetailsCommand { get; set; } - public ObservableCollection OutletInfoModels { get; set; } diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs index 5b27c78e..583e3cc4 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs @@ -5,10 +5,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; -using BPASmartClient.SmallBatchingSystem.Models; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; -using BPASmartClient.SmallBatchingSystem.Services; namespace BPASmartClient.SmallBatchingSystem.ViewModels { diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs index ab203f7e..195467dc 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs @@ -5,18 +5,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; -using BPASmartClient.SmallBatchingSystem.Models; using BPASmartClient.SmallBatchingSystem.Views; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.SmallBatchingSystem.ViewModels { - public class RecipeViewModel : ObservableObject + public class RecipeViewModel : BaseModel { public RecipeViewModel() { - NewRecipeCommand = new RelayCommand(() => + AddCommand = new RelayCommand(() => { NewRecipeView newOutletView = new NewRecipeView(); newOutletView.ShowDialog(); @@ -40,33 +39,13 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels if (res != null) { NewRecipeView newOutletView = new NewRecipeView(); - newOutletView.outName.Text = o.ToString(); - //res.SiloInfoModels?.ToList()?.ForEach(item => { NewRecipeViewModel.SiloInfoModels.Add(item); }); - //int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); - //if (index >= 0 && index < Json.Data.Recipes.Count) - //{ - // NewRecipeViewModel.SiloInfoModels = Json.Data.Recipes.ElementAt(index).SiloInfoModels; - //} + ActionManage.GetInstance.Send("OpenNewRecipe", res); newOutletView.ShowDialog(); - //int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); - //if (index >= 0 && index < Json.Data.Recipes.Count) - //{ - // NewRecipeViewModel.SiloInfoModels = Json.Data.Recipes.ElementAt(index).SiloInfoModels; - //} - } } }); } - public RelayCommand NewRecipeCommand { get; set; } - - public RelayCommand SaveCommand { get; set; } - - public RelayCommand RemoveCommand { get; set; } - - public RelayCommand DetailsCommand { get; set; } - public ObservableCollection RecipeInfoModels { get; set; } } } diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs index e124fbdd..068c4803 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs @@ -6,31 +6,45 @@ using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using BPASmartClient.SmallBatchingSystem.Views; -using BPASmartClient.SmallBatchingSystem.Models; using System.Collections.ObjectModel; using BPA.Helper; namespace BPASmartClient.SmallBatchingSystem.ViewModels { - public class SiloManagementViewModel : ObservableObject + public class SiloManagementViewModel : BaseModel { public SiloManagementViewModel() { - AddSilo = new RelayCommand(() => + AddCommand = new RelayCommand(() => { NewSiloView newSiloView = new NewSiloView(); - if (newSiloView.ShowDialog() == true) + newSiloView.ShowDialog(); + }); + SaveCommand = new RelayCommand(() => { Json.Save(); }); + SiloInfoModels = Json.Data.SiloInfoModels; + RemoveCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) { - //if (newSiloView.Tag!=null && newSiloView.Tag is ) + var res = Json.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == o.ToString()); + if (res != null) Json.Data.SiloInfoModels.Remove(res); } }); - SaveData = new RelayCommand(() => { Json.Save(); }); - SiloInfoModels = Json.Data.SiloInfoModels; - } - - public RelayCommand AddSilo { get; set; } - public RelayCommand SaveData { get; set; } + DetailsCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = Json.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == o.ToString()); + if (res != null) + { + NewSiloView newSiloView = new NewSiloView(); + ActionManage.GetInstance.Send("OpenNewSilo", res); + newSiloView.ShowDialog(); + } + } + }); + } public ObservableCollection SiloInfoModels { get; set; } diff --git a/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml b/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml index e5c26338..58c5c5c5 100644 --- a/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml +++ b/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml @@ -182,7 +182,7 @@ Width="90" Height="30" Margin="5,0,5,0" - Command="{Binding AddRawMaterialCommand}" + Command="{Binding AddCommand}" Content="添加原料" FontSize="20" Style="{StaticResource ImageButtonStyle}" /> @@ -251,51 +251,52 @@ - + + + + + + + + + +