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.
AUCMA_SCADA/Aucma.Core.Palletiz/ViewModels/StatisticsPageViewModel.cs

140 lines
4.7 KiB
C#

using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model;
using Aucma.Core.Palletiz.Business;
using Aucma.Core.Palletiz.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Elasticsearch.Net;
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.Windows.Documents;
namespace Aucma.Core.Palletiz.ViewModels
{
public partial class StatisticsPageViewModel : ObservableObject
{
/// <summary>
/// 入库数量统计
/// </summary>
public delegate void CountInstore(int count);
public static event CountInstore? CountInstoreEvent;
// private static readonly Lazy<StatisticsPageViewModel> lazy = new Lazy<StatisticsPageViewModel>(() => new StatisticsPageViewModel());
// public static StatisticsPageViewModel Instance => lazy.Value;
public StatisticsPageViewModel()
{
10 months ago
MainWindowViewModel.RefreshInfoEvent += LoadData;
InStoreBusiness.AddDataEvent += AddData;
10 months ago
LoadData();
}
private readonly IRecordInStoreServices? _recordInstoreServices = App.ServiceProvider.GetService<IRecordInStoreServices>();
List<MaterialComplateInfo> materialComplateInfos = new List<MaterialComplateInfo>();
public string storeCodeA = Appsettings.app("StoreInfo", "PalletizStoreCodeA");
public string storeCodeB = Appsettings.app("StoreInfo", "PalletizStoreCodeB");
/// <summary>
/// 入库时DataGrid添加一条记录
/// </summary>
/// <returns></returns>
public void AddData(RecordInStore record)
{
App.Current.Dispatcher.Invoke(() =>
{
MaterialDataGrid.Add(record);
CountInstoreEvent?.Invoke(MaterialDataGrid.Count);
});
}
#region 加载DataGrid数据
private async Task LoadData()
{
await Task.Run(() =>
{
try
{
10 months ago
List<RecordInStore> list = _recordInstoreServices.QueryAsync(x => (x.StoreCode == storeCodeA || x.StoreCode == storeCodeB) && x.InStoreTime >= DateTime.Today).Result;
if (list != null && list.Count > 0)
{
App.Current.Dispatcher.Invoke(() =>
{
MaterialDataGrid.Clear();
CountInstoreEvent?.Invoke(list.Count);
list.OrderByDescending(x => x.InStoreTime);
foreach (RecordInStore record in list)
{
MaterialDataGrid.Add(record);
}
});
}
}
catch (Exception ex)
{
Console.WriteLine("" + ex.Message.ToString());
10 months ago
}
});
10 months ago
//MaterialDataGrid.Add(new MaterialComplateInfo() { No = 1, ProductPlanCode = "8659452123",MaterialCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10 });
}
#endregion
#region 初始化datagrid
private ObservableCollection<RecordInStore> materialDataGrid = new ObservableCollection<RecordInStore>();
public ObservableCollection<RecordInStore> MaterialDataGrid
{
get { return materialDataGrid; }
set
{
materialDataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 查询
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private async Task ExecQuery(object obj)
{
await Task.Run(() =>
{
10 months ago
string result = (string)obj;
List<RecordInStore> list = _recordInstoreServices.QueryAsync(x => (x.StoreCode == storeCodeA || x.StoreCode == storeCodeB) && x.BarCodeCode.Contains(result)).Result;
if (list != null && list.Count > 0)
{
App.Current.Dispatcher.Invoke(() =>
10 months ago
{
MaterialDataGrid.Clear();
foreach (RecordInStore record in list)
10 months ago
{
MaterialDataGrid.Add(record);
}
});
}
});
}
#endregion
}
}