|
- 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.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;
- using BPASmartClient.JXJFoodSmallStation.View;
-
- namespace BPASmartClient.JXJFoodSmallStation.ViewModel
- {
- public class RecipeReceiveViewModel : NotifyBase
- {
- //ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
- public RecipeReceiveViewModel()
- {
- NotUseSmallDosing = GVL_SmallStation.GetInstance.NotUseSmallStation;
- IsUseLocalRecipe = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
- IsUseWindSendDosing = GVL_SmallStation.GetInstance.IsUseWindSend;
- RemoteRecipes = Json<LocalRecipeDataColl>.Data.RemoteRecipes;
-
- NewRecipe = new BPARelayCommand(() =>
- {
- NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView();
- NewLocalRecipe.ShowDialog();
- });
- RemoveRecipe = new BPARelayCommand<object>((o) =>
- {
- if (o != null && o is string cnt)
- {
- if (MessageNotify.GetInstance.ShowDialog($"请确认,是否删除订单【{cnt}】?"))
- {
- var res = Json<LocalRecipeDataColl>.Data.RemoteRecipes.FirstOrDefault(p => p.RecipeCode == cnt);
- var res1= Json<LocalRecipeDataColl>.Data.SelectedRecipes.FirstOrDefault(p => p.RecipeCode == cnt);
- if (res1 is not null)
- {
- Json<LocalRecipeDataColl>.Data.SelectedRecipes.Remove(res1);
- }
- if (res != null)
- {
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.Remove(res);
- Json<LocalRecipeDataColl>.Save();
- MessageNotify.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}");
- }
- }
- }
- });
- DetailsCommand = new BPARelayCommand<object>((o) =>
- {
- if (o != null && o is string cnt)
- {
- if (MessageNotify.GetInstance.ShowDialog($"请确认,是否进行编辑订单【{cnt}】操作?"))
- {
- //ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
- NewLocalRecipeView nrv = new NewLocalRecipeView();
- var res = Json<LocalRecipeDataColl>.Data.RemoteRecipes.FirstOrDefault(p => p.RecipeCode == cnt);
- if (res != null)
- {
- ActionManage.GetInstance.Send("LocalRecipeEdit", res);
- nrv.ShowDialog();
- MessageNotify.GetInstance.ShowUserLog($"编辑配方——{res.RecipeName}");
- }
- }
- }
- });
- IssueRecipe = new BPARelayCommand<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.RemoteRecipes.FirstOrDefault(p => p.RecipeCode == cnt);
- var res1 = Json<RemoteRecipeDataColl>.Data.RemoteRecipes.FirstOrDefault(p => p.RecipeCode == cnt);
- if (MessageNotify.GetInstance.ShowDialog($"请确认,是否进行下发订单【{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}】");
- }
- GVL_SmallStation.GetInstance.LatestIssueRecipe=DateTime.Now;
- }
- }
- }
- });
- NewSimulateRecipe = new BPARelayCommand(() =>
- {
- ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
- string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.RemoteRecipes.Count + 1) + "";
- go:
- string recipeCode = new Random().Next(1000, 9999).ToString();
- foreach (var item in Json<LocalRecipeDataColl>.Data.RemoteRecipes)
- {
- if (item.RecipeCode == recipeCode)
- {
- goto go;
- }
- }
- int trayCode = new Random().Next(1, 2);
- for (int i = 1; i < 16; i++)
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialName = "原料" + i,
- RawMaterialType = "小料",
- RawMaterialWeight = (float)Math.Round(new Random().Next(200, 300) * 0.001, 3),
- RawMaterialBarrelNum = (short)new Random().Next(6, 9),
- RawMaterialLocation = i,
- });
- }
- if (GVL_SmallStation.GetInstance.IsUseWindSend && trayCode == 1)
- {
- for (int i = 1; i < 6; i++)
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialName = "粉料" + i,
- RawMaterialType = "粉料",
- RawMaterialWeight = new Random().Next(1, 6),
- RawMaterialLocation = i,
- RawMaterialBarrelNum = 3
- });
- }
- }
- var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.RemoteRecipes.ToArray(), p => p.RecipeCode == recipeCode);
- if (res < 0)
- {
- var newRemoteRecipedata = new RecipeData()
- {
- RecipeName = recipeName,
- RecipeCode = recipeCode,
- TrayCode = trayCode,
- RawMaterial = RawMaterials,
- };
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.Add(newRemoteRecipedata);
-
- //新增了配方之后应该默认显示出来。
- Json<LocalRecipeDataColl>.Data.SelectedRecipes.Add(newRemoteRecipedata);
- MessageNotify.GetInstance.ShowUserLog("新增一条本地模拟配方。");
- }
-
- });
- ClearAllRecipe = new BPARelayCommand(() =>
- {
- if (MessageNotify.GetInstance.ShowDialog("请确认,是否清除所有本地配方?", DialogType.Warning))
- {
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.Clear();
- Json<LocalRecipeDataColl>.Data.SelectedRecipes.Clear();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"本地配方清空成功。");
- MessageNotify.GetInstance.ShowUserLog("手动清除所有本地配方");
- }
- });
-
-
- SelectedRecipes = Json<LocalRecipeDataColl>.Data.SelectedRecipes;
- SelectRecipesCommand = new BPARelayCommand(() =>
- {
- var selectView = new SelectRecipesView();
- selectView.ShowDialog();
-
- Json<LocalRecipeDataColl>.Data.SelectedRecipes.Clear();
- foreach (var recipe in SelectRecipesViewModel.SelectRecipes)
- {
- if (recipe != null && !Json<LocalRecipeDataColl>.Data.SelectedRecipes.Any(p => p.RecipeCode == recipe.RecipeCode))
- {
- Json<LocalRecipeDataColl>.Data.SelectedRecipes.Add(recipe);
- }
- }
- //不保存会导致下次打开本地配方下发页面,会重新读取之前存储的文件。
- Json<LocalRecipeDataColl>.Save();
- MessageNotify.GetInstance.ShowUserLog("筛选了一次配方。");
- });
- }
-
- public bool NotUseSmallDosing { get { return _mNotUseSmallDosing; } set { _mNotUseSmallDosing = value; OnPropertyChanged(); } }
- private bool _mNotUseSmallDosing;
-
- 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;
-
- /// <summary>
- /// 筛选后的配方列表。
- /// </summary>
- public static ObservableCollection<RecipeData> SelectedRecipes { get; set; }
-
- public BPARelayCommand<object> DetailsCommand { get; set; }
- public BPARelayCommand<object> IssueRecipe { get; set; }
- public BPARelayCommand<object> RemoveRecipe { get; set; }
- public BPARelayCommand NewSimulateRecipe { get; set; }
- public BPARelayCommand ClearAllRecipe { get; set; }
- public BPARelayCommand NewRecipe { get; set; }
- public BPARelayCommand SelectRecipesCommand { get; set; }
- public ObservableCollection<RecipeData> RemoteRecipes { get; set; }
- }
- }
|