1 year ago
commit 7a9e59d1b3

@ -41,6 +41,7 @@ namespace Khd.Core.Wcs.Wcs
//createRemoveThread.Name = "CreateRemoveLogic";
//createRemoveThread.Start();
//创建退库任务
var stockReturnThread = new Thread(StockReturnLogic);
stockReturnThread.IsBackground = true;
stockReturnThread.Name = "StockReturnLogic";
@ -135,6 +136,18 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.taskType == "5")
.Where(t => t.auditStatus == "1")
.ToList();
//浅库位退库单往前排序,尽量避免移库操作
if(rawOutStock!= null && rawOutStock.Count > 0)
{
var locationOrder = dbContext.WmsBaseLocation
.Where(t => rawOutStock.Select(x => x.locationCode).Contains(t.locationCode))
.OrderBy(x => x.locDeep == 2 ? 0 : 99)
.Select((loc, index) => new { loc.locationCode, Index = index })
.ToDictionary(item => item.locationCode, item => item.Index);
rawOutStock = rawOutStock.OrderBy(x => locationOrder[x.locationCode]).ToList();
}
foreach (var item in rawOutStock)
{
int taskType = 0;
@ -165,7 +178,7 @@ namespace Khd.Core.Wcs.Wcs
var wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locationCode == item.locationCode).FirstOrDefault();
if (wmsBaseLocation != null)
{
if (!string.IsNullOrEmpty(wmsBaseLocation.containerCode) && wmsBaseLocation.locationStatus == "1")
if (!string.IsNullOrEmpty(wmsBaseLocation.containerCode)) // && wmsBaseLocation.locationStatus == "1"
{
// 目标库位处于深库位,判断是否需要移库浅库位
if (wmsBaseLocation.locDeep == 1)

@ -131,12 +131,24 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.locDeep == 1)
.Select(t => t.containerCode).ToList();//深库位的托盘
containerCodes.RemoveAll(t => string.IsNullOrEmpty(t));
List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock
.Where(t => t.materialId == mesBaseBarcodeInfo.materialId)
.Where(t => t.saleOrderId == mesBaseBarcodeInfo.saleOrderId)
.Where(t => t.palletInfoCode != null)
.Where(t => t.warehouseId == 511)
.Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();
//List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock
// .Where(t => t.materialId == mesBaseBarcodeInfo.materialId)
// .Where(t => t.saleOrderId == mesBaseBarcodeInfo.saleOrderId)
// .Where(t => t.palletInfoCode != null)
// .Where(t => t.warehouseId == 511)
// .Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();
//优先把相同采购订单及批次号的放一块 ==》改为找相同型号及采购订单及批次号的深库位库存
List<WmsRawStock> wmsRawStocks = (from stock in dbContext.WmsRawStock
join codeInfo in dbContext.MesBaseBarcodeInfo
on stock.instockBatch equals codeInfo.barcodeInfo
where codeInfo.batchCode == mesBaseBarcodeInfo.batchCode
&& codeInfo.poNo == mesBaseBarcodeInfo.poNo && stock.materialId == mesBaseBarcodeInfo.materialId && stock.warehouseId == 511
select stock).ToList();
var bill = from a in wmsRawStocks
join b in wmsBaseLocations

@ -830,11 +830,14 @@ namespace Khd.Core.Wcs.Wcs
{
var AgvCardStatus = reponse.data.First(t => t.RobotCode == "2034");
AgvCardStatus.DateNow = DateTime.Now;
AgvCardStatus.AgvName = "5楼叉车";
dbContext.Update(AgvCardStatus);
var BearCardStatus = reponse.data.First(t => t.RobotCode == "6011");
BearCardStatus.AgvName = "5楼背负式";
BearCardStatus.DateNow = DateTime.Now;
dbContext.Update(BearCardStatus);
var CtuCardStatus = reponse.data.First(t => t.RobotCode == "8161");
CtuCardStatus.AgvName = "5楼CTU";
CtuCardStatus.DateNow = DateTime.Now;
dbContext.Update(CtuCardStatus);
dbContext.SaveChanges();
@ -969,6 +972,7 @@ namespace Khd.Core.Wcs.Wcs
{
var cardStatus = reponse.data.First(t => t.RobotCode == "2032");
cardStatus.DateNow = DateTime.Now;
cardStatus.AgvName = "3楼叉车 ";
dbContext.Update(cardStatus);
dbContext.SaveChanges();
var quantityPlc = basePlcs.First(t => t.Name.Contains("电量"));
@ -1033,6 +1037,7 @@ namespace Khd.Core.Wcs.Wcs
{
var cardStatus = reponse.data.First(t => t.RobotCode == "2033");
cardStatus.DateNow = DateTime.Now;
cardStatus.AgvName = "2楼叉车";
dbContext.Update(cardStatus);
dbContext.SaveChanges();
var quantityPlc = basePlcs.First(t => t.Name.Contains("电量"));

@ -9,6 +9,7 @@ using Khd.Core.Wcs.Global;
using Masuit.Tools;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Security.Cryptography;
using Z.EntityFramework.Plus;
namespace Khd.Core.Wcs.Wcs
@ -30,6 +31,8 @@ namespace Khd.Core.Wcs.Wcs
this.LineRFID = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID003");
this.LineSignal = StaticData.BasePlcpointList.First(t => t.plcpointNo == "linesignal03");
}
/// <summary>
/// 启动上件扫描监听
/// </summary>
@ -60,6 +63,7 @@ namespace Khd.Core.Wcs.Wcs
var isSignal = StaticData.PlcDic[0].Read(LineSignal.plcpointAddress);
if (rfid != null && isSignal != null)
{
if (Convert.ToInt32(isSignal) == 1)//托盘到位
{
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 3 && t.equipType == 1);
@ -94,13 +98,46 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => !string.IsNullOrEmpty(t.containerCode))
.Select(t => t.containerCode).ToList();
//相同型号及销售订单的深库位库存
List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock.Where(t => t.materialId == mesBaseBarcodeInfo.materialId)
.Where(t => t.saleOrderId == mesBaseBarcodeInfo.saleOrderId)
.Where(t => DeepContainerCodes.Contains(t.palletInfoCode))
.Where(t => t.warehouseId == 311).ToList();
if (wmsRawStocks.Count > 0)
//#region 弃用:改为优先把相同采购订单及批次号的放一块 优先找同销售订单的有库存的深库位对应的浅库位
////找相同型号及销售订单的深库位库存
//List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock.Where(t => t.materialId == mesBaseBarcodeInfo.materialId)
// .Where(t => t.saleOrderId == mesBaseBarcodeInfo.saleOrderId)
// .Where(t => DeepContainerCodes.Contains(t.palletInfoCode))
// .Where(t => t.warehouseId == 311).ToList();
//if (wmsRawStocks.Count > 0)
//{
// //优先找同销售订单的有库存的深库位对应的浅库位
// foreach (var wmsRawStock in wmsRawStocks)
// {
// // 深库位库存对用的Location信息
// var deepStockLocation = wmsBaseLocations.Where(t => t.containerCode == wmsRawStock.palletInfoCode).First();
// wmsBaseLocation = wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode) && t.locationStatus == "1")
// .Where(t => t.locDeep == 2 && t.locColumn == deepStockLocation.locColumn)
// .Where(t => t.locRow == (deepStockLocation.locRow % 2 == 0 ? (deepStockLocation.locRow - 1) : (deepStockLocation.locRow + 1)))
// .FirstOrDefault();
// if (wmsBaseLocation != null)
// {
// break;
// }
// }
//}
//#endregion
#region 优先找同采购订单及批次号的有库存的深库位对应的浅库位
//找相同型号及采购订单及批次号的深库位库存
List<WmsRawStock> wmsRawStocks = (from stock in dbContext.WmsRawStock
join codeInfo in dbContext.MesBaseBarcodeInfo
on stock.instockBatch equals codeInfo.barcodeInfo
where codeInfo.batchCode == mesBaseBarcodeInfo.batchCode
&& codeInfo.poNo== mesBaseBarcodeInfo.poNo && stock.materialId == mesBaseBarcodeInfo.materialId && stock.warehouseId == 311
select stock).ToList();
if (wmsRawStocks!=null && wmsRawStocks.Count > 0)
{
//优先找同销售订单的有库存的深库位对应的浅库位
foreach (var wmsRawStock in wmsRawStocks)
@ -117,22 +154,12 @@ namespace Khd.Core.Wcs.Wcs
}
}
}
//if (wmsBaseLocation == null)
//{
// // 找深库位有库存的库位对应的浅库位
// var stockLocations = wmsBaseLocations.Where(x => !string.IsNullOrEmpty(x.containerCode) && x.locDeep == 1).ToList();
// foreach (var item in stockLocations)
// {
// wmsBaseLocation = wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode) && t.locationStatus == "1")
// .Where(t => t.locDeep == 2 && t.locColumn == item.locColumn)
// .Where(t => t.locRow == (item.locRow % 2 == 0 ? (item.locRow - 1) : (item.locRow + 1)))
// .FirstOrDefault();
// if (wmsBaseLocation != null)
// {
// break;
// }
// }
//}
#endregion
if (wmsBaseLocation == null)
{ // 在所有符合条件的库位里,找一个库位,优先深库位,但是如果是深库位,需要判断浅库位状态是否正常
var searchLocations = wmsBaseLocations.Where(x => string.IsNullOrEmpty(x.containerCode) && x.locationStatus == "1").OrderBy(x => x.locDeep).ToList();

@ -513,6 +513,17 @@
</ControlTemplate>
</Button.Template>
</Button>
<Button Content="任务历史" FontSize="25" Foreground="White" Margin="60 0 0 0 " Height="50" Width="132" Click="btnTaskHistory_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
<Border.Background>YellowGreen</Border.Background>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" ></ContentPresenter>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
<!--<Button Content="手动完成" Margin="800,-8,0,-100" Foreground="White" Height="50" Width="132" Click="btnFinishTask_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
@ -1313,7 +1324,7 @@
</Grid>
</TabItem>
<TabItem Header="库位状态" Style="{StaticResource DefaultItem}" FontSize="25" HorizontalContentAlignment="Center" Background="#213269" VerticalContentAlignment="Center" Foreground="White" Width="160" Height="80" Margin="5">
<Grid>
<Grid Margin="0 10 10 0" Height="1080" Width="1680">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>

@ -1819,6 +1819,31 @@ namespace Khd.Core.Wpf.Form
}
}
/// <summary>
/// 打开任务历史记录界面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnTaskHistory_Click(object sender, RoutedEventArgs e)
{
try
{
TaskHistoryWindow taskHistoryWindow = new TaskHistoryWindow(_host);
taskHistoryWindow.ShowDialog();
}
catch (Exception ex)
{
HandyControl.Controls.MessageBox.Error(ex.Message);
}
}
/// <summary>
/// 单选
/// </summary>

@ -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" />

@ -0,0 +1,307 @@
<Window x:Class="Khd.Core.Wpf.WindowPage.TaskHistoryWindow"
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: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">
<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="200*"
Binding="{Binding serialNo}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="流水号"
IsReadOnly="True" Visibility="Hidden" />
<DataGridTextColumn
Width="250*"
Binding="{Binding equipmentNo}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="设备编号"
IsReadOnly="True" Visibility="Hidden"/>
<DataGridTextColumn
Width="300*"
Binding="{Binding containerNo}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="容器号"
IsReadOnly="True" />
<DataGridTextColumn
Width="300*"
Binding="{Binding taskType,Converter={StaticResource taskTypeConverter}}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="任务类型"
IsReadOnly="True" />
<DataGridTextColumn
Width="300*"
Binding="{Binding ., Converter={StaticResource AgvTaskStatusConverter}}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="任务状态"
IsReadOnly="True" />
<DataGridTextColumn
Width="180*"
Binding="{Binding qty}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="数量"
IsReadOnly="True" Visibility="Hidden"/>
<DataGridTextColumn
Width="300*"
Binding="{Binding currPointNo,Converter={StaticResource EquipConverter}}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="起始站点"
IsReadOnly="True"/>
<DataGridTextColumn
Width="300*"
Binding="{Binding endPointNo,Converter={StaticResource EquipConverter}}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="目的站点"
IsReadOnly="True" />
<DataGridTextColumn
Width="230*"
Binding="{Binding fromFloorNo}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="起始楼层"
IsReadOnly="True" />
<DataGridTextColumn
Width="230*"
Binding="{Binding floorNo}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="目的楼层"
IsReadOnly="True" />
<DataGridTextColumn
Width="350*"
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,89 @@
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;
using Khd.Core.Wpf.dto;
namespace Khd.Core.Wpf.WindowPage
{
/// <summary>
/// TaskHistoryWindow.xaml 的交互逻辑
/// </summary>
public partial class TaskHistoryWindow : Window
{
private IHost _host;
public TaskHistoryWindow(IHost host)
{
_host = host;
InitializeComponent();
Task.Run(async() =>
{
await GetTask(DateTime.Now.AddDays(-3), DateTime.Now.AddDays(3));
});
}
/// <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;
}
private async Task GetTask(DateTime startTime,DateTime endTime)
{
try
{
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