|
- 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<LocalMaterail> Materails { get; set; } = new ObservableCollection<LocalMaterail>();
-
- public Dictionary<string, string> materialNames { get; set; } = new Dictionary<string, string>();
-
- 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<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();
- }
- }
- }
|