终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

77 rindas
2.3 KiB

  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 : NotifyBase
  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. public string Name { get { return _name; } set { _name = value; OnPropertyChanged(); } }
  14. private string _name;
  15. //[BPARelayCommand]
  16. private void AddMaterial()
  17. {
  18. Materails.Add(new LocalMaterail());
  19. }
  20. //[BPARelayCommand]
  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. //[BPARelayCommand]
  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. }