using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; namespace BPASmartClient.MilkWithTea.ViewModel { partial class RecipeConfigeViewModel : NotifyBase { public static ObservableCollection Materails { get; set; } = new ObservableCollection(); public Dictionary materialNames { get; set; } = new Dictionary(); public string Name { get { return _name; } set { _name = value; OnPropertyChanged(); } } private string _name; //[BPARelayCommand] private void AddMaterial() { Materails.Add(new LocalMaterail()); } //[BPARelayCommand] private void Delete(object o) { if (o == null) return; if (o is ListBoxItem id) { Materails.Remove((LocalMaterail)id.DataContext); } } //[BPARelayCommand] private void Save() { if (Name == String.Empty) { return; } if (Json.Data.localRecipes.FirstOrDefault(p => p.RecipeName == Name) != null) { return; } foreach (var materail in Materails) { materail.MaterialName = materialNames[materail.MaterialID]; } Json.Data.localRecipes.Add(new LocalRecipe { RecipeID = Guid.NewGuid().ToString(), RecipeName = Name, localMaterails = Materails, }); Json.Save(); ActionManage.GetInstance.Send("RecipeConfigeViewClose"); } public RecipeConfigeViewModel() { if (Json.Data.localMaterails.Count > 0) { foreach (var item in Json.Data.localMaterails) { if (item.MaterialID != null && item.MaterialName != null) { materialNames.Add(item.MaterialID, item.MaterialName); } } } Materails.Clear(); } } }