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 { // private static readonly Lazy lazy = new Lazy(() => new StatisticsPageViewModel()); // public static StatisticsPageViewModel Instance => lazy.Value; public StatisticsPageViewModel() { MainWindowViewModel.RefreshInfoEvent += LoadData; LoadData(); } private readonly IRecordInStoreServices? _recordInstoreServices = App.ServiceProvider.GetService(); List materialComplateInfos = new List(); public string storeCodeA = Appsettings.app("StoreInfo", "PalletizStoreCodeA"); public string storeCodeB = Appsettings.app("StoreInfo", "PalletizStoreCodeB"); #region 加载DataGrid数据 private async void LoadData() { //Task.Run(() => //{ try { List list = await _recordInstoreServices.QueryAsync(x => (x.StoreCode == storeCodeA || x.StoreCode == storeCodeB) && x.InStoreTime >= DateTime.Today); if (list != null && list.Count > 0) { list.OrderByDescending(x => x.InStoreTime); foreach (RecordInStore record in list) { App.Current.Dispatcher.Invoke(() => { MaterialDataGrid.Add(record); }); } } } 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 materialDataGrid = new ObservableCollection(); public ObservableCollection MaterialDataGrid { get { return materialDataGrid; } set { materialDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #region 查询 /// /// 查询 /// [RelayCommand] private void ExecQuery(object obj) { string result = (string)obj; List list = _recordInstoreServices.QueryAsync(x => (x.StoreCode == storeCodeA || x.StoreCode == storeCodeB) && x.BarCodeCode.Contains(result)).Result; if (list != null && list.Count > 0) { MaterialDataGrid.Clear(); foreach (RecordInStore record in list) { App.Current.Dispatcher.Invoke(() => { MaterialDataGrid.Add(record); }); } } } #endregion } }