add-添加可视化库位界面

master
liuwf 1 year ago
parent 9ed019e039
commit bac382ce78

@ -15,7 +15,12 @@
Height="1080"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--<hc:ThemeResources/>
<hc:Theme/>-->
@ -362,6 +367,36 @@
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="FontSize" Value="14"></Setter>
</Style>
<DataTemplate x:Key="LocationTemplate">
<Button Content="{Binding}" Click="LocationButton_Click" Height="150" Margin="0 0 5 10">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="#75F76D"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="OutOfStock">
<Setter Property="Background" Value="#4789AE"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Code}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="20"
RenderTransformOrigin="0.5, 0.5">
<TextBlock.RenderTransform>
<RotateTransform Angle="90"/>
</TextBlock.RenderTransform>
</TextBlock>
</DataTemplate>
</Button.ContentTemplate>
</Button>
</DataTemplate>
</ResourceDictionary>
</Window.Resources>
@ -1203,6 +1238,39 @@
</Grid>
</StackPanel>
</TabItem>
<TabItem x:Name="LocationManager11" Header="库位状态" Background="#213269"
Style="{StaticResource DefaultItem}" Foreground="White"
FontSize="25" Width="160" Height="100" VerticalAlignment="Top" HorizontalAlignment="Center">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="9*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="仓库位置:" FontSize="25" VerticalAlignment="Center" Foreground="White" />
<ComboBox x:Name="QueryPositionCombox" Height="50" Width="150" FontSize="25" SelectionChanged="QueryPositionCombox_SelectionChanged">
<ComboBoxItem Content="南侧" Tag="1" />
<ComboBoxItem Content="北侧" Tag="2" />
</ComboBox>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<ItemsControl x:Name="LocationsControl" ItemTemplate="{StaticResource LocationTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="36" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Grid>
</Grid>
</TabItem>
<!--<TabItem Header="指令管理" Foreground="White" FontSize="25" Width="160" Height="100" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5" >
<StackPanel
x:Name="UpperStart"

@ -10,6 +10,7 @@ using Khd.Core.Plc.S7;
using Khd.Core.Wpf.dto;
using Khd.Core.Wpf.Scan;
using Khd.Core.Wpf.TaskForm;
using Khd.Core.Wpf.WindowPage;
using Masuit.Tools;
using Masuit.Tools.Logging;
using Microsoft.EntityFrameworkCore;
@ -119,7 +120,7 @@ namespace Khd.Core.Wpf.Form
/// <param name="e"></param>
private void FormBoard_Loaded(object sender, RoutedEventArgs e)
{
InitializeData(1);
try
{
@ -294,6 +295,82 @@ namespace Khd.Core.Wpf.Form
}
}
#region 库位状态可视化
private void InitializeData(int rowPosition)
{
try
{
LocationsControl.ItemsSource = null;
using var scope = _host.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
// 该侧所有库位
var allLocationLists = dbContext.WmsBaseLocation.Where(x => x.warehouseId == 512 && x.locRow == rowPosition).ToList();
allLocationLists = allLocationLists.OrderBy(x => x.layerNum).ThenBy(x => x.locColumn).ToList();
//在库里的库位
var inLocationList = allLocationLists.Where(x => x.ContainerStatus == "1").Select(x => x.locationCode).ToList();
//在库里有库存的库位
var withStockLocationList = dbContext.WmsRawStock.Where(x => x.warehouseId == 512 && inLocationList.Contains(x.locationCode)).Select(x => x.locationCode).Distinct().ToList();
var locations = new List<Location>();
for (int i = 0; i < 6 * 36; i++)
{
LocationStatus status = LocationStatus.OutOfStock;
WmsBaseLocation targetLocation = allLocationLists[i];
if (withStockLocationList.Contains(targetLocation.locationCode))
{
status = LocationStatus.InAndStock;
}
//Location item = new Location();
//item.Code = "";
//item.LocationId = targetLocation.locationId;
//item.Status = status;
//if (i < 36)
//{
// item.Code = targetLocation.locColumn.ToString();
//}
//locations.Add(item);
locations.Add(new Location { LocationId = targetLocation.locationId, Code = targetLocation.locColumn.ToString(), Status = status });
}
LocationsControl.ItemsSource = locations;
}catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void LocationButton_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
if (button != null)
{
var location = button.DataContext as Location;
if (location != null)
{
StockWindow window = new StockWindow(_host,location.LocationId);
window.Show();
// MessageBox.Show(location.LocationId.ToString());
}
}
}
private void QueryPositionCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 获取选中的 ComboBoxItem
ComboBox comboBox = sender as ComboBox;
ComboBoxItem selectedItem = comboBox.SelectedItem as ComboBoxItem;
if (selectedItem != null)
{
// 获取选中项的内容和 Tag
string content = selectedItem.Content.ToString();
object tag = selectedItem.Tag;
InitializeData(int.Parse(tag.ToString()));
}
}
#endregion
private void ReturnOrderTimer(object? obj)
{

@ -0,0 +1,167 @@
<Window x:Class="Khd.Core.Wpf.WindowPage.StockWindow"
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"
mc:Ignorable="d"
Title="查看库存" Height="600" Width="1500" WindowStartupLocation="CenterScreen" Background="#172557">
<Window.Resources>
<ResourceDictionary>
<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="8*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal">
<TextBox x:Name="positionRowTxt" FontSize="25" Margin="0 0 10 0" Width="100"/>
<TextBlock Text="行" Foreground="White" FontSize="25" Margin="0 0 25 0"/>
<TextBox x:Name="positionColumnTxt" FontSize="25" Margin="0 0 10 0" Width="100"/>
<TextBlock Text="列" Foreground="White" FontSize="25" Margin="0 0 25 0"/>
<TextBox x:Name="positionLayerTxt" FontSize="25" Margin="0 0 10 0" Width="80"/>
<TextBlock Text="层" Foreground="White" FontSize="25" Margin="0 0 150 0"/>
<TextBlock Text="库位编号:" Foreground="White" FontSize="25" Margin="0 0 8 0"/>
<TextBlock x:Name="locationTxt" Foreground="White" FontSize="25" Margin="0 0 58 0" Width="250"/>
<TextBlock Text="托盘编号:" Foreground="White" FontSize="25" Margin="0 0 8 0"/>
<TextBlock x:Name="palletTxt" Foreground="White" FontSize="25"/>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<DataGrid
Style="{StaticResource DataGridStyle}"
Grid.Row="2" AlternationCount="2"
AutoGenerateColumns="False"
MinRowHeight="50"
Background="#172557"
CanUserAddRows="False"
GridLinesVisibility="None"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
Focusable="False"
Height="auto"
HeadersVisibility="Column"
IsReadOnly="True"
RowHeaderWidth="0"
SelectionMode="Single" FontSize="16"
Visibility="Visible"
VerticalAlignment="Top"
x:Name="StockDataGrid">
<DataGrid.Columns>
<DataGridTextColumn
Width="200*"
Binding="{Binding materialCode}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="物料编码"
IsReadOnly="True" />
<DataGridTemplateColumn
Width="280*"
CanUserSort="False"
Header="物料名称"
IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding materialName}" ToolTip="{Binding materialNameSrc}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Width="300*"
CanUserSort="False"
Header="物料规格"
IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding materialSpec}" ToolTip="{Binding materialSpecSrc}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Width="130*"
CanUserSort="False"
Header="总数"
IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding totalAmount}" ToolTip="{Binding totalAmount}" Height="auto" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Width="130*"
CanUserSort="False"
Header="冻结数量"
IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="WrapWithOverflow" Text="{Binding frozenAmount}" Height="auto" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="#213269" />
<Setter Property="Foreground" Value="White" />
<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" />
</Style>
</DataGrid.RowStyle>
<DataGrid.RowHeaderStyle>
<Style TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Background" Value="#213269" />
<Setter Property="Foreground" Value="White" />
<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="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>
</Window>

@ -0,0 +1,75 @@
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Microsoft.EntityFrameworkCore;
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>
/// StockWindow.xaml 的交互逻辑
/// </summary>
public partial class StockWindow : Window
{
private IHost host = null;
public StockWindow(IHost _host,long locationId)
{
host = _host;
InitializeComponent();
Init(locationId);
}
public async Task Init(long locationId)
{
using var scope = host.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var location = await dbContext.WmsBaseLocation.Where(x => x.locationId == locationId).FirstOrDefaultAsync();
positionRowTxt.Text = location.locRow.ToString();
positionColumnTxt.Text = location.locColumn.ToString();
positionLayerTxt.Text = location.layerNum.ToString();
locationTxt.Text = location.locationCode;
palletTxt.Text = location.containerCode;
var stockList = await dbContext.WmsRawStock.Where(x => x.palletInfoCode == location.containerCode).ToListAsync();
if(stockList != null && stockList.Count > 0)
{
// 获取所有库存物料 ID
var materialIds = stockList.Select(stock => stock.materialId).Distinct().ToList();
var materialInfos = await dbContext.MesBaseMaterialInfo
.Where(material => materialIds.Contains(material.MaterialId))
.ToListAsync();
// 将库存物料信息和物料详细信息合并
var stockDetails = from stock in stockList
from material in materialInfos
where stock.materialId == material.MaterialId
select new
{
materialCode = material.MaterialCode,
materialName = material.MaterialName,
materialSpec = material.MaterialSpec,
totalAmount = stock.totalAmount,
frozenAmount = stock.frozenAmount
};
StockDataGrid.ItemsSource = stockDetails;
}
}
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Khd.Core.Wpf.dto
{
public class Location
{
public long LocationId { get; set; } // 新增 LocationId
public string Code { get; set; }
public LocationStatus Status { get; set; }
}
public enum LocationStatus
{
// 在库有库存
InAndStock,
//// 在库无库存
//InNoStock,
//库外
OutOfStock,
}
}
Loading…
Cancel
Save