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.

349 lines
11 KiB
C#

using Admin.Core.Model;
using Admin.Core.Service;
using Aucma.Scada.UI.Common;
using Aucma.Scada.UI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LiveCharts;
using LiveCharts.Wpf;
using log4net;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
namespace Aucma.Scada.UI.ViewModel.InStoreInfo
{
public partial class InStoreInfoViewModel : ObservableObject
{
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(ExecutePlanInfoServices));
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
private ObservableCollection<RealTaskInfo> taskItems = new ObservableCollection<RealTaskInfo>();
private InStoreBusiness inStoreBusiness = new InStoreBusiness();// InStoreBusiness.Instance;
private OutStoreBusiness outStoreBusiness = new OutStoreBusiness();// OutStoreBusiness.Instance;
private AppConfig appConfig = new AppConfig();//AppConfig.Instance;
public InStoreInfoViewModel()
{
inStoreBusiness.RefreshInStoreTaskEvent += RefreshInStoreTask;
inStoreBusiness.RefreshScanMateriaCodeEvent += RefreshScanInfo;
inStoreBusiness.RefreshLogMessageEvent += PrintMessageToListBox;
outStoreBusiness.RefreshStoreStockEvent += Init;
materialTypeCombox = "所有";
Init();
}
#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 => linerMaterialName;
set => SetProperty(ref linerMaterialName, value);
}
/// <summary>
/// 内胆入库货道
/// </summary>
private string linerSpaceName = string.Empty;
public string LinerSpaceName
{
get => linerSpaceName;
set => SetProperty(ref linerSpaceName, value);
}
/// <summary>
/// LisBox数据模板
/// </summary>
private IEnumerable logInfoListBox;
public IEnumerable LogInfoListBox
{
get => logInfoListBox;
set => SetProperty(ref logInfoListBox, value);
}
/// <summary>
/// 箱壳入库任务DataGrid
/// </summary>
private IEnumerable instoreTask;
public IEnumerable InstoreTask
{
get => instoreTask;
set => SetProperty(ref instoreTask, value);
}
/// <summary>
/// 内胆入库任务DataGrid
/// </summary>
private ObservableCollection<SysUserInfo> linerInstoreTask;
public ObservableCollection<SysUserInfo> LinerInstoreTask
{
get => linerInstoreTask;
set => SetProperty(ref linerInstoreTask, value);
}
/// <summary>
/// 任务列表搜索条件
/// </summary>
private String search = String.Empty;
public String Search
{
get => search;
set => SetProperty(ref search, value);
}
/// <summary>
/// 下拉框
/// </summary>
public string materialTypeCombox;
public string MaterialTypeCombox
{
get => materialTypeCombox;
set => SetProperty(ref materialTypeCombox, value);
}
/// <summary>
/// 库存统计柱状图
/// </summary>
private SeriesCollection achievement = new SeriesCollection();
public SeriesCollection Achievement
{
get { return achievement; }
set { achievement = value; }
}
/// <summary>
/// 库存统计柱状图X轴物料信息
/// </summary>
private List<string> materialNameList;
public List<string> MaterialNameList
{
get { return materialNameList; }
set { materialNameList = value; }
}
#endregion
/// <summary>
/// listBox绑定日志
/// </summary>
/// <param name="message"></param>
private void PrintMessageToListBox(string message)
{
try
{
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}");
LogInfoListBox = listItems.OrderByDescending(x => x);
}
catch (Exception ex)
{
logHelper.Error("日志数据绑定异常", ex);
}
}
/// <summary>
/// 箱壳入库任务列表查询
/// </summary>
[RelayCommand]
public async void Query()
{
try
{
taskItems = new ObservableCollection<RealTaskInfo>();
#region 通过数据库获取数据进行刷新
var info = await inStoreBusiness.GetInStoreTask();
if (info != null)
{
if (materialTypeCombox == "箱壳")
{
materialTypeCombox = appConfig.shellStoreCode;
}
else if (materialTypeCombox == "内胆")
{
materialTypeCombox = appConfig.linerStoreCode;
}
else if (materialTypeCombox == "所有")
{
materialTypeCombox = string.Empty;
}
//info.ForEach(x => RefreshInStoreTask(x));
try
{
info = info.Where(x => !string.IsNullOrEmpty(search) ? x.MaterialCode == search : 1 == 1 && !string.IsNullOrEmpty(materialTypeCombox) ? x.StoreCode == materialTypeCombox : 1 == 1).ToList();
_ = App.Current.Dispatcher.BeginInvoke((Action)(async () =>
{
foreach (var item in info)
{
item.MaterialType = await inStoreBusiness.GetMaterialName(item.MaterialType);
taskItems.Add(item);
}
InstoreTask = taskItems;
}));
}
catch (Exception ex)
{
logHelper.Error("入库任务列表刷新异常", ex);
}
}
#endregion
}
catch (Exception ex)
{
logHelper.Error("入库任务加载异常", ex);
}
}
/// <summary>
/// 重置
/// </summary>
[RelayCommand]
public void Reset()
{
Search = string.Empty;
MaterialTypeCombox = string.Empty;
this.Query();
}
/// <summary>
/// 柱状体加载
/// </summary>
public async void Init()
{
Query();
ChartValues<double> shellAchievement = new ChartValues<double>();
ChartValues<double> linerAchievement = new ChartValues<double>();
MaterialNameList = new List<string>();
_ = App.Current.Dispatcher.BeginInvoke((Action)(async () =>
{
List<dynamic> info = await inStoreBusiness.GetMaterialStock();
if (info != null)
{
Achievement.Clear();
foreach (var item in info)
{
MaterialNameList.Add(item.parentMaterialName);
shellAchievement.Add(Convert.ToDouble(item.shellStock));
linerAchievement.Add(Convert.ToDouble(item.linerStock));
}
}
var shellColumn = new ColumnSeries();
shellColumn.DataLabels = true;
shellColumn.Title = "箱壳";
shellColumn.Values = shellAchievement;
var linerColumn = new ColumnSeries();
linerColumn.DataLabels = true;
linerColumn.Title = "内胆";
linerColumn.Values = linerAchievement;
Achievement.Add(shellColumn);
Achievement.Add(linerColumn);
}));
}
/// <summary>
/// 刷新入库任务列表
/// </summary>
/// <param name="taskInfo"></param>
private void RefreshInStoreTask(RealTaskInfo taskInfo, bool isFinsih = false)
{
if (isFinsih)
{
Init();
}
else
{
Query();
}
}
/// <summary>
/// 刷新扫码信息
/// </summary>
/// <param name="materialCode"></param>
/// <param name="materialName"></param>
/// <param name="spaceName"></param>
/// <param name="materialType"></param>
private void RefreshScanInfo(string materialCode, string materialName, string spaceName, string materialType)
{
if (materialType == appConfig.shellStoreCode)
{
ShellMaterialCode = materialCode;
ShellMaterialName = materialName;
ShellSpaceName = spaceName;
}
else if (materialType == appConfig.linerStoreCode)
{
LinerMaterialCode = materialCode;
LinerMaterialName = materialName;
LinerSpaceName = spaceName;
}
}
}
}