|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using System.Collections.ObjectModel;
- using BPASmartClient.JXJFoodSmallStation.Model;
- using BPA.Helper;
-
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.UserControls;
- using System.Diagnostics;
- using BPASmartClient.JXJFoodSmallStation.Model.Siemens;
- using Google.Protobuf.WellKnownTypes;
- using Newtonsoft.Json.Linq;
- using BPASmartClient.CustomResource.Pages.Model;
-
- namespace BPASmartClient.JXJFoodSmallStation.ViewModel
- {
- public class NewLocalRecipeViewModel : NotifyBase
- {
- public NewLocalRecipeViewModel()
- {
- //ActionManage.GetInstance.CancelRegister("LocalRecipeEdit");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is RecipeData rm)
- {
- RecipeName = rm.RecipeName;
- RecipeCode = rm.RecipeCode;
- TrayNum = rm.TrayCode;
- foreach (RemoteRecipeRawMaterial item in rm.RawMaterial)
- {
- var res = Json<DevicePar>.Data.rawMaterialStockBin.FirstOrDefault(p => p.RawMaterialLocation == item.RawMaterialLocation);
- if (res != null && !string.IsNullOrEmpty(res.RawMaterialName))
- {
- var temp = Json<DevicePar>.Data.BomMaterial.FirstOrDefault(p => p.MaterialCode == res.RawMaterialName);
- if (temp != null && !string.IsNullOrEmpty(temp.MaterialName))
- {
- item.RawMaterialName = temp.MaterialName;
- }
- }
- //AllRawMaterial.Add(item);
- AllRawMaterial.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialType = item.RawMaterialType,
- RawMaterialName = item.RawMaterialName,
- RawMaterialWeight = item.RawMaterialWeight,
- RawMaterialLocation = item.RawMaterialLocation,
- RawMaterialBarrelNum = item.RawMaterialBarrelNum,
- });
- }
- foreach (var item1 in rm.WindSend)
- {
-
- var res = Json<DevicePar>.Data.windSendRawMaterial.FirstOrDefault(p => p.Location == item1.Location);
- if (res != null)
- {
- item1.RawMaterialName = res.RawMaterialChineseName;
- }
-
- AllRawMaterial.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialType = item1.RawMaterialType,
- RawMaterialName = item1.RawMaterialName,
- RawMaterialWeight = item1.RawMaterialWeight,
- RawMaterialLocation = item1.Location,
- RawMaterialBarrelNum = item1.RawMaterialBarrelNum,
- });
- }
- }
- }), "LocalRecipeEdit", true);
-
-
- RemoveCommand = new BPARelayCommand<object>((o) =>
- {
- var res = AllRawMaterial.FirstOrDefault(p => p.RawMaterialName == o.ToString());
- if (res != null) AllRawMaterial.Remove(res);
- //NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{o.ToString()}:原料删除成功!");
- });
-
- AddCommand = new BPARelayCommand(() =>
- {
- int MaxRawMaterial = 15;
- var res = AllRawMaterial.Where(p => p.RawMaterialType == "小料").ToList();
- if (res.Count < MaxRawMaterial)
- {
- AllRawMaterial.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialType = "小料",
- RawMaterialName = "小料" + (res.Count + 1),
- RawMaterialLocation = res.Count + 1,
- RawMaterialBarrelNum = (short)new Random().Next(6, 9),
- RawMaterialWeight = (float)(new Random().Next(100, 300) * 0.001),
- });
- }
- else
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料最多添加{MaxRawMaterial}种");
- }
-
- });
- AddFLCommand = new BPARelayCommand(() =>
- {
- int MaxRawMaterial = 5;
- var res = AllRawMaterial.Where(p => p.RawMaterialType == "粉料").ToList();
- if (res.Count < MaxRawMaterial)
- {
- AllRawMaterial.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialType = "粉料",
- RawMaterialName = "粉料" + (res.Count + 1),
- RawMaterialLocation = res.Count + 1,
- RawMaterialWeight = new Random().Next(1, 5),
- RawMaterialBarrelNum = 3,
- });
- }
- else
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"粉料最多添加{MaxRawMaterial}种");
- }
- });
- SaveCommand = new BPARelayCommand(() =>
- {
- if (!MessageNotify.GetInstance.ShowDialog("请确认,是否保存该配方配置?"))
- {
- return;
- }
- if (RecipeName.Length < 0 || RecipeName == null || RecipeName == String.Empty || RecipeName == "")
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"配方名称不能为空");
- return;
- }
- if (RecipeCode.Length < 0 || RecipeCode == null || RecipeCode == String.Empty || RecipeCode == "")
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"配方编号不能为空");
- return;
- }
- if (TrayNum != 1 && TrayNum != 2)
- {
- TrayNum = 1;
- }
- ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
- ObservableCollection<WindSendRawMaterial> WindSendRawMaterials = new ObservableCollection<WindSendRawMaterial>();
- if (AllRawMaterial == null || AllRawMaterial.Count <= 0)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"没有可保存的参数!");
- return;
- }
- var res = AllRawMaterial.Where(p => p.RawMaterialType == "小料").ToList();
- for (int i = 0; i < res.Count; i++)
- {
- if (res.Where(p => p.RawMaterialLocation == res.ElementAt(i).RawMaterialLocation)?.ToList()?.Count >= 2)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"原料位置冲突,请检查后重试!");
- return;
- }
- }
- var res1 = AllRawMaterial.Where(p => p.RawMaterialType == "粉料").ToList();
- for (int i = 0; i < res1.Count; i++)
- {
- if (res1.Where(p => p.RawMaterialLocation == res1.ElementAt(i).RawMaterialLocation)?.ToList()?.Count >= 2)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"粉料位置冲突,请检查后重试!");
- return;
- }
- }
- int index = Array.FindIndex(Json<LocalRecipeDataColl>.Data.RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeCode);
- if (index >= 0)
- {
- foreach (var item in AllRawMaterial)
- {
- if (item.RawMaterialType == "小料")
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialName = item.RawMaterialName,
- RawMaterialType = item.RawMaterialType,
- RawMaterialLocation = item.RawMaterialLocation,
- RawMaterialBarrelNum = item.RawMaterialBarrelNum,
- RawMaterialWeight = item.RawMaterialWeight,
- });
- }
- if (item.RawMaterialType == "粉料")
- {
- WindSendRawMaterials.Add(new WindSendRawMaterial()
- {
- RawMaterialName = item.RawMaterialName,
- RawMaterialWeight = item.RawMaterialWeight,
- Location = item.RawMaterialLocation,
- RawMaterialType = item.RawMaterialType,
- RawMaterialBarrelNum = item.RawMaterialBarrelNum,
- });
- }
- }
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.ElementAt(index).RecipeName = RecipeName;
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.ElementAt(index).TrayCode = TrayNum;
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.ElementAt(index).RecipeCode = RecipeCode;
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.ElementAt(index).RawMaterial = RawMaterials;
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.ElementAt(index).WindSend = WindSendRawMaterials;
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"修改配方完成!");
- MessageNotify.GetInstance.ShowUserLog($"修改配方名称:【{RecipeName}】,配方编号:【{RecipeCode}】。");
- }
- else
- {
- foreach (var item in AllRawMaterial)
- {
- if (item.RawMaterialType == "小料")
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialName = item.RawMaterialName,
- RawMaterialType = item.RawMaterialType,
- RawMaterialLocation = item.RawMaterialLocation,
- RawMaterialBarrelNum = item.RawMaterialBarrelNum,
- RawMaterialWeight = item.RawMaterialWeight,
- });
- }
- if (item.RawMaterialType == "粉料")
- {
- WindSendRawMaterials.Add(new WindSendRawMaterial()
- {
- RawMaterialName = item.RawMaterialName,
- RawMaterialWeight = item.RawMaterialWeight,
- Location = item.RawMaterialLocation,
- RawMaterialType = item.RawMaterialType,
- RawMaterialBarrelNum = item.RawMaterialBarrelNum,
- });
- }
- }
- var newRemoteRecipeData = new RecipeData()
- {
- RecipeName = RecipeName,
- RecipeCode = RecipeCode,
- TrayCode = TrayNum,
- RawMaterial = RawMaterials,
- WindSend = WindSendRawMaterials,
- };
- Json<LocalRecipeDataColl>.Data.RemoteRecipes.Add(newRemoteRecipeData);
- //新增一条配方应该默认显示出来。
- Json<LocalRecipeDataColl>.Data.SelectedRecipes.Add(newRemoteRecipeData);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"自定义配方添加完成!");
- MessageNotify.GetInstance.ShowUserLog($"添加一个自定义配方,配方名称:【{RecipeName}】,配方编号:【{RecipeCode}】。");
- }
- ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
- });
- }
- public string RecipeCode { get { return _mRecipeCode; } set { _mRecipeCode = value; OnPropertyChanged(); } }
- private string _mRecipeCode = string.Empty;
-
- public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
- private string _mRecipeName = string.Empty;
-
- public int TrayNum { get { return _mTrayNum; } set { _mTrayNum = value; OnPropertyChanged(); } }
- private int _mTrayNum = 1;
-
- public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
- private string _mErrorInfo;
-
- public ObservableCollection<RemoteRecipeRawMaterial> AllRawMaterial { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
- //public ObservableCollection<NewRemoteRecipeModel> AllRawMaterial { get; set; } = new ObservableCollection<NewRemoteRecipeModel>();
-
-
-
- public BPARelayCommand<object> RemoveCommand { get; set; }
-
- public BPARelayCommand AddCommand { get; set; }
- public BPARelayCommand AddFLCommand { get; set; }
- public BPARelayCommand SaveCommand { get; set; }
-
- }
- }
|