|
- 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.JXJFoodBigStation.Model;
- using BPASmartClient.JXJFoodBigStation.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.JXJFoodBigStation.Model.Siemens;
-
- namespace BPASmartClient.JXJFoodBigStation.ViewModel
- {
- public class RecipeReceiveViewModel : ObservableObject
- {
- public ObservableCollection<RawMaterialModel> RawMaterials { get; set; } = new ObservableCollection<RawMaterialModel>();
- public RecipeReceiveViewModel()
- {
- Json<LocaPar>.Read();
- Recipes = Json<LocaPar>.Data.Recipes;
- DetailsCommand = new RelayCommand<object>((o) =>
- {
- if (o != null && o is long num)
- {
- ActionManage.GetInstance.CancelRegister("RecipeInfo");
- RecipeInfosView nrv = new RecipeInfosView();
- var res = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == num);
- ActionManage.GetInstance.Send("RecipeInfo", res);
- nrv.Show();
- MessageLog.GetInstance.ShowUserLog($"查看配方——{res.RecipeName}");
- }
- });
- NewRecipe = new RelayCommand(() => {
-
- RecipeInfosView nrv = new RecipeInfosView();
- nrv.ShowDialog();
- });
-
- NewSimulateRecipe = new RelayCommand(() =>
- {
- RawMaterials.Clear();
- string recipeName = "配方" + (Json<LocaPar>.Data.Recipes.Count + 1) + "";
- go:
- long recipeCode = new Random().Next(10000, 99999);
- foreach (var item in Recipes)
- {
- if (item.RecipeCode == recipeCode)
- {
- goto go;
- }
- }
- int trayCode = new Random().Next(1,6);
- for (int i = 1; i < 13; i++)
- {
- int a = new Random().Next(1, 5);
- if (a == 3)
- {
- a = 1;
- }
- RawMaterials.Add(new RawMaterialModel()
- {
- RawMaterialWeight = new Random().Next(10, 1000),
- RawMaterialBarrelNum = a,
- RawMaterialLocation = i,
- });
- }
- Json<LocaPar>.Data.Recipes.Add(new RecipeModel()
- {
- RecipeName = recipeName,
- RecipeCode = recipeCode,
- TrayCode = trayCode,
- RawMaterial = RawMaterials,
- });
-
- });
- ClearAllRecipe = new RelayCommand(() =>
- {
- Json<LocaPar>.Data.Recipes.Clear();
- Json<LocaPar>.Save();
- });
-
- RemoveCommand = new RelayCommand<long>((recipeCode) => {
-
- var res = Recipes.FirstOrDefault(p=>p.RecipeCode==recipeCode);
- if(res!=null)
- {
- Recipes.Remove(res);
- Json<LocaPar>.Save();
- }
-
- });
- }
-
- public RelayCommand<object> DetailsCommand { get; set; }
-
- public RelayCommand NewSimulateRecipe { get; set; }
- public RelayCommand ClearAllRecipe { get; set; }
-
- public RelayCommand NewRecipe { get; set; }
-
- public RelayCommand<long> RemoveCommand { get; set; }
-
- public ObservableCollection<RecipeModel> Recipes { get; set; } = new ObservableCollection<RecipeModel>();
- }
- }
|