|
|
|
|
using Aucma.Scada.Business;
|
|
|
|
|
using Aucma.Scada.Model.domain;
|
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
using HighWayIot.Config;
|
|
|
|
|
using HighWayIot.Log4net;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace Aucma.Scada.UI.viewModel.OutStoreInfo
|
|
|
|
|
{
|
|
|
|
|
public class OutStoreInfoViewModel : ViewModelBase
|
|
|
|
|
{
|
|
|
|
|
private LogHelper logHelper = LogHelper.Instance;
|
|
|
|
|
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
|
|
|
|
|
private ObservableCollection<RealTaskInfo> taskItems = new ObservableCollection<RealTaskInfo>();
|
|
|
|
|
|
|
|
|
|
private OutStoreBusiness outStoreBusiness = OutStoreBusiness.Instance;
|
|
|
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
|
|
|
|
|
|
|
|
public OutStoreInfoViewModel()
|
|
|
|
|
{
|
|
|
|
|
outStoreBusiness.RefreshOutStoreTaskEvent += RefreashOutStoreTask;
|
|
|
|
|
outStoreBusiness.RefreshScanMateriaCodeEvent += RefreshScanInfo;
|
|
|
|
|
outStoreBusiness.RefreshLogMessageEvent += PrintMessageToListBox;
|
|
|
|
|
|
|
|
|
|
QueryCommand = new RelayCommand(Query);
|
|
|
|
|
ResetCommand = new RelayCommand(Reset);
|
|
|
|
|
DeleteAllCommand = new RelayCommand(DeleteAll);
|
|
|
|
|
DeleteTaskInfoCommand = new RelayCommand<object>(obj => DeleteTaskInfo(obj));
|
|
|
|
|
|
|
|
|
|
this.Query();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 参数定义
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 任务编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string taskCode = string.Empty;
|
|
|
|
|
public string TaskCode
|
|
|
|
|
{
|
|
|
|
|
get { return taskCode; }
|
|
|
|
|
set { taskCode = value; RaisePropertyChanged(nameof(TaskCode)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计划编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string planCode = string.Empty;
|
|
|
|
|
public string PlanCode
|
|
|
|
|
{
|
|
|
|
|
get { return planCode; }
|
|
|
|
|
set { planCode = value; RaisePropertyChanged(nameof(PlanCode)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 订单编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string orderCode = string.Empty;
|
|
|
|
|
public string OrderCode
|
|
|
|
|
{
|
|
|
|
|
get { return orderCode; }
|
|
|
|
|
set { orderCode = value; RaisePropertyChanged(nameof(OrderCode)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 物料条码
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string materialCode = string.Empty;
|
|
|
|
|
public string MaterialCode
|
|
|
|
|
{
|
|
|
|
|
get { return materialCode; }
|
|
|
|
|
set { materialCode = value; RaisePropertyChanged(nameof(MaterialCode)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 物料名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string materialName = string.Empty;
|
|
|
|
|
public string MaterialName
|
|
|
|
|
{
|
|
|
|
|
get { return materialName; }
|
|
|
|
|
set { materialName = value; RaisePropertyChanged(nameof(MaterialName)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 出库货道
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string spaceName = string.Empty;
|
|
|
|
|
public string SpaceName
|
|
|
|
|
{
|
|
|
|
|
get { return spaceName; }
|
|
|
|
|
set { spaceName = value; RaisePropertyChanged(nameof(SpaceName)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// LisBox数据模板
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerable logInfoListBox;
|
|
|
|
|
public IEnumerable LogInfoListBox
|
|
|
|
|
{
|
|
|
|
|
get { return logInfoListBox; }
|
|
|
|
|
set { logInfoListBox = value; RaisePropertyChanged(() => LogInfoListBox); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 出库任务DataGrid
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerable outstoreTask;
|
|
|
|
|
|
|
|
|
|
public IEnumerable OutstoreTask
|
|
|
|
|
{
|
|
|
|
|
get { return outstoreTask; }
|
|
|
|
|
set { outstoreTask = value; RaisePropertyChanged(() => OutstoreTask); }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件-任务编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string taskCodeSearch = string.Empty;
|
|
|
|
|
|
|
|
|
|
public string TaskCodeSearch
|
|
|
|
|
{
|
|
|
|
|
get { return taskCodeSearch; }
|
|
|
|
|
set { taskCodeSearch = value; RaisePropertyChanged(nameof(TaskCodeSearch)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string materialCodeSearch = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件-物料编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string MaterialCodeSearch
|
|
|
|
|
{
|
|
|
|
|
get { return materialCodeSearch; }
|
|
|
|
|
set { materialCodeSearch = value; RaisePropertyChanged(nameof(MaterialCodeSearch)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件-计划编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string planCodeSearch = string.Empty;
|
|
|
|
|
|
|
|
|
|
public string PlanCodeSearch
|
|
|
|
|
{
|
|
|
|
|
get { return planCodeSearch; }
|
|
|
|
|
set { planCodeSearch = value; RaisePropertyChanged(nameof(PlanCodeSearch)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 事件定义
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RelayCommand QueryCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重置
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RelayCommand ResetCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除所有出库任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RelayCommand DeleteAllCommand { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RelayCommand<object> DeleteTaskInfoCommand { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string lastMessage = "";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// listBox绑定日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
private void PrintMessageToListBox(string message)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (lastMessage != message)
|
|
|
|
|
{
|
|
|
|
|
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss.ss")}==>{message}");
|
|
|
|
|
lastMessage = message;
|
|
|
|
|
LogInfoListBox = listItems.OrderByDescending(x => x);
|
|
|
|
|
|
|
|
|
|
while (listItems.Count > 120)
|
|
|
|
|
{
|
|
|
|
|
listItems.RemoveAt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("日志数据绑定异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新出库任务列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="taskInfo"></param>
|
|
|
|
|
private void RefreashOutStoreTask()
|
|
|
|
|
{
|
|
|
|
|
// Query();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<RealTaskInfo> list = outStoreBusiness.GetOutStoreTask();
|
|
|
|
|
if (list != null && list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
App.Current.Dispatcher.Invoke((Action)(() =>
|
|
|
|
|
{
|
|
|
|
|
if(taskItems.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
taskItems.Clear();
|
|
|
|
|
}
|
|
|
|
|
foreach (RealTaskInfo item in list)
|
|
|
|
|
{
|
|
|
|
|
taskItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
OutstoreTask = new ObservableCollection<RealTaskInfo>(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)
|
|
|
|
|
{
|
|
|
|
|
MaterialCode = materialCode;
|
|
|
|
|
MaterialName = materialName;
|
|
|
|
|
SpaceName = spaceName;
|
|
|
|
|
|
|
|
|
|
Query();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Query()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var info = 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)(() =>
|
|
|
|
|
{
|
|
|
|
|
taskItems = new ObservableCollection<RealTaskInfo>();
|
|
|
|
|
foreach (var item in info)
|
|
|
|
|
{
|
|
|
|
|
item.materialType = outStoreBusiness.GetMaterialName(item.materialType);
|
|
|
|
|
taskItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
OutstoreTask = taskItems.OrderBy(x => x.createTime);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
taskItems.Clear();
|
|
|
|
|
OutstoreTask = taskItems;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("OutStoreViewModel初始化异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重置
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Reset()
|
|
|
|
|
{
|
|
|
|
|
this.TaskCodeSearch = string.Empty;
|
|
|
|
|
this.MaterialCodeSearch = string.Empty;
|
|
|
|
|
this.PlanCodeSearch = string.Empty;
|
|
|
|
|
this.Query();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除所有任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
private void DeleteAll()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MessageBoxResult result = MessageBox.Show("是否删除所有出库任务?", "删除确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
if (result == MessageBoxResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
if (outStoreBusiness.DeleteAllTaskByStoreCode(appConfig.foamStoreCode, 2))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("任务删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
|
|
// RefreashOutStoreTask();
|
|
|
|
|
Query();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
private void DeleteTaskInfo(object obj)
|
|
|
|
|
{
|
|
|
|
|
string taskCode = obj as string;
|
|
|
|
|
MessageBoxResult result = MessageBox.Show("货物是否已出库?", "出库确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
if (result == MessageBoxResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
if (outStoreBusiness.DeleteTaskInfoByTaskCode(taskCode, true))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("任务删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
|
|
Query();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outStoreBusiness.DeleteTaskInfoByTaskCode(taskCode, false))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("任务删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
|
|
Query();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("任务删除失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|