using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using Microsoft.Extensions.DependencyInjection; using SlnMesnac.Business; using SlnMesnac.Model.domain; using SlnMesnac.Model.dto; using SqlSugar; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- * 版权所有 (c) 2024 WenJY 保留所有权利。 * CLR版本:4.0.30319.42000 * 机器名称:LAPTOP-E0N2L34V * 命名空间:SlnMesnac.WPF.ViewModel * 唯一标识:14008fcc-0a31-4f1e-bc80-9f9ea84d3de5 * * 创建者:WenJY * 电子邮箱:wenjy@mesnac.com * 创建时间:2024-04-10 16:18:57 * 版本:V1.0.0 * 描述: * *-------------------------------------------------------------------- * 修改人: * 时间: * 修改说明: * * 版本:V1.0.0 *--------------------------------------------------------------------*/ #endregion << 版 本 注 释 >> namespace SlnMesnac.WPF.ViewModel { /// /// 生产统计ViewModel /// internal class AgvAndTaskViewModel : ViewModelBase { private readonly ISqlSugarClient? sqlSugarClient; // private readonly ProdCompletionBusiness _prodCompletionBusiness; private System.Timers.Timer refreshTimer = new System.Timers.Timer(5000); public AgvAndTaskViewModel() { sqlSugarClient = App.ServiceProvider.GetService(); // _prodCompletionBusiness = App.ServiceProvider.GetService(); // DeletePalletCommand = new RelayCommand(DeletePallet); // DeleteBarCodeCommand = new RelayCommand (DeleteBarCode); // _palletStowBusiness.RefreshPalletTaskListEvent += RefreshPalletTaskDataGrid; refreshTimer.Elapsed += OnTimedEvent; refreshTimer.AutoReset = true; // 设置为自动重置 refreshTimer.Enabled = true; // 启用定时器 } private async void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e) { await RefreshWcsAgvStatusDataGrid(); await RefreshWcsTaskDataGrid(); } #region 参数定义 /// /// AGV任务队列DataGrid /// private ObservableCollection wcsTaskDataGrid = new ObservableCollection(); public ObservableCollection WcsTaskDataGrid { get { return wcsTaskDataGrid; } set { wcsTaskDataGrid = value; RaisePropertyChanged(() => WcsTaskDataGrid); } } /// /// AGV状态队列DataGrid /// private ObservableCollection wcsAgvStatusDataGrid = new ObservableCollection(); public ObservableCollection WcsAgvStatusDataGrid { get { return wcsAgvStatusDataGrid; } set { wcsAgvStatusDataGrid = value; RaisePropertyChanged(() => WcsAgvStatusDataGrid); } } #endregion #region 事件定义 // public RelayCommand DeletePalletCommand { get;set; } // public RelayCommand DeleteBarCodeCommand { get; set; } #endregion /// /// 刷新AGV状态信息 /// /// private async Task RefreshWcsAgvStatusDataGrid() { List agvList = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable().ToListAsync(); await App.Current.Dispatcher.BeginInvoke((Action)(() => { WcsAgvStatusDataGrid.Clear(); foreach (var agv in agvList) { agv.Online = agv.Online=="true"? "在线": "离线"; WcsAgvStatusDataGrid.Add(agv); } })); } /// /// 刷新AGV状态信息 /// /// private async Task RefreshWcsTaskDataGrid() { List agvList = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable().Where(x => x.NextPointId == 8 || x.NextPointId==9).ToListAsync(); await App.Current.Dispatcher.BeginInvoke((Action)(() => { WcsTaskDataGrid.Clear(); foreach (var agv in agvList) { WcsTaskDataGrid.Add(agv); } })); } } }