Files
6098/Cowain.Bake.Main/ViewModels/ManualTaskViewModel.cs

124 lines
4.3 KiB
C#

using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Common.Core;
using Cowain.Bake.Common.Enums;
using Cowain.Bake.Main.Station;
using Cowain.Bake.Model;
using Cowain.Bake.Model.Entity;
using Cowain.Bake.Model.Models;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Data;
using Unity;
namespace Cowain.Bake.Main.ViewModels
{
public class ManualTaskViewModel: BindableBase
{
private IUnityContainer _unityContainer;
private string selectFromValue;
public string SelectFromValue
{
get => selectFromValue;
set => SetProperty(ref selectFromValue, value);
}
private string selectToValue;
public string SelectToValue
{
get => selectToValue;
set => SetProperty(ref selectToValue, value);
}
//不写set;get还设置不了这里的值
public List<string> StationDtl { set; get; } = new List<string>();
public void GetStationDtl()
{
List<string> table = _unityContainer.Resolve<CavityInfoService>().GetCanUseStationName();
foreach (var item in table)
{
StationDtl.Add(item);
}
}
public ManualTaskViewModel(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
}
public DelegateCommand GenerateTaskCommand => new DelegateCommand(() =>
{
GenerateTask();
});
private void GenerateTask()
{
if (SettingProvider.Instance.DispMode == EDispatchMode.Auto)
{
HandyControl.Controls.Growl.Warning("自动调度,不能手动生成任务!");
return;
}
if (string.IsNullOrEmpty(selectFromValue)
|| string.IsNullOrEmpty(SelectToValue))
{
HandyControl.Controls.Growl.Error("取放为空,不能手动生成任务!");
return;
}
if (_unityContainer.Resolve<TaskRecordService>().UnexecuteTask() != null)
{
HandyControl.Controls.Growl.Warning("还有调度任务没有执行完成,不能手动生成任务!");
return;
}
TCavityInfo fromTable = _unityContainer.Resolve<CavityInfoService>().GetStationID(selectFromValue);
TCavityInfo toTable = _unityContainer.Resolve<CavityInfoService>().GetStationID(SelectToValue);
Cowain.Bake.Model.TTaskRecord taskRecord = new Model.TTaskRecord();
if (0 == fromTable.PalletId)
{
LogHelper.Instance.Error("添加失败,取位置无托盘记忆!", true);
return;
}
if (!fromTable.IsLoad)
{
LogHelper.Instance.Error("添加失败,取位置感应不到夹具到位!", true);
return;
}
if (0 != toTable.PalletId || toTable.IsLoad)
{
LogHelper.Instance.Error("添加失败,放位置有托盘信息!", true);
return;
}
TPalletInfo palletInfo = _unityContainer.Resolve<PalletInfoService>().GetPalletInfo(fromTable.PalletId);
if (palletInfo.PalletStatus == (int)EPalletStatus.Bake)
{
LogHelper.Instance.Error("添加失败,无法将在烘烤中的托盘添加到任务!", true);
return;
}
taskRecord.PalletId = fromTable.PalletId;
taskRecord.TaskTypeId = 0;
taskRecord.Source = fromTable.Id;
taskRecord.Target = toTable.Id;
taskRecord.Status = (int)ETaskStatus.UnExecute;
taskRecord.BuildTime = DateTime.Now;
taskRecord.StepId = (int)ETaskStep.Unexecuted;
if (0 == _unityContainer.Resolve<TaskRecordService>().Insert(taskRecord))
{
LogHelper.Instance.Error("插入任务到数据库失败!", true);
return;
}
_unityContainer.Resolve<TaskStation>()._newTaskEvent.Set();
LogHelper.Instance.Info($"插入任务成功!{JsonConvert.SerializeObject(taskRecord)}");
HandyControl.Controls.MessageBox.Success("已添加成功!");
}
}
}