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.DosingHKProject.Model; using BPASmartClient.DosingHKProject.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.DosingHKProject.Model.Siemens; using BPASmartClient.DosingHKProject.Model.GVL; using BPASmartClient.DosingProject; namespace BPASmartClient.DosingHKProject.ViewModel { public class RecipeReceiveViewModel : ObservableObject { //ObservableCollection RawMaterials { get; set; } = new ObservableCollection(); public RecipeReceiveViewModel() { Recipes = Json.Data.Recipes; NewRecipe = new RelayCommand(() => { NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView(); NewLocalRecipe.ShowDialog(); }); RemoveRecipe = new RelayCommand((o) => { if (o != null && o is string cnt) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt); if (res != null) { Json.Data.Recipes.Remove(res); MessageNotify.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}"); } } }); DetailsCommand = new RelayCommand((o) => { if (o != null && o is string cnt) { ActionManage.GetInstance.Send("CloseNewRemoteRecipeView"); NewLocalRecipeView nrv = new NewLocalRecipeView(); var res = Json.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((o) => { if (o != null && o is string cnt) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt); if (res != null) { Json.Data.Recipes.Add(res); MessageNotify.GetInstance.ShowUserLog($"下发配方——{res.RecipeName}"); } } }); NewSimulateRecipe = new RelayCommand(() => { ObservableCollection RawMaterials = new ObservableCollection(); string recipeName = "配方" + (Json.Data.Recipes.Count + 1) + ""; go: string recipeCode = new Random().Next(1000, 9999).ToString(); foreach (var item in Json.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, }); } var res = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode); if (res < 0) { Json.Data.Recipes.Add(new RemoteRecipeData() { RecipeName = recipeName, RecipeCode = recipeCode, //TrayCode = trayCode, RawMaterial = RawMaterials, }); } }); ClearAllRecipe = new RelayCommand(() => { Json.Data.Recipes.Clear(); }); } public RelayCommand DetailsCommand { get; set; } public RelayCommand IssueRecipe { get; set; } public RelayCommand RemoveRecipe { get; set; } public RelayCommand NewSimulateRecipe { get; set; } public RelayCommand ClearAllRecipe { get; set; } public RelayCommand NewRecipe { get; set; } public ObservableCollection Recipes { get; set; } } }