Sfoglia il codice sorgente

配方业务修改

master
pry 2 anni fa
parent
commit
de2778b793
1 ha cambiato i file con 44 aggiunte e 71 eliminazioni
  1. +44
    -71
      DosingSystem/ViewModel/RecipeControlViewModel.cs

+ 44
- 71
DosingSystem/ViewModel/RecipeControlViewModel.cs Vedi File

@@ -23,39 +23,51 @@ namespace BPASmartClient.DosingSystem.ViewModel
ObservableCollection<StockStatusModel> StockStatus = new ObservableCollection<StockStatusModel>();
public RecipeControlViewModel()
{
StartCommand = new RelayCommand<object>((o) =>
StartCommand = new RelayCommand<object>(RecipeIssued);
ChangeRecipeStateCommand = new RelayCommand<object>(ChangeRecipeState);
RecipeRun();
RecipeStatusInquire();
}

/// <summary>
/// 配方下发
/// </summary>
private void RecipeIssued(object o)
{
if (o != null && o is string deviceName)
{
if (o != null && o is string deviceName)
int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == deviceName);
if (index >= 0 && index < Recipes.Count)
{
int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == deviceName);
if (index >= 0 && index < Recipes.Count)
for (int i = 0; i < Recipes.ElementAt(index).RawMaterials.Count; i++)
{
for (int i = 0; i < Recipes.ElementAt(index).RawMaterials.Count; i++)
if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1)
{
if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1)
{
string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp;
var device = DeviceInquire.GetInstance.GetDevice(ip);
//if (!device.IsConnected)
//{
// MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error);
// return;
//}
}
string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp;
var device = DeviceInquire.GetInstance.GetDevice(ip);
//if (!device.IsConnected)
//{
// MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error);
// return;
//}
}
Recipes.ElementAt(index).IsEnable = false;
}
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}");
RecipeNames.Enqueue(deviceName);
var res = Recipes.FirstOrDefault(p => p.RecipeName == deviceName);
UserTreeWait.Add(new RecipeModel {SerialNum= UserTreeWait.Count + 1, RecipeName = deviceName, RawMaterials = res.RawMaterials });
Recipes.ElementAt(index).IsEnable = false;
}
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!");
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Guid.NewGuid().ToString()}");
});

ChangeRecipeStateCommand = new RelayCommand<object>(ChangeRecipeState);
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}");
RecipeNames.Enqueue(deviceName);
var res = Recipes.FirstOrDefault(p => p.RecipeName == deviceName);
UserTreeWait.Add(new RecipeModel { SerialNum = UserTreeWait.Count + 1, RecipeName = deviceName, RawMaterials = res.RawMaterials });
}
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!");
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Guid.NewGuid().ToString()}");
}

/// <summary>
/// 配方业务执行
/// </summary>
private void RecipeRun()
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (RecipeNames.Count > 0)
@@ -132,35 +144,6 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
#endregion

//foreach (var item in Recipes.ElementAt(index).RawMaterials)
//{
// //DeviceInquire.GetInstance.GetDevice(item.DeviceIp)?.Start(item.RawMaterialWeight);//启动并写入每个原料重量
// //var res = DeviceInquire.GetInstance.GetDevice(item.DeviceIp).deviceStatus.DeviceNum;
// App.Current.Dispatcher.Invoke(new Action(() =>
// {

// //ObservableCollection<RawMaterialModel> rawMaterialModels = new ObservableCollection<RawMaterialModel>();
// //rawMaterialModels.Add(new RawMaterialModel()
// //{
// // RawMaterialName = item.RawMaterialName,
// // RecipeStatus = item.RecipeStatus,
// // RawMaterialSource = item.RawMaterialSource,
// // RawMaterialId = item.RawMaterialId,
// //});

// //if (recipeProcesses.Count > 0)
// //{
// // recipeProcesses.ElementAt(0).RawMaterials.Add(new RawMaterialModel()
// // {
// // RawMaterialName = item.RawMaterialName,
// // RecipeStatus = item.RecipeStatus,
// // RawMaterialSource = item.RawMaterialSource,
// // RawMaterialId = item.RawMaterialId,
// // });
// //}
// }));
//}

Recipes.ElementAt(index).Are.WaitOne();//阻塞,直到当前配方完成
RecipeNames.TryDequeue(out string deviceName);
App.Current.Dispatcher.Invoke(new Action(() =>
@@ -177,8 +160,13 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
Thread.Sleep(100);
}), "启动配方下发");
}


/// <summary>
/// 配方执行状态监听
/// </summary>
private void RecipeStatusInquire()
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
for (int i = 0; i < Recipes.Count; i++)
@@ -190,7 +178,6 @@ namespace BPASmartClient.DosingSystem.ViewModel
if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName)
{
string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName;
//int index = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == tempRawMaterialName);
int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName);
if (recIndex >= 0 && recIndex < recipeProcesses.Count)
{
@@ -198,9 +185,7 @@ namespace BPASmartClient.DosingSystem.ViewModel
if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count)
{
recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus;
//App.Current?.Dispatcher?.Invoke(new Action(() => { recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; }));
}
//App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.ElementAt(index).RecipeStatus = RunStatus; }));
for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++)
{
if (GlobalDevice.PlcData.IsAllowIngredients[j])
@@ -270,12 +255,12 @@ namespace BPASmartClient.DosingSystem.ViewModel
/// 当前正在制作的配方
/// </summary>
public static ObservableCollection<RecipeModel> recipeProcesses { get; set; } = new ObservableCollection<RecipeModel>();
//public static ObservableCollection<RawMaterialModel> recipeProcesses { get; set; } = new ObservableCollection<RawMaterialModel>();

/// <summary>
/// 等待制作的配方
/// </summary>
public static ObservableCollection<RecipeModel> UserTreeWait { get; set; } = new ObservableCollection<RecipeModel>();

/// <summary>
/// 已完成的配方
/// </summary>
@@ -303,18 +288,6 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
}
}
//var res = recipeProcesses.FirstOrDefault(p => p.RawMaterialId == id);
//if (res != null)
//{
// if (res.RecipeStatus == 3)
// {
// res.RecipeStatus = 1;
// }
// else
// {
// res.RecipeStatus = 3;
// }
//}
}
}
}


Caricamento…
Annulla
Salva