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

112 lines
3.8 KiB
C#

using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model;
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;
namespace Aucma.Core.Palletiz.ViewModels
{
public partial class StatisticsPageViewModel : ObservableObject
{
10 months ago
// private static readonly Lazy<StatisticsPageViewModel> lazy = new Lazy<StatisticsPageViewModel>(() => new StatisticsPageViewModel());
// public static StatisticsPageViewModel Instance => lazy.Value;
public StatisticsPageViewModel() {
MainWindowViewModel.RefreshInfoEvent += LoadData;
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");
10 months ago
#region 加载DataGrid数据
10 months ago
private async void LoadData()
{
10 months ago
//Task.Run(() =>
//{
try
{
10 months ago
List<RecordInStore> list = await _recordInstoreServices.QueryAsync(x => (x.StoreCode == storeCodeA || x.StoreCode == storeCodeB) && x.InStoreTime >= DateTime.Today);
if (list != null && list.Count > 0)
{
10 months ago
list.OrderByDescending(x => x.InStoreTime);
foreach (RecordInStore record in list)
{
App.Current.Dispatcher.Invoke(() =>
{
MaterialDataGrid.Add(record);
});
}
}
}
10 months ago
catch (Exception ex)
{
Console.WriteLine("" + ex.Message.ToString());
}
// });
//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 void ExecQuery(object obj)
{
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)
{
MaterialDataGrid.Clear();
10 months ago
foreach (RecordInStore record in list)
{
App.Current.Dispatcher.Invoke(() =>
{
MaterialDataGrid.Add(record);
});
}
}
10 months ago
}
#endregion
}
}