using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPA.Helper; using BPASmartClient.JXJFoodSmallStation.Model; using BPASmartClient.JXJFoodSmallStation.Model.Bom; using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC; using BPA.Helper; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; namespace BPASmartClient.JXJFoodSmallStation.ViewModel { public class BomOfMaterialViewModel : NotifyBase { public BomOfMaterialViewModel() { RawMaterialInfo = Json.Data.BomMaterial; AddMaterial = new BPARelayCommand(() => { RawMaterialInfo.Add(new BomMaterial() { Count = Json.Data.BomMaterial.Count +1 , }); MessageNotify.GetInstance.ShowUserLog("新增一条物料数据。"); }); SaveMaterials = new BPARelayCommand(() => { if (MessageNotify.GetInstance.ShowDialog("请确认是否保存!") == true) { Json.Save(); MessageNotify.GetInstance.ShowUserLog($"西门子物料清单保存成功"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"原料与料仓对应关系保存成功"); } }); GetBomMaterialData = new BPARelayCommand(() => { 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 }); } MessageNotify.GetInstance.ShowUserLog("西门子物料数据拉取了本地数据。"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"读取程序的Bom清单"); }); DeleteAllMaterial = new BPARelayCommand(() => { if (MessageNotify.GetInstance.ShowDialog("请确认,是否删除所有原料数据!") == true) { Json.Data.BomMaterial.Clear(); MessageNotify.GetInstance.ShowUserLog($"手动点击西门子物料清单全部清除。"); } }); RemoveCommand = new BPARelayCommand((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, "成功", $"删除成功"); MessageNotify.GetInstance.ShowUserLog($"删除一条物料数据,物料编码:【{res.MaterialCode}】,物料名称:{res.MaterialName}。"); } } } }); } public ObservableCollection RawMaterialInfo { get; set; } = new ObservableCollection(); public BPARelayCommand AddMaterial { get; set; } public BPARelayCommand SaveMaterials { get; set; } public BPARelayCommand RemoveCommand { get; set; } public BPARelayCommand GetBomMaterialData { get; set; } public BPARelayCommand DeleteAllMaterial { get; set; } } }