134 lines
4.6 KiB
C#
134 lines
4.6 KiB
C#
using Cowain.Bake.BLL;
|
|
using Cowain.Bake.Common;
|
|
using Cowain.Bake.Model;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using Unity;
|
|
using Prism.Commands;
|
|
using System.Windows;
|
|
using HandyControl.Controls;
|
|
using Cowain.Bake.UI.CsvMap;
|
|
|
|
namespace Cowain.Bake.UI.DataQuery.ViewModels
|
|
{
|
|
public class PalletInfoViewModel:ViewModelBase
|
|
{
|
|
private DateTime _startTime = DateTime.Now.AddDays(-1);
|
|
public DateTime StartDatetime
|
|
{
|
|
get { return _startTime; }
|
|
set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
|
|
}
|
|
private DateTime _endTime = DateTime.Now.AddHours(1);
|
|
public DateTime EndDatetime
|
|
{
|
|
get { return _endTime; }
|
|
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
|
|
}
|
|
|
|
public PalletInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
|
|
{
|
|
this.PageTitle = "托盘追踪";
|
|
}
|
|
|
|
private ObservableCollection<TPalletInfo> palletList;
|
|
public ObservableCollection<TPalletInfo> PalletList
|
|
{
|
|
get => palletList ?? (palletList = new ObservableCollection<TPalletInfo>());
|
|
set { SetProperty(ref palletList, value); }
|
|
}
|
|
|
|
List<TPalletInfo> SaveList = new List<TPalletInfo>();
|
|
public void AsyncRefreshTask()
|
|
{
|
|
Application.Current?.Dispatcher?.Invoke(new Action(() =>
|
|
{
|
|
Refresh();
|
|
}));
|
|
}
|
|
|
|
public async override void Refresh()
|
|
{
|
|
PalletList.Clear();
|
|
SaveList.Clear();
|
|
SaveList = await System.Threading.Tasks.Task.Run(() =>
|
|
{
|
|
//从数据库查询任务
|
|
return _unityContainer.Resolve<PalletInfoService>().GetAll();
|
|
});
|
|
|
|
SaveList.ForEach(x => PalletList.Add(x));
|
|
}
|
|
|
|
public DelegateCommand<object> ExportCommand => new DelegateCommand<object>((x) =>
|
|
{
|
|
if (SaveList.Count == 0)
|
|
{
|
|
HandyControl.Controls.MessageBox.Show("没有数据!");
|
|
return;
|
|
}
|
|
|
|
Common.Core.CSVHelper.WriteMap<TPalletInfo, PalletInfoMap>(SaveList);
|
|
//Common.Core.CSVHelper.WriteDataTableToCsv(SaveList, new List<string> { "Id","PalletCode", "PalletStatus",
|
|
// "BatteryQty", "BakingCount","BakingPosition", "ScanTime", "LoadingOverTime","InStoveTime","BakingBeginTime","BakingOverTime","OutStoveTime","JobNum"},
|
|
// new List<string> { "序号", "托盘条码", "托盘状态", "电芯数量", "烘烤次数", "烘烤位置", "扫码时间", "上料完成时间", "入炉时间", "开始烘烤时间", "烘烤完成时间", "出炉时间", "工单号"});
|
|
});
|
|
|
|
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
|
|
{
|
|
PalletList.Clear();
|
|
SaveList.Clear();
|
|
if ((EndDatetime - StartDatetime).TotalDays > 30)
|
|
{
|
|
HandyControl.Controls.MessageBox.Warning("查询时间差在 30 天以内!");
|
|
return;
|
|
}
|
|
|
|
var palletInfoService = _unityContainer.Resolve<PalletInfoService>();
|
|
SaveList = palletInfoService.Query(StartDatetime, EndDatetime, Code);
|
|
|
|
if (0 != SaveList.Count)
|
|
{
|
|
SaveList.ForEach(item => PalletList.Add(item));
|
|
Growl.Success("查询完成!");
|
|
}
|
|
else
|
|
{
|
|
Growl.Success("没有数据!");
|
|
}
|
|
});
|
|
public DelegateCommand<object> DeleteCommand => new DelegateCommand<object>((x) =>
|
|
{
|
|
var result = HandyControl.Controls.MessageBox.Ask($@"确定删除?", "操作提示");
|
|
if (result == System.Windows.MessageBoxResult.Cancel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var t = x as TPalletInfo;
|
|
if (t != null)
|
|
{
|
|
int delCount = _unityContainer.Resolve<PalletInfoService>().Delete(t);
|
|
palletList.Remove(t);
|
|
if (delCount > 0)
|
|
{
|
|
Growl.Success("删除成功!");
|
|
|
|
}
|
|
else
|
|
{
|
|
Growl.Fatal("删除失败!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Growl.Fatal("删除失败!");
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
|