change-提交盘库修改

master
liuwf 1 year ago
parent cde5e5dd0e
commit 29e1a311be

@ -3029,6 +3029,7 @@ namespace Khd.Core.Wpf.Form
MaterialId = rawItem.materialId,
ErpStatus = "0",
ErpAmount = 0,
CheckType ="1"
});
}
}
@ -3629,6 +3630,25 @@ namespace Khd.Core.Wpf.Form
SystemData.PlcDic[1].WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
MsgText.Text = "一键收料发送成功";
HandyControl.Controls.MessageBox.Show("一键收料发送成功!");
// 修改所有盘库明细任务状态
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
List<WmsInventoryCheckDetail> list = dbContext.WmsInventoryCheckDetail.Where(t => t.CheckStatus=="1").ToList();
if (list != null)
{
list.ForEach(t => t.CheckStatus = "2");
dbContext.UpdateRange(list);
}
WmsInventoryCheck wmsInventoryCheck = dbContext.WmsInventoryCheck.FirstOrDefault(t => t.CheckStatus == "1");
if(wmsInventoryCheck != null)
{
wmsInventoryCheck.InventoriedAmount = dbContext.WmsInventoryCheckDetail.Where(t => t.InventoryCheckId == wmsInventoryCheck.InventoryCheckId).ToList().Count();
wmsInventoryCheck.InventoryingAmount = 0;
dbContext.SaveChanges();
}
}
catch (Exception ex)
{

@ -42,13 +42,14 @@
<DataGrid
Style="{StaticResource DataGridStyle}"
Grid.Row="1"
x:Name="InventoryDataGrid"
AlternationCount="2"
AutoGenerateColumns="False"
MinRowHeight="50"
Background="Transparent"
CanUserAddRows="False"
GridLinesVisibility="None"
CanUserReorderColumns="False"
@ -56,7 +57,7 @@
CanUserResizeRows="False"
Focusable="False"
HeadersVisibility="Column"
IsReadOnly="False"
VerticalAlignment="Stretch"
RowHeaderWidth="0"
SelectionMode="Single" FontSize="16"
@ -80,10 +81,22 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="库存数量" Binding="{Binding StockAmount}" ElementStyle="{StaticResource dgCell}" Width="110*"/>
<DataGridTextColumn Header="实际数量" Binding="{Binding RealAmount}" IsReadOnly="False" ElementStyle="{StaticResource dgCell}" Width="110*"/>
<!--<DataGridTemplateColumn Header="实际数量" Width="110*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding RealAmount}"
HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="16" Foreground="White" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox IsReadOnly="False" Text="{Binding RealAmount}"
HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="16" Foreground="Black" Background="White" BorderThickness="1" BorderBrush="#2196F3"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>-->
<DataGridTemplateColumn Header="操作" Width="100*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>

@ -31,6 +31,7 @@ namespace Khd.Core.Wpf.TaskForm
Thread scanThread = new Thread(ScanMessage);
scanThread.IsBackground = true;
scanThread.Start();
UpdateAmountWindow.RefreshDelegateEvent += GetData;
}
@ -122,19 +123,34 @@ namespace Khd.Core.Wpf.TaskForm
.ToList();
List<long?> list = wmsInventoryCheckDetails.Select(t => t.MaterialId).Distinct().ToList();
List<MesBaseMaterialInfo> mesBaseMaterialInfos = dbContext.MesBaseMaterialInfo.Where(t => list.Contains(t.MaterialId)).ToList();
this.InventoryDataGrid.ItemsSource = wmsInventoryCheckDetails.GroupBy(t => t.MaterialId).Select(t =>
new
{
//ContainerNo = wcsTask.containerNo,
MaterialBatch = t.FirstOrDefault(n => n.MaterialId == t.Key)?.MaterialBatch,
MaterialSpec = mesBaseMaterialInfos.FirstOrDefault(m => m.MaterialId == t.Key)?.MaterialSpec,
MaterialName = mesBaseMaterialInfos.FirstOrDefault(m => m.MaterialId == t.Key)?.MaterialName,
StockAmount = t.Sum(n => n.StockAmount),
LocationCode = wcsTask.currPointNo,
MaterialId = t.Key,
RealAmount = (t.Sum(n => n.RealAmount)).ToString(),
});
this.InventoryDataGrid.Items.Refresh();
//this.InventoryDataGrid.ItemsSource = wmsInventoryCheckDetails.GroupBy(t => t.MaterialId).Select(t =>
// new
// {
// //ContainerNo = wcsTask.containerNo,
// MaterialBatch = t.FirstOrDefault(n => n.MaterialId == t.Key)?.MaterialBatch,
// MaterialSpec = mesBaseMaterialInfos.FirstOrDefault(m => m.MaterialId == t.Key)?.MaterialSpec,
// MaterialName = mesBaseMaterialInfos.FirstOrDefault(m => m.MaterialId == t.Key)?.MaterialName,
// StockAmount = t.Sum(n => n.StockAmount),
// LocationCode = wcsTask.currPointNo,
// MaterialId = t.Key,
// //RealAmount = (t.Sum(n => n.RealAmount)).ToString(),
// });
this.InventoryDataGrid.ItemsSource = wmsInventoryCheckDetails.Select(t =>
new
{
//ContainerNo = wcsTask.containerNo,
MaterialBatch = t.MaterialBatch,
MaterialSpec = mesBaseMaterialInfos.FirstOrDefault(m => m.MaterialId == t.MaterialId)?.MaterialSpec,
MaterialName = mesBaseMaterialInfos.FirstOrDefault(m => m.MaterialId == t.MaterialId)?.MaterialName,
StockAmount = t.StockAmount,
LocationCode = wcsTask.currPointNo,
MaterialId = t.MaterialId,
//RealAmount = (t.Sum(n => n.RealAmount)).ToString(),
});
this.InventoryDataGrid.Items.Refresh();
if (wmsInventoryCheckDetails.Count == 0)
{
HandyControl.Controls.MessageBox.Show("该料箱为空料箱");
@ -155,32 +171,19 @@ namespace Khd.Core.Wpf.TaskForm
private void EditBtn_Click(object sender, RoutedEventArgs e)
{
//if (this.InventoryDataGrid.SelectedItem != null)
//{
// dynamic item = this.InventoryDataGrid.SelectedItem;
// long materialId = item.MaterialId;
// string containerNo = item.ContainerNo;
// string materialName = item.MaterialName;
// string locationCode = item.LocationCode;
// InventoryTaskEditForm editForm = new InventoryTaskEditForm(_host, materialId, containerNo, materialName, locationCode, this);
// this.Hide();
// editForm.ShowDialog();
// GetData();
//}
//else
//{
// if (this.ContainerCodeBox.SelectedItem is WcsTask task)
// {
// InventoryTaskEditForm editForm = new InventoryTaskEditForm(_host, 0, task.containerNo, "", task.currPointNo, this);
// this.Hide();
// editForm.ShowDialog();
// GetData();
// }
// else
// {
// HandyControl.Controls.MessageBox.Show("请先选择料箱号!");
// }
//}
//if (!string.IsNullOrEmpty(txtInBox.Text))
//{
// InventoryTaskEditForm editForm = new InventoryTaskEditForm(_host, 0, txtInBox.Text, "", task.currPointNo, this);
// this.Hide();
// editForm.ShowDialog();
// GetData();
//}
//else
//{
// HandyControl.Controls.MessageBox.Show("请先选择料箱号!");
//}
}
private void Update_Click(object sender, RoutedEventArgs e)
@ -188,15 +191,15 @@ namespace Khd.Core.Wpf.TaskForm
if (this.InventoryDataGrid.SelectedItem != null)
{
dynamic item = this.InventoryDataGrid.SelectedItem;
UpdateStockAmount updateStockAmount = new UpdateStockAmount(_host, item.MaterialBatch);
UpdateAmountWindow updateStockAmount = new UpdateAmountWindow(_host, item.MaterialBatch, item.LocationCode, txtInBox.Text);
updateStockAmount.ShowDialog();
//long materialId = item.MaterialId;
//string containerNo = txtInBox.Text;
//string materialName = item.MaterialName;
//string locationCode = item.LocationCode;
//string realAmount = item.RealAmount;
//GetData(txtInBox.Text);
}
}

@ -0,0 +1,34 @@
<Window x:Class="Khd.Core.Wpf.TaskForm.UpdateAmountWindow"
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.TaskForm"
mc:Ignorable="d"
WindowState="Normal"
WindowStartupLocation="CenterScreen"
Background="#333333"
Loaded="Window_Loaded"
Title="" Height="450" Width="800" ResizeMode="NoResize" WindowStyle="None">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="库存数量修改: " Foreground="White" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox x:Name="StockAmount" Text="" Width="250" Background="White" Foreground="Black" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Row="2" HorizontalAlignment="Center" >
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="AddTaskBtn" Content="修改库存" FontSize="25" Width="160" Height="50" Foreground="White" Background="#2196F3" VerticalAlignment="Center" HorizontalAlignment="Center" Click="UpdateBtn_Click"/>
<Button x:Name="CancelBtn" Content="取消" FontSize="25" Width="160" Height="50" Foreground="White" Background="#F44336" Click="CancelBtn_Click" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="100,0,0,0"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>

@ -0,0 +1,99 @@
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Khd.Core.Library.Mapper;
using Khd.Core.Plc;
using Khd.Core.Plc.S7;
using Khd.Core.Wpf.Form;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace Khd.Core.Wpf.TaskForm
{
/// <summary>
/// AddTask.xaml 的交互逻辑
/// </summary>
public partial class UpdateAmountWindow : Window
{
public delegate void RefreshDelegate(string containerCode);
public static event RefreshDelegate? RefreshDelegateEvent;
private string barcodeInfo;
private string locationCode;
private string containerCode;
private readonly IHost _host;
public UpdateAmountWindow(IHost host,string barcodeInfo,string locationCode,string containerCode)
{
InitializeComponent();
_host = host;
this.barcodeInfo = barcodeInfo;
this.locationCode = locationCode;
this.containerCode = containerCode;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void UpdateBtn_Click(object sender, RoutedEventArgs e)
{
string input = this.StockAmount.Text.Trim(); // 去除前后空白
if (string.IsNullOrEmpty(input))
{
MessageBox.Show("数量不能为空,请输入有效数值。");
return;
}
decimal stockAmountValue;
if (!decimal.TryParse(input, out stockAmountValue))
{
MessageBox.Show("输入的数值格式不正确,请输入有效的十进制数。");
return;
}
//
if (stockAmountValue <0)
{
MessageBox.Show("数值必须大于0");
return;
}
var scope = _host.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
WmsRawStock wmsRawStock = dbContext.WmsRawStock.Where(x => x.locationCode == locationCode && x.instockBatch == barcodeInfo).FirstOrDefault();
if (wmsRawStock != null)
{
wmsRawStock.totalAmount = stockAmountValue;
dbContext.Update(wmsRawStock);
// 修改盘库明细
WmsInventoryCheckDetail wmsInventoryDetail = dbContext.WmsInventoryCheckDetail.Where(x => x.LocationCode == locationCode && x.MaterialBatch == barcodeInfo).FirstOrDefault();
if(wmsInventoryDetail != null)
{
wmsInventoryDetail.StockAmount = stockAmountValue;
wmsInventoryDetail.RealAmount = stockAmountValue;
wmsInventoryDetail.UpdateTime = DateTime.Now;
dbContext.Update(wmsInventoryDetail);
}
dbContext.SaveChanges();
this.Close();
RefreshDelegateEvent?.Invoke(containerCode);
}
}
private void CancelBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Loading…
Cancel
Save