159 lines
4.9 KiB
C#
159 lines
4.9 KiB
C#
using Cowain.Bake.Common;
|
|
using Cowain.Bake.Common.Core;
|
|
using Cowain.Bake.Common.Enums;
|
|
using Cowain.Bake.BLL;
|
|
using Cowain.Bake.Model;
|
|
using HandyControl.Controls;
|
|
using Prism.Commands;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity;
|
|
|
|
namespace Cowain.Bake.UI.ProductManagement.ViewModels
|
|
{
|
|
public class TaskMaintainViewModel : ViewModelBase //BindableBase
|
|
{
|
|
private string _title;
|
|
public string Title
|
|
{
|
|
get { return _title; }
|
|
set { SetProperty(ref _title, value); }
|
|
}
|
|
|
|
private TTaskType selectTask;
|
|
public TTaskType SelectTask
|
|
{
|
|
get => selectTask ?? (selectTask = new TTaskType());
|
|
set
|
|
{
|
|
SetProperty(ref selectTask, value);
|
|
}
|
|
}
|
|
|
|
private TTaskType _editTask;
|
|
public TTaskType EditTask
|
|
{
|
|
get => _editTask ?? (_editTask = new TTaskType());
|
|
set
|
|
{
|
|
SetProperty(ref _editTask, value);
|
|
}
|
|
}
|
|
|
|
private ObservableCollection<TTaskType> _taskList;
|
|
public ObservableCollection<TTaskType> TaskList
|
|
{
|
|
//get { return _taskList; }
|
|
get => _taskList ?? (_taskList = new ObservableCollection<TTaskType>());
|
|
set { SetProperty(ref _taskList, value); }
|
|
}
|
|
|
|
private List<string> machineList;
|
|
public List<string> MachineList
|
|
{
|
|
get => machineList ?? (machineList = new List<string>());
|
|
set { SetProperty(ref machineList, value); }
|
|
}
|
|
|
|
private List<string> _palletStatusList;
|
|
public List<string> PalletStatusList
|
|
{
|
|
get => _palletStatusList ?? (_palletStatusList = new List<string>());
|
|
set { SetProperty(ref _palletStatusList, value); }
|
|
}
|
|
|
|
|
|
public TaskMaintainViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
|
|
{
|
|
_taskList = new ObservableCollection<TTaskType>();
|
|
_unityContainer = unityContainer;
|
|
_regionManager = regionManager;
|
|
PalletStatusList = EPalletStatus.Loading.GetListDesc();
|
|
MachineList = EnumHelper.GetDescriptions<EStationType>();
|
|
Refresh();
|
|
}
|
|
|
|
public DelegateCommand EnableCommand => new DelegateCommand(() =>
|
|
{
|
|
if (SelectTask != null && SelectTask.Id > 0)
|
|
{
|
|
var tServices = _unityContainer.Resolve<TaskTypeService>();
|
|
|
|
var res = tServices.UpdateEnableTask(SelectTask.Id, !SelectTask.Enable);
|
|
if (res > 0)
|
|
{
|
|
Growl.Success("是否启用任务修改完成!");
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
Growl.Fatal("是否启用任务失败!");
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
public DelegateCommand SelectCommand => new DelegateCommand(() =>
|
|
{
|
|
if (SelectTask != null && SelectTask.Id > 0)
|
|
{
|
|
//深拷贝
|
|
EditTask = BasicFramework.DeepCopy<TTaskType>(SelectTask);
|
|
}
|
|
});
|
|
|
|
public DelegateCommand AddCommand => new DelegateCommand(() =>
|
|
{
|
|
var result = HandyControl.Controls.MessageBox.Ask($@"是否确定要添加任务?", "操作提示");
|
|
if (result == System.Windows.MessageBoxResult.Cancel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var res = _unityContainer.Resolve<TaskTypeService>().AddTaskConfig(EditTask);
|
|
if (res > 0)
|
|
{
|
|
Growl.Success("任务添加完成!");
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
Growl.Fatal("任务添加失败!");
|
|
}
|
|
});
|
|
|
|
public DelegateCommand EditCommand => new DelegateCommand(() =>
|
|
{
|
|
var result = HandyControl.Controls.MessageBox.Ask($@"是否确定要修改任务?", "操作提示");
|
|
if (result == System.Windows.MessageBoxResult.Cancel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var res = _unityContainer.Resolve<TaskTypeService>().EditTaskConfig(EditTask);
|
|
if (res > 0)
|
|
{
|
|
Growl.Success("任务修改完成!");
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
Growl.Fatal("任务修改失败,优先级不存在!");
|
|
}
|
|
});
|
|
|
|
public override void Refresh()
|
|
{
|
|
TaskList.Clear();
|
|
List<TTaskType> list = _unityContainer.Resolve<TaskTypeService>().GetAll();
|
|
list.ForEach(p => TaskList.Add(p));
|
|
}
|
|
}
|
|
}
|