|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
- using FryPot_DosingSystem.Model;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace FryPot_DosingSystem.ViewModel
- {
- internal class RecipeSetDownViewModel : ObservableObject
- {
-
-
- /// <summary>
- /// 配方下发
- /// </summary>
- public RelayCommand<object> RecipeSetDownCommand { get; set; }
- /// <summary>
- /// 配方一键下发
- /// </summary>
- public RelayCommand AllRecipeSetDownCommand { get; set; }
- public ObservableCollection<NewRecipeModel> Recipes { get; set; } = new ObservableCollection<NewRecipeModel>();
- public RecipeSetDownViewModel()
- {
- //Json<RecipeManage>.Read();
- Recipes =Json<RecipeManage>.Data.Recipes;
- RecipeSetDownCommand = new RelayCommand<object>((Id) =>
- {
- if (Id != null && Id is string strId)
- {
- var res = Recipes.FirstOrDefault(p => p.RecipeId == strId);
- if (res != null)
- {
- RecipeSetDown(new NewRecipeModel[] { res });
- //res.RecipeSetInfo = "配方下发成功";
- //Task.Run(() => { Thread.Sleep(1500); res.RecipeSetInfo = string.Empty; });
-
- }
- else
- {
- //res.RecipeSetInfo = "配方下发失败";
- //Task.Run(() => { Thread.Sleep(1500); res.RecipeSetInfo = string.Empty; });
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
- }
-
- }
- });
- AllRecipeSetDownCommand = new RelayCommand(() =>
- {
- if (Recipes != null)
- {
- try
- {
- RecipeSetDown(Recipes.ToArray());
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"所有配方下发成功!");
- }
- catch (Exception)
- {
-
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
- }
- //Task.Run(() =>
- //{
- // foreach (var item in Recipes)
- // {
- // item.RecipeSetInfo = "下发成功";
- // }
- // Thread.Sleep(1500);
- // foreach (var item in Recipes)
- // {
- // item.RecipeSetInfo = string.Empty;
- // }
- //});
-
- }
-
- });
- }
- /// <summary>
- /// 数据下发方法
- /// </summary>
- public void RecipeSetDown(NewRecipeModel[] recipes)
- {
- ActionManage.GetInstance.Send("RecipeSetDown", recipes);
- }
- }
- }
|