首次提交:添加src文件夹代码
This commit is contained in:
192
Cowain.Bake.UI/DataQuery/ViewModels/GetMesLogViewModel.cs
Normal file
192
Cowain.Bake.UI/DataQuery/ViewModels/GetMesLogViewModel.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
using Cowain.Bake.Model.Entity;
|
||||
using Cowain.Bake.BLL;
|
||||
using Cowain.Bake.Common;
|
||||
using Cowain.Bake.Common.Enums;
|
||||
using Cowain.Bake.Common.Interface;
|
||||
using Cowain.Bake.Model;
|
||||
using HandyControl.Controls;
|
||||
using Microsoft.Win32;
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
using Prism.Regions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Unity;
|
||||
using Cowain.Bake.Common.CsvMap;
|
||||
|
||||
namespace Cowain.Bake.UI.DataQuery.ViewModels
|
||||
{
|
||||
|
||||
public class GetMesLogViewModel : ViewModelBase, INavigationAware
|
||||
{
|
||||
TimeSpan intervalDateTime;
|
||||
private bool isChecked;
|
||||
public bool IsChecked
|
||||
{
|
||||
get => isChecked;
|
||||
set => SetProperty(ref isChecked, value);
|
||||
}
|
||||
|
||||
private string batteryCode;
|
||||
public string BatteryCode
|
||||
{
|
||||
get => batteryCode;
|
||||
set => SetProperty(ref batteryCode, value);
|
||||
}
|
||||
|
||||
private string mesClass;
|
||||
public string MesClass
|
||||
{
|
||||
get => mesClass;
|
||||
set => SetProperty(ref mesClass, value);
|
||||
}
|
||||
private ObservableCollection<MesDataEntity> mesDataList;
|
||||
public ObservableCollection<MesDataEntity> MesDataList
|
||||
{
|
||||
get => mesDataList;
|
||||
set => SetProperty(ref mesDataList, value);
|
||||
}
|
||||
private List<string> mesClassList;
|
||||
public List<string> MesClassList
|
||||
{
|
||||
get => mesClassList;
|
||||
set => SetProperty(ref mesClassList, value);
|
||||
}
|
||||
|
||||
private DateTime _startTime = DateTime.Now.AddDays(-2);
|
||||
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;
|
||||
public DateTime EndDatetime
|
||||
{
|
||||
get { return _endTime; }
|
||||
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
|
||||
}
|
||||
public GetMesLogViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
|
||||
{
|
||||
BatteryCode = "";
|
||||
_unityContainer = unityContainer;
|
||||
SetPalletStatusCombox();
|
||||
MesDataList = new ObservableCollection<MesDataEntity>();
|
||||
}
|
||||
|
||||
private void SetPalletStatusCombox()
|
||||
{
|
||||
mesClassList = new List<string>();
|
||||
foreach (EMesLogClass eMesLogClass in System.Enum.GetValues(typeof(EMesLogClass)))
|
||||
{
|
||||
mesClassList.Add(eMesLogClass.GetDescription());
|
||||
}
|
||||
|
||||
MesClass = EMesLogClass.EnterStation.GetDescription();
|
||||
}
|
||||
|
||||
public DelegateCommand AutoUploadCommand => new DelegateCommand(() =>
|
||||
{
|
||||
foreach (var item in MesDataList)
|
||||
{
|
||||
if (item.IsCheck)
|
||||
{
|
||||
_unityContainer.Resolve<MesDataService>().ModifySendFlag(item.Id, (sbyte)EMesUpLoadStatus.Wait);
|
||||
}
|
||||
}
|
||||
QueryMesStation();
|
||||
});
|
||||
|
||||
bool QueryMesStation()
|
||||
{
|
||||
MesDataList.Clear();
|
||||
List<MesDataEntity> dataList = null;
|
||||
if (!ExecuttableOrNot())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsChecked)
|
||||
{
|
||||
if (string.IsNullOrEmpty(BatteryCode))
|
||||
{
|
||||
Growl.Warning("电芯条码为空!");
|
||||
return false;
|
||||
}
|
||||
dataList = _unityContainer.Resolve<MesDataService>().GetMesDataCellState(BatteryCode, StartDatetime, EndDatetime);
|
||||
dataList.AddRange(_unityContainer.Resolve<MesDataService>().GetMesDataBakingOutput(BatteryCode, StartDatetime, EndDatetime));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(MesClass))
|
||||
{
|
||||
Growl.Warning("Mes信息类别为空!");
|
||||
return false;
|
||||
}
|
||||
|
||||
var Cmd = EnumHelper.GetValueByDescription<EMesLogClass>(MesClass);
|
||||
dataList = _unityContainer.Resolve<MesDataService>().GetMesDataList(Cmd, StartDatetime, EndDatetime);
|
||||
}
|
||||
|
||||
dataList.ForEach(item => MesDataList.Add(item));
|
||||
return true;
|
||||
}
|
||||
|
||||
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
|
||||
{
|
||||
if (!QueryMesStation())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MesDataList.Count == 0)
|
||||
{
|
||||
Growl.Warning("没有数据!");
|
||||
return;
|
||||
}
|
||||
});
|
||||
public DelegateCommand<object> GetMesCvsCommand => new DelegateCommand<object>((x) =>
|
||||
{
|
||||
if (MesDataList == null
|
||||
|| MesDataList.Count == 0)
|
||||
{
|
||||
Growl.Warning("没有数据!");
|
||||
return;
|
||||
}
|
||||
|
||||
Common.Core.CSVHelper.WriteMap<MesDataEntity, MesDataMap>(MesDataList);
|
||||
//Common.Core.CSVHelper.WriteDataTableToCsv(MesDataList, new List<string>() {"CreateTime", "SendTime", "RecvTime", "Content", "RecvContent", "BatteryCode" },
|
||||
// new List<string>() {"创建时间", "发送时间", "接收时间", "发送信息", "接收信息" , "电芯条码"});
|
||||
});
|
||||
|
||||
void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
|
||||
{
|
||||
// 导航到当前页面时的处理逻辑,先执行构造方法,再执行本方法
|
||||
}
|
||||
|
||||
bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
|
||||
{
|
||||
return false; //false:表示每次导航都创建新实例,不重用旧实例; true:用旧实例,不会执行构造方法
|
||||
}
|
||||
|
||||
void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
|
||||
{
|
||||
//相当于析构方法,退出时(切换时)再执行。
|
||||
// 在这里添加释放旧视图实例资源的代码
|
||||
}
|
||||
|
||||
private bool ExecuttableOrNot()
|
||||
{
|
||||
intervalDateTime = EndDatetime - StartDatetime;
|
||||
if (intervalDateTime.TotalDays > 10)
|
||||
{
|
||||
Growl.Warning("请选择时间区间小于10天的数据!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user