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.

182 lines
6.3 KiB
C#

2 days ago
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using NPOI.SS.Formula.Functions;
2 days ago
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.WPF.MessageTips;
using SlnMesnac.WPF.Model;
using SlnMesnac.WPF.Templates;
2 days ago
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DevExpress.Drawing.Printing.Internal.DXPageSizeInfo;
2 days ago
#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>
public class MachineStopHistoryViewModel : ViewModelBase
2 days ago
{
private readonly ISqlSugarClient? sqlSugarClient;
public PagenationModel<T> PagenationModel { get; set; }
private Dictionary<int,string> machineNameDic = new Dictionary<int, string>();
2 days ago
public MachineStopHistoryViewModel()
{
PagenationModel = new PagenationModel<T>()
{
FindPreCommand = new RelayCommand(OnPreCommand),
FindNextCommand = new RelayCommand(OnNextCommand),
FindTargetCommand = new RelayCommand(OnGoCommand)
};
2 days ago
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
InitList();
}
#region 事件定义
private void OnPreCommand()
{
if (PagenationModel.Current == 1) return;
// 处理前一页逻辑
PagenationModel.Current = PagenationModel.Current - 1;
Task.Run(async () => await RefreshWcsTaskDataGrid(PagenationModel.Current, PagenationModel.PageSize));
}
private void OnNextCommand()
{
// 处理下一页逻辑
PagenationModel.Current = PagenationModel.Current + 1;
Task.Run(async () => await RefreshWcsTaskDataGrid(PagenationModel.Current, PagenationModel.PageSize));
}
private void OnGoCommand()
{
// 处理跳转到指定页逻辑
// 处理下一页逻辑
Task.Run(async () => await RefreshWcsTaskDataGrid(PagenationModel.Current, PagenationModel.PageSize));
}
#endregion
2 days ago
private async void InitList()
{
machineNameDic.Add(1016, "3楼拆包机");
machineNameDic.Add(1017, "2楼磁选机");
machineNameDic.Add(1018, "2楼螺旋机");
machineNameDic.Add(1019, "2楼烘干机");
machineNameDic.Add(1020, "2楼除尘机");
machineNameDic.Add(1021, "2楼喷码机");
PagenationModel.Total = await getListTotal();
PagenationModel.computePage();
await RefreshWcsTaskDataGrid(PagenationModel.Current, PagenationModel.PageSize);
2 days ago
}
private async Task<int> getListTotal()
{
List<int> deviceIds = new List<int> { 1016, 1017, 1018, 1019, 1020, 1021 };
int aa = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordShutDown>().Where(x => deviceIds.Contains(x.DeviceId)).CountAsync();
return aa;
}
2 days ago
#region 参数定义
/// <summary>
/// 停机记录DataGrid
/// </summary>
private ObservableCollection<DmsShutDownModel> dmsShutDownModelDataGrid = new ObservableCollection<DmsShutDownModel>();
public ObservableCollection<DmsShutDownModel> DmsShutDownModelDataGrid
{
get { return dmsShutDownModelDataGrid; }
set { dmsShutDownModelDataGrid = value; RaisePropertyChanged(() => DmsShutDownModelDataGrid); }
}
#endregion
/// <summary>
/// 刷新停机记录信息
/// </summary>
/// <param name="palletTasks"></param>
private async Task RefreshWcsTaskDataGrid(int pageNumber=1,int pageSize=0)
2 days ago
{
2 days ago
try
{
PagenationModel.computePage();
2 days ago
List<int> deviceIds = new List<int> { 1016, 1017, 1018, 1019, 1020, 1021 };
List<DmsRecordShutDown> list = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordShutDown>().Where(x=>deviceIds.Contains(x.DeviceId)).OrderByDescending(x=>x.ShutBeginTime).ToPageListAsync(pageNumber,pageSize);
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
dmsShutDownModelDataGrid.Clear();
int startId = (pageNumber-1)*pageSize+1;
foreach (var item in list)
{
DmsShutDownModel model = new DmsShutDownModel();
model.id = startId++;
model.deviceName = machineNameDic[item.DeviceId];
model.shutReason = item.ShutReason??"未知";
model.shutBeginTime = item.ShutBeginTime==null?"":item.ShutBeginTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
model.shutEndTime = item.ShutEndTime == null?"":item.ShutEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
model.totalTime = item.ShutEndTime == null ? "" : (item.ShutEndTime.Value - item.ShutBeginTime.Value).TotalMinutes.ToString("F2");
dmsShutDownModelDataGrid.Add(model);
}
}));
}catch(Exception ex)
{
Msg.MsgShow($"刷新停机记录信息{ex.Message}", 2, 3);
2 days ago
}
}
}
}