using CommunityToolkit.Mvvm.ComponentModel; using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using System.Collections; using log4net; using Admin.Core.Tasks; using Admin.Core.IService; using Microsoft.Extensions.DependencyInjection; using Admin.Core.Common; using Admin.Core.Model.ViewModels; using System.Threading; using Aucma.Core.BoxFoam.Business; using Admin.Core.Model; using System.Collections.Generic; /* * 首页信息 */ namespace Aucma.Core.BoxFoam.ViewModels { public partial class IndexPageViewModel : ObservableObject { private ObservableCollection listItems = new ObservableCollection(); private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); public readonly IRecordInStoreServices? _recordInstoreServices; private readonly IRealTaskInfoServices? _realTaskInfoService; private InStoreBusiness inStoreBusiness = InStoreBusiness.Instance; public IndexPageViewModel() { inStoreBusiness.init(); _recordInstoreServices = App.ServiceProvider.GetService(); _realTaskInfoService =App.ServiceProvider.GetService(); //Job_BoxFoamInStoreTask_Quartz.RefreshDataGridDelegateEvent += LoadData;//刷新底部列表 InStoreBusiness.RefreshDataGridDelegateEvent += LoadData;//刷新底部列表 // Job_TestTask_Quartz.DataGridDelegateEvent += ExecMethod;//刷新日志 // Job_BoxFoamInStoreTask_Quartz.RefreshScanMateriaCodeEvent += RefreshScanInfo;//扫码信息刷新 InStoreBusiness.RefreshScanMateriaCodeEvent += RefreshScanInfo;//扫码信息刷新 // Job_BoxFoamInStoreTask_Quartz.LogDelegateEvent += PrintMessageToListBox;//入库日志事件 InStoreBusiness.LogDelegateEvent += PrintMessageToListBox;//入库日志事件 LoadData(); } #region 扫描记录 data #region 加载DataGrid数据 private async Task LoadData() { var storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode"); DateTime startTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); DateTime endTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); List list = _realTaskInfoService.QueryAsync(x=>x.StoreCode.Equals(storeCode)).Result.OrderBy(x=>x.CreateTime).Take(4).ToList(); System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { PlanInfoDataGrid.Clear(); int i = 1; try { foreach (var item in list) { PlanInfoDataGrid.Add(new RealTaskInfo() { TaskCode = item.TaskCode, MaterialCode = item.MaterialCode, MaterialType = item.MaterialType, SpaceName = item.SpaceName, CreateTime = item.CreateTime, TaskStatus = item.TaskStatus }); i++; }; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } //Datalist.Insert(0, Datalist[Datalist.Count - 1]); //Datalist.RemoveAt(Datalist.Count - 1); })); } #endregion #region 初始化datagrid private ObservableCollection planInfoDataGrid = new ObservableCollection(); public ObservableCollection PlanInfoDataGrid { get { return planInfoDataGrid; } set { planInfoDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #endregion #region 扫描信息 #region 物料条码 private string _materialBarCode; public string MaterialBarCode { get => _materialBarCode; set=>SetProperty(ref _materialBarCode, value); } #endregion #region 物料编码 private string _materialCode; public string MaterialCode { get => _materialCode; set => SetProperty(ref _materialCode, value); } #endregion #region 物料名称 private string _materialName; public string MaterialName { get => _materialName; set => SetProperty(ref _materialName, value); } #endregion #region 目的信息 private string _destination; public string Destination { get => _destination; set => SetProperty(ref _destination, value); } #endregion #region 提示信息 private string _prompt; public string Prompt { get => _prompt; set => SetProperty(ref _prompt, value); } #endregion #region 开始时间 private string _beginTime; public string BeginTime { get => _beginTime; set => SetProperty(ref _beginTime, value); } #endregion #endregion #region 日志信息 /// /// LisBox数据模板 /// private IEnumerable logInfoListBox; public IEnumerable LogInfoListBox { get => logInfoListBox; set => SetProperty(ref logInfoListBox, value); } /// /// listBox绑定日志 /// /// private void PrintMessageToListBox(string message) { try { listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}"); LogInfoListBox = listItems.OrderByDescending(x => x); } catch (Exception ex) { log.Error("日志数据绑定异常", ex); } } #endregion #region 刷新扫码信息 /// /// 刷新扫码信息 /// /// /// /// /// private void RefreshScanInfo(string materialBarCode, string materialCode, string materialName, string spaceName,string msg) { System.Windows.Application.Current.Dispatcher.Invoke((Action)( () => { MaterialBarCode = materialBarCode; MaterialCode = materialCode; MaterialName = materialName; Destination = spaceName;//货道 Prompt = msg; BeginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd"); })); } #endregion } }