using BPASmart.Model.配方; using BPASmartClient.Helper; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace BPASmart.RecipeManagement.ViewModel { public class CreateOrderViewModel: ObservableObject { public ObservableCollection recipes { get; set; } = new ObservableCollection(); public ObservableCollection recipesName { get; set; } = new ObservableCollection(); public RelayCommand SaveCommand { get; set; } public RelayCommand DeleteCommand { get; set; } public RelayCommand AddRecipeCommand { get; set; } private void Delete(object o) { if(o == null) return; if(o is string id) { var res = recipes.FirstOrDefault(x => x.ID == id); recipes.Remove(res); } } public CreateOrderViewModel() { SaveCommand = new RelayCommand(() => { Globle.GlobleData.orders.Add(new Order { OrderId = Guid.NewGuid().ToString(), OrderdateTime = DateTime.Now.ToString(), Recipes = recipes }); }); DeleteCommand = new RelayCommand(Delete); AddRecipeCommand = new RelayCommand(() => { recipes.Add(new Recipes() { ID = Guid.NewGuid().ToString() }); }); foreach( var item in Json.Data.locaRecipes ) { recipesName.Add(item.Name); } } } }