|
- 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:ObservableObject
- {
- public static ObservableCollection<LocalMaterail> Materails { get; set; } = new ObservableCollection<LocalMaterail>();
-
- public Dictionary<string,string> materialNames { get; set; } = new Dictionary<string,string>();
-
- [ObservableProperty]
- private string _name = String.Empty;
-
-
- [RelayCommand]
- private void AddMaterial()
- {
- Materails.Add(new LocalMaterail());
- }
- [RelayCommand]
- private void Delete(object o)
- {
- if (o == null) return;
- if(o is ListBoxItem id)
- {
- Materails.Remove((LocalMaterail)id.DataContext);
- }
- }
- [RelayCommand]
- private void Save()
- {
- if(Name == String.Empty)
- {
- return;
- }
- if(Json<JsonLocalRecipes>.Data.localRecipes.FirstOrDefault(p=>p.RecipeName == Name)!= null)
- {
- return;
- }
- foreach(var materail in Materails)
- {
- materail.MaterialName = materialNames[materail.MaterialID];
- }
- Json<JsonLocalRecipes>.Data.localRecipes.Add(new LocalRecipe
- {
- RecipeID = Guid.NewGuid().ToString(),
- RecipeName = Name,
- localMaterails = Materails,
- });
-
- Json<JsonLocalRecipes>.Save();
- ActionManage.GetInstance.Send("RecipeConfigeViewClose");
- }
-
- public RecipeConfigeViewModel()
- {
- if(Json<JsonLocalRecipes>.Data.localMaterails.Count > 0)
- {
- foreach(var item in Json<JsonLocalRecipes>.Data.localMaterails)
- {
- if(item.MaterialID!=null&&item.MaterialName!=null)
- {
- materialNames.Add(item.MaterialID, item.MaterialName);
- }
- }
- }
- Materails.Clear();
- }
- }
- }
|