|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using System.Collections.Concurrent;
- using System.Collections.ObjectModel;
- using System.Windows;
- using BPA.Helper;
-
- using BPASmartClient.DosingSystem.View;
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.Model;
- using BPASmartClient.CustomResource.UserControls.Enum;
- using System.Windows.Media;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Model;
-
- 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}");
- }
- 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; }
- }
- }
|