终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

93 řádky
3.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.Input;
  12. using BPASmartClient.DosingSystem.View;
  13. using BPASmartClient.CustomResource.UserControls;
  14. using BPASmartClient.CustomResource.UserControls.Model;
  15. using BPASmartClient.CustomResource.UserControls.Enum;
  16. using System.Windows.Media;
  17. using BPASmartClient.CustomResource.UserControls.MessageShow;
  18. using BPASmartClient.CustomResource.Pages.Model;
  19. using BPASmartClient.Model;
  20. namespace BPASmartClient.DosingSystem.ViewModel
  21. {
  22. public class RecipeSettingsViewModel : ObservableObject
  23. {
  24. public RecipeSettingsViewModel()
  25. {
  26. Recipes = Json<LocaPar>.Data.Recipes;
  27. NewMaterital = new RelayCommand(() =>
  28. {
  29. NewMaterialView newMateritalView = new NewMaterialView();
  30. newMateritalView.ShowDialog();
  31. });
  32. NewRecipe = new RelayCommand(() =>
  33. {
  34. NewRecipeView nrv = new NewRecipeView();
  35. nrv.ShowDialog();
  36. MessageLog.GetInstance.ShowUserLog("新建配方");
  37. });
  38. SaveRecipe = new RelayCommand(() =>
  39. {
  40. Json<LocaPar>.Save();
  41. MessageLog.GetInstance.ShowUserLog("保存配方");
  42. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
  43. });
  44. RemoveCommand = new RelayCommand<object>((o) =>
  45. {
  46. if (!string.IsNullOrEmpty(o?.ToString()))
  47. {
  48. if (MessageLog.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning))
  49. {
  50. var res = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
  51. if (res != null) Json<LocaPar>.Data.Recipes.Remove(res);
  52. Json<LocaPar>.Save();
  53. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!");
  54. MessageLog.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}");
  55. }
  56. }
  57. });
  58. DetailsCommand = new RelayCommand<object>((o) =>
  59. {
  60. if (!string.IsNullOrEmpty(o?.ToString()))
  61. {
  62. var res = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
  63. if (res != null)
  64. {
  65. NewRecipeView nrv = new NewRecipeView();
  66. ActionManage.GetInstance.Send("Details", res);
  67. nrv.ShowDialog();
  68. }
  69. //MessageLog.GetInstance.ShowUserLog($"编辑配方名称——{res.RecipeName}");
  70. }
  71. });
  72. }
  73. public RelayCommand NewMaterital { get; set; }
  74. public RelayCommand NewRecipe { get; set; }
  75. public RelayCommand SaveRecipe { get; set; }
  76. public RelayCommand<object> EditCommand { get; set; }
  77. public RelayCommand<object> DetailsCommand { get; set; }
  78. public RelayCommand<object> RemoveCommand { get; set; }
  79. public ObservableCollection<RecipeModel> Recipes { get; set; }
  80. }
  81. }