From 49cf92b0f77403889738e9fe86b1f4a7782eb5b9 Mon Sep 17 00:00:00 2001 From: pengliangyang <1406009520@qq.com> Date: Wed, 26 Oct 2022 16:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmartClient.DosingSystem.csproj | 2 +- DosingSystem/Model/DeviceInquire.cs | 2 +- DosingSystem/Service/SiemensDevice.cs | 2 +- DosingSystem/View/RecipeControlView.xaml | 2 -- DosingSystem/View/RecipeControlView.xaml.cs | 2 +- DosingSystem/ViewModel/NewRecipeViewModel.cs | 2 +- .../ViewModel/RecipeControlViewModel.cs | 24 ++++++++++------ .../ViewModel/RecipeSettingsViewModel.cs | 28 ++++++++++++++----- 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/DosingSystem/BPASmartClient.DosingSystem.csproj b/DosingSystem/BPASmartClient.DosingSystem.csproj index 15315834..8a2d893c 100644 --- a/DosingSystem/BPASmartClient.DosingSystem.csproj +++ b/DosingSystem/BPASmartClient.DosingSystem.csproj @@ -16,7 +16,7 @@ - + diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index 120b1252..9d803541 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -115,7 +115,7 @@ namespace BPASmartClient.DosingSystem else Json.Data.BaseParModel.NetworkSegAddress = IPSegment; TestData(); IpAddressLines(); - DeviceDataInit(); + //DeviceDataInit(); ThreadManage.GetInstance().StartLong(new Action(() => { if (IPQueues.Count >= IPLists.Count) diff --git a/DosingSystem/Service/SiemensDevice.cs b/DosingSystem/Service/SiemensDevice.cs index 3187285d..90315ec0 100644 --- a/DosingSystem/Service/SiemensDevice.cs +++ b/DosingSystem/Service/SiemensDevice.cs @@ -38,7 +38,7 @@ namespace BPASmartClient.DosingSystem ThreadManage.GetInstance().StartLong(new Action(() => { - GlobalDevice.PlcData = MySiemens.ReadClass(3);//获取PLC到上位机的数据 + //GlobalDevice.PlcData = MySiemens.ReadClass(3);//获取PLC到上位机的数据 var res = MySiemens.Read(DataType.DataBlock, 4, 134, VarType.Word, 32); if (res != null && res is ushort[] ushorts && ushorts.Length == 32) { diff --git a/DosingSystem/View/RecipeControlView.xaml b/DosingSystem/View/RecipeControlView.xaml index bf2c21b4..a05ea430 100644 --- a/DosingSystem/View/RecipeControlView.xaml +++ b/DosingSystem/View/RecipeControlView.xaml @@ -875,8 +875,6 @@ BorderThickness="1,0,1,0" Cursor="SizeWE" /> - - p.RawMaterialId == rm); - if (res != null) Global.DeviceRawMaterials.Remove(res); + if (res != null) RawMaterials.Remove(res); } }); diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index 374d5d0b..78e1dc23 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -19,8 +19,8 @@ namespace BPASmartClient.DosingSystem.ViewModel { public class RecipeControlViewModel : NotifyBase { - ConcurrentQueue RecipeNames = new ConcurrentQueue(); - ObservableCollection StockStatus = new ObservableCollection(); + public static ConcurrentQueue RecipeNames = new ConcurrentQueue(); + public static ObservableCollection StockStatus = new ObservableCollection(); public RecipeControlViewModel() { StartCommand = new RelayCommand(RecipeIssued); @@ -53,9 +53,11 @@ namespace BPASmartClient.DosingSystem.ViewModel } } Recipes.ElementAt(index).IsEnable = false; + Json.Data.Recipes.ElementAt(index).IsEnable = false; } MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}"); RecipeNames.Enqueue(deviceName); + var t = RecipeNames.GetHashCode(); var res = Recipes.FirstOrDefault(p => p.RecipeName == deviceName); UserTreeWait.Add(new RecipeModel { SerialNum = UserTreeWait.Count + 1, RecipeName = deviceName, RawMaterials = res.RawMaterials }); } @@ -184,17 +186,17 @@ namespace BPASmartClient.DosingSystem.ViewModel int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) { - recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; + //recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; } for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) { if (GlobalDevice.PlcData.IsAllowIngredients[j]) { int cnt = j + 1;//获取允许配料信号桶号的料仓位置 - float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.Loc == j)).RawMaterialWeight; + float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.Loc == cnt)).RawMaterialWeight; string deviceName = DeviceInquire.GetInstance.devices.ElementAt(Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt)).DeviceName; int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == deviceName); - if (cnt > 0 && loc > 0 && deviceName != null && weight > 0) + if (cnt > 0 && loc >= 0 && deviceName != null && weight >= 0) { int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == deviceName); if (St_index < 0) @@ -206,7 +208,8 @@ namespace BPASmartClient.DosingSystem.ViewModel IssueStatus = 0, }); } - else + St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == deviceName); + if (St_index >= 0) { if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) { @@ -214,7 +217,7 @@ namespace BPASmartClient.DosingSystem.ViewModel DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); } - if (RTrig.GetInstance("StatusReset").Start(recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3) && StockStatus.ElementAt(St_index).IssueStatus == 1) + if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) { StockStatus.ElementAt(St_index).IssueStatus = 2; DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); @@ -225,15 +228,18 @@ namespace BPASmartClient.DosingSystem.ViewModel } } } - if (StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 + int Finish_Count = StockStatus.Where(s => s.IssueStatus == 2).Count(); + if (StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && Finish_Count >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 { StockStatus.Clear(); SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.1", true);//配方使用桶数写入 int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); Recipes.ElementAt(recipIndex).IsEnable = true; + Json.Data.Recipes.ElementAt(recipIndex).IsEnable = true; Recipes.ElementAt(recipIndex).Are.Set(); } + } } } @@ -248,7 +254,7 @@ namespace BPASmartClient.DosingSystem.ViewModel public static ObservableCollection Recipes { get; set; } = Json.Data.Recipes; - public string CurrentRecipeName { get { return _RecipeName; } set { _RecipeName = value; OnPropertyChanged(); } } + public static string CurrentRecipeName { get { return _RecipeName; } set { _RecipeName = value; OnStaticPropertyChanged(); } } private static string _RecipeName; /// diff --git a/DosingSystem/ViewModel/RecipeSettingsViewModel.cs b/DosingSystem/ViewModel/RecipeSettingsViewModel.cs index 5dfc62c2..347513c3 100644 --- a/DosingSystem/ViewModel/RecipeSettingsViewModel.cs +++ b/DosingSystem/ViewModel/RecipeSettingsViewModel.cs @@ -50,10 +50,17 @@ namespace BPASmartClient.DosingSystem.ViewModel if (MessageNotify.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning)) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); - if (res != null) Json.Data.Recipes.Remove(res); - Json.Save(); - NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!"); - MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}"); + if (res.IsEnable) + { + if (res != null) Json.Data.Recipes.Remove(res); + Json.Save(); + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!"); + MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}"); + } + else + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"删除【{o.ToString()}】配方失败,配方正在使用!"); + } } } }); @@ -65,9 +72,16 @@ namespace BPASmartClient.DosingSystem.ViewModel var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); if (res != null) { - NewRecipeView nrv = new NewRecipeView(); - ActionManage.GetInstance.Send("Details", res); - nrv.ShowDialog(); + if (res.IsEnable) + { + NewRecipeView nrv = new NewRecipeView(); + ActionManage.GetInstance.Send("Details", res); + nrv.ShowDialog(); + } + else + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"编辑【{o.ToString()}】配方失败,配方正在使用!"); + } } //MessageLog.GetInstance.ShowUserLog($"编辑配方名称——{res.RecipeName}"); }