|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using System.Collections.Concurrent;
- using System.Collections.ObjectModel;
- using System.Windows;
- using BPASmartClient.Helper;
- using Microsoft.Toolkit.Mvvm.Input;
- using BPASmartClient.JXJFoodSmallStation.Model;
- using BPASmartClient.JXJFoodSmallStation.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.JXJFoodSmallStation.Model.Siemens;
- using BPASmartClient.JXJFoodSmallStation.Model.GVL;
-
- namespace BPASmartClient.JXJFoodSmallStation.ViewModel
- {
- public class RecipeReceiveViewModel : ObservableObject
- {
- //ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
- public RecipeReceiveViewModel()
- {
- IsUseLocalRecipe = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
- IsUseWindSendDosing = GVL_SmallStation.GetInstance.IsUseWindSend;
- //Json<LocaPar>.Read();
- Recipes = Json<LocalRecipeDataColl>.Data.Recipes;
-
- NewRecipe = new RelayCommand(() =>
- {
- NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView();
- NewLocalRecipe.ShowDialog();
- });
- RemoveRecipe = new RelayCommand<object>((o) =>
- {
- if (o != null && o is string cnt)
- {
- var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
- if (res != null)
- {
- Json<LocalRecipeDataColl>.Data.Recipes.Remove(res);
- MessageNotify.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}");
- }
- }
- });
- DetailsCommand = new RelayCommand<object>((o) =>
- {
- if (o != null && o is string cnt)
- {
- ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
- NewLocalRecipeView nrv = new NewLocalRecipeView();
- var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
- if (res != null)
- {
- ActionManage.GetInstance.Send("LocalRecipeEdit", res);
- nrv.Show();
- MessageNotify.GetInstance.ShowUserLog($"编辑配方——{res.RecipeName}");
- }
- }
- });
- IssueRecipe = new RelayCommand<object>((o) =>
- {
- if (IsUseLocalRecipe == false)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"未处于本地模拟配方状态!");
- return;
- }
- else
- {
- if (o != null && o is string cnt)
- {
- var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
- var res1 = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
- if (res1 != null)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"远程已经存在该配方!");
- return;
- }
- if (res != null && res1 ==null)
- {
- ActionManage.GetInstance.Send("LocalSimulationRecipeIssue", res);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{res.RecipeName}配方下发成功!");
- MessageNotify.GetInstance.ShowUserLog($"下发本地模拟配方——{res.RecipeName}");
- }
- }
- }
- });
- NewSimulateRecipe = new RelayCommand(() =>
- {
- ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
- string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.Recipes.Count + 1) + "";
- go:
- string recipeCode = new Random().Next(1000, 9999).ToString();
- foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
- {
- if (item.RecipeCode == recipeCode)
- {
- goto go;
- }
- }
- int trayCode = new Random().Next(1, 3);
- for (int i = 1; i < 16; i++)
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialName = "原料" + i,
- RawMaterialWeight = new Random().Next(200, 300),
- RawMaterialBarrelNum = (short)new Random().Next(1, 5),
- RawMaterialLocation = i,
- });
- }
- if (GVL_SmallStation.GetInstance.IsUseWindSend && trayCode == 1)
- {
- for (int i = 1; i < 6; i++)
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialName = "粉料" + i,
- RawMaterialWeight = new Random().Next(200, 300),
- RawMaterialLocation = i,
- RawMaterialBarrelNum = 7
- });
- }
- }
- var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode);
- if (res < 0)
- {
- Json<LocalRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
- {
- RecipeName = recipeName,
- RecipeCode = recipeCode,
- TrayCode = trayCode,
- RawMaterial = RawMaterials,
- });
- }
-
- });
- ClearAllRecipe = new RelayCommand(() =>
- {
- Json<LocalRecipeDataColl>.Data.Recipes.Clear();
- });
- }
- public bool IsUseLocalRecipe { get { return _mIsUseLocalRecipe; }set { _mIsUseLocalRecipe = value; OnPropertyChanged(); } }
- private bool _mIsUseLocalRecipe ;
-
- public bool IsUseWindSendDosing { get { return _mIsUseWindSendDosing; } set { _mIsUseWindSendDosing = value;OnPropertyChanged(); } }
- private bool _mIsUseWindSendDosing ;
-
- public RelayCommand<object> DetailsCommand { get; set; }
- public RelayCommand<object> IssueRecipe { get; set; }
- public RelayCommand<object> RemoveRecipe { get; set; }
- public RelayCommand NewSimulateRecipe { get;set; }
- public RelayCommand ClearAllRecipe { get; set; }
- public RelayCommand NewRecipe { get; set; }
- public ObservableCollection<RemoteRecipeData> Recipes { get; set; }
- }
- }
|