终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

100 行
4.4 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.CustomResource.UserControls;
  4. using BPASmartClient.CustomResource.UserControls.MessageShow;
  5. using BPASmartClient.DosingSystem.Model;
  6. using BPASmartClient.DosingSystem.View;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. namespace BPASmartClient.DosingSystem.ViewModel
  10. {
  11. public class RecipeSettingsViewModel : NotifyBase
  12. {
  13. public RecipeSettingsViewModel()
  14. {
  15. Recipes = Json<LocalRecipe>.Data.Recipes;
  16. NewMaterital = new BPARelayCommand(() =>
  17. {
  18. NewMaterialView newMateritalView = new NewMaterialView();
  19. newMateritalView.ShowDialog();
  20. });
  21. NewRecipe = new BPARelayCommand(() =>
  22. {
  23. NewRecipeView nrv = new NewRecipeView();
  24. nrv.ShowDialog();
  25. MessageNotify.GetInstance.ShowUserLog("新建配方");
  26. });
  27. SaveRecipe = new BPARelayCommand(() =>
  28. {
  29. Json<LocalRecipe>.Save();
  30. MessageNotify.GetInstance.ShowUserLog("保存配方");
  31. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
  32. });
  33. RemoveCommand = new BPARelayCommand<object>((o) =>
  34. {
  35. if (!string.IsNullOrEmpty(o?.ToString()))
  36. {
  37. if (MessageNotify.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning))
  38. {
  39. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
  40. if (res.IsEnable)
  41. {
  42. if (res != null) Json<LocalRecipe>.Data.Recipes.Remove(res);
  43. Json<LocalRecipe>.Save();
  44. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!");
  45. MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}");
  46. //配方名称集合上报
  47. if (ExcuteControl.GetInstance.mqttCollection.ContainsKey("Conveyer") && ExcuteControl.GetInstance.mqttCollection["Conveyer"]._mqttClient.IsConnected)
  48. {
  49. AliyunSystemPropertyReportModel m1 = new AliyunSystemPropertyReportModel();
  50. m1.RecipeCollection = new string[Json<LocalRecipe>.Data.Recipes.Count];
  51. for (int i = 0; i < Json<LocalRecipe>.Data.Recipes.Count; i++)
  52. {
  53. m1.RecipeCollection[i] = Json<LocalRecipe>.Data.Recipes[i].RecipeName;
  54. }
  55. ExcuteControl.GetInstance.SystemPropertyReport(m1);
  56. }
  57. }
  58. else
  59. {
  60. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"删除【{o.ToString()}】配方失败,配方正在使用!");
  61. }
  62. }
  63. }
  64. });
  65. DetailsCommand = new BPARelayCommand<object>((o) =>
  66. {
  67. if (!string.IsNullOrEmpty(o?.ToString()))
  68. {
  69. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
  70. if (res != null)
  71. {
  72. NewRecipeView nrv = new NewRecipeView();
  73. ActionManage.GetInstance.Send("Details", res);
  74. nrv.ShowDialog();
  75. }
  76. //MessageLog.GetInstance.ShowUserLog($"编辑配方名称——{res.RecipeName}");
  77. }
  78. });
  79. }
  80. public BPARelayCommand NewMaterital { get; set; }
  81. public BPARelayCommand NewRecipe { get; set; }
  82. public BPARelayCommand SaveRecipe { get; set; }
  83. public BPARelayCommand<object> EditCommand { get; set; }
  84. public BPARelayCommand<object> DetailsCommand { get; set; }
  85. public BPARelayCommand<object> RemoveCommand { get; set; }
  86. public ObservableCollection<RecipeModel> Recipes { get; set; }
  87. }
  88. }