@ -1,7 +1,6 @@
using HandyControl.Tools.Extension ;
using Jc.SnowId ;
using Khd.Core.Domain.Auth ;
using Khd.Core.Domain.Dto.webapi ;
using Khd.Core.Domain.Models ;
using Khd.Core.EntityFramework ;
using Khd.Core.Library.Mapper ;
@ -12,12 +11,11 @@ using Khd.Core.Wpf.Scan;
using Khd.Core.Wpf.TaskForm ;
using Masuit.Tools ;
using Masuit.Tools.Logging ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.Hosting ;
using Newtonsoft.Json ;
using System ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
using System.Data ;
using System.Diagnostics ;
using System.IO.Ports ;
@ -25,13 +23,11 @@ using System.Linq;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;
using Z.EntityFramework.Plus ;
using System.Windows.Threading ;
using System.Windows.Input ;
using System.Windows ;
using System.Windows.Controls ;
using System.Collections.ObjectModel ;
using static HandyControl . Tools . Interop . InteropValues ;
using System.Windows.Input ;
using System.Windows.Threading ;
using Z.EntityFramework.Plus ;
namespace Khd.Core.Wpf.Form
{
@ -617,6 +613,7 @@ namespace Khd.Core.Wpf.Form
}
public int i = 0 ;
/// <summary>
/// 查询任务
/// </summary>
@ -1758,6 +1755,14 @@ namespace Khd.Core.Wpf.Form
}
}
private void rawSourceBoxClear_Click ( object sender , RoutedEventArgs e )
{
this . rawSourceBox . Text = string . Empty ;
}
private void removeSourceBoxClear_Click ( object sender , RoutedEventArgs e )
{
this . removeSourceBox . Text = string . Empty ;
}
/// <summary>
/// 入库扫描
/// </summary>
@ -2588,7 +2593,10 @@ namespace Khd.Core.Wpf.Form
//}
var wmsBaseLocation = dbContext . WmsBaseLocation
. Where ( t = > t . locationStatus = = "1" )
. Where ( t = > t . warehouseId = = 512 & & t . ContainerStatus = = "1" ) . ToList ( ) ;
. Where ( t = > t . warehouseId = = 512 & & t . ContainerStatus = = "1" )
. OrderBy ( t = > t . locColumn )
. ThenBy ( t = > t . locRow )
. ToList ( ) ;
var wmsRawStock = dbContext . WmsRawStock . Where ( t = > t . warehouseId = = 512 ) . ToList ( ) ;
List < string > palletInfoCodes = wmsRawStock . Select ( t = > t . palletInfoCode ) . ToList ( ) ;
wmsBaseLocation . RemoveAll ( t = > palletInfoCodes . Contains ( t . containerCode ) ) ;
@ -2653,7 +2661,7 @@ namespace Khd.Core.Wpf.Form
BaseEquip endEquip = SystemData . BaseEquip . First ( t = > t . objid = = 20 ) ;
if ( itemsControlItems . Count = = 0 )
{
MessageBox. Show ( "请选择料箱!" ) ;
HandyControl. Controls . MessageBox. Show ( "请选择料箱!" ) ;
return ;
}
@ -2708,13 +2716,270 @@ namespace Khd.Core.Wpf.Form
item . locationStatus = "6" ;
dbContext . Update ( item ) ;
}
if ( addList . Count < 6 )
{
var messageBoxResult = HandyControl . Controls . MessageBox . Show ( $"已创建{addList.Count}个料箱的任务,是否需要创建出空箱的任务?" , "提示" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
if ( messageBoxResult = = MessageBoxResult . Yes )
{
EmptyCountForm emptyCountForm = new ( 1 , 6 - addList . Count ) ;
emptyCountForm . ShowDialog ( ) ;
if ( EmptyCountForm . IsSelect )
{
List < WmsBaseLocation > emptyLocations = dbContext . ExecuteSqlQuery < WmsBaseLocation > ( @ $ "
select t1 . location_id locationId ,
t1 . container_code containerCode ,
t1 . location_code locationCode
from wms_base_location t1
left join wms_raw_stock t2
on t1 . location_code = t2 . location_code
where t2 . location_code is null and t1 . location_status = 1
and t1 . container_status = 1 and t1 . warehouse_id = 512
order by t1 . loc_column , t1 . loc_row
");
if ( emptyLocations . Count < EmptyCountForm . EmptyTaskCount )
{
messageBoxResult = HandyControl . Controls . MessageBox . Show ( "没有足够的空箱库位库位,剩余空库位数量为" + emptyLocations . Count + "!\n是否将现有的空箱全部出库? " , "提示" , MessageBoxButton . YesNo , MessageBoxImage . Information ) ;
if ( messageBoxResult = = MessageBoxResult . Yes )
{
foreach ( var item in emptyLocations )
{
item . locationStatus = "6" ;
item . ContainerStatus = "2" ;
addList . Add ( new WcsTaskManual ( )
{
objid = Global . SnowId . NextId ( ) ,
taskType = 30 ,
containerNo = item . containerCode ,
startPointId = item . locationId ,
startPointNo = item . locationCode ,
currPointId = item . locationId ,
currPointNo = item . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = endEquip . objid ,
endPointNo = endEquip . equipNo ,
createTime = DateTime . Now ,
ud1 = item . locColumn ,
taskStatus = 0 ,
remark = "CTU空库任务" ,
floorNo = 5 ,
fromFloorNo = 5 ,
useFlag = 1
} ) ;
dbContext . Update ( item ) ;
}
}
}
else
{
for ( int i = 0 ; i < EmptyCountForm . EmptyTaskCount ; i + + )
{
emptyLocations [ i ] . locationStatus = "6" ;
emptyLocations [ i ] . ContainerStatus = "2" ;
addList . Add ( new WcsTaskManual ( )
{
objid = Global . SnowId . NextId ( ) ,
taskType = 30 ,
containerNo = emptyLocations [ i ] . containerCode ,
startPointId = emptyLocations [ i ] . locationId ,
startPointNo = emptyLocations [ i ] . locationCode ,
currPointId = emptyLocations [ i ] . locationId ,
currPointNo = emptyLocations [ i ] . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = endEquip . objid ,
endPointNo = endEquip . equipNo ,
createTime = DateTime . Now ,
ud1 = emptyLocations [ i ] . locColumn ,
taskStatus = 0 ,
remark = "CTU空库任务" ,
floorNo = 5 ,
fromFloorNo = 5 ,
useFlag = 1
} ) ;
dbContext . Update ( emptyLocations [ i ] ) ;
}
}
}
}
}
dbContext . AddRange ( addList ) ;
dbContext . SaveChanges ( ) ;
HandyControl . Controls . MessageBox . Show ( "创建出库任务成功!" ) ;
itemsControlItems . Clear ( ) ;
CallSelectedItem . Clear ( ) ;
GetPersonCallMaterialData ( ) ;
}
}
catch
{
}
}
/// <summary>
/// 叫托盘
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RemoveTrayBtn_Click ( object sender , RoutedEventArgs e )
{
try
{
BaseEquip ctuEquip = SystemData . BaseEquip . First ( t = > t . objid = = 11 ) ;
BaseEquip endEquip = SystemData . BaseEquip . First ( t = > t . objid = = 20 ) ;
List < WcsTaskManual > taskList = new List < WcsTaskManual > ( ) ;
if ( itemsControlItems . Count = = 0 )
{
HandyControl . Controls . MessageBox . Show ( "请选择料箱!" ) ;
return ;
}
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
List < long > idList = itemsControlItems . Select ( x = > x . baseLocationId ) . ToList ( ) ;
if ( idList . Count = = 0 )
{
HandyControl . Controls . MessageBox . Error ( "请选择需要移库的料箱!" ) ;
return ;
}
else
{
if ( idList . Count = = 1 )
{
List < WmsBaseLocation > emptyLocations = dbContext . ExecuteSqlQuery < WmsBaseLocation > ( @ $ "
select t1 . location_id locationId ,
t1 . container_code containerCode ,
t1 . location_code locationCode
from wms_base_location t1
left join wms_raw_stock t2
on t1 . location_code = t2 . location_code
where t2 . location_code is null and t1 . location_status = 1
and t1 . container_status = 1 and t1 . warehouse_id = 512
order by t1 . loc_column , t1 . loc_row
");
var wmsLocation = dbContext . WmsBaseLocation . FirstOrDefault ( t = > t . locationId = = idList [ 0 ] & & t . locationStatus = = "1" ) ;
if ( wmsLocation = = null )
{
HandyControl . Controls . MessageBox . Error ( "选择的料箱错误,请重新选择!" ) ;
return ;
}
if ( emptyLocations . Count = = 0 )
{
HandyControl . Controls . MessageBox . Error ( "只选择了一个移库料箱,但是没有空箱库位库位,无法移库!" ) ;
return ;
}
MessageBoxResult messageBoxResult = HandyControl . Controls . MessageBox . Show ( "选择了一个移库料箱,需要出空料箱,是否确认?" , "提示" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
if ( messageBoxResult = = MessageBoxResult . Yes )
{
WmsBaseLocation emptyLocation = emptyLocations . First ( ) ;
emptyLocation . locationStatus = "4" ;
emptyLocation . ContainerStatus = "2" ;
wmsLocation . locationStatus = "4" ;
wmsLocation . ContainerStatus = "2" ;
taskList . Add ( new WcsTaskManual ( )
{
objid = Global . SnowId . NextId ( ) ,
taskType = 102 ,
containerNo = wmsLocation . containerCode ,
startPointId = wmsLocation . locationId ,
startPointNo = wmsLocation . locationCode ,
currPointId = wmsLocation . locationId ,
currPointNo = wmsLocation . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = endEquip . objid ,
endPointNo = endEquip . equipNo ,
createTime = DateTime . Now ,
ud1 = wmsLocation . locColumn ,
taskStatus = 0 ,
remark = "CTU托盘任务" ,
floorNo = 5 ,
fromFloorNo = 5 ,
useFlag = 1
} ) ;
taskList . Add ( new WcsTaskManual ( )
{
objid = Global . SnowId . NextId ( ) ,
taskType = 102 ,
containerNo = emptyLocation . containerCode ,
startPointId = emptyLocation . locationId ,
startPointNo = emptyLocation . locationCode ,
currPointId = emptyLocation . locationId ,
currPointNo = emptyLocation . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = endEquip . objid ,
endPointNo = endEquip . equipNo ,
createTime = DateTime . Now ,
ud1 = emptyLocation . locColumn ,
taskStatus = 0 ,
remark = "CTU托盘任务" ,
floorNo = 5 ,
fromFloorNo = 5 ,
useFlag = 1
} ) ;
dbContext . Update ( wmsLocation ) ;
dbContext . Update ( emptyLocation ) ;
dbContext . AddRange ( taskList ) ;
dbContext . SaveChanges ( ) ;
HandyControl . Controls . MessageBox . Show ( "移库任务创建成功!" ) ;
itemsControlItems . Clear ( ) ;
CallSelectedItem . Clear ( ) ;
GetPersonCallMaterialData ( ) ;
}
}
else if ( idList . Count = = 2 )
{
List < WmsBaseLocation > wmsBaseLocations = dbContext . WmsBaseLocation . Where ( t = > idList . Contains ( t . locationId ) )
. Where ( t = > t . ContainerStatus = = "1" )
. Where ( t = > t . locationStatus = = "1" )
. ToList ( ) ;
if ( wmsBaseLocations . Count ! = 2 )
{
HandyControl . Controls . MessageBox . Error ( "选择的料箱库位状态异常,请重新选择!" ) ;
return ;
}
foreach ( var item in wmsBaseLocations )
{
taskList . Add ( new WcsTaskManual ( )
{
objid = Global . SnowId . NextId ( ) ,
taskType = 102 ,
containerNo = item . containerCode ,
startPointId = item . locationId ,
startPointNo = item . locationCode ,
currPointId = item . locationId ,
currPointNo = item . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = endEquip . objid ,
endPointNo = endEquip . equipNo ,
createTime = DateTime . Now ,
ud1 = item . locColumn ,
taskStatus = 0 ,
remark = "CTU托盘任务" ,
floorNo = 5 ,
fromFloorNo = 5 ,
useFlag = 1
} ) ;
item . ContainerStatus = "2" ;
item . locationStatus = "6" ;
dbContext . Update ( item ) ;
}
dbContext . AddRange ( taskList ) ;
dbContext . SaveChanges ( ) ;
HandyControl . Controls . MessageBox . Show ( "移库任务创建成功!" ) ;
itemsControlItems . Clear ( ) ;
CallSelectedItem . Clear ( ) ;
GetPersonCallMaterialData ( ) ;
}
else if ( idList . Count > 2 )
{
HandyControl . Controls . MessageBox . Error ( "选择料箱不能超过2个! " ) ;
return ;
}
}
itemsControlItems . Clear ( ) ;
CallSelectedItem . Clear ( ) ;
GetPersonCallMaterialData ( ) ;
}
catch
{
@ -3607,5 +3872,135 @@ namespace Khd.Core.Wpf.Form
}
}
#region 移库方法
private void removeSourceBox_LostFocus ( object sender , RoutedEventArgs e )
{
if ( string . IsNullOrEmpty ( this . removeSourceBox . Text ) )
{
return ;
}
try
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
WcsTask ? wcsTask = dbContext . WcsTask . Where ( t = > t . containerNo = = this . removeSourceBox . Text ) . FirstOrDefault ( ) ;
if ( wcsTask = = null )
{
HandyControl . Controls . MessageBox . Show ( "未找到该托盘!" ) ;
this . removeSourceBox . Text = "" ;
return ;
}
}
catch
{
}
}
private void rawSourceBox_LostFocus ( object sender , RoutedEventArgs e )
{
if ( string . IsNullOrEmpty ( this . rawSourceBox . Text ) )
{
return ;
}
try
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
WcsTask ? wcsTask = dbContext . WcsTask . Where ( t = > t . containerNo = = this . rawSourceBox . Text ) . FirstOrDefault ( ) ;
if ( wcsTask = = null )
{
HandyControl . Controls . MessageBox . Show ( "未找到该托盘!" ) ;
this . rawSourceBox . Text = "" ;
return ;
}
}
catch
{
}
}
private void removeBarCodeClear_Click ( object sender , RoutedEventArgs e )
{
removeBarCode . Text = "" ;
}
private void removeBarCode_LostFocus ( Object sender , RoutedEventArgs e )
{
try
{
if ( string . IsNullOrEmpty ( this . rawSourceBox . Text ) )
{
HandyControl . Controls . MessageBox . Show ( "请先选择托盘!" ) ;
return ;
}
if ( string . IsNullOrEmpty ( this . removeBarCode . Text ) )
{
return ;
}
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
WmsRawStock ? wmsRawStock = dbContext . WmsRawStock . Where ( t = > t . palletInfoCode = = this . rawSourceBox . Text )
. Where ( t = > t . instockBatch = = this . removeBarCode . Text )
. FirstOrDefault ( ) ;
if ( wmsRawStock = = null )
{
HandyControl . Controls . MessageBox . Show ( $"未在{this.rawSourceBox.Text}托盘中找到{this.removeBarCode.Text}条码!" ) ;
this . removeBarCode . Text = "" ;
this . removeScan . Text = string . Empty ;
return ;
}
else
{
this . removeScan . Text = wmsRawStock . frozenAmount . ToString ( ) ;
}
}
catch
{
}
}
private void btnRemoveConfirmBox_Click ( object sender , RoutedEventArgs e )
{
if ( string . IsNullOrEmpty ( this . rawSourceBox . Text ) )
{
HandyControl . Controls . MessageBox . Show ( "请先选择移库源托盘!" ) ;
return ;
}
if ( string . IsNullOrEmpty ( this . removeSourceBox . Text ) )
{
HandyControl . Controls . MessageBox . Show ( "请先选择移库条码!" ) ;
return ;
}
if ( string . IsNullOrEmpty ( this . removeBarCode . Text ) )
{
HandyControl . Controls . MessageBox . Show ( "请先扫码移库数量!" ) ;
return ;
}
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
try
{
WmsBaseLocation removeLocation = dbContext . WmsBaseLocation . Where ( t = > t . containerCode = = this . removeSourceBox . Text ) . First ( ) ;
WmsBaseLocation rawLocation = dbContext . WmsBaseLocation . Where ( t = > t . containerCode = = this . rawSourceBox . Text ) . First ( ) ;
dbContext . WmsRawStock . Where ( t = > t . locationCode = = rawLocation . locationCode )
. Where ( t = > t . instockBatch = = this . removeBarCode . Text )
. Update ( t = > new WmsRawStock
{
locationCode = removeLocation . locationCode ,
} ) ;
HandyControl . Controls . MessageBox . Show ( "移库成功!" ) ;
this . removeBarCode . Text = "" ;
this . removeScan . Text = string . Empty ;
}
catch
{
}
}
# endregion
}
}