@ -1,5 +1,6 @@
using Khd.Core.Domain.Models ;
using Khd.Core.EntityFramework ;
using Masuit.Tools ;
using Microsoft.Extensions.DependencyInjection ;
using System ;
using System.Collections.Generic ;
@ -41,7 +42,9 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
this . MaterialSpec . Text = _materialName ;
using var scope = this . _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var wmsRawStocks = dbContext . WmsRawStock . Where ( t = > t . palletInfoCode = = _containerNo & & t . materialId = = _materialId ) . ToList ( ) ;
var wmsRawStocks = dbContext . WmsRawStock . Where ( t = > t . palletInfoCode = = _containerNo )
. WhereIf ( _materialId ! = 0 , t = > t . materialId = = _materialId )
. ToList ( ) ;
if ( wmsRawStocks . Count = = 0 )
{
this . BarCode . Text = "空" ;
@ -55,7 +58,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
}
catch
{
MessageBox. Show ( "加载数据失败,请重试" ) ;
HandyControl. Controls . MessageBox . Error ( "加载数据失败,请重试" ) ;
this . Close ( ) ;
}
}
@ -88,7 +91,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
}
catch
{
MessageBoxResult messageBoxResult = MessageBox. Show ( "该条码已经添加过,是否更新该条码?" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
MessageBoxResult messageBoxResult = HandyControl. Controls . MessageBox. Show ( "该条码已经添加过,是否更新该条码?" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
if ( messageBoxResult = = MessageBoxResult . OK )
{
string [ ] barCodes = this . BarCodeList . Text . Split ( '\n' ) ;
@ -106,13 +109,10 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
}
}
}
this . BarCodeList . Text + = mesBaseBarcodeInfo . barcodeInfo + "\n" ;
this . CountList . Text + = this . NewCount . Text + "\n" ;
this . NewBarCode . Text = "" ;
}
else
{
MessageBox. Show ( "条码不存在,请重新扫码" ) ;
HandyControl. Controls . MessageBox. Show ( "条码不存在,请重新扫码" ) ;
this . NewBarCode . Text = "" ;
}
}
@ -125,7 +125,10 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
private void SaveButton_Click ( object sender , RoutedEventArgs e )
{
List < string > newList = this . BarCodeList . Text . Split ( '\n' ) . ToList ( ) ;
newList . RemoveAll ( t = > string . IsNullOrEmpty ( t ) ) ;
List < string > list = this . BarCode . Text . Split ( '\n' ) . ToList ( ) ;
list . RemoveAll ( t = > string . IsNullOrEmpty ( t ) ) ;
List < string > countList = CountList . Text . Split ( "\n" ) . ToList ( ) ;
StringBuilder addStr = new ( ) ;
List < string > addList = newList . Where ( t = > ! list . Contains ( t ) ) . ToList ( ) ;
if ( addList . Count > 0 )
@ -142,7 +145,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
}
if ( addStr . Length > 0 | | removeStr . Length > 0 )
{
MessageBoxResult messageBoxResult = MessageBox. Show ( addStr . ToString ( ) + "\n" + removeStr . ToString ( ) , "提示" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
MessageBoxResult messageBoxResult = HandyControl. Controls . MessageBox. Show ( addStr . ToString ( ) + "\n" + removeStr . ToString ( ) , "提示" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
if ( messageBoxResult = = MessageBoxResult . OK )
{
using var scope = this . _host . Services . CreateScope ( ) ;
@ -158,7 +161,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
{
message = t . locationCode + ":" + t . instockBatch
} ) ) ;
MessageBoxResult result = MessageBox. Show ( "条码已经在其他料箱中" + waring + "确认移动到当前料箱吗?" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
MessageBoxResult result = HandyControl. Controls . MessageBox. Show ( "条码已经在其他料箱中" + waring + "确认移动到当前料箱吗?" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
if ( result = = MessageBoxResult . OK )
{
foreach ( var wmsRawStock in wmsRawStocks )
@ -177,48 +180,105 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
}
if ( addList . Count > 0 )
{
List < WmsRawStock > newWmsRawStocks = new List < WmsRawStock > ( ) ;
List < WmsRawStock > newWmsRawStocks = dbContext . WmsRawStock
. WhereIf ( _materialId ! = 0 , t = > t . materialId = = _materialId )
. Where ( t = > t . palletInfoCode = = _containerNo ) . ToList ( ) ;
var mesBaseBarcodeInfos = dbContext . MesBaseBarcodeInfo . Where ( t = > addList . Contains ( t . barcodeInfo ) ) . ToList ( ) ;
foreach ( var barcode in addList )
for ( int i = 0 ; i < addList . Count ; i + + )
{
var barcode = addList [ i ] ;
var count = countList [ i ] ;
var mesBaseBarcodeInfo = mesBaseBarcodeInfos . FirstOrDefault ( t = > t . barcodeInfo = = barcode ) ;
if ( mesBaseBarcodeInfo ! = null )
{
newWmsRawStocks . Add ( new WmsRawStock
if ( wmsRawStocks . Where ( t = > t . materialId = = mesBaseBarcodeInfo . materialId ) . Any ( ) )
{
palletInfoCode = _containerNo ,
materialId = _materialId ,
instockBatch = barcode ,
safeFlag = mesBaseBarcodeInfo . safeFlag ,
stockType = "1" ,
activeFlag = "1" ,
supplierId = mesBaseBarcodeInfo . manufacturerId ,
completeFlag = "1" ,
frozenAmount = 0 ,
instockDate = DateTime . Now ,
qualityStatus = "0" ,
rawStockId = Global . SnowId . NextId ( ) ,
occupyAmount = 0 ,
totalAmount = mesBaseBarcodeInfo . batchFlag = = "1" ? mesBaseBarcodeInfo . amount : 1 ,
warehouseFloor = 5 ,
warehouseId = 512 ,
saleOrderId = mesBaseBarcodeInfo . saleOrderId = = null ? 0 : mesBaseBarcodeInfo . saleOrderId ,
locationCode = _locationCode ,
createBy = "WCS" ,
createDate = DateTime . Now ,
updateBy = "WCS" ,
updateDate = DateTime . Now ,
} ) ;
WmsRawStock wmsRawStock = wmsRawStocks . First ( t = > t . materialId = = mesBaseBarcodeInfo . materialId ) ;
wmsRawStock . totalAmount = decimal . Parse ( count ) ;
}
else
{
newWmsRawStocks . Add ( new WmsRawStock
{
palletInfoCode = _containerNo ,
materialId = mesBaseBarcodeInfo . materialId ,
instockBatch = mesBaseBarcodeInfo . barcodeInfo ,
safeFlag = mesBaseBarcodeInfo . safeFlag ,
stockType = "1" ,
activeFlag = "1" ,
supplierId = mesBaseBarcodeInfo . manufacturerId ,
completeFlag = "1" ,
frozenAmount = 0 ,
instockDate = DateTime . Now ,
qualityStatus = "0" ,
rawStockId = Global . SnowId . NextId ( ) ,
occupyAmount = 0 ,
totalAmount = mesBaseBarcodeInfo . batchFlag = = "1" ? decimal . Parse ( count ) : 1 ,
warehouseFloor = 5 ,
warehouseId = 512 ,
saleOrderId = mesBaseBarcodeInfo . saleOrderId = = null ? 0 : mesBaseBarcodeInfo . saleOrderId ,
locationCode = _locationCode ,
createBy = "WCS" ,
createDate = DateTime . Now ,
updateBy = "WCS" ,
updateDate = DateTime . Now ,
} ) ;
}
}
else
{
MessageBox . Show ( $"{barcode}条码信息不存在,无法入库" ) ;
HandyControl. Controls . MessageBox. Show ( $"{barcode}条码信息不存在,无法入库" ) ;
return ;
}
}
if ( newWmsRawStocks . Count > 0 )
{
dbContext . AddRange ( newWmsRawStocks ) ;
WcsTask ? wcsTask = dbContext . WcsTask . Where ( t = > t . containerNo = = _containerNo ) . FirstOrDefault ( ) ;
if ( wcsTask ! = null )
{
var wmsInventoryCheckDetails = dbContext . WmsInventoryCheckDetail
. Where ( t = > t . InventoryCheckId = = wcsTask . orderId & & t . LocationCode = = wcsTask . currPointNo ) . ToList ( ) ;
List < long? > hasMaterialId = newWmsRawStocks . Select ( t = > t . materialId ) . ToList ( ) ;
var hasDetails = wmsInventoryCheckDetails
. Where ( t = > hasMaterialId . Contains ( t . MaterialId ) & & t . LocationCode = = wcsTask . currPointNo )
. ToList ( ) ;
foreach ( var item in hasDetails )
{
var wmsRawStock = newWmsRawStocks . Where ( t = > t . materialId = = item . ErpAmount ) . First ( ) ;
item . RealAmount = wmsRawStock . totalAmount ;
item . InventoryCount + + ;
item . UpdateBy = "WCS" ;
item . UpdateTime = DateTime . Now ;
}
newWmsRawStocks . Where ( t = > ! wmsInventoryCheckDetails . Select ( y = > y . MaterialId ) . Contains ( t . materialId ) ) . ToList ( ) ;
List < WmsInventoryCheckDetail > addDetailList = new List < WmsInventoryCheckDetail > ( ) ;
foreach ( var item in newWmsRawStocks )
{
addDetailList . Add ( new WmsInventoryCheckDetail
{
InventoryCheckDetailId = Global . SnowId . NextId ( ) ,
InventoryCheckId = wcsTask . orderId ,
CheckStatus = "1" ,
CreateBy = "WCS" ,
CreateTime = DateTime . Now ,
StockAmount = 0 ,
RealAmount = item . totalAmount ,
InventoryCount = 1 ,
LocationCode = item . locationCode ,
StockId = 1 ,
StockType = "1" ,
MaterialId = item . materialId ,
ErpStatus = "0" ,
ErpAmount = 0 ,
} ) ;
}
if ( addDetailList . Count > 0 )
dbContext . AddRange ( addDetailList ) ;
if ( hasDetails . Count > 0 )
dbContext . UpdateRange ( hasDetails ) ;
dbContext . AddRange ( newWmsRawStocks ) ;
dbContext . SaveChanges ( ) ;
}
}
}
}
@ -226,7 +286,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
{
}
MessageBox. Show ( "保存成功" ) ;
HandyControl. Controls . MessageBox. Show ( "保存成功" ) ;
}
else
{
@ -235,7 +295,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
}
else
{
MessageBox. Show ( "条码未变动" ) ;
HandyControl. Controls . MessageBox. Show ( "条码未变动" ) ;
}
this . Close ( ) ;
}
@ -244,18 +304,22 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
{
try
{
using var scope = this . _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . FirstOrDefault ( t = > t . barcodeInfo = = this . NewBarCode . Text ) ;
if ( mesBaseBarcodeInfo ! = null )
if ( ! string . IsNullOrEmpty ( this . NewBarCode . Text ) )
{
this . NewCount . Text = mesBaseBarcodeInfo . batchFlag = = "1" ? mesBaseBarcodeInfo . amount . ToString ( ) : "1" ;
}
else
{
MessageBox . Show ( "条码不存在,请重新扫码" ) ;
this . NewBarCode . Text = "" ;
using var scope = this . _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . FirstOrDefault ( t = > t . barcodeInfo = = this . NewBarCode . Text ) ;
if ( mesBaseBarcodeInfo ! = null )
{
this . NewCount . Text = mesBaseBarcodeInfo . batchFlag = = "1" ? mesBaseBarcodeInfo . amount . ToString ( ) : "1" ;
this . NewCount . IsReadOnly = mesBaseBarcodeInfo . batchFlag ! = "1" ;
}
else
{
HandyControl . Controls . MessageBox . Show ( "条码不存在,请重新扫码" ) ;
this . NewBarCode . Text = "" ;
this . NewCount . Text = string . Empty ;
}
}
}
catch