add-添加提升机相关报警记录及WPF界面查询

master
liuwf 1 year ago
parent cad78852b4
commit cd4b11d01d

@ -6,7 +6,7 @@ namespace Khd.Core.Domain.Models
{
[Table("dms_record_alarm_info")]
public class DmsRecordAlarmInfo
{
{
[Key]
[Column("alarm_id")]
public long AlarmId { get; set; }

@ -426,8 +426,8 @@ namespace Khd.Core.Wcs.Wcs
}
else
{
//TODO 物料未绑定仓库,添加报警
SystemData.InsertWaringLog(dbContext, WaringType.);
SystemData.InsertWaringLog(dbContext, WaringType., "一楼接驳位物料未绑定仓库信息");
continue;
}
}
@ -840,7 +840,7 @@ namespace Khd.Core.Wcs.Wcs
}
else
{
SystemData.InsertWaringLog(dbContext, WaringType., ex.Message);
SystemData.InsertWaringLog(dbContext, WaringType., "提升机任务下发异常"+ex.Message);
_logger.Error(ex.Message + "\n" + ex.StackTrace);
}
}

@ -3377,6 +3377,7 @@ IsReadOnly="True">
<Button Content="打开键盘" Background="#346DFF" Foreground="White" Width="150" Height="75" FontSize="25" Click="Button_Click"/>
<Button Content="最小化" Background="#346DFF" Foreground="White" Width="100" Margin="20,0,0,0" Height="75" FontSize="25" Click="WindowHidden_Click"/>
<Button Content="退出" Background="#346DFF" Foreground="White" Width="100" Margin="20,0,0,0" Height="75" FontSize="25" Click="WindowClose_Click"/>
<Button Content="提升机报警记录" x:Name="HoistWarnInfoButton" Background="#346DFF" Foreground="White" Width="200" Margin="20,0,0,0" Height="75" FontSize="25" Click="HoistWarnInfoButton_Click" />
</StackPanel>
</StackPanel>
</Grid>

@ -5868,6 +5868,12 @@ namespace Khd.Core.Wpf.Form
}
GetInvertoryData();
}
private void HoistWarnInfoButton_Click(object sender, RoutedEventArgs e)
{
HoistWarnInfoWindow window = new HoistWarnInfoWindow(_host);
window.ShowDialog();
}
}
}

@ -0,0 +1,243 @@
<Window x:Class="Khd.Core.Wpf.WindowPage.HoistWarnInfoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:Khd.Core.Wpf.WindowPage"
xmlns:localConverter="clr-namespace:Khd.Core.Wpf.myConverter"
mc:Ignorable="d"
Title="提升机报警记录" Height="1080" Width="1880" WindowStartupLocation="CenterScreen" Background="#172557">
<Window.Resources>
<ResourceDictionary>
<!-- 定义样式 -->
<Style x:Key="CustomDatePicker" TargetType="DatePicker">
<!-- 设置背景颜色 -->
<Setter Property="Background" Value="LightBlue"></Setter>
<!-- 设置边框颜色 -->
<Setter Property="BorderBrush" Value="DarkBlue"></Setter>
<!-- 设置字体样式 -->
<Setter Property="FontSize" Value="20"></Setter>
<!-- 设置前景色(文本颜色) -->
<Setter Property="Foreground" Value="Black"></Setter>
</Style>
<!-- 定义日历的样式 -->
<Style x:Key="CustomCalendarStyle" TargetType="Calendar">
<!-- 设置背景颜色 -->
<Setter Property="Background" Value="White"></Setter>
<!-- 设置边框颜色 -->
<Setter Property="BorderBrush" Value="Blue"></Setter>
<Setter Property="Width" Value="350"></Setter>
<Setter Property="Height" Value="250"></Setter>
<!-- 设置字体样式 -->
<Setter Property="FontSize" Value="16"></Setter>
</Style>
<Style x:Key="XingHaoBianMaYangShi" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border BorderThickness="1" BorderBrush="Gray" CornerRadius="8" Background="{TemplateBinding Background}">
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" BorderThickness="0" IsTabStop="False"></ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Left"></Setter>
</Style>
<localConverter:TypeDataConverter x:Key="taskTypeConverter"/>
<localConverter:EquipConverter x:Key="EquipConverter"/>
<localConverter:AgvTaskStatusConverter x:Key="AgvTaskStatusConverter"/>
<Style x:Key="dgCell" TargetType="TextBlock" BasedOn="{x:Null}">
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<ResourceDictionary.MergedDictionaries>
<!--<hc:ThemeResources/>
<hc:Theme/>-->
<ResourceDictionary Source="/CSS/SearchBtnClass.xaml" />
<ResourceDictionary Source="/CSS/SearchTextClass.xaml" />
<ResourceDictionary Source="/CSS/DataGridClass.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="10*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<WrapPanel HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="开始时间" Margin="10 0" Foreground="White" FontSize="20" VerticalAlignment="Center"/>
<DatePicker Style="{StaticResource CustomDatePicker}" CalendarStyle="{StaticResource CustomCalendarStyle}"
x:Name="BeginTime" FontSize="20"
Width="170" Margin="10 0" BorderBrush="White"
materialDesign:CalendarAssist.IsHeaderVisible="False">
<!--<DatePicker.SelectedDate >
<Binding
Path="BeginDate"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
</Binding.ValidationRules>
</Binding>
</DatePicker.SelectedDate>-->
</DatePicker>
<TextBlock Text="结束时间" Margin="10 0" Foreground="White" FontSize="20" VerticalAlignment="Center"/>
<DatePicker Style="{StaticResource CustomDatePicker}"
x:Name="EndTime" Margin="10 0"
Width="170" BorderBrush="White" FontSize="20"
materialDesign:CalendarAssist.IsHeaderVisible="False"
CalendarStyle="{StaticResource CustomCalendarStyle}">
<!-- 添加这一行 -->
<!--<DatePicker.SelectedDate>
<Binding
Path="EndDate"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
</Binding.ValidationRules>
</Binding>
</DatePicker.SelectedDate>-->
</DatePicker>
<Button Margin="10 0"
Content="时间查询" x:Name="SelectByTime"
Background="LimeGreen" Width="100" Height="40" FontSize="20" Click="SelectByTime_Click">
</Button>
</WrapPanel>
</Grid>
<Grid Grid.Row="1">
<Grid Margin="0,5,0,0" HorizontalAlignment="Left">
<Grid Background="#172557" Grid.Row="1" ></Grid>
<Grid Grid.Row="2">
<DataGrid
x:Name="LoadMaterial0"
AlternationCount="2"
AutoGenerateColumns="False"
Background="#172557"
CanUserAddRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
Focusable="False"
HeadersVisibility="Column"
IsReadOnly="True"
LoadingRow="dgData_LoadingRow"
RowHeaderWidth="0"
SelectionMode="Single" FontSize="16" HorizontalAlignment="Left" >
<DataGrid.Columns>
<DataGridTemplateColumn
x:Name="orderControlData0"
Width="100"
MinWidth="10"
Header=" 序号"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Focusable="False"
FontSize="20"
Text="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}, Mode=FindAncestor}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn
Width="400*"
Binding="{Binding AlarmData}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="报警信息"
IsReadOnly="True" />
<DataGridTextColumn
Width="250*"
Binding="{Binding HandleSuggest}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="处理建议"
IsReadOnly="True" />
<DataGridTextColumn
Width="140*"
Binding="{Binding CreateTime,StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="报警时间"
IsReadOnly="True" />
</DataGrid.Columns>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="#213269" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="50" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Background" Value="#213269" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="50" />
</Style>
</DataGrid.RowStyle>
<DataGrid.RowHeaderStyle>
<Style TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Background" Value="#213269" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="50" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="#172560" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="50" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="BorderThickness" Value="5" />
<Setter Property="BorderBrush" Value="#172540" />
<Setter Property="FontSize" Value="30" />
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
</Grid>
</Grid>
</Grid>
</Grid>
</Window>

@ -0,0 +1,111 @@
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Khd.Core.Library.Mapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Khd.Core.Wpf.WindowPage
{
/// <summary>
/// HoistWarnInfoWindow.xaml 的交互逻辑
/// </summary>
public partial class HoistWarnInfoWindow : Window
{
private IHost _host;
public HoistWarnInfoWindow(IHost host)
{
_host = host;
InitializeComponent();
Task.Run(async () =>
{
await InitList();
});
}
/// <summary>
/// 显示序号事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgData_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
}
/// <summary>
/// 初始加载500条数据
/// </summary>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
private async Task InitList()
{
try
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
List<DmsRecordAlarmInfo> list = await dbContext.DmsRecordAlarmInfo.Where(x => x.DeviceId == 6 ).OrderByDescending(x => x.CreateTime).Take(500).ToListAsync();
Dispatcher.Invoke(() =>
{
this.LoadMaterial0.ItemsSource = null;
this.LoadMaterial0.ItemsSource = list;
this.LoadMaterial0.Items.Refresh();
});
}
catch (Exception ex)
{
MessageBox.Show($"查询报警出现异常,请重新尝试:{ex.Message}");
}
}
private async Task GetHistory(DateTime startTime, DateTime endTime)
{
try
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
List< DmsRecordAlarmInfo > list = await dbContext.DmsRecordAlarmInfo.Where(x => x.DeviceId ==6 && x.CreateTime>= startTime && x.CreateTime <= endTime).OrderByDescending(x => x.CreateTime).ToListAsync();
Dispatcher.Invoke(() =>
{
this.LoadMaterial0.ItemsSource = null;
this.LoadMaterial0.ItemsSource = list;
this.LoadMaterial0.Items.Refresh();
});
}
catch (Exception ex)
{
MessageBox.Show($"查询报警出现异常,请重新尝试:{ex.Message}");
}
}
private async void SelectByTime_Click(object sender, RoutedEventArgs e)
{
DateTime? begin = this.BeginTime.SelectedDate;
DateTime? end = this.EndTime.SelectedDate;
if (begin == null || end == null)
{
MessageBox.Show($"请选择开始或者结束时间");
return;
}
await GetHistory(begin.Value, end.Value);
}
}
}
Loading…
Cancel
Save