using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.FoodStationTest.Model; using BPASmartClient.FoodStationTest.Model.Bom; using BPASmartClient.Helper; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System.Collections.ObjectModel; using System.Linq; namespace BPASmartClient.FoodStationTest.ViewModel { public class BomOfMaterialViewModel : ObservableObject { public BomOfMaterialViewModel() { RawMaterialInfo = Json.Data.BomMaterial; AddMaterial = new RelayCommand(() => { RawMaterialInfo.Add(new BomMaterial() { Count = Json.Data.BomMaterial.Count + 1, }); }); SaveMaterials = new RelayCommand(() => { if (MessageNotify.GetInstance.ShowDialog("请确认是否保存!") == true) { Json.Save(); MessageNotify.GetInstance.ShowUserLog($"西门子物料清单保存成功"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"原料与料仓对应关系保存成功"); } }); GetBomMaterialData = new RelayCommand(() => { Json.Data.BomMaterial.Clear(); ProcessControl.GetInstance.RawMaterialNameWithCode();//原料的名称和编码对应 :西门子mes定义的物料编码 foreach (var item in GVL_SmallStation.GetInstance.RawMaterialsNameCode) { Json.Data.BomMaterial.Add(new BomMaterial() { Count = Json.Data.BomMaterial.Count + 1, MaterialCode = item.Key, MaterialName = item.Value }); } NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"读取程序的Bom清单"); }); DeleteAllMaterial = new RelayCommand(() => { if (MessageNotify.GetInstance.ShowDialog("请确认是否删除所有原料数据!") == true) { Json.Data.BomMaterial.Clear(); MessageNotify.GetInstance.ShowUserLog($"西门子物料清单删除完成"); } }); RemoveCommand = new RelayCommand((Count) => { if (Count is int cnt) { var res = RawMaterialInfo.FirstOrDefault(p => p.Count == cnt); if (res != null) { if (MessageNotify.GetInstance.ShowDialog($"请确认是否删除[{res.MaterialCode}],[{res.MaterialName}]!") == true) { RawMaterialInfo.Remove(res); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"删除成功"); } } } }); } public ObservableCollection RawMaterialInfo { get; set; } = new ObservableCollection(); public RelayCommand AddMaterial { get; set; } public RelayCommand SaveMaterials { get; set; } public RelayCommand RemoveCommand { get; set; } public RelayCommand GetBomMaterialData { get; set; } public RelayCommand DeleteAllMaterial { get; set; } } }