You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
9.1 KiB
C#

using Admin.Core.Model;
using Aucma.Scada.UI.Common;
using Aucma.Scada.UI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using log4net;
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
namespace Aucma.Scada.UI.ViewModel.OutStoreInfo
{
public partial class OutStoreInfoViewModel : ObservableObject
{
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(OutStoreInfoViewModel));
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
private ObservableCollection<RealTaskInfo> taskItems = new ObservableCollection<RealTaskInfo>();
private OutStoreBusiness outStoreBusiness = new OutStoreBusiness();// OutStoreBusiness.Instance;
private AppConfig appConfig = new AppConfig();//AppConfig.Instance;
public OutStoreInfoViewModel()
{
outStoreBusiness.RefreshOutStoreTaskEvent += RefreshOutStoreTask;
outStoreBusiness.RefreshScanMateriaCodeEvent += RefreshScanInfo;
outStoreBusiness.RefreshLogMessageEvent += PrintMessageToListBox;
this.Query();
}
#region 参数定义
/// <summary>
/// 箱壳物料条码
/// </summary>
private string shellMaterialCode = string.Empty;
public string ShellMaterialCode
{
get => shellMaterialCode;
set => SetProperty(ref shellMaterialCode, value);
}
/// <summary>
/// 箱壳物料名称
/// </summary>
private string shellMaterialName = string.Empty;
public string ShellMaterialName
{
get => shellMaterialName;
set => SetProperty(ref shellMaterialName, value);
}
/// <summary>
/// 箱壳入库货道
/// </summary>
private string shellSpaceName = string.Empty;
public string ShellSpaceName
{
get => shellSpaceName;
set => SetProperty(ref shellSpaceName, value);
}
/// <summary>
/// 内胆物料条码
/// </summary>
private string linerMaterialCode = string.Empty;
public string LinerMaterialCode
{
get => linerMaterialCode;
set => SetProperty(ref linerMaterialCode, value);
}
/// <summary>
/// 内胆物料名称
/// </summary>
private string linerMaterialName = string.Empty;
public string LinerMaterialName
{
get => linerMaterialCode;
set => SetProperty(ref linerMaterialCode, value);
}
/// <summary>
/// 内胆入库货道
/// </summary>
private string linerSpaceName = string.Empty;
public string LinerSpaceName
{
get => linerMaterialCode;
set => SetProperty(ref linerMaterialCode, value);
}
/// <summary>
/// LisBox数据模板
/// </summary>
private IEnumerable logInfoListBox;
public IEnumerable LogInfoListBox
{
get => logInfoListBox;
set => SetProperty(ref logInfoListBox, value);
}
/// <summary>
/// 出库任务DataGrid
/// </summary>
private IEnumerable outstoreTask;
public IEnumerable OutstoreTask
{
get => outstoreTask;
set => SetProperty(ref outstoreTask, value);
}
/// <summary>
/// 查询条件-任务编号
/// </summary>
private string taskCodeSearch = string.Empty;
public string TaskCodeSearch
{
get => taskCodeSearch;
set => SetProperty(ref taskCodeSearch, value);
}
private string materialCodeSearch = string.Empty;
/// <summary>
/// 查询条件-物料编号
/// </summary>
public string MaterialCodeSearch
{
get => materialCodeSearch;
set => SetProperty(ref materialCodeSearch, value);
}
/// <summary>
/// 查询条件-计划编号
/// </summary>
private string planCodeSearch = string.Empty;
public string PlanCodeSearch
{
get => planCodeSearch;
set => SetProperty(ref planCodeSearch, value);
}
#endregion
/// <summary>
/// listBox绑定日志
/// </summary>
/// <param name="message"></param>
private void PrintMessageToListBox(string message)
{
try
{
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss.ss")}==>{message}");
LogInfoListBox = listItems.OrderByDescending(x => x);
}
catch (Exception ex)
{
logHelper.Error("日志数据绑定异常", ex);
}
}
/// <summary>
/// 刷新出库任务列表
/// </summary>
/// <param name="taskInfo"></param>
private void RefreshOutStoreTask(RealTaskInfo taskInfo)
{
try
{
App.Current.Dispatcher.Invoke((Action)(async () =>
{
taskInfo.MaterialType =await outStoreBusiness.GetMaterialName(taskInfo.MaterialType);
taskItems.Add(taskInfo);
OutstoreTask = taskItems;
}));
}
catch (Exception ex)
{
logHelper.Error("入库任务列表刷新异常", ex);
}
}
/// <summary>
/// 刷新扫码信息
/// </summary>
/// <param name="materialCode"></param>
/// <param name="materialName"></param>
/// <param name="spaceName"></param>
/// <param name="storeCode"></param>
private void RefreshScanInfo(string materialCode, string materialName, string spaceName, string storeCode)
{
if (storeCode == appConfig.shellStoreCode)
{
ShellMaterialCode = materialCode;
ShellMaterialName = materialName;
ShellSpaceName = spaceName;
}
else if (storeCode == appConfig.linerStoreCode)
{
LinerMaterialCode = materialCode;
LinerMaterialName = materialName;
LinerSpaceName = spaceName;
}
Query();
}
/// <summary>
/// 初始化
/// </summary>
[RelayCommand]
private async void Query()
{
try
{
var info =await outStoreBusiness.GetOutStoreTask();
if (info != null)
{
if (!string.IsNullOrEmpty(taskCodeSearch))
{
info = info.Where(x => x.TaskCode.Contains(taskCodeSearch)).ToList();
}
else if (!string.IsNullOrEmpty(materialCodeSearch))
{
info = info.Where(x => x.MaterialCode.Contains(materialCodeSearch)).ToList();
}
else if (!string.IsNullOrEmpty(planCodeSearch))
{
info = info.Where(x => x.PlanCode.Contains(planCodeSearch)).ToList();
}
App.Current.Dispatcher.Invoke((Action)(async () =>
{
taskItems = new ObservableCollection<RealTaskInfo>();
foreach (var item in info)
{
item.MaterialType =await outStoreBusiness.GetMaterialName(item.MaterialType);
taskItems.Add(item);
}
OutstoreTask = taskItems.OrderBy(x => x.CreateTime);
}));
}
}
catch (Exception ex)
{
logHelper.Error("OutStoreViewModel初始化异常", ex);
}
}
/// <summary>
/// 重置
/// </summary>
[RelayCommand]
private void Reset()
{
this.TaskCodeSearch = string.Empty;
this.MaterialCodeSearch = string.Empty;
this.PlanCodeSearch = string.Empty;
this.Query();
}
/// <summary>
/// 删除任务
/// </summary>
/// <param name="obj"></param>
[RelayCommand]
private async void DeleteTaskInfo(object obj)
{
string taskCode = obj as string;
var r = await outStoreBusiness.DeleteTaskInfoByTaskCode(taskCode);
if (r)
{
MessageBox.Show("任务删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
Query();
}
else
{
MessageBox.Show("任务删除失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
}
}
}
}