Files
CapMachine/CapMachine.Wpf/ViewModels/QuickMeterStepViewModel.cs

346 lines
19 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using CapMachine.Core;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.ProPars;
using CapMachine.Wpf.Services;
using Ganss.Excel;
using Microsoft.Win32;
using NPOI.SS.Formula.Functions;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using Syncfusion.Data.Extensions;
using System.Collections.ObjectModel;
using System.Windows;
namespace CapMachine.Wpf.ViewModels
{
public class QuickMeterStepViewModel : NavigationViewModel
{
/// <summary>
/// 实例化函数
/// </summary>
public QuickMeterStepViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator,
IRegionManager regionManager, MachineRtDataService machineRtDataService, SysRunService sysRunService)
{
FreeSql = freeSql;
EventAggregator = eventAggregator;
RegionManager = regionManager;
this.MachineRtDataService = machineRtDataService;
SysRunService = sysRunService;
//MachineDataService = machineDataService;
DialogService = dialogService;
ListQuickMeterStepDto = new ObservableCollection<QuickMeterStepDto>();
//{
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
// //new QuickMeterStepDto(){ Cond1Temp=12,Cond2Press=23,Cond2Temp=34,Cycle=2,EnvRH=12,EnvTemp=3,EVAPExpTemp=56,ExPress=67,HVVol=3,InhPress=23.4,InhTemp=90,LubePress=23,LVVol=23,OCR=34,OS1Temp=78,OS2Temp=78,PTCEntTemp=89,PTCFlow=90,PTCPw=22,Speed=340,StepNo=4,TimeMin=23,TimeSec=34},
//};
}
/// <summary>
/// FreeSQL 实例函数
/// </summary>
public IFreeSql FreeSql { get; }
public IEventAggregator EventAggregator { get; }
public IRegionManager RegionManager { get; }
public MachineRtDataService MachineRtDataService { get; }
public SysRunService SysRunService { get; }
/// <summary>
/// 弹窗服务
/// </summary>
public IDialogService DialogService { get; }
private ObservableCollection<QuickMeterStepDto> _ListQuickMeterStepDto;
/// <summary>
/// 程序集合
/// </summary>
public ObservableCollection<QuickMeterStepDto> ListQuickMeterStepDto
{
get { return _ListQuickMeterStepDto; }
set { _ListQuickMeterStepDto = value; RaisePropertyChanged(); }
}
private DelegateCommand _ProStepLoadFileCmd;
/// <summary>
/// 新增命令
/// </summary>
public DelegateCommand ProStepLoadFileCmd
{
set
{
_ProStepLoadFileCmd = value;
}
get
{
if (_ProStepLoadFileCmd == null)
{
_ProStepLoadFileCmd = new DelegateCommand(() => ProStepLoadFileCmdMethod());
}
return _ProStepLoadFileCmd;
}
}
/// <summary>
/// 加载步骤信息数据
/// </summary>
private void ProStepLoadFileCmdMethod()
{
try
{
//var dd = ListQuickMeterStepDto;
OpenFileDialog OpenFileDialogInfo = new OpenFileDialog(); //new一个方法
OpenFileDialogInfo.Filter = "(*.xls;*.xlsx)|*.xls;*.xlsx|all|*.*"; //删选、设定文件显示类型
OpenFileDialogInfo.CheckFileExists = true;
OpenFileDialogInfo.ShowDialog(); //显示打开文件的窗口
string fileName = OpenFileDialogInfo.FileName; //获得选择的文件路径
ListQuickMeterStepDto = new ExcelMapper(fileName).Fetch<QuickMeterStepDto>().ToObservableCollection();
DataSourceStr = "Excel文件";
//System.Diagnostics.Process.Start(fileName);//打开指定路径下的文件
}
catch (Exception ex)
{
MessageBox.Show("可能未选择信息", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
private string _DataSourceStr="";
/// <summary>
/// 数据来源
/// </summary>
public string DataSourceStr
{
get { return _DataSourceStr; }
set { _DataSourceStr = value; RaisePropertyChanged(); }
}
private DelegateCommand _ProStepExpFileCmd;
/// <summary>
/// 新增命令
/// </summary>
public DelegateCommand ProStepExpFileCmd
{
set
{
_ProStepExpFileCmd = value;
}
get
{
if (_ProStepExpFileCmd == null)
{
_ProStepExpFileCmd = new DelegateCommand(() => ProStepExpFileCmdMethod());
}
return _ProStepExpFileCmd;
}
}
/// <summary>
/// 导出到Excel文件
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void ProStepExpFileCmdMethod()
{
try
{
if (ListQuickMeterStepDto.Count > 0)
{
SaveFileDialog SaveFileDialogInfo = new SaveFileDialog();
SaveFileDialogInfo.Filter = "(*.xls;*.xlsx)|*.xls;*.xlsx|all|*.*"; //删选、设定文件显示类型
SaveFileDialogInfo.ShowDialog();
string SavePath = SaveFileDialogInfo.FileName;
new ExcelMapper().Save(SavePath, ListQuickMeterStepDto, "工况");
}
else
{
MessageBox.Show("当前未发现数据", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
private DelegateCommand _ProStepDbSelectedCmd;
/// <summary>
/// Db选择
/// </summary>
public DelegateCommand ProStepDbSelectedCmd
{
set
{
_ProStepDbSelectedCmd = value;
}
get
{
if (_ProStepDbSelectedCmd == null)
{
_ProStepDbSelectedCmd = new DelegateCommand(() => ProStepDbSelectedCmdMethod());
}
return _ProStepDbSelectedCmd;
}
}
/// <summary>
/// Db选择文件
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void ProStepDbSelectedCmdMethod()
{
try
{
if (ListQuickMeterStepDto.Count > 0)
{
DataSourceStr = "本地工况库";
}
else
{
MessageBox.Show("当前未发现数据", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
private DelegateCommand _ProStepSaveDbCmd;
/// <summary>
/// Db保存
/// </summary>
public DelegateCommand ProStepSaveDbCmd
{
set
{
_ProStepSaveDbCmd = value;
}
get
{
if (_ProStepSaveDbCmd == null)
{
_ProStepSaveDbCmd = new DelegateCommand(() => ProStepSaveDbCmdMethod());
}
return _ProStepSaveDbCmd;
}
}
/// <summary>
/// Db保存
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void ProStepSaveDbCmdMethod()
{
try
{
if (ListQuickMeterStepDto.Count > 0)
{
}
else
{
MessageBox.Show("当前未发现数据", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
private DelegateCommand _ProStepLoadPlcCmd;
/// <summary>
/// Db保存
/// </summary>
public DelegateCommand ProStepLoadPlcCmd
{
set
{
_ProStepLoadPlcCmd = value;
}
get
{
if (_ProStepLoadPlcCmd == null)
{
_ProStepLoadPlcCmd = new DelegateCommand(() => ProStepLoadPlcCmdMethod());
}
return _ProStepLoadPlcCmd;
}
}
/// <summary>
/// Db保存
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void ProStepLoadPlcCmdMethod()
{
try
{
if (ListQuickMeterStepDto.Count > 0)
{
if (MachineRtDataService.LinkState==false)
{
MessageBox.Show("当前PLC链接失败无法下载程序但会标记下载!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
SysRunService.MachineRunState1.IsProLoad = true;
return;
}
ProParsHelperQuick.GetPlcParsData(ListQuickMeterStepDto.ToList(), this.MachineRtDataService.SiemensDrive);
//下载完成的话,则标记状态
SysRunService.MachineRunState1.IsProLoad = true;
}
else
{
MessageBox.Show("当前未发现数据", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
}
}