add-任务历史记录添加时间范围查询

master
liuwf 1 year ago
parent c119f7fcc5
commit 0378b6a9b1

@ -142,6 +142,7 @@
<PackageReference Include="HandyControl" Version="3.5.0" />
<PackageReference Include="HandyControls" Version="3.5.0" />
<PackageReference Include="Masuit.Tools.Core" Version="2.6.7.5" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.32.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.3" />

@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Khd.Core.Wpf.WindowPage"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:localConverter="clr-namespace:Khd.Core.Wpf.myConverter"
mc:Ignorable="d"
Title="任务历史记录" Height="1080" Width="1880" WindowStartupLocation="CenterScreen" Background="#172557">
@ -12,6 +13,35 @@
<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">
@ -55,11 +85,48 @@
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<StackPanel Orientation="Horizontal" Margin="10">
</StackPanel>
<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">

@ -25,12 +25,14 @@ namespace Khd.Core.Wpf.WindowPage
public partial class TaskHistoryWindow : Window
{
private IHost _host;
public TaskHistoryWindow(IHost host)
public TaskHistoryWindow(IHost host)
{
_host = host;
InitializeComponent();
GetTask();
Task.Run(async() =>
{
await GetTask(DateTime.Now.AddDays(-3), DateTime.Now.AddDays(3));
});
}
@ -47,36 +49,41 @@ namespace Khd.Core.Wpf.WindowPage
private void GetTask()
private async Task GetTask(DateTime startTime,DateTime endTime)
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
Dispatcher.Invoke(() =>
try
{
long? nextPointId = 0;
var data = dbContext.WcsTaskLog.ToList();
List<taskModel> taskModel = CoreMapper.Map<List<taskModel>>(data);
//foreach (var item in taskModel)
//{
// SelectedItem.Add(item.objid, false);
// if (item.nextPointId == 6)
// {
// item.isShow = Visibility.Visible;
// }
// else
// {
// item.isShow = Visibility.Collapsed;
// }
//}
this.LoadMaterial0.ItemsSource = null;
this.LoadMaterial0.ItemsSource = taskModel;
this.LoadMaterial0.Items.Refresh();
});
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var data = await dbContext.WcsTaskLog.Where(x => x.createTime >= startTime && x.createTime <= endTime).OrderByDescending(x => x.createTime).ToListAsync();
Dispatcher.Invoke(() =>
{
long? nextPointId = 0;
List<taskModel> taskModel = CoreMapper.Map<List<taskModel>>(data);
this.LoadMaterial0.ItemsSource = null;
this.LoadMaterial0.ItemsSource = taskModel;
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 GetTask(begin.Value, end.Value);
}
}
}

Loading…
Cancel
Save