using AutoMapper;
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.PrismEvent;
using CapMachine.Wpf.Services;
using CapMachine.Wpf.Views;
using CsvHelper;
using CsvHelper.Configuration;
using Masuit.Tools;
using Masuit.Tools.Win32;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Threading;
using Application = System.Windows.Application;
namespace CapMachine.Wpf.ViewModels
{
///
/// 历史数据模型
///
public class HistoryDataViewModel : NavigationViewModel
{
public IDialogService DialogService { get; }
public IFreeSql FreeSql { get; }
public IEventAggregator EventAggregator { get; }
public IMapper Mapper { get; }
public ConfigService ConfigService { get; }
public ILogService Logger { get; }
///
/// 实例化函数
///
///
///
///
///
///
public HistoryDataViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator, IMapper mapper,ConfigService configService)
{
DialogService = dialogService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
Mapper = mapper;
ConfigService = configService;
ListChartTabGroupDto = Mapper.Map>(FreeSql.Select().Where(a => a.IsEnable == true).ToList());
ListHistoryWorkCondDto = new List()
{
new HistoryWorkCondDto(){ Name="测试名称1",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称2",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称3",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称4",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称5",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称6",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称7",CreateTime=DateTime.Now},
new HistoryWorkCondDto(){ Name="测试名称8",CreateTime=DateTime.Now},
};
//加载试验数据
ListHistoryExp = FreeSql.Select().IncludeMany(a => a.HistoryWorkCondFiles).ToList();
//
Task.Run(new Action(() =>
{
Thread.Sleep(1000);
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new Action(() =>
{
//Thread.Sleep(TimeSpan.FromSeconds(1));
//都要加载数据
EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 0, ActionMsg = "Start" });
EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 1, ActionMsg = "Start" });
EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 2, ActionMsg = "Start" });
EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 3, ActionMsg = "Start" });
EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 4, ActionMsg = "Start" });
EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 5, ActionMsg = "Start" });
}));
}));
}
private DelegateCommand _TestCmd;
///
/// 刷新数据命令
///
public DelegateCommand TestCmd
{
set
{
_TestCmd = value;
}
get
{
if (_TestCmd == null)
{
_TestCmd = new DelegateCommand(() => TestCmdMethod());
}
return _TestCmd;
}
}
private bool _IsLeftDrawerOpen;
///
/// 左侧的打开
///
public bool IsLeftDrawerOpen
{
get { return _IsLeftDrawerOpen; }
set { _IsLeftDrawerOpen = value; RaisePropertyChanged(); }
}
///
/// tEST
///
private void TestCmdMethod()
{
IsLeftDrawerOpen = true;
var openDrawerCommand = MaterialDesignThemes.Wpf.DrawerHost.OpenDrawerCommand;
// 获取 DrawerHost 的实例
var drawerHost = Application.Current.MainWindow.FindName("HistoryDrawerHost") as MaterialDesignThemes.Wpf.DrawerHost;
if (drawerHost != null)
{
drawerHost.IsLeftDrawerOpen = true; // 打开左侧 Drawer
}
//RegionManager.RequestNavigate("ProStepDrawerContentRegion", nameof(ProStepConfigPsView));
//EventAggregator.GetEvent().Publish("Right");
}
private List _ListChartTabGroupDto;
///
/// Tab集合信息数据
///
public List ListChartTabGroupDto
{
get { return _ListChartTabGroupDto; }
set { _ListChartTabGroupDto = value; RaisePropertyChanged(); }
}
///
/// 当前的Machine
///
private string CurSelectedMachine { get; set; } = "History";
#region 试验工况信息
///
/// 当前的文档数据
///
public List CsvRecordModels { get; set; } = new List();
private List _ListHistoryExp;
///
/// 试验集合信息数据
///
public List ListHistoryExp
{
get { return _ListHistoryExp; }
set { _ListHistoryExp = value; RaisePropertyChanged(); }
}
private List _ListHistoryWorkCondFile;
///
/// 试验集合保存的文件信息数据
///
public List ListHistoryWorkCondFile
{
get { return _ListHistoryWorkCondFile; }
set { _ListHistoryWorkCondFile = value; RaisePropertyChanged(); }
}
private List _ListHistoryWorkCondDto;
///
/// 历史工况集合信息数据
///
public List ListHistoryWorkCondDto
{
get { return _ListHistoryWorkCondDto; }
set { _ListHistoryWorkCondDto = value; RaisePropertyChanged(); }
}
private HistoryExp _SelectedHistoryExp;
///
/// 当前选中的行数据
///
public HistoryExp SelectedHistoryExp
{
get { return _SelectedHistoryExp; }
set { _SelectedHistoryExp = value; RaisePropertyChanged(); }
}
private HistoryWorkCondFile _SelectedHistoryWorkCondFile;
///
/// 选中的历史数据文件
///
public HistoryWorkCondFile SelectedHistoryWorkCondFile
{
get { return _SelectedHistoryWorkCondFile; }
set { _SelectedHistoryWorkCondFile = value; RaisePropertyChanged(); }
}
///
/// 当前搜索的工况条件
///
public ExpSearchDto CurExpSearchDto { get; set; } = new ExpSearchDto() { StartTime = DateTime.Now.AddDays(-1), EndTime = DateTime.Now };
private DelegateCommand