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.
132 lines
4.9 KiB
C#
132 lines
4.9 KiB
C#
using Admin.Core.IService;
|
|
using Admin.Core.Model;
|
|
using Admin.Core.Service;
|
|
using Aucma.Core.CodeBinding.Models;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using log4net;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Aucma.Core.CodeBinding.ViewModels
|
|
{
|
|
public partial class StatisticsPageViewModel : ObservableObject
|
|
{
|
|
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(StatisticsPageViewModel));
|
|
private readonly ICodeBindingRecordServices? _codeBindingRecordServices;
|
|
public StatisticsPageViewModel() {
|
|
MainWindowViewModel.queryListEvent += ExecQueryAsync;
|
|
_codeBindingRecordServices = App.ServiceProvider.GetService<ICodeBindingRecordServices>();
|
|
LoadData();
|
|
}
|
|
|
|
List<MaterialComplateInfo> materialComplateInfos = new List<MaterialComplateInfo>();
|
|
|
|
#region 加载DataGrid数据
|
|
private async void LoadData()
|
|
{
|
|
|
|
List<CodeBindingRecord> records = null;
|
|
records = await _codeBindingRecordServices.QueryAsync(x => x.BoxCode != null && x.RecordTime2 >= System.DateTime.Now.AddDays(-1), "RECORD_TIME2 desc");
|
|
if (records != null)
|
|
{
|
|
foreach (CodeBindingRecord record in records)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
ListItems.Add(new ReaderInfo() { No = ListItems.Count + 1, BoxCode = record.BoxCode, ProductCode = record.ProductCode, BoxName = record.BoxName, BindingResult = record.BindingResult, IsPlcPass = record.isPlcPass == 2 ? "plc放行成功" : "", RecordTime = record.RecordTime2.ToString() });
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
#region 初始化datagrid
|
|
private ObservableCollection<ReaderInfo> listItems = new ObservableCollection<ReaderInfo>();
|
|
public ObservableCollection<ReaderInfo> ListItems
|
|
{
|
|
get { return listItems; }
|
|
set
|
|
{
|
|
listItems = value;
|
|
OnPropertyChanged();//属性通知
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
[RelayCommand]
|
|
private async Task ExecQueryAsync(object obj)
|
|
{
|
|
try
|
|
{
|
|
List<CodeBindingRecord> list;
|
|
if (obj == null)
|
|
{
|
|
list = await _codeBindingRecordServices.QueryAllByTime(null, null);
|
|
}
|
|
else
|
|
{
|
|
var result = (StatisticModel)obj;
|
|
if (string.IsNullOrEmpty(result.BeginTime) && string.IsNullOrEmpty(result.EndTime))
|
|
{
|
|
list = await _codeBindingRecordServices.QueryAllByTime(null, null);
|
|
}
|
|
else if (string.IsNullOrEmpty(result.BeginTime))
|
|
{
|
|
list = await _codeBindingRecordServices.QueryAllByTime(null, result.EndTime);
|
|
}
|
|
else if (string.IsNullOrEmpty(result.EndTime))
|
|
{
|
|
list = await _codeBindingRecordServices.QueryAllByTime(result.BeginTime, null);
|
|
}
|
|
else
|
|
{
|
|
DateTime theBeginTime = Convert.ToDateTime(result.BeginTime);
|
|
DateTime theEndTime = Convert.ToDateTime(result.EndTime);
|
|
if (theBeginTime > theEndTime)
|
|
{
|
|
MessageBox.Show("结束时间要大于开始时间!");
|
|
return;
|
|
}
|
|
list = await _codeBindingRecordServices.QueryAllByTime(result.BeginTime, result.EndTime);
|
|
}
|
|
|
|
}
|
|
if (list != null)
|
|
{
|
|
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
|
|
{
|
|
ListItems.Clear();
|
|
|
|
foreach (CodeBindingRecord record in list)
|
|
{
|
|
ListItems.Add(new ReaderInfo() { No = ListItems.Count + 1, BoxCode = record.BoxCode, ProductCode = record.ProductCode, BoxName = record.BoxName, BindingResult = record.BindingResult, IsPlcPass = record.isPlcPass == 2 ? "plc放行成功" : "", RecordTime = record.RecordTime2.ToString() });
|
|
}
|
|
|
|
}));
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.ToString());
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|