增加报警

This commit is contained in:
2025-01-01 17:41:48 +08:00
parent f26bf28181
commit 7b5df5877d
16 changed files with 896 additions and 122 deletions

View File

@@ -0,0 +1,75 @@
using FreeSql.DataAnnotations;
using System;
namespace CapMachine.Model.Alarm
{
/// <summary>
/// 报警配置信息
/// </summary>
[Table(Name = "AlarmConfig")]
public class AlarmConfig
{
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimary = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 报警配置类别
/// </summary>
[Column(Name = "Category", IsNullable = false, StringLength = 20)]
public string? Category { get; set; }
/// <summary>
/// 报警的地址
/// </summary>
[Column(Name = "Address", IsNullable = false, StringLength = 20)]
public string? Address { get; set; }
/// <summary>
/// 报警等级
/// </summary>
[Column(Name = "AlarmLevel", IsNullable = false)]
public AlarmLevel AlarmLevel { get; set; }
/// <summary>
/// 激活类型
/// </summary>
[Column(Name = "ActiveType", IsNullable = false)]
public ActiveType ActiveType { get; set; }
/// <summary>
/// 报警配置名称
/// </summary>
[Column(Name = "Name", IsNullable = false, StringLength = 50)]
public string? Name { get; set; }
/// <summary>
/// 报警消息
/// </summary>
[Column(Name = "Message", IsNullable = false, StringLength = 150)]
public string? Message { get; set; }
/// <summary>
/// 布尔激活的阀值
/// </summary>
[Column(Name = "BoolActiveValue", IsNullable = false)]
public bool BoolActiveValue { get; set; }
/// <summary>
/// 报警上限阀值
/// </summary>
[Column(Name = "ThresholdUp", DbType = "decimal(8, 3)", IsNullable = true)]
public decimal ThresholdUp { get; set; }
/// <summary>
/// 报警下限阀值
/// </summary>
[Column(Name = "ThresholdDown", DbType = "decimal(8, 3)", IsNullable = true)]
public decimal ThresholdDown { get; set; }
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
public DateTime CreateTime { get; set; }
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Model.Alarm
{
/// <summary>
/// 报警等级
/// </summary>
public enum AlarmLevel
{
/// <summary>
/// 一级
/// </summary>
Level1=1,
/// <summary>
/// 二级
/// </summary>
Level2 = 2,
/// <summary>
/// 三级
/// </summary>
Level3 = 3,
}
/// <summary>
/// 报警激活类型
/// </summary>
public enum ActiveType
{
/// <summary>
/// 阀值
/// </summary>
Threshold = 1,
/// <summary>
/// 布尔类型
/// </summary>
Bool = 2,
}
}

View File

@@ -0,0 +1,59 @@
using FreeSql.DataAnnotations;
using System;
namespace CapMachine.Model.Alarm
{
/// <summary>
/// PLC报警 HistoryAlarm
/// </summary>
[Table(Name = "HistoryAlarm")]
public class HistoryAlarm
{
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimary = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 报警消息分类
/// </summary>
[Column(Name = "Category", IsNullable = false, StringLength = 20)]
public string? Category { get; set; }
/// <summary>
/// 报警等级
/// </summary>
[Column(Name = "AlarmLevel", IsNullable = false)]
public AlarmLevel AlarmLevel { get; set; }
/// <summary>
/// 报警名称
/// </summary>
[Column(Name = "Name", IsNullable = false, StringLength = 50)]
public string? Name { get; set; }
/// <summary>
/// 报警消息
/// </summary>
[Column(Name = "Message", IsNullable = false, StringLength = 150)]
public string? Message { get; set; }
/// <summary>
/// 报警时长
/// 秒
/// </summary>
[Column(Name = "Duration")]
public long Duration { get; set; }
[Column(Name = "CreateTime")]
public DateTime CreateTime { get; set; }
/// <summary>
/// ///////////////////////////////////////////导航属性///////////////////////////////////////////////////////
/// </summary>
//public Guid? AlarmAddressId { get; set; }
//public AlarmAddress AlarmAddress { get; set; }
}
}

View File

@@ -0,0 +1,105 @@
using CapMachine.Model.Alarm;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Alarm
{
/// <summary>
/// 报警运行单元
/// </summary>
public class AlarmRunCell : BindableBase
{
/// <summary>
/// 实例化函数
/// </summary>
public AlarmRunCell(IFreeSql freeSql)
{
CurAlarmConfig = new AlarmConfig();
FreeSql = freeSql;
}
/// <summary>
/// 更新报警对应的值
/// </summary>
public void UpdateBoolValue(bool Value)
{
if (CurAlarmConfig.ActiveType == ActiveType.Bool)
{
if (CurAlarmConfig.BoolActiveValue == Value)
{
ActiveState = true;
ActiveTime = DateTime.Now;
}
else
{
ActiveState = false;
}
}
}
/// <summary>
/// 布尔类型的变量 序号
/// </summary>
public long Index { get; set; }
private bool _ActiveState = false;
/// <summary>
/// 报警激活状态
/// </summary>
public bool ActiveState
{
get { return _ActiveState; }
set
{
if (_ActiveState != value)
{
_ActiveState = value;
RaisePropertyChanged();
//报警结束时保存报警
if (ActiveState==false)
{
SaveAlarm();
}
}
}
}
/// <summary>
/// 保存报警
/// </summary>
private void SaveAlarm()
{
FreeSql.Insert<HistoryAlarm>(new HistoryAlarm()
{
AlarmLevel = CurAlarmConfig.AlarmLevel,
Category = CurAlarmConfig.Category,
Message = CurAlarmConfig.Message,
Name = CurAlarmConfig.Name,
Duration = (long)(DateTime.Now - ActiveTime).TotalSeconds,
CreateTime = ActiveTime,
}).ExecuteAffrows();
}
/// <summary>
/// 报警时长
/// </summary>
public int TimeDuration { get; set; }
/// <summary>
/// 激活时间
/// </summary>
public DateTime ActiveTime { get; set; }
/// <summary>
/// 当前的报警配置
/// </summary>
public AlarmConfig CurAlarmConfig { get; set; }
public IFreeSql FreeSql { get; }
}
}

View File

@@ -92,6 +92,7 @@ namespace CapMachine.Wpf
containerRegistry.RegisterSingleton<SysRunService>(); containerRegistry.RegisterSingleton<SysRunService>();
containerRegistry.RegisterSingleton<ConfigService>(); containerRegistry.RegisterSingleton<ConfigService>();
containerRegistry.RegisterSingleton<AlarmService>();
////注册设备服务 ////注册设备服务
//containerRegistry.RegisterSingleton<MachineDataService>(); //containerRegistry.RegisterSingleton<MachineDataService>();
containerRegistry.RegisterSingleton<MachineRtDataService>(); containerRegistry.RegisterSingleton<MachineRtDataService>();
@@ -100,6 +101,7 @@ namespace CapMachine.Wpf
containerRegistry.RegisterSingleton<HighSpeedDataService>(); containerRegistry.RegisterSingleton<HighSpeedDataService>();
containerRegistry.RegisterSingleton<PPCService>(); containerRegistry.RegisterSingleton<PPCService>();
//注册AutoMapper 将IAutoMapperProvider注入IOC容器并对外提供IMapper注入类型。 //注册AutoMapper 将IAutoMapperProvider注入IOC容器并对外提供IMapper注入类型。
containerRegistry.RegisterSingleton<IMapperProvider, MapperConfig>(); containerRegistry.RegisterSingleton<IMapperProvider, MapperConfig>();
containerRegistry.Register(typeof(IMapper), GetMapper); containerRegistry.Register(typeof(IMapper), GetMapper);
@@ -220,6 +222,7 @@ namespace CapMachine.Wpf
var appVersionService = ContainerLocator.Container.Resolve<IFreeSql>(); var appVersionService = ContainerLocator.Container.Resolve<IFreeSql>();
//var appVersionService1 = ContainerLocator.Container.Resolve<MachineDataService>(); //var appVersionService1 = ContainerLocator.Container.Resolve<MachineDataService>();
//var appVersionService2 = ContainerLocator.Container.Resolve<ILogService>(); //var appVersionService2 = ContainerLocator.Container.Resolve<ILogService>();
var appVersionService12 = ContainerLocator.Container.Resolve<AlarmService>();
var appVersionService3 = ContainerLocator.Container.Resolve<MachineRtDataService>(); var appVersionService3 = ContainerLocator.Container.Resolve<MachineRtDataService>();
var appVersionService4 = ContainerLocator.Container.Resolve<ProStepConfigPsView>(); var appVersionService4 = ContainerLocator.Container.Resolve<ProStepConfigPsView>();
var appVersionService5 = ContainerLocator.Container.Resolve<ProConfigView>(); var appVersionService5 = ContainerLocator.Container.Resolve<ProConfigView>();
@@ -231,6 +234,7 @@ namespace CapMachine.Wpf
var appVersionService11 = ContainerLocator.Container.Resolve<PPCService>(); var appVersionService11 = ContainerLocator.Container.Resolve<PPCService>();
//给当前的全局异常捕捉服务使用 //给当前的全局异常捕捉服务使用
LogService = ContainerLocator.Container.Resolve<ILogService>(); LogService = ContainerLocator.Container.Resolve<ILogService>();
LogService.Error("ex.ToString()"); LogService.Error("ex.ToString()");

View File

@@ -1,6 +1,7 @@
using Prism.Mvvm; using Prism.Mvvm;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -15,21 +16,25 @@ namespace CapMachine.Wpf.Dtos
/// <summary> /// <summary>
/// 等级 /// 等级
/// </summary> /// </summary>
[Description("等级")]
public int Level { get; set; } public int Level { get; set; }
/// <summary> /// <summary>
/// 分类 /// 分类
/// </summary> /// </summary>
[Description("分类")]
public string? Category { get; set; } public string? Category { get; set; }
/// <summary> /// <summary>
/// 内容 /// 内容
/// </summary> /// </summary>
[Description("内容")]
public string? Content { get; set; } public string? Content { get; set; }
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>
[Description("创建时间")]
public DateTime CreateTime { get; set; } public DateTime CreateTime { get; set; }
} }
} }

View File

@@ -0,0 +1,57 @@
using CapMachine.Model.Alarm;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Dtos
{
/// <summary>
/// 报警实时模型
/// </summary>
public class AlarmRtDto:BindableBase
{
private string? _Name;
/// <summary>
/// 报警名称
/// </summary>
public string? Name
{
get { return _Name; }
set { _Name = value; RaisePropertyChanged(); }
}
private string? _Message;
/// <summary>
/// 报警消息
/// </summary>
public string? Message
{
get { return _Message; }
set { _Message = value; RaisePropertyChanged(); }
}
private string? _Category;
/// <summary>
/// 报警消息分类
/// </summary>
public string? Category
{
get { return _Category; }
set { _Category = value; RaisePropertyChanged(); }
}
private AlarmLevel? _AlarmLevel;
/// <summary>
/// 报警等级
/// </summary>
public AlarmLevel? AlarmLevel
{
get { return _AlarmLevel; }
set { _AlarmLevel = value; RaisePropertyChanged(); }
}
}
}

View File

@@ -0,0 +1,56 @@
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Dtos
{
/// <summary>
/// 历史报警模型
/// </summary>
public class HistoryAlarmDto : BindableBase
{
private string? _Category;
[Description("分类")]
public string? Category
{
get { return _Category; }
set { _Category = value; RaisePropertyChanged(); }
}
private string? _AlarmLevel;
[Description("报警等级")]
public string? AlarmLevel
{
get { return _AlarmLevel; }
set { _AlarmLevel = value; RaisePropertyChanged(); }
}
private string? _Name;
[Description("报警名称")]
public string? Name
{
get { return _Name; }
set { _Name = value; RaisePropertyChanged(); }
}
private long _Duration;
[Description("报警时长")]
public long Duration
{
get { return _Duration; }
set { _Duration = value; RaisePropertyChanged(); }
}
private DateTime _CreateTime;
[Description("报警时间")]
public DateTime CreateTime
{
get { return _CreateTime; }
set { _CreateTime = value; RaisePropertyChanged(); }
}
}
}

View File

@@ -0,0 +1,20 @@
using AutoMapper;
using CapMachine.Model;
using CapMachine.Model.Alarm;
using CapMachine.Wpf.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.MapperProfile
{
public class HistoryAlarmProfile : Profile
{
public HistoryAlarmProfile()
{
CreateMap<HistoryAlarm, HistoryAlarmDto>().ReverseMap();
}
}
}

View File

@@ -0,0 +1,235 @@
using CapMachine.Model.Alarm;
using CapMachine.Wpf.Alarm;
using CapMachine.Wpf.Dtos;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Services
{
/// <summary>
/// 报警服务
/// </summary>
public class AlarmService : BindableBase
{
public AlarmService(ConfigService configService, IEventAggregator eventAggregator,IFreeSql freeSql
)
{
ConfigService = configService;
//事件服务
_EventAggregator = eventAggregator;
FreeSql = freeSql;
//DataRecordService = dataRecordService;
//SysRunServer = sysRunService;
ListAlarmRunCell = new ObservableCollection<AlarmRunCell>()
{
new AlarmRunCell(FreeSql){Index=0,CurAlarmConfig=new AlarmConfig()
{
Name="急停报警",
ActiveType=ActiveType.Bool,
Address="V0.0",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="急停报警",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=1,CurAlarmConfig=new AlarmConfig()
{
Name="高压压控",
ActiveType=ActiveType.Bool,
Address="V0.1",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="高压压控",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=2,CurAlarmConfig=new AlarmConfig()
{
Name="低压压控",
ActiveType=ActiveType.Bool,
Address="V0.2",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="低压压控",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=3,CurAlarmConfig=new AlarmConfig()
{
Name="水压低",
ActiveType=ActiveType.Bool,
Address="V0.3",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="水压低",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=4,CurAlarmConfig=new AlarmConfig()
{
Name="水泵过载",
ActiveType=ActiveType.Bool,
Address="V0.4",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="水泵过载",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=5,CurAlarmConfig=new AlarmConfig()
{
Name="冷水机组故障",
ActiveType=ActiveType.Bool,
Address="V0.5",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="冷水机组故障",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=6,CurAlarmConfig=new AlarmConfig()
{
Name="排气压力",
ActiveType=ActiveType.Bool,
Address="V0.6",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="排气压力",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=7,CurAlarmConfig=new AlarmConfig()
{
Name="吸气压力",
ActiveType=ActiveType.Bool,
Address="V0.7",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="吸气压力",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=8,CurAlarmConfig=new AlarmConfig()
{
Name="吸气温度",
ActiveType=ActiveType.Bool,
Address="V1.0",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="吸气温度",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=9,CurAlarmConfig=new AlarmConfig()
{
Name="吸气混合器温度",
ActiveType=ActiveType.Bool,
Address="V1.1",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="吸气混合器温度",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=10,CurAlarmConfig=new AlarmConfig()
{
Name="水加热温度",
ActiveType=ActiveType.Bool,
Address="V1.2",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="水加热温度",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=11,CurAlarmConfig=new AlarmConfig()
{
Name="排气温度",
ActiveType=ActiveType.Bool,
Address="V1.3",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="排气温度",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=12,CurAlarmConfig=new AlarmConfig()
{
Name="水箱进水温度",
ActiveType=ActiveType.Bool,
Address="V1.4",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="水箱进水温度",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=13,CurAlarmConfig=new AlarmConfig()
{
Name="压缩机表面温度",
ActiveType=ActiveType.Bool,
Address="V1.5",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="压缩机表面温度",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
new AlarmRunCell(FreeSql){Index=14,CurAlarmConfig=new AlarmConfig()
{
Name="试验箱",
ActiveType=ActiveType.Bool,
Address="V1.6",
AlarmLevel=AlarmLevel.Level1,
Category="一般报警",
Message="试验箱",
ThresholdDown=1,
ThresholdUp=1,
BoolActiveValue=true
}},
};
}
public ConfigService ConfigService { get; }
private IEventAggregator _EventAggregator { get; set; }
public IFreeSql FreeSql { get; }
public DataRecordService DataRecordService { get; }
public SysRunService SysRunServer { get; }
public MachineRtDataService MachineRtDataService { get; }
private ObservableCollection<AlarmRunCell> _ListAlarmRunCell;
/// <summary>
/// 报警实时数据集合
/// </summary>
public ObservableCollection<AlarmRunCell> ListAlarmRunCell
{
get { return _ListAlarmRunCell; }
set { _ListAlarmRunCell = value; RaisePropertyChanged(); }
}
}
}

View File

@@ -32,6 +32,7 @@ namespace CapMachine.Wpf.Services
/// 事件聚合器 /// 事件聚合器
/// </summary> /// </summary>
private IEventAggregator _EventAggregator { get; set; } private IEventAggregator _EventAggregator { get; set; }
public AlarmService AlarmService { get; }
/// <summary> /// <summary>
/// PLCScanTask扫描Task /// PLCScanTask扫描Task
@@ -97,7 +98,7 @@ namespace CapMachine.Wpf.Services
/// 实例化函数 /// 实例化函数
/// </summary> /// </summary>
/// <param name="eventAggregator"></param> /// <param name="eventAggregator"></param>
public MachineRtDataService(IEventAggregator eventAggregator) public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService)//, AlarmService alarmService
{ {
//ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>(); //ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>();
@@ -110,6 +111,7 @@ namespace CapMachine.Wpf.Services
//事件服务 //事件服务
_EventAggregator = eventAggregator; _EventAggregator = eventAggregator;
AlarmService = alarmService;
//秒触发一次 //秒触发一次
CycleTimer = new System.Timers.Timer(500); CycleTimer = new System.Timers.Timer(500);
@@ -181,7 +183,7 @@ namespace CapMachine.Wpf.Services
SVAddress = "VW200", SVAddress = "VW200",
MVAddress = "VW250", MVAddress = "VW250",
IsMeter = true, IsMeter = true,
AutoHandSwitchAddress= "VW240", AutoHandSwitchAddress = "VW240",
Precision = 1, Precision = 1,
DecimalPoint = 0, DecimalPoint = 0,
Samp = 1, Samp = 1,
@@ -895,6 +897,11 @@ namespace CapMachine.Wpf.Services
private Random Random { get; set; } = new Random(); private Random Random { get; set; } = new Random();
/// <summary>
/// 报警结果集合
/// </summary>
private OperateResult<bool[]> OperateResultAlarm { get; set; }
/// <summary> /// <summary>
/// PLC扫描线程 /// PLC扫描线程
/// </summary> /// </summary>
@@ -912,28 +919,8 @@ namespace CapMachine.Wpf.Services
//DiagnosticsTime.Start(); //DiagnosticsTime.Start();
try try
{ {
//var MyProperty = typeof(int);
//foreach (var item in TagManger.DicTags)
//{
// if (item.Value.ValueType == typeof(short))
// {
// var Tag = TagManger.GetTagByName<short>(item.Key);
// Tag.RtValue.Value++;
// }
// else if (item.Value.ValueType == typeof(double))
// {
// var Tag = TagManger.GetTagByName<double>(item.Key);
// Tag.RtValue.Value++;
// }
//}
//TagInfo.RtValue.Value++; //TagInfo.RtValue.Value++;
//RT TODO
//SiemensDrive.Read("VW1", 2);
//var data = TagManger.DicTags["转速"].ValueType.Name; //var data = TagManger.DicTags["转速"].ValueType.Name;
////第一次计时 ////第一次计时
@@ -1001,6 +988,16 @@ namespace CapMachine.Wpf.Services
//stopwatch.Stop(); //停止Stopwatch //stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("Add Elapsed output runTime:{0}", stopwatch.Elapsed.TotalSeconds.ToString()); //Console.WriteLine("Add Elapsed output runTime:{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset(); //stopwatch.Reset();
OperateResultAlarm = SiemensDrive.ReadBool("V0.0", 15);
if (OperateResultAlarm.IsSuccess)
{
foreach (var item in AlarmService.ListAlarmRunCell)
{
item.UpdateBoolValue(OperateResultAlarm.Content[item.Index]);
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -1,6 +1,7 @@
using AutoMapper; using AutoMapper;
using CapMachine.Core; using CapMachine.Core;
using CapMachine.Model; using CapMachine.Model;
using CapMachine.Model.Alarm;
using CapMachine.Wpf.Dtos; using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.Models; using CapMachine.Wpf.Models;
using CapMachine.Wpf.Services; using CapMachine.Wpf.Services;
@@ -40,13 +41,13 @@ namespace CapMachine.Wpf.ViewModels
CategoryComboBoxList = new List<ComboBoxModel>() CategoryComboBoxList = new List<ComboBoxModel>()
{ {
new ComboBoxModel(){Key="0",Text="系统" }, new ComboBoxModel(){Key="0",Text="系统日志" },
new ComboBoxModel(){Key="1",Text="程序步骤" }, new ComboBoxModel(){Key="1",Text="程序步骤" },
new ComboBoxModel(){Key="2",Text="报警" }, new ComboBoxModel(){Key="2",Text="历史报警" },
}; };
} }
private string CurrentName = "埋塞敲入螺旋钉安装"; private string CurrentName = "";
private string CurrentTemplate = "BurPlugInstallTemplate.xlsx"; private string CurrentTemplate = "BurPlugInstallTemplate.xlsx";
@@ -89,14 +90,14 @@ namespace CapMachine.Wpf.ViewModels
/// <summary> /// <summary>
/// 列表集合 /// 列表集合
/// </summary> /// </summary>
private ObservableCollection<ActionLogDto> _ListModelDto=new ObservableCollection<ActionLogDto>(); private ObservableCollection<object> _ListModelDto = new ObservableCollection<object>();
/// <summary> /// <summary>
/// 列表集合 /// 列表集合
/// </summary> /// </summary>
public ObservableCollection<ActionLogDto> ListModelDto public ObservableCollection<object> ListModelDto
{ {
get { return _ListModelDto; } get { return _ListModelDto; }
set { _ListModelDto = value; } set { _ListModelDto = value; RaisePropertyChanged(); }
} }
#region #region
@@ -201,32 +202,47 @@ namespace CapMachine.Wpf.ViewModels
{ {
try try
{ {
var MulConQueryable = FreeSql.Select<ActionLog>(); switch (SearchCategory)
//多条件查询
if (!string.IsNullOrEmpty(SearchCategory))
{ {
MulConQueryable = MulConQueryable.Where(t => t.Category == SearchCategory); case "历史报警":
} var MulConHistoryAlarmQueryable = FreeSql.Select<HistoryAlarm>();
//多条件查询
if (!string.IsNullOrEmpty(SearchStartDate))
{
MulConQueryable = MulConQueryable.Where(t => t.CreateTime.Date >= Convert.ToDateTime(SearchStartDate));
}
//多条件查询
if (!string.IsNullOrEmpty(SearchEndDate))
{
MulConQueryable = MulConQueryable.Where(t => t.CreateTime.Date < Convert.ToDateTime(SearchEndDate).AddDays(1));
}
var ListDpI = MulConQueryable.OrderByDescending(a => a.CreateTime).ToList();//.Where(a => a.CreateTime >= DateTime.Now);
ListModelDto.Clear();
//多条件查询
if (!string.IsNullOrEmpty(SearchStartDate))
{
MulConHistoryAlarmQueryable = MulConHistoryAlarmQueryable.Where(t => t.CreateTime.Date >= Convert.ToDateTime(SearchStartDate));
}
//多条件查询
if (!string.IsNullOrEmpty(SearchEndDate))
{
MulConHistoryAlarmQueryable = MulConHistoryAlarmQueryable.Where(t => t.CreateTime.Date < Convert.ToDateTime(SearchEndDate).AddDays(1));
}
var ListHistoryAlarmDpI = MulConHistoryAlarmQueryable.OrderByDescending(a => a.CreateTime).ToList();//.Where(a => a.CreateTime >= DateTime.Now);
foreach (var item in ListDpI) ListModelDto = new ObservableCollection<object>(Mapper.Map<List<HistoryAlarmDto>>(ListHistoryAlarmDpI));
{ break;
ListModelDto.Add(Mapper.Map<ActionLogDto>(item)); case "系统日志":
//ActionLog
var MulConActionLogQueryable = FreeSql.Select<ActionLog>();
//多条件查询
if (!string.IsNullOrEmpty(SearchStartDate))
{
MulConActionLogQueryable = MulConActionLogQueryable.Where(t => t.CreateTime.Date >= Convert.ToDateTime(SearchStartDate));
}
//多条件查询
if (!string.IsNullOrEmpty(SearchEndDate))
{
MulConActionLogQueryable = MulConActionLogQueryable.Where(t => t.CreateTime.Date < Convert.ToDateTime(SearchEndDate).AddDays(1));
}
var ListActionLogDpI = MulConActionLogQueryable.OrderByDescending(a => a.CreateTime).ToList();//.Where(a => a.CreateTime >= DateTime.Now);
ListModelDto = new ObservableCollection<object>(Mapper.Map<List<ActionLogDto>>(ListActionLogDpI));
break;
default:
break;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -26,7 +26,7 @@ namespace CapMachine.Wpf.ViewModels
/// <param name="machineRtDataService"></param> /// <param name="machineRtDataService"></param>
/// <param name="dialogService"></param> /// <param name="dialogService"></param>
public MonitorViewModel(ConfigService configService, IEventAggregator eventAggregator, public MonitorViewModel(ConfigService configService, IEventAggregator eventAggregator,
DataRecordService dataRecordService, SysRunService sysRunService, DataRecordService dataRecordService, SysRunService sysRunService, AlarmService alarmService,
MachineRtDataService machineRtDataService, IDialogService dialogService) MachineRtDataService machineRtDataService, IDialogService dialogService)
{ {
ConfigService = configService; ConfigService = configService;
@@ -34,6 +34,7 @@ namespace CapMachine.Wpf.ViewModels
_EventAggregator = eventAggregator; _EventAggregator = eventAggregator;
DataRecordService = dataRecordService; DataRecordService = dataRecordService;
SysRunServer = sysRunService; SysRunServer = sysRunService;
AlarmService = alarmService;
MachineRtDataService = machineRtDataService; MachineRtDataService = machineRtDataService;
DialogService = dialogService; DialogService = dialogService;
TagManager = MachineRtDataService.TagManger; TagManager = MachineRtDataService.TagManger;
@@ -85,6 +86,7 @@ namespace CapMachine.Wpf.ViewModels
private IEventAggregator _EventAggregator { get; set; } private IEventAggregator _EventAggregator { get; set; }
public DataRecordService DataRecordService { get; } public DataRecordService DataRecordService { get; }
public SysRunService SysRunServer { get; } public SysRunService SysRunServer { get; }
public AlarmService AlarmService { get; }
public MachineRtDataService MachineRtDataService { get; } public MachineRtDataService MachineRtDataService { get; }
public IDialogService DialogService { get; } public IDialogService DialogService { get; }
public List<ChartRtValue> ListChartRtValue { get; set; } = new List<ChartRtValue>() public List<ChartRtValue> ListChartRtValue { get; set; } = new List<ChartRtValue>()

View File

@@ -8,14 +8,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
Width="1920" Width="1920"
Height="980" Height="960"
prism:ViewModelLocator.AutoWireViewModel="True"> prism:ViewModelLocator.AutoWireViewModel="True">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="220" /> <RowDefinition Height="160" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<GroupBox Margin="5,10,5,10" Header="日志查询条件"> <GroupBox Margin="3,5,3,3" Header="日志/历史报警查询">
<StackPanel Margin="0,0,0,0" Orientation="Vertical"> <StackPanel Margin="0,0,0,0" Orientation="Vertical">
<StackPanel.Resources> <StackPanel.Resources>
<Style TargetType="StackPanel"> <Style TargetType="StackPanel">
@@ -35,23 +35,20 @@
</StackPanel.Resources> </StackPanel.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="9*" /> <RowDefinition Height="Auto" />
<RowDefinition Height="3*" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
Grid.Column="0"
Margin="0,0,0,20"
HorizontalAlignment="Center"
Orientation="Horizontal">
<StackPanel <StackPanel
Margin="20" Margin="20,5"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Orientation="Horizontal"> Orientation="Horizontal">
<Label <Label
HorizontalAlignment="Center" HorizontalAlignment="Center"
HorizontalContentAlignment="Center" HorizontalContentAlignment="Center"
Content="分类:" /> Content="分类:"
FontSize="20" />
<DockPanel x:Name="Combbox1"> <DockPanel x:Name="Combbox1">
<StackPanel> <StackPanel>
<!--<ComboBox Width="200" HorizontalAlignment="Left" ItemsSource="{Binding CombboxList}" SelectedItem="{Binding CombboxItem}" DisplayMemberPath="Text" SelectedValuePath="Key" ></ComboBox>--> <!--<ComboBox Width="200" HorizontalAlignment="Left" ItemsSource="{Binding CombboxList}" SelectedItem="{Binding CombboxItem}" DisplayMemberPath="Text" SelectedValuePath="Key" ></ComboBox>-->
@@ -59,18 +56,23 @@
Width="120" Width="120"
materialDesign:HintAssist.Hint="分类" materialDesign:HintAssist.Hint="分类"
DisplayMemberPath="Text" DisplayMemberPath="Text"
FontSize="18"
ItemsSource="{Binding CategoryComboBoxList}" ItemsSource="{Binding CategoryComboBoxList}"
SelectedValue="{Binding SearchCategory}" SelectedValue="{Binding SearchCategory}"
SelectedValuePath="Text" /> SelectedValuePath="Text" />
</StackPanel> </StackPanel>
</DockPanel> </DockPanel>
</StackPanel> </StackPanel>
<StackPanel Margin="20"> <StackPanel Margin="20,5">
<Label HorizontalContentAlignment="Center" Content="创建时间:" /> <Label
HorizontalContentAlignment="Center"
Content="创建时间:"
FontSize="20" />
<DatePicker <DatePicker
Width="120" Width="120"
Margin="0,0,10,0" Margin="0,0,10,0"
materialDesign:HintAssist.Hint="开始时间" materialDesign:HintAssist.Hint="开始时间"
FontSize="16"
Language="zh-CN" Language="zh-CN"
SelectedDate="{Binding SearchStartDate, Mode=TwoWay}" SelectedDate="{Binding SearchStartDate, Mode=TwoWay}"
Style="{StaticResource MaterialDesignFloatingHintDatePicker}" /> Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
@@ -78,78 +80,95 @@
Width="120" Width="120"
Margin="10,0,10,0" Margin="10,0,10,0"
materialDesign:HintAssist.Hint="结束时间" materialDesign:HintAssist.Hint="结束时间"
FontSize="16"
Language="zh-CN" Language="zh-CN"
SelectedDate="{Binding SearchEndDate, Mode=TwoWay}" SelectedDate="{Binding SearchEndDate, Mode=TwoWay}"
Style="{StaticResource MaterialDesignFloatingHintDatePicker}" /> Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<StackPanel <StackPanel Grid.Row="1" Orientation="Horizontal">
Grid.Row="1"
Background=" AliceBlue"
Orientation="Horizontal">
<Button <Button
Width="120"
Height="30"
Margin="10,10,10,10"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Background="Green"
Command="{Binding SearchCmd}" Command="{Binding SearchCmd}"
Content="搜索" Foreground="White">
Foreground="White" /> <StackPanel
<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock
Margin="0,0,5,0"
VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont"
FontSize="18"
Text="&#xe75a;" />
<TextBlock
Margin="0,0,5,0"
VerticalAlignment="Center"
FontSize="18"
Text="搜索" />
</StackPanel>
</Button>
<!--<Button
Width="120" Width="120"
Height="30"
Margin="10,10,10,10" Margin="10,10,10,10"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Background="Orange"
Command="{Binding OutputDataCmd}" Command="{Binding OutputDataCmd}"
Content="导出数据" Content="导出数据"
Foreground="White" /> Foreground="White" />-->
</StackPanel> </StackPanel>
</Grid> </Grid>
</StackPanel> </StackPanel>
</GroupBox> </GroupBox>
<Grid Grid.Row="1" Margin="8"> <Border
<DataGrid Grid.Row="1"
x:Name="dg1" Margin="2"
Grid.ColumnSpan="2" BorderBrush="Gray"
AutoGenerateColumns="False" BorderThickness="1"
IsReadOnly="True" CornerRadius="3">
ItemsSource="{Binding ListModelDto}" <Grid>
SelectionMode="Single" <DataGrid
SelectionUnit="Cell"> x:Name="dg1"
<!--<i:Interaction.Triggers> VerticalAlignment="Stretch"
<i:EventTrigger EventName="SelectionChanged"> AutoGenerateColumns="True"
<i:InvokeCommandAction Command="{Binding SelectedItemsCmd}" CommandParameter="{Binding ElementName=dg1}" /> AutoGeneratingColumn="dg1_AutoGeneratingColumn"
</i:EventTrigger> IsReadOnly="True"
</i:Interaction.Triggers>--> ItemsSource="{Binding ListModelDto}"
<DataGrid.Columns> ScrollViewer.HorizontalScrollBarVisibility="Auto"
SelectionMode="Extended">
<!--<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectedItemsCmd}" CommandParameter="{Binding ElementName=dg1}" />
</i:EventTrigger>
</i:Interaction.Triggers>-->
<!--<DataGrid.Columns>
<DataGridTextColumn <DataGridTextColumn
Width="100" Width="100"
Binding="{Binding Level}" Binding="{Binding Level}"
Header="等级" /> Header="等级" />
<DataGridTextColumn <DataGridTextColumn
Width="200" Width="200"
Binding="{Binding Category}" Binding="{Binding Category}"
Header="分类" /> Header="分类" />
<DataGridTextColumn <DataGridTextColumn
Width="1200" Width="1200"
Binding="{Binding Content}" Binding="{Binding Content}"
Header="内容" /> Header="内容" />
<DataGridTextColumn
Width="180"
Binding="{Binding CreateTime, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"
Header="创建时间" />
</DataGrid.Columns>-->
</DataGrid>
</Grid>
</Border>
<DataGridTextColumn
Width="180"
Binding="{Binding CreateTime, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"
Header="创建时间" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -1,4 +1,5 @@
using System; using Microsoft.VisualBasic;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -24,5 +25,17 @@ namespace CapMachine.Wpf.Views
{ {
InitializeComponent(); InitializeComponent();
} }
private void dg1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (string.IsNullOrEmpty((e.PropertyDescriptor as System.ComponentModel.PropertyDescriptor).Description))
{
e.Column.Visibility = Visibility.Collapsed;
}
else
{
e.Column.Header = (e.PropertyDescriptor as System.ComponentModel.PropertyDescriptor).Description;
}
}
} }
} }

View File

@@ -183,7 +183,7 @@
<Grid> <Grid>
<Grid.Resources> <Grid.Resources>
<Style x:Key="TitelStyle" TargetType="TextBlock"> <Style x:Key="TitelStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="32" /> <Setter Property="FontSize" Value="26" />
<Setter Property="Margin" Value="10,0" /> <Setter Property="Margin" Value="10,0" />
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
</Style> </Style>
@@ -195,6 +195,7 @@
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
@@ -216,12 +217,12 @@
Margin="10,0,0,0" Margin="10,0,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont" FontFamily="/Assets/Fonts/#iconfont"
FontSize="30" FontSize="26"
Text="&#xe9f8;" /> Text="&#xe9f8;" />
<TextBlock Style="{StaticResource TitelStyle}" Text="试验名称:" /> <TextBlock Style="{StaticResource TitelStyle}" Text="试验名称:" />
<TextBlock <TextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="30" FontSize="26"
FontWeight="Bold" FontWeight="Bold"
Text="{Binding ConfigService.CurExpInfo.Name}" /> Text="{Binding ConfigService.CurExpInfo.Name}" />
</StackPanel> </StackPanel>
@@ -239,7 +240,7 @@
Margin="10,0,0,0" Margin="10,0,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont" FontFamily="/Assets/Fonts/#iconfont"
FontSize="30" FontSize="26"
Text="&#xe7b8;" /> Text="&#xe7b8;" />
<TextBlock Style="{StaticResource TitelStyle}" Text="当前进度:" /> <TextBlock Style="{StaticResource TitelStyle}" Text="当前进度:" />
@@ -264,7 +265,7 @@
Margin="10,0,0,0" Margin="10,0,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont" FontFamily="/Assets/Fonts/#iconfont"
FontSize="30" FontSize="26"
Text="&#xe7e7;" /> Text="&#xe7e7;" />
<TextBlock Style="{StaticResource TitelStyle}" Text="总时间:" /> <TextBlock Style="{StaticResource TitelStyle}" Text="总时间:" />
<TextBlock <TextBlock
@@ -288,7 +289,7 @@
Margin="10,0,0,0" Margin="10,0,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont" FontFamily="/Assets/Fonts/#iconfont"
FontSize="30" FontSize="26"
Text="&#xe7f7;" /> Text="&#xe7f7;" />
<TextBlock Style="{StaticResource TitelStyle}" Text="剩余时间:" /> <TextBlock Style="{StaticResource TitelStyle}" Text="剩余时间:" />
<TextBlock <TextBlock
@@ -312,12 +313,12 @@
Margin="10,0,0,0" Margin="10,0,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont" FontFamily="/Assets/Fonts/#iconfont"
FontSize="30" FontSize="26"
Text="&#xe69e;" /> Text="&#xe69e;" />
<TextBlock Style="{StaticResource TitelStyle}" Text="当前步骤:" /> <TextBlock Style="{StaticResource TitelStyle}" Text="当前步骤:" />
<TextBlock <TextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="30" FontSize="26"
FontWeight="Bold" FontWeight="Bold"
Text="0" /> Text="0" />
</StackPanel> </StackPanel>
@@ -476,6 +477,71 @@
</StackPanel> </StackPanel>
</materialDesign:Card> </materialDesign:Card>
<materialDesign:Card
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="6"
Margin="3"
Background="{DynamicResource MaterialDesignLightBackground}"
Foreground="{DynamicResource PrimaryHueLightForegroundBrush}"
UniformCornerRadius="5">
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="10,0,0,0"
VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont"
FontSize="26"
Foreground="OrangeRed"
Text="&#xe636;" />
<TextBlock
Foreground="OrangeRed"
Style="{StaticResource TitelStyle}"
Text="报警:" />
<ItemsControl ItemsSource="{Binding AlarmService.ListAlarmRunCell}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<!-- HandValueParameter="{Binding MVValue}" -->
<DataTemplate>
<Border Margin="3,6" CornerRadius="2">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ActiveState}" Value="True">
<Setter Property="Background" Value="Red" />
</DataTrigger>
<DataTrigger Binding="{Binding ActiveState}" Value="false">
<Setter Property="Background" Value="LightSlateGray" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock
Margin="5,0"
VerticalAlignment="Center"
FontSize="16"
Foreground="WhiteSmoke"
Text="{Binding CurAlarmConfig.Name}"
ToolTip="{Binding CurAlarmConfig.Message}">
<!--<TextBlock.ToolTip>
<StackPanel>
<TextBlock FontWeight="Bold" Text="官方网站" />
<TextBlock Text="点击这个按钮,进入百度首页" />
</StackPanel>
</TextBlock.ToolTip>-->
</TextBlock>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</materialDesign:Card>
</Grid> </Grid>
</materialDesign:Card> </materialDesign:Card>