Files
CapMachine/CapMachine.Wpf/Services/ComActionService.cs

194 lines
5.8 KiB
C#
Raw 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.Wpf.PrismEvent;
using Prism.Events;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace CapMachine.Wpf.Services
{
/// <summary>
/// 公共操作的服务
/// 存放公共事件的服务
/// </summary>
public class ComActionService
{
public ConfigService ConfigService { get; }
private IEventAggregator EventAggregator { get; set; }
public DataRecordService DataRecordService { get; }
public SysRunService SysRunServer { get; }
public PPCService PPCService { get; }
public CanDriveService CanDriveService { get; }
public LinDriveService LinDriveService { get; }
public MachineRtDataService MachineRtDataService { get; }
public IDialogService DialogService { get; }
public ComActionService(ConfigService configService, IEventAggregator eventAggregator,
DataRecordService dataRecordService, SysRunService sysRunService, PPCService pPCService, CanDriveService canDriveService, LinDriveService linDriveService,
MachineRtDataService machineRtDataService, IDialogService dialogService)
{
ConfigService = configService;
//事件服务
EventAggregator = eventAggregator;
DataRecordService = dataRecordService;
SysRunServer = sysRunService;
PPCService = pPCService;
CanDriveService = canDriveService;
LinDriveService = linDriveService;
MachineRtDataService = machineRtDataService;
DialogService = dialogService;
EventAggregator.GetEvent<ComDialogEvent>().Subscribe(ComDialogEventCall);
}
#region
/// <summary>
/// 公共弹窗事件执行方法
/// </summary>
/// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception>
private void ComDialogEventCall(ComDialogMsg msg)
{
switch (msg.Name)
{
case "过热度/过冷度配置":
ShowSuperHeatCool(msg.Par);
break;
case "规则转换":
if (SysRunServer.MachineRunState1.IsRunState)
{
MessageBox.Show("请不要在运行时编辑规则转换,此时更改可能导致运行出错,请停止后再编辑");
return;
}
ShowLogicRule(msg.Par);
break;
case "CAN/CANFD/LIN配置导入导出":
ShowCanLinConfigImExport(msg.Par);
break;
default:
break;
}
}
/// <summary>
/// 过热度和过冷度配置弹窗
/// </summary>
private void ShowSuperHeatCool(object par)
{
//弹窗
DialogService.ShowDialog("DialogSuperHeatCoolConfigView", new DialogParameters() { { "Name", par } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//保存配置信息
PPCService.SaveSuperHeatCoolConfig();
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
/// <summary>
/// 过热度和过冷度配置弹窗
/// </summary>
private void ShowLogicRule(object par)
{
//弹窗
DialogService.ShowDialog("DialogLogicRuleView", new DialogParameters() { { "Name", par } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//保存配置信息
//PPCService.SaveSuperHeatCoolConfig();
//是否改变规格
var ReturnValue = par.Parameters.GetValue<bool>("IsRuleEdit");
if (ReturnValue)
{
MessageBox.Show("检测到你已经改变了规则CAN或者LIN配置中如果已经加载规则或者连接的话则会出现错误那么你需要重启软件");
//逻辑可能更改了
EventAggregator.GetEvent<LogicRuleChangeEvent>().Publish("");
}
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
/// <summary>
/// CAN/CANFD/LIN 配置导入导出弹窗。
/// </summary>
/// <param name="par">透传参数。</param>
private void ShowCanLinConfigImExport(object par)
{
DialogService.ShowDialog("DialogCanLinConfigImExportView", new DialogParameters() { { "Name", par } }, (dialogResult) =>
{
if (dialogResult.Result == ButtonResult.OK)
{
}
});
}
#endregion
#region CAN和LIN协调
//CAN和LIN同一个时刻只能有一个在工作
/// <summary>
/// CAN是否可以工作
/// </summary>
/// <returns></returns>
public bool IsCanToDoWork()
{
if (LinDriveService.ToomossLinDrive.OpenState == true)
{
return false;
}
return true;
}
/// <summary>
/// LIN是否可以工作
/// </summary>
/// <returns></returns>
public bool IsLINToDoWork()
{
if (CanDriveService.ToomossCanDrive.OpenState == true)
{
return false;
}
return true;
}
#endregion
}
}