|
- 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.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 : NotifyBase
- {
- public ObservableCollection<RawMaterial> RawMaterials { get; set; } = new ObservableCollection<RawMaterial>();
- public RecipeReceiveViewModel()
- {
- IsUseLocalRecipe = GVL_BigStation.IsUseLocalRecipe;
- Json<LocalRecipe>.Read();
- Recipes = Json<LocalRecipe>.Data.Recipes;
- DetailsCommand = new BPARelayCommand<object>((o) =>
- {
- if (o != null && o is string num)
- {
- ActionManage.GetInstance.CancelRegister("RecipeInfo");
- RecipeInfosView nrv = new RecipeInfosView();
- var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == num);
- ActionManage.GetInstance.Send("RecipeInfo", res);
- nrv.Show();
- MessageNotify.GetInstance.ShowUserLog($"编辑配方,配方名称:【{res.RecipeName}】");
- }
- });
- NewRecipe = new BPARelayCommand(() =>
- {
- RecipeInfosView nrv = new RecipeInfosView();
- nrv.ShowDialog();
- });
-
- //RefreshRecipe = new BPARelayCommand(() =>
- //{
- // foreach (var item in ProcessControl.GetInstance.RawMaterialsInfo)
- // {
- // RawMaterialNames.Add(item.RawMaterialName);
- // }
-
- // foreach (var item in Json<LocalRecipe>.Data.Recipes)
- // {
- // foreach (var tep in item.RawMaterial)
- // {
- // if (RawMaterialNames.Contains(tep.RawMaterialName))
- // {
- // int index = Array.FindIndex(ProcessControl.GetInstance.RawMaterialsInfo.ToArray(), p => p.RawMaterialName == tep.RawMaterialName);
- // tep.RawMaterialLocation = ProcessControl.GetInstance.RawMaterialsInfo.ElementAt(index).RawMaterialLocation;
- // }
- // }
- // }
- //});
-
- //模拟配方
- //NewSimulateRecipe = new BPARelayCommand(() =>
- //{
- // RawMaterials.Clear();
- // string recipeName = "配方" + (Json<LocaPar>.Data.Recipes.Count + 1) + "";
- //go:
- // string recipeCode = new Random().Next(10000, 99999).ToString();
- // 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,
- // });
- // Json<LocaPar>.Save();
- //});
- ClearAllRecipe = new BPARelayCommand(() =>
- {
- if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否删除所有本地配方?",DialogType.Warning))
- {
- return;
- }
-
- Json<LocalRecipe>.Data.Recipes.Clear();
- Json<LocalRecipe>.Data.SelectedRecipes.Clear();
- Json<LocalRecipe>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"本地配方已全部删除!");
- MessageNotify.GetInstance.ShowUserLog($"手动清除所有配方。");
- });
-
- RemoveCommand = new BPARelayCommand<string>((recipeCode) =>
- {
- if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否删除配方【{recipeCode}】?",DialogType.Warning))
- {
- return;
- }
- var res = Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
- var res1 = Json<LocalRecipe>.Data.SelectedRecipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
- if (res1 is not null)
- {
- Json<LocalRecipe>.Data.SelectedRecipes.Remove(res1);
- }
- if (res != null)
- {
- Recipes.Remove(res);
- Json<LocalRecipe>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方删除完成");
- MessageNotify.GetInstance.ShowUserLog($"手动删除【{res.RecipeName}】配方,编号:【{recipeCode}】,");
- }
- });
- }
- public BPARelayCommand<object> DetailsCommand { get; set; }
- // public BPARelayCommand NewSimulateRecipe { get; set; }
- public BPARelayCommand ClearAllRecipe { get; set; }
- public BPARelayCommand NewRecipe { get; set; }
- public BPARelayCommand RefreshRecipe { get; set; }
- public bool IsUseLocalRecipe { get { return _isUseLocalRecipe; } set { _isUseLocalRecipe = value; OnPropertyChanged(); } }
- public bool _isUseLocalRecipe { get; set; }
- public BPARelayCommand<string> RemoveCommand { get; set; }
- public ObservableCollection<RecipeData> Recipes { get; set; } = new ObservableCollection<RecipeData>();
-
- public ObservableCollection<string> RawMaterialNames { get; set; } = new ObservableCollection<string>();
- }
- }
|