终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
1.8 KiB

  1. using BPASmart.Model;
  2. using BPASmartClient.Helper;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. namespace BPASmart.RecipeManagement.ViewModel
  10. {
  11. public class CreateOrderViewModel : ObservableObject
  12. {
  13. public ObservableCollection<Recipes> recipes { get; set; } = new ObservableCollection<Recipes>();
  14. public ObservableCollection<string> recipesName { get; set; } = new ObservableCollection<string>();
  15. public RelayCommand SaveCommand { get; set; }
  16. public RelayCommand<object> DeleteCommand { get; set; }
  17. public RelayCommand AddRecipeCommand { get; set; }
  18. private void Delete(object o)
  19. {
  20. if (o == null) return;
  21. if (o is string id)
  22. {
  23. var res = recipes.FirstOrDefault(x => x.ID == id);
  24. recipes.Remove(res);
  25. }
  26. }
  27. public CreateOrderViewModel()
  28. {
  29. SaveCommand = new RelayCommand(() =>
  30. {
  31. Globle.GlobleData.orders.Add(new Order
  32. {
  33. OrderId = Guid.NewGuid().ToString(),
  34. OrderdateTime = DateTime.Now.ToString(),
  35. Recipes = recipes
  36. });
  37. ActionManage.GetInstance.Send("CloseCreateOrderView");
  38. });
  39. DeleteCommand = new RelayCommand<object>(Delete);
  40. AddRecipeCommand = new RelayCommand(() =>
  41. {
  42. recipes.Add(new Recipes() { ID = Guid.NewGuid().ToString(), RecipeCount = 1, });
  43. });
  44. foreach (var item in Json<LocalRecipes>.Data.locaRecipes)
  45. {
  46. recipesName.Add(item.Name);
  47. }
  48. }
  49. }
  50. }