|
- using BPA.Helper;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.DosingSystem.Model;
- using BPASmartClient.DosingSystem.View;
- using System.Collections.ObjectModel;
- using System.Linq;
-
- namespace BPASmartClient.DosingSystem.ViewModel
- {
- public class RecipeSettingsViewModel : NotifyBase
- {
- public RecipeSettingsViewModel()
- {
- Recipes = Json<LocalRecipe>.Data.Recipes;
-
- NewMaterital = new BPARelayCommand(() =>
- {
- NewMaterialView newMateritalView = new NewMaterialView();
- newMateritalView.ShowDialog();
- });
- NewRecipe = new BPARelayCommand(() =>
- {
- NewRecipeView nrv = new NewRecipeView();
- nrv.ShowDialog();
- MessageNotify.GetInstance.ShowUserLog("新建配方");
- });
- SaveRecipe = new BPARelayCommand(() =>
- {
- Json<LocalRecipe>.Save();
- MessageNotify.GetInstance.ShowUserLog("保存配方");
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
- });
- RemoveCommand = new BPARelayCommand<object>((o) =>
- {
- if (!string.IsNullOrEmpty(o?.ToString()))
- {
- if (MessageNotify.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning))
- {
- var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
- if (res.IsEnable)
- {
- if (res != null) Json<LocalRecipe>.Data.Recipes.Remove(res);
- Json<LocalRecipe>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!");
- MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}");
- //配方名称集合上报
- if (ExcuteControl.GetInstance.mqttCollection.ContainsKey("Conveyer") && ExcuteControl.GetInstance.mqttCollection["Conveyer"]._mqttClient.IsConnected)
- {
- AliyunSystemPropertyReportModel m1 = new AliyunSystemPropertyReportModel();
- m1.RecipeCollection = new string[Json<LocalRecipe>.Data.Recipes.Count];
- for (int i = 0; i < Json<LocalRecipe>.Data.Recipes.Count; i++)
- {
- m1.RecipeCollection[i] = Json<LocalRecipe>.Data.Recipes[i].RecipeName;
- }
- ExcuteControl.GetInstance.SystemPropertyReport(m1);
- }
- }
- else
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"删除【{o.ToString()}】配方失败,配方正在使用!");
- }
- }
- }
- });
-
- DetailsCommand = new BPARelayCommand<object>((o) =>
- {
- if (!string.IsNullOrEmpty(o?.ToString()))
- {
- var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
- if (res != null)
- {
- NewRecipeView nrv = new NewRecipeView();
- ActionManage.GetInstance.Send("Details", res);
- nrv.ShowDialog();
- }
- //MessageLog.GetInstance.ShowUserLog($"编辑配方名称——{res.RecipeName}");
- }
- });
-
- }
-
- public BPARelayCommand NewMaterital { get; set; }
-
- public BPARelayCommand NewRecipe { get; set; }
-
- public BPARelayCommand SaveRecipe { get; set; }
-
- public BPARelayCommand<object> EditCommand { get; set; }
-
- public BPARelayCommand<object> DetailsCommand { get; set; }
-
- public BPARelayCommand<object> RemoveCommand { get; set; }
-
- public ObservableCollection<RecipeModel> Recipes { get; set; }
- }
- }
|