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.

159 lines
4.9 KiB
C#

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.WPF.MessageTips;
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
* CLR4.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
{
/// <summary>
/// 生产统计ViewModel
/// </summary>
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<ISqlSugarClient>();
// _prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
// DeletePalletCommand = new RelayCommand<string>(DeletePallet);
// DeleteBarCodeCommand = new RelayCommand<string> (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 参数定义
/// <summary>
/// AGV任务队列DataGrid
/// </summary>
private ObservableCollection<WcsTask> wcsTaskDataGrid = new ObservableCollection<WcsTask>();
public ObservableCollection<WcsTask> WcsTaskDataGrid
{
get { return wcsTaskDataGrid; }
set { wcsTaskDataGrid = value; RaisePropertyChanged(() => WcsTaskDataGrid); }
}
/// <summary>
/// AGV状态队列DataGrid
/// </summary>
private ObservableCollection<WcsAgvStatus> wcsAgvStatusDataGrid = new ObservableCollection<WcsAgvStatus>();
public ObservableCollection<WcsAgvStatus> WcsAgvStatusDataGrid
{
get { return wcsAgvStatusDataGrid; }
set { wcsAgvStatusDataGrid = value; RaisePropertyChanged(() => WcsAgvStatusDataGrid); }
}
#endregion
#region 事件定义
// public RelayCommand<string> DeletePalletCommand { get;set; }
// public RelayCommand<string> DeleteBarCodeCommand { get; set; }
#endregion
/// <summary>
/// 刷新AGV状态信息
/// </summary>
/// <param name="palletTasks"></param>
private async Task RefreshWcsAgvStatusDataGrid()
{
List<WcsAgvStatus> agvList = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WcsAgvStatus>().ToListAsync();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
WcsAgvStatusDataGrid.Clear();
foreach (var agv in agvList)
{
agv.Online = agv.Online=="true"? "在线": "离线";
WcsAgvStatusDataGrid.Add(agv);
}
}));
}
/// <summary>
/// 刷新AGV状态信息
/// </summary>
/// <param name="palletTasks"></param>
private async Task RefreshWcsTaskDataGrid()
{
try
{
List<WcsTask> agvList = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WcsTask>().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);
}
}));
}catch(Exception ex)
{
Msg.MsgShow($"刷新AGV状态信息异常{ex.Message}", 2, 3);
}
}
}
}