@ -11,8 +11,10 @@ using Khd.Core.Wpf.Scan;
using Khd.Core.Wpf.TaskForm ;
using Khd.Core.Wpf.TaskForm ;
using Masuit.Tools ;
using Masuit.Tools ;
using Masuit.Tools.Logging ;
using Masuit.Tools.Logging ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.Hosting ;
using Microsoft.Extensions.Hosting ;
using Microsoft.IdentityModel.Tokens ;
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
using System.Collections.ObjectModel ;
@ -28,6 +30,7 @@ using System.Windows.Controls;
using System.Windows.Input ;
using System.Windows.Input ;
using System.Windows.Threading ;
using System.Windows.Threading ;
using Z.EntityFramework.Plus ;
using Z.EntityFramework.Plus ;
using static HandyControl . Tools . Interop . InteropValues ;
namespace Khd.Core.Wpf.Form
namespace Khd.Core.Wpf.Form
{
{
@ -36,7 +39,7 @@ namespace Khd.Core.Wpf.Form
/// </summary>
/// </summary>
public partial class FormBoardT : Window
public partial class FormBoardT : Window
{
{
private List < long > productIds = new List < long > ( ) { 231 , 531 , 521 } ;
public static long? UserId = 1 ;
public static long? UserId = 1 ;
public static readonly JcSnowId _jcSnowId = new JcSnowId ( ) ;
public static readonly JcSnowId _jcSnowId = new JcSnowId ( ) ;
private readonly IHost _host ;
private readonly IHost _host ;
@ -57,7 +60,7 @@ namespace Khd.Core.Wpf.Form
public List < MesBaseBarcodeInfo > barcodeLsit = new List < MesBaseBarcodeInfo > ( ) ;
public List < MesBaseBarcodeInfo > barcodeLsit = new List < MesBaseBarcodeInfo > ( ) ;
private int pageCount = 15 ;
private int pageCount = 15 ;
private object updateLock = new object ( ) ;
private object updateLock = new object ( ) ;
private readonly List < LocationDto > locationDtos = new List < LocationDto > ( ) ;
private ObservableCollection < SelectItemModel > itemsControlItems ;
private ObservableCollection < SelectItemModel > itemsControlItems ;
//人工叫料选中类
//人工叫料选中类
@ -117,7 +120,6 @@ namespace Khd.Core.Wpf.Form
{
{
itemsControlItems = new ObservableCollection < SelectItemModel > ( ) ;
itemsControlItems = new ObservableCollection < SelectItemModel > ( ) ;
itemsControl . ItemsSource = itemsControlItems ;
itemsControl . ItemsSource = itemsControlItems ;
Task . Run ( ( ) = >
Task . Run ( ( ) = >
{
{
foreach ( var plcConfig in SystemData . PlcConfigs )
foreach ( var plcConfig in SystemData . PlcConfigs )
@ -876,6 +878,7 @@ namespace Khd.Core.Wpf.Form
{
{
Pagination1 . PageIndex = 1 ;
Pagination1 . PageIndex = 1 ;
this . EquipListSelectDy . SelectedIndex = - 1 ;
this . EquipListSelectDy . SelectedIndex = - 1 ;
locationDtos . Clear ( ) ;
GetBaseLocations ( ) ;
GetBaseLocations ( ) ;
}
}
/// <summary>
/// <summary>
@ -888,28 +891,54 @@ namespace Khd.Core.Wpf.Form
var scope = _host . Services . CreateScope ( ) ;
var scope = _host . Services . CreateScope ( ) ;
var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var locationCode = lba_ThrifTtitle6 . Text ;
var locationCode = lba_ThrifTtitle6 . Text ;
long materialId = 0 ;
string sql ;
try
if ( productIds . Contains ( warehouse . warehouseId ) )
{
{
materialId = Convert . ToInt64 ( lba_ThrifTtitle5 . Text ) ;
sql = $ @ "select distinct t1.location_id LocationId,
t1 . location_code LocationCode ,
t1 . location_status LocationStatus ,
t1 . warehouse_floor FloorNo ,
t2 . pallet_info_code ContainerCode ,
t2 . material_id MaterialId ,
t2 . sale_order_id SaleOrderId
from wms_base_location t1
left join wms_raw_stock t2
on t1 . location_code = t2 . location_code
where t1 . warehouse_id = { warehouse . warehouseId } ";
}
}
catch
else
{
{
sql = $ @ "select distinct t1.location_id LocationId,
t1 . location_code LocationCode ,
t1 . warehouse_floor FloorNo ,
t1 . location_status LocationStatus ,
t2 . pallet_info_code ContainerCode ,
t2 . product_id MaterialId ,
t2 . sale_order_id SaleOrderId
from wms_base_location t1
left join wms_product_stock t2
on t1 . location_code = t2 . location_code
where t1 . warehouse_id = { warehouse . warehouseId } ";
}
}
int sum = dbContext . WmsRawStock
if ( ! string . IsNullOrEmpty ( locationCode ) )
. WhereIf ( ! string . IsNullOrEmpty ( lba_ThrifTtitle6 . Text ) , t = > t . locationCode . Contains ( locationCode ) )
{
. WhereIf ( ! string . IsNullOrEmpty ( lba_ThrifTtitle5 . Text ) , t = > t . materialId = = materialId )
sql + = " and t1.location_code like '%" + locationCode + "%'" ;
. Where ( t = > t . warehouseId = = warehouse . warehouseId )
}
. Count ( ) ;
if ( ! string . IsNullOrEmpty ( this . locationStatus . SelectedItem ? . ToString ( ) ) )
{
if ( this . locationStatus . SelectedItem is ComboBoxItem item & & ! string . IsNullOrEmpty ( item . Tag ? . ToString ( ) ) )
{
sql + = " and t1.location_status = " + item . Tag + "" ;
}
}
var data = dbContext . ExecuteSqlQuery < LocationDto > ( sql ) ;
int sum = data . Count ;
data = data . Skip ( ( this . Pagination1 . PageIndex - 1 ) * this . pageCount ) . Take ( this . pageCount ) . ToList ( ) ;
data . ForEach ( t = >
{
t . LocationStatus = SystemData . LocationStatusDic . GetValueOrDefault ( t . LocationStatus , "未知" ) ;
} ) ;
Pagination1 . MaxPageCount = ( sum / pageCount ) + ( sum % pageCount = = 0 ? 0 : 1 ) ;
Pagination1 . MaxPageCount = ( sum / pageCount ) + ( sum % pageCount = = 0 ? 0 : 1 ) ;
var data = dbContext . WmsRawStock
. WhereIf ( ! string . IsNullOrEmpty ( lba_ThrifTtitle6 . Text ) , t = > t . locationCode . Contains ( locationCode ) )
. WhereIf ( ! string . IsNullOrEmpty ( lba_ThrifTtitle5 . Text ) , t = > t . materialId = = materialId )
. Where ( t = > t . warehouseId = = warehouse . warehouseId )
. Skip ( ( Pagination1 . PageIndex - 1 ) * pageCount )
. Take ( pageCount )
. ToList ( ) ;
this . LoadMaterial1 . ItemsSource = null ;
this . LoadMaterial1 . ItemsSource = null ;
this . LoadMaterial1 . ItemsSource = data ;
this . LoadMaterial1 . ItemsSource = data ;
this . LoadMaterial1 . Items . Refresh ( ) ;
this . LoadMaterial1 . Items . Refresh ( ) ;
@ -4158,6 +4187,104 @@ namespace Khd.Core.Wpf.Form
}
}
}
}
private void LocationPersonBox_Click ( object sender , RoutedEventArgs e )
{
if ( sender is CheckBox check )
{
if ( check . IsChecked = = true )
{
if ( LoadMaterial1 . SelectedItem is LocationDto location )
{
locationDtos . Add ( location ) ;
}
}
else
{
if ( LoadMaterial1 . SelectedItem is LocationDto location )
{
locationDtos . Remove ( location ) ;
}
}
}
}
private void LockLocation_Click ( object sender , RoutedEventArgs e )
{
if ( locationDtos . Count = = 0 )
{
HandyControl . Controls . MessageBox . Show ( "请选择库位!" ) ;
return ;
}
List < string > locationCodes = locationDtos . Select ( t = > t . LocationCode ) . ToList ( ) ;
MessageBoxResult messageBoxResult = HandyControl . Controls . MessageBox . Show ( $"锁定库位{string.Join(" \ n ", locationCodes)}" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
if ( messageBoxResult = = MessageBoxResult . OK )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
using var transaction = dbContext . Database . BeginTransaction ( ) ;
try
{
List < WmsBaseLocation > wmsBaseLocations = dbContext . WmsBaseLocation . Where ( t = > locationCodes . Contains ( t . locationCode ) ) . ToList ( ) ;
foreach ( var location in wmsBaseLocations )
{
location . locationStatus = "3" ;
location . ExceptionDesc = "人工锁定" ;
SystemData . AlarmLocation ( location , dbContext ) ;
dbContext . Update ( location ) ;
}
dbContext . SaveChanges ( ) ;
transaction . Commit ( ) ;
locationDtos . Clear ( ) ;
GetBaseLocations ( ) ;
HandyControl . Controls . MessageBox . Show ( "锁定成功!" ) ;
}
catch
{
transaction . Rollback ( ) ;
}
}
}
private void UnLockLocation_Click ( object sender , RoutedEventArgs e )
{
if ( locationDtos . Count = = 0 )
{
HandyControl . Controls . MessageBox . Show ( "请选择库位!" ) ;
return ;
}
List < string > locationCodes = locationDtos . Select ( t = > t . LocationCode ) . ToList ( ) ;
MessageBoxResult messageBoxResult = HandyControl . Controls . MessageBox . Show ( $"解锁库位{string.Join(" \ n ", locationCodes)}" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
if ( messageBoxResult = = MessageBoxResult . OK )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
using var transaction = dbContext . Database . BeginTransaction ( ) ;
try
{
List < WmsBaseLocation > wmsBaseLocations = dbContext . WmsBaseLocation . Where ( t = > locationCodes . Contains ( t . locationCode ) ) . ToList ( ) ;
foreach ( var location in wmsBaseLocations )
{
location . locationStatus = "1" ;
location . ExceptionDesc = "人工解锁" ;
SystemData . UnAlarmLocation ( location , dbContext ) ;
dbContext . Update ( location ) ;
}
dbContext . SaveChanges ( ) ;
transaction . Commit ( ) ;
locationDtos . Clear ( ) ;
GetBaseLocations ( ) ;
HandyControl . Controls . MessageBox . Show ( "解锁成功!" ) ;
}
catch
{
transaction . Rollback ( ) ;
}
}
}
}
}
}
}