终端一体化运控平台
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.

RecipeConfigeViewModel.cs 2.2 KiB

2 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Controls;
  7. namespace BPASmartClient.MilkWithTea.ViewModel
  8. {
  9. partial class RecipeConfigeViewModel:ObservableObject
  10. {
  11. public static ObservableCollection<LocalMaterail> Materails { get; set; } = new ObservableCollection<LocalMaterail>();
  12. public Dictionary<string,string> materialNames { get; set; } = new Dictionary<string,string>();
  13. [ObservableProperty]
  14. private string _name = String.Empty;
  15. [RelayCommand]
  16. private void AddMaterial()
  17. {
  18. Materails.Add(new LocalMaterail());
  19. }
  20. [RelayCommand]
  21. private void Delete(object o)
  22. {
  23. if (o == null) return;
  24. if(o is ListBoxItem id)
  25. {
  26. Materails.Remove((LocalMaterail)id.DataContext);
  27. }
  28. }
  29. [RelayCommand]
  30. private void Save()
  31. {
  32. if(Name == String.Empty)
  33. {
  34. return;
  35. }
  36. if(Json<JsonLocalRecipes>.Data.localRecipes.FirstOrDefault(p=>p.RecipeName == Name)!= null)
  37. {
  38. return;
  39. }
  40. foreach(var materail in Materails)
  41. {
  42. materail.MaterialName = materialNames[materail.MaterialID];
  43. }
  44. Json<JsonLocalRecipes>.Data.localRecipes.Add(new LocalRecipe
  45. {
  46. RecipeID = Guid.NewGuid().ToString(),
  47. RecipeName = Name,
  48. localMaterails = Materails,
  49. });
  50. Json<JsonLocalRecipes>.Save();
  51. ActionManage.GetInstance.Send("RecipeConfigeViewClose");
  52. }
  53. public RecipeConfigeViewModel()
  54. {
  55. if(Json<JsonLocalRecipes>.Data.localMaterails.Count > 0)
  56. {
  57. foreach(var item in Json<JsonLocalRecipes>.Data.localMaterails)
  58. {
  59. if(item.MaterialID!=null&&item.MaterialName!=null)
  60. {
  61. materialNames.Add(item.MaterialID, item.MaterialName);
  62. }
  63. }
  64. }
  65. Materails.Clear();
  66. }
  67. }
  68. }