add-提交盘库测试版

master
liuwf 1 year ago
parent 29e1a311be
commit f4ebdf7317

@ -3643,12 +3643,12 @@ namespace Khd.Core.Wpf.Form
WmsInventoryCheck wmsInventoryCheck = dbContext.WmsInventoryCheck.FirstOrDefault(t => t.CheckStatus == "1"); WmsInventoryCheck wmsInventoryCheck = dbContext.WmsInventoryCheck.FirstOrDefault(t => t.CheckStatus == "1");
if(wmsInventoryCheck != null) if(wmsInventoryCheck != null)
{ {
wmsInventoryCheck.InventoriedAmount = dbContext.WmsInventoryCheckDetail.Where(t => t.InventoryCheckId == wmsInventoryCheck.InventoryCheckId).ToList().Count(); wmsInventoryCheck.InventoriedAmount = dbContext.WmsInventoryCheckDetail.Where(t => t.InventoryCheckId == wmsInventoryCheck.InventoryCheckId).Select(t=>t.LocationCode).Distinct().Count();
wmsInventoryCheck.InventoryingAmount = 0; wmsInventoryCheck.InventoryingAmount = 0;
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
GetInvertoryData();
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -0,0 +1,52 @@
<Window x:Class="Khd.Core.Wpf.TaskForm.AddNewStockForm"
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="DarkBlue"
Loaded="Window_Loaded"
Title="" Height="450" Width="800" ResizeMode="NoResize" WindowStyle="None">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text=" 料箱号: " FontSize="30" Foreground="White" />
<TextBlock x:Name="txtInBox" Text="" Width="500" FontSize="30" Foreground="Black" Background="White" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text=" 条码号: " FontSize="30" Foreground="White" />
<TextBox x:Name="txtInBarCode" Text="" TextChanged="txtInBarCode_TextChanged" Width="500" FontSize="30" Foreground="Black" Background="White" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="物料名称: " FontSize="30" Foreground="White" />
<TextBlock x:Name="materialName" Text="" Width="500" FontSize="30" Foreground="Black" Background="White" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="物料规格: " FontSize="30" Foreground="White" />
<TextBlock x:Name="materialSpec" Text="" Width="500" FontSize="30" Foreground="Black" Background="White" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text=" 库存数: " FontSize="30" Foreground="White" />
<TextBox x:Name="txtInScan" Text="" Width="500" FontSize="30" Foreground="Black" Background="White" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Grid.Row="5" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<RepeatButton Background="LimeGreen" x:Name="ScanButton" Content="添加入库" Style="{StaticResource RepeatButtonPrimary}" Width="100" Height="40" FontSize="20" Margin="20,0,0,0" Click="InRawBaseLocaltion_Click" />
<RepeatButton Background="Yellow" x:Name="ScanButton11" Content="取 消" Style="{StaticResource RepeatButtonPrimary}" Width="100" Height="40" FontSize="20" Margin="200,0,0,0" Click="CancelBtn_Click" />
</StackPanel>
</Grid>
</Window>

@ -0,0 +1,335 @@
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 AddNewStockForm : Window
{
public delegate void RefreshDelegate(string containerCode);
public static event RefreshDelegate? RefreshDelegateEvent;
private readonly IHost _host;
public AddNewStockForm(IHost host,string containerCode)
{
InitializeComponent();
_host = host;
txtInBox.Text = containerCode;
txtInBarCode.Focus();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void UpdateBtn_Click(object sender, RoutedEventArgs e)
{
}
private void CancelBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
//入库
private void InRawBaseLocaltion_Click(object sender, RoutedEventArgs e)
{
ScanInBox();
}
private void ScanInBox()
{
try
{
if (!string.IsNullOrEmpty(txtInBox.Text) && !string.IsNullOrEmpty(txtInBarCode.Text))
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
if (txtInScan.Text == "")
{
HandyControl.Controls.MessageBox.Error("请先输入数量"); return;
}
decimal amount = decimal.Parse(txtInScan.Text);
// 计算入库后当前总数量,仅用来提示使用
decimal? totalMessage = 0;
if (amount <= 0)
{
HandyControl.Controls.MessageBox.Error("入库数量需大于0");
return;
}
var material = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == txtInBarCode.Text);
var container = dbContext.WmsBaseLocation.FirstOrDefault(t => t.containerCode == txtInBox.Text && t.warehouseId == 512);
List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock
.Where(t => txtInBarCode.Text == t.instockBatch && t.palletInfoCode== txtInBox.Text)
.Where(t => t.warehouseFloor == 5 && t.warehouseId == 512).ToList();
if (container == null)
{
txtInBox.Focus();
txtInBox.Text = string.Empty;
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
HandyControl.Controls.MessageBox.Error("未查询到该容器"); return;
}
if (material == null)
{
HandyControl.Controls.MessageBox.Error("未查询到该条码内容");
txtInBox.Text = string.Empty;
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
txtInBox.Focus();
return;
}
if (wmsRawStocks.Count > 0)
{
if (material.batchFlag != "1")
{
HandyControl.Controls.MessageBox.Error($"该条码已入库!料箱号为{wmsRawStocks.First().palletInfoCode},库位号为{wmsRawStocks.First().locationCode}");
txtInBox.Text = string.Empty;
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
txtInBox.Focus();
return;
}
else
{
WmsRawStock wmsRawStock = wmsRawStocks.First();
wmsRawStock.totalAmount += amount;
dbContext.WmsRawStock.Update(wmsRawStock);
var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == txtInBarCode.Text);
WmsRawInstock wmsRawInstock = new WmsRawInstock()
{
taskCode = Global.SnowId.NextId().ToString(),
materialBarCode = mesBaseBarcodeInfo.barcodeInfo,
materialBatchCode = mesBaseBarcodeInfo.batchCode,
applyBy = "WPF",
applyDate = System.DateTime.Now,
purchaseOrderId = mesBaseBarcodeInfo.PurchaseOrderId,
beginTime = System.DateTime.Now,
endTime = DateTime.Now,
locationCode = container.locationCode,
executeStatus = "1",
instockAmount = amount,
instockType = "1",
materialId = material.materialId,
operationType = "1",
palletInfoCode = container.containerCode,
poNo = mesBaseBarcodeInfo.poNo,
warehouseId = 512
};
dbContext.WmsRawInstock.Add(wmsRawInstock);
dbContext.SaveChanges();
totalMessage = wmsRawStock.totalAmount;
}
}
else
{
var newRawStock = new WmsRawStock()
{
materialId = material.materialId,
supplierId = material.manufacturerId,
instockBatch = txtInBarCode.Text,
locationCode = container.locationCode,
stockType = "1",
palletInfoCode = container.containerCode,
totalAmount = material.batchFlag == "1" ? amount : 1,
activeFlag = "1",
occupyAmount = 0,
completeFlag = "1",
frozenAmount = 0,
instockDate = System.DateTime.Now,
rawStockId = Global.SnowId.NextId(),
saleOrderId = material.saleOrderId == null ? 0 : material.saleOrderId,
warehouseFloor = 5,
warehouseId = 512,
createBy = "扫描入库",
createDate = System.DateTime.Now,
safeFlag = material.safeFlag
};
dbContext.WmsRawStock.Add(newRawStock);
var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == txtInBarCode.Text);
WmsRawInstock wmsRawInstock = new WmsRawInstock()
{
taskCode = Global.SnowId.NextId().ToString(),
materialBarCode = mesBaseBarcodeInfo.barcodeInfo,
materialBatchCode = mesBaseBarcodeInfo.batchCode,
applyBy = "WPF",
applyDate = System.DateTime.Now,
purchaseOrderId = mesBaseBarcodeInfo.PurchaseOrderId,
beginTime = System.DateTime.Now,
endTime = DateTime.Now,
locationCode = container.locationCode,
executeStatus = "2",
instockAmount = amount,
instockType = "1",
materialId = material.materialId,
operationType = "1",
palletInfoCode = container.containerCode,
poNo = mesBaseBarcodeInfo.poNo,
warehouseId = 512
};
dbContext.WmsRawInstock.Add(wmsRawInstock);
#region 添加盘点明细
WmsInventoryCheck wmsInventoryCheck = dbContext.WmsInventoryCheck.Where(x => x.CheckStatus == "1").FirstOrDefault();
if(wmsInventoryCheck != null)
{
WmsInventoryCheckDetail wmsInventoryCheckDetail= new WmsInventoryCheckDetail
{
InventoryCheckDetailId = Global.SnowId.NextId(),
InventoryCheckId = wmsInventoryCheck.InventoryCheckId,
CheckStatus = "2",
CreateBy = "WPF",
CreateTime = DateTime.Now,
StockAmount = newRawStock.totalAmount,
RealAmount = newRawStock.totalAmount,
InventoryCount = 0,
LocationCode = newRawStock.locationCode,
MaterialBatch = newRawStock.instockBatch,
StockId = 1,
StockType = "1",
MaterialId = newRawStock.materialId,
ErpStatus = "0",
ErpAmount = 0,
CheckType = "2"
};
dbContext.WmsInventoryCheckDetail.Add(wmsInventoryCheckDetail);
}
#endregion
dbContext.SaveChanges();
totalMessage = newRawStock.totalAmount;
}
txtInBox.Focus();
HandyControl.Controls.MessageBox.Info($"入库成功!当前库存:{totalMessage}");
txtInBox.Text = string.Empty;
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
}
else
{
HandyControl.Controls.MessageBox.Error("请先扫描容器号和条码");
}
}
catch (Exception ex)
{
txtInBox.Text = string.Empty;
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
HandyControl.Controls.MessageBox.Error("入库失败");
txtInBarCode.Focus();
}
}
/// <summary>
/// 入库条码改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtInBarCode_TextChanged(object sender, RoutedEventArgs e)
{
try
{
materialName.Text = string.Empty;
materialSpec.Text = string.Empty;
string barCode = txtInBarCode.Text;
if (barCode.Length < 19) return;
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
if (!string.IsNullOrEmpty(barCode))
{
var material = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == barCode);
if (material == null)
{
HandyControl.Controls.MessageBox.Error("未查询到该条码内容!");
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
txtInBarCode.Focus();
}
else
{
var mesBaseMaterialInfo = dbContext.MesBaseMaterialInfo.FirstOrDefault(t => t.MaterialId == material.materialId);
if (mesBaseMaterialInfo == null)
{
HandyControl.Controls.MessageBox.Error("未查询到该条码绑定的物料信息!");
txtInBarCode.Text = string.Empty;
txtInScan.Text = string.Empty;
txtInBarCode.Focus();
}
else
{
txtInScan.Text = (material.batchFlag == "1") ? "" : "1.00";
materialName.Text = mesBaseMaterialInfo.MaterialName;
materialSpec.Text = mesBaseMaterialInfo.MaterialSpec;
if (mesBaseMaterialInfo.BatchFlag == "0")
{
txtInScan.IsReadOnly = true;
}
else
{
txtInScan.IsReadOnly = false;
}
txtInScan.Focus();
}
}
}
}
catch
{
}
}
}
}

@ -37,7 +37,7 @@
<!--<ComboBox x:Name="ContainerCodeBox" IsEditable="True" DisplayMemberPath="containerNo" Style="{StaticResource ComboBoxExtend}" Width="300" hc:InfoElement.Placeholder="容器编码" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Necessary="True" FontSize="30" />--> <!--<ComboBox x:Name="ContainerCodeBox" IsEditable="True" DisplayMemberPath="containerNo" Style="{StaticResource ComboBoxExtend}" Width="300" hc:InfoElement.Placeholder="容器编码" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Necessary="True" FontSize="30" />-->
<hc:TextBox x:Name="txtInBox" hc:InfoElement.ShowClearButton="True" FontSize="20" TextChanged="txtInBox_TextChanged" Width="300" Background="White" HorizontalAlignment="Left" VerticalAlignment="Center" Height="50" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="4"/> <hc:TextBox x:Name="txtInBox" hc:InfoElement.ShowClearButton="True" FontSize="20" TextChanged="txtInBox_TextChanged" Width="300" Background="White" HorizontalAlignment="Left" VerticalAlignment="Center" Height="50" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="4"/>
<Button x:Name="SearchBtn" Content="搜索" FontSize="30" Height="50" Foreground="White" Width="100" Background="#2196F3" Margin="10,0,0,0" Click="SearchBtn_Click"/> <Button x:Name="SearchBtn" Content="搜索" FontSize="30" Height="50" Foreground="White" Width="100" Background="#2196F3" Margin="10,0,0,0" Click="SearchBtn_Click"/>
<Button Content="编辑" FontSize="30" Height="50" Foreground="White" Width="100" Background="#2196F3" Margin="10,0,0,0" Click="EditBtn_Click"/> <Button Content="补入库" FontSize="30" Height="50" Foreground="White" Width="150" Background="GreenYellow" Margin="50,0,0,0" Click="EditBtn_Click"/>
</StackPanel> </StackPanel>

@ -171,19 +171,19 @@ namespace Khd.Core.Wpf.TaskForm
private void EditBtn_Click(object sender, RoutedEventArgs e) private void EditBtn_Click(object sender, RoutedEventArgs e)
{ {
//if (!string.IsNullOrEmpty(txtInBox.Text)) if (!string.IsNullOrEmpty(txtInBox.Text))
//{ {
// InventoryTaskEditForm editForm = new InventoryTaskEditForm(_host, 0, txtInBox.Text, "", task.currPointNo, this); AddNewStockForm editForm = new AddNewStockForm(_host, txtInBox.Text);
// this.Hide();
// editForm.ShowDialog(); editForm.ShowDialog();
// GetData();
//} }
//else else
//{ {
// HandyControl.Controls.MessageBox.Show("请先选择料箱号!"); HandyControl.Controls.MessageBox.Show("请先选择料箱号!");
//} }
} }
private void Update_Click(object sender, RoutedEventArgs e) private void Update_Click(object sender, RoutedEventArgs e)

@ -68,13 +68,14 @@ namespace Khd.Core.Wpf.TaskForm
} }
var scope = _host.Services.CreateScope(); var scope = _host.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>(); var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
WmsRawStock wmsRawStock = dbContext.WmsRawStock.Where(x => x.locationCode == locationCode && x.instockBatch == barcodeInfo).FirstOrDefault(); var wmsRawStocks = dbContext.WmsRawStock.Where(x => x.locationCode == locationCode && x.instockBatch == barcodeInfo).ToList();
WmsRawStock wmsRawStock = wmsRawStocks.FirstOrDefault();
if (wmsRawStock != null) if (wmsRawStock != null)
{ {
wmsRawStock.totalAmount = stockAmountValue; wmsRawStock.totalAmount = stockAmountValue;
dbContext.Update(wmsRawStock); dbContext.Update(wmsRawStock);
// 修改盘库明细 // 修改盘库明细
WmsInventoryCheckDetail wmsInventoryDetail = dbContext.WmsInventoryCheckDetail.Where(x => x.LocationCode == locationCode && x.MaterialBatch == barcodeInfo).FirstOrDefault(); WmsInventoryCheckDetail wmsInventoryDetail = dbContext.WmsInventoryCheckDetail.Where(x => x.LocationCode == locationCode && x.MaterialBatch == barcodeInfo && x.CheckStatus=="1").OrderByDescending(X=>X.CreateTime).FirstOrDefault();
if(wmsInventoryDetail != null) if(wmsInventoryDetail != null)
{ {
wmsInventoryDetail.StockAmount = stockAmountValue; wmsInventoryDetail.StockAmount = stockAmountValue;

Loading…
Cancel
Save