@ -1,5 +1,6 @@
using Khd.Core.Domain.Models ;
using Khd.Core.EntityFramework ;
using Khd.Core.Plc.S7.Types ;
using Masuit.Tools.Logging ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
@ -22,6 +23,9 @@ using Thrift.Server;
using Thrift.Transport ;
using ThriftService ;
using Z.EntityFramework.Plus ;
using Jc.SnowId ;
using Masuit.Tools ;
using System.Windows.Input ;
namespace Khd.Core.Wpf.Form
{
@ -40,11 +44,17 @@ namespace Khd.Core.Wpf.Form
private int UpState ; //对应上件站点的状态,0为良好 1为损坏
List < BasePlcpoint > basePlcpoints = new List < BasePlcpoint > ( ) ;
object timerjilu ;
public class selectOrderData
public class barcodeinfo
{
public string Id { get ; set ; }
public string orderCode { get ; set ; }
public string barcode { get ; set ; }
public long? materialId { get ; set ; }
public decimal? qty { get ; set ; }
}
public List < barcodeinfo > barcodeLsit = new List < barcodeinfo > ( ) ;
private string selectedId ;
//FormShowSelect formSelect;
// public static int WeekNo = CommonHelper.WeekOfYear(DateTime.Now, new System.Globalization.CultureInfo("zh-CN"));
@ -62,7 +72,7 @@ namespace Khd.Core.Wpf.Form
{
try
{
LogManager . Info ( $"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;" ) ;
//LogManager.Info( $"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;");
//设置显示任务栏
if ( WindowState = = WindowState . Normal )
{
@ -115,148 +125,6 @@ namespace Khd.Core.Wpf.Form
}
}
/// <summary>
/// 刷新日期
/// </summary>
private void SetTime ( )
{
new Thread ( ( ) = >
{
while ( true )
{
try
{
Dispatcher . Invoke ( new Action ( delegate
{
LabDate . Content = DateTime . Now . ToString ( "yyyy年MM月dd日" ) ;
LabTime . Content = DateTime . Now . ToString ( "HH:mm:ss" ) ;
} ) ) ;
}
catch ( Exception ex )
{
}
finally
{
Thread . Sleep ( 1000 ) ;
}
}
} ) . Start ( ) ;
}
public void UpMessage ( object sender , EventArgs e )
{
MoHuChaXunWuLiaoName_SelectionChanged ( timerjilu , null ) ;
}
/// <summary>
/// WCS通讯方法
/// </summary>
public void StartThriftServer ( )
{
try
{
int point = Convert . ToInt32 ( ThriftConfig . JiesShouDuanKou ) ;
WcsServer wcsServer = new WcsServer ( ) ;
//wcsServer.SendCarEvent += SendCar;
// wcsServer.helloEvent += hello;
WcsThrift . Processor processor = new WcsThrift . Processor ( wcsServer ) ;
TServerTransport serverTransport = new TServerSocket ( point ) ;
TServer server = new TSimpleServer ( processor , serverTransport ) ;
server . Serve ( ) ;
}
catch ( Exception ex )
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
//设置图片为未到位
} ) ) ;
LogManager . Error ( ex ) ;
}
}
public string hello ( string name )
{
//Console.WriteLine($"hello {name}");
//return $"ServerResponse receive from client name:{name}";
try
{
if ( ! string . IsNullOrWhiteSpace ( name ) )
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
//设置图片为已到位、显示挂具号
} ) ) ;
}
else
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
} ) ) ;
}
}
catch ( Exception ex )
{
LogManager . Info ( $"客户端接收服务端推送的小车信息方法报错 >>> {ex.Message}" ) ;
}
return "" ;
}
/// <summary>
/// 发车方法
///
/// </summary>
/// <param name="carlist"></param>
/// <param name="prodCode">物料号</param>
/// <param name="amount">三轮车辆长度</param>
public void SendCar ( List < string > carlist , string prodCode , string bunber , string ordercodeid )
{
TTransport transport = new TSocket ( ThriftConfig . ThriftIpAddress , ThriftConfig . TuiSongDuankou ) ;
try
{
//Console.WriteLine($"hello carlist[0]:{carlist.FirstOrDefault()}|order_code:{order_code}|amount:{amount}");
//return $"ServerResponse receive from client order_code:{order_code}";
transport . Open ( ) ;
TProtocol protocol = new TBinaryProtocol ( transport ) ;
WcsThrift . Client client = new WcsThrift . Client ( protocol ) ;
// var ret = client.SendCar(carlist, prodCode, bunber, ordercodeid);
if ( "1" = = "1" ) //与服务端交互成功发车时
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
//发车成功提示反馈
this . lba_ThrifTtitle . Foreground = new SolidColorBrush ( Colors . Green ) ;
this . lba_ThrifTtitle . Text = "发车成功!" ;
} ) ) ;
}
else //与服务端交互失败时
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
this . lba_ThrifTtitle . Foreground = new SolidColorBrush ( Colors . Red ) ;
this . lba_ThrifTtitle . Text = $"Thrift交互失败!" ;
} ) ) ;
}
}
catch ( Exception ex )
{
LogManager . Info ( $"发车方法报错 >>> {ex.Message}" ) ;
}
finally
{
transport . Close ( ) ;
transport . Dispose ( ) ;
}
}
/// <summary>
/// 显示序号事件
/// </summary>
/// <param name="sender"></param>
@ -281,132 +149,100 @@ namespace Khd.Core.Wpf.Form
}
public int i = 0 ;
/// <summary>
/// 电气机柜信息面板定时器调用方法
/// 查询任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PLCmessage ( object sender , EventArgs e )
private void btnGetTask_Click ( object sender , Routed EventArgs e )
{
try
GetTask ( ) ;
}
private void GetTask ( )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var equipCode = lba_ThrifTtitle1 . Text ;
var palletNo = lba_ThrifTtitle2 . Text ;
var data = dbContext . WcsTask . Where ( t = > t . useFlag = = 1 & & t . containerNo . Contains ( palletNo ) & & t . equipmentNo . Contains ( equipCode ) ) . ToList ( ) ;
this . LoadMaterial0 . ItemsSource = null ;
this . LoadMaterial0 . ItemsSource = data ;
this . LoadMaterial0 . Items . Refresh ( ) ;
if ( data . Count = = 0 )
{
if ( i = = 1000 )
{
i = 0 ;
}
foreach ( var item in basePlcpoints )
{
//通过名称找到TextBox
TextBox FoundTextBox = ( TextBox ) FindName ( item . plcpointNo ) ;
if ( FoundTextBox = = null )
{
continue ;
}
string value = i . ToString ( ) ;
//string value = _plc.Read(item.plcpointAddress).ToString();
//if (value.IsNullOrEmpty())
//{
// continue;
//}
//if (FoundTextBox.IsFocused == true)
//{
// continue;
//}
FoundTextBox . Text = value ;
i + + ;
LogManager . Info ( i . ToString ( ) ) ;
}
}
catch ( Exception ex )
{
LogManager . Info ( $"电气机柜信息面板定时器调用方法报错 >>> {ex.Message}" ) ;
MessageBox . Show ( "未查询到数据" ) ;
}
}
/// <summary>
/// PLC读取方法封装
/// </summary>
/// <param name="plcAddress">plc地址位</param>
/// <param name="plcDataType">plc数据类型(int类型默认为1)</param>
/// <param name="plcValueLength">plc地址位长度(string类型默认为2)</param>
/// <param name="textBoxXcid">载具号文本输入框</param>
/// <param name="textBoxGjdw">载具到位文本输入框</param>
/// <param name="textBoxClzt">PLC车辆状态文本输入框</param>
/// <param name="textBoxXcqx">载具去向文本输入框</param>
/// <param name="textBoxWcsclzt">WCS处理状态文本输入框</param>
private void ReadPlcData ( string plcAddress , int plcDataType , string plcValueLength ,
TextBox textBoxXcid , TextBox textBoxGjdw , TextBox textBoxClzt ,
TextBox textBoxXcqx , TextBox textBoxWcsclzt )
{
try
{
// 载具号
ReadAndSetText ( plcAddress , textBoxXcid ) ;
// 载具到位
//DQXX.plcpointAddress = $"DB4.DBW{GetOffset(plcAddress, 0)}";
string gjdw = $"DB4.DBW{GetOffset(plcAddress, 0)}" ;
ReadAndSetText ( gjdw , textBoxGjdw ) ;
// PLC处理状态
//DQXX.plcpointAddress = $"DB4.DBW{GetOffset(plcAddress, 2)}";
string plcclzt = $"DB4.DBW{GetOffset(plcAddress, 2)}" ;
ReadAndSetText ( plcclzt , textBoxClzt ) ;
// 小车去向
//DQXX.plcpointAddress = $"DB5.DBW{GetOffset(plcAddress, 0)}";
string xcqx = $"DB5.DBW{GetOffset(plcAddress, 0)}" ;
ReadAndSetText ( xcqx , textBoxXcqx , textBoxXcqx . IsFocused ) ;
// WCS处理完成
//DQXX.plcpointAddress = $"DB5.DBW{GetOffset(plcAddress, 2)}";
string wcsclzt = $"DB5.DBW{GetOffset(plcAddress, 2)}" ;
ReadAndSetText ( wcsclzt , textBoxWcsclzt , textBoxWcsclzt . IsFocused ) ;
//-------------------------------------------------------------------------以下为方法内部嵌套方法
//嵌套方法1
void ReadAndSetText ( string dw , TextBox textBox , bool checkFocus = false )
{
string value = _plc . Read ( dw ) . ToString ( ) ;
if ( value ! = null & & ( ! checkFocus | | ! textBox . IsFocused ) )
{
textBox . Text = value ;
}
}
//嵌套方法2
int GetOffset ( string PlcAddress , int baseOffset )
{
int result = int . Parse ( PlcAddress . Substring ( 4 , 1 ) ) * 4 + baseOffset ;
return result ;
}
}
catch ( Exception ex )
{
LogManager . Info ( $"PLC读取方法封装报错 >>> {ex.Message}" ) ;
}
}
/// <summary>
/// 订单导入按钮点击事件
/// 删除任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn _dingdandaoru _Click( object sender , RoutedEventArgs e )
private void btnDelTask_Click ( object sender , RoutedEventArgs e )
{
try
if ( LoadMaterial0 . SelectedIndex = = - 1 )
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
// 设置 EPPlus 许可上下文
ExcelPackage . LicenseContext = LicenseContext . NonCommercial ;
OpenFileDialog openFileDialog = new OpenFileDialog ( ) ;
openFileDialog . Filter = "Excel Files|*.xls;*.xlsx" ;
if ( openFileDialog . ShowDialog ( ) = = true )
{
FileInfo fileInfo = new FileInfo ( openFileDialog . FileName ) ;
MessageBox . Show ( "请选择要删除的任务!" ) ;
}
else
{
var Currentselected = LoadMaterial0 . SelectedItem as WcsTask ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
Currentselected . useFlag = 0 ;
dbContext . WcsTask . Update ( Currentselected ) ;
dbContext . SaveChanges ( ) ;
GetTask ( ) ;
}
}
/// <summary>
/// 完成任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFinishTask_Click ( object sender , RoutedEventArgs e )
{
if ( LoadMaterial0 . SelectedIndex = = - 1 )
{
MessageBox . Show ( "请选择要完成的任务!" ) ;
}
else
{
var Currentselected = LoadMaterial0 . SelectedItem as WcsTask ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
Currentselected . taskStatus = 5 ;
dbContext . WcsTask . Update ( Currentselected ) ;
dbContext . SaveChanges ( ) ;
GetTask ( ) ;
}
}
/// <summary>
/// 查询设备信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetEquip_Click ( object sender , RoutedEventArgs e )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var equipCode = lba_ThrifTtitle3 . Text ;
var data = dbContext . BaseEquip . Where ( t = > t . useFlag = = 1 & & t . equipNo . Contains ( equipCode ) ) . ToList ( ) ;
this . LoadMaterial3 . ItemsSource = null ;
this . LoadMaterial3 . ItemsSource = data ;
this . LoadMaterial3 . Items . Refresh ( ) ;
if ( data . Count = = 0 )
{
MessageBox . Show ( "未查询到数据" ) ;
}
}
/// <summary>
/// 查询库存信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetStocK_Click ( object sender , RoutedEventArgs e )
{
using ( ExcelPackage package = new ExcelPackage ( fileInfo ) )
{
@ -422,12 +258,12 @@ namespace Khd.Core.Wpf.Form
// 映射数据库字段,这里需要根据你的实际需求进行调整
var columnMappings = new Dictionary < string , string >
{
// 添加映射
{ columnHeaders [ 0 ] , "production_sequence" } ,
{ columnHeaders [ 1 ] , "line_code" } ,
{ columnHeaders [ 3 ] , "prod_code" } ,
{ columnHeaders [ 4 ] , "Quantity" } ,
{ columnHeaders [ 5 ] , "order_code" }
// 添加映射
{ columnHeaders [ 0 ] , "production_sequence" } ,
{ columnHeaders [ 1 ] , "line_code" } ,
{ columnHeaders [ 3 ] , "prod_code" } ,
{ columnHeaders [ 4 ] , "Quantity" } ,
{ columnHeaders [ 5 ] , "order_code" }
} ;
int ordernum = 0 ;
// 获取实际的行数和列数
@ -486,158 +322,255 @@ namespace Khd.Core.Wpf.Form
}
catch ( Exception ex )
{
MessageBox . Show ( $"订单导入失败 >>> {ex.Message}" , "订单导入操作提示!" ) ;
LogManager . Info ( $"按钮订单导入事件报错 >>> {ex.Message}" ) ;
MessageBox . Show ( "未查询到数据" ) ;
}
}
/// <summary>
/// 接收到载具号后,清空残留信息
/// 删除指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CarNo_TextChanged( object sender , TextChang edEventArgs e )
private void btnDelCmd_Click( object sender , Rout edEventArgs e )
{
//if (!string.IsNullOrWhiteSpace(this.tBoxMessage.Text) && this.tBoxMessage.Text.Length == 17)
//{
// //清空缓存信息
// this.CarNo.Clear();
// this.tBoxMessage.Clear();
// this.lba_ThrifTtitle.Text = string.Empty;
//}
}
/// <summary>
/// 订单清空按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_ClearOrder_Click ( object sender , RoutedEventArgs e )
{
try
if ( LoadMaterial . SelectedIndex = = - 1 )
{
var data = this . LoadMaterial . ItemsSource ;
if ( data = = null )
{
MessageBox . Show ( $"当前订单信息为空,无需清空操作!" , "订单手动清空提示!" ) ;
return ;
}
if ( MessageBox . Show ( "确认是否清空当前预存订单?" ,
"订单手动清空提示" ,
MessageBoxButton . YesNo , MessageBoxImage . Information ) = = MessageBoxResult . Yes )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
string sqlQuery = @ "INSERT INTO
base_production_order_split_bak
( id , site_code , line_code , line_name , order_code , prod_code , prod_desc , IsOver , est , Quantity , production_sequence )
SELECT
id , site_code , line_code , line_name , order_code , prod_code , prod_desc , IsOver , est , Quantity , production_sequence
FROM base_production_order_split ; ";
string sqlDelete = @ "Delete
FROM
base_production_order_split ; ";
var ret = dbContext . Database . ExecuteSqlRaw ( sqlQuery ) ;
dbContext . Database . ExecuteSqlRaw ( sqlDelete ) ;
string zhandianText = ThriftConfig . UpSite = = "k46" ? "K46" : "K48" ;
string saveLog = ret = = 0 ? "清空后备份任务SQL执行失败!" : "清空后备份任务SQL语句执行成功!" ;
if ( ret ! = 0 ) MessageBox . Show ( $"{ret}条订单清空完毕!" , "订单清空提示!" ) ;
LogManager . Info ( $"手动清空任务日志记录 >>> 站点:{zhandianText}{saveLog}" ) ;
this . LoadMaterial . ItemsSource = null ;
//LoadMaterial_GetMessage("");
}
}
catch ( Exception ex )
{
LogManager . Info ( $"手动清空任务方法报错 >>> {ex.Message}" ) ;
}
}
private void Button_Click_1 ( object sender , RoutedEventArgs e )
{
try
{
/ /
}
catch ( Exception ex )
{
MessageBox . Show ( "查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex ) ;
LogManager . Info ( "查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex ) ;
}
}
/// <summary>
/// 选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MoHuChaXunWuLiaoName_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
timerjilu = sender ;
ComboBox comboBox = ( ComboBox ) sender ;
var shangjiandian = comboBox . SelectedItem ;
string numberPart = Regex . Match ( shangjiandian . ToString ( ) , @"\d+" ) . Value ;
try
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
/ /
}
catch ( Exception ex )
{
MessageBox . Show ( "查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex ) ;
LogManager . Info ( "查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex ) ;
}
}
/// <summary>
/// 删除物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click_2 ( object sender , RoutedEventArgs e )
{
if ( LoadMaterial0 . SelectedIndex = = - 1 )
{
MessageBox . Show ( "请选择要删除的物料!" ) ;
MessageBox . Show ( "请选择要删除的指令!" ) ;
}
else
{
var quere = MessageBox . Show ( "确定删除吗" , "提示" , MessageBoxButton . OKCancel , MessageBoxImage . Asterisk ) ;
/ /
var Currentselected = LoadMaterial . SelectedItem as WcsCmd ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
Currentselected . useFlag = 0 ;
dbContext . WcsCmd . Update ( Currentselected ) ;
dbContext . SaveChanges ( ) ;
GetWcsCmd ( ) ;
}
}
/// <summary>
/// 刷新产线
/// 重发指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click_3 ( object sender , RoutedEventArgs e )
private void btnReSendCmd_Click ( object sender , RoutedEventArgs e )
{
/ /
if ( LoadMaterial . SelectedIndex = = - 1 )
{
MessageBox . Show ( "请选择要重发的指令!" ) ;
}
else
{
var Currentselected = LoadMaterial . SelectedItem as WcsCmd ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
Currentselected . sendFlag = 0 ;
dbContext . WcsCmd . Update ( Currentselected ) ;
dbContext . SaveChanges ( ) ;
GetWcsCmd ( ) ;
}
}
/// <summary>
/// 物料选择事件
/// 呼叫料箱
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void shangjianwuliaocombox_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
/ /
}
private void orderselect_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
}
private void Button_Click ( object sender , RoutedEventArgs e )
private void btnCallBox_Click ( object sender , RoutedEventArgs e )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var data = dbContext . WcsTask . Where ( t = > t . useFlag = = 0 ) . ToList ( ) ;
this . LoadMaterial0 . ItemsSource = null ;
this . LoadMaterial0 . ItemsSource = data ;
this . LoadMaterial0 . Items . Refresh ( ) ;
//MessageBox.Show("查询");
if ( int . TryParse ( txtNum . Text , out int num ) )
{
//目的地
var endEquip = dbContext . BaseEquip . Where ( t = > t . equipNo = = "FL05" ) . FirstOrDefault ( ) ;
//所有辅料库位
var wmsBaseLocation = dbContext . WmsBaseLocation . Where ( t = > t . warehouseId = = 5 ) . ToList ( ) ; //五楼辅料库
//有库存的库位
var wmsStock = dbContext . WcsStock . Where ( t = > t . useFlag = = 1 ) . Select ( t = > t . locationCode ) . ToList ( ) ;
var EmptyBox = wmsBaseLocation . Where ( t = > ! t . locationCode . Contains ( wmsStock ) ) . ToList ( ) ;
for ( int i = 0 ; i < num ; i + + )
{
var wcsTask = new WcsTask ( )
{
objid = Global . SnowId . NextId ( ) ,
startPointId = EmptyBox [ i ] . locationId ,
startPointNo = EmptyBox [ i ] . agvPositionCode ,
currPointId = EmptyBox [ i ] . locationId ,
currPointNo = EmptyBox [ i ] . agvPositionCode ,
nextPointId = endEquip . objid ,
nextPointNo = endEquip . equipNo ,
endPointId = endEquip . objid ,
endPointNo = endEquip . equipNo ,
taskType = 13 ,
taskStatus = 0 ,
floorNo = 5 ,
containerNo = EmptyBox [ i ] . containerCode ,
equipmentNo = endEquip . equipNo ,
createBy = "5楼呼叫料箱任务" ,
createTime = System . DateTime . Now ,
} ;
dbContext . Add ( wcsTask ) ;
dbContext . SaveChanges ( ) ;
}
}
else
{
MessageBox . Show ( "请输入有效的数字" ) ;
}
}
/// <summary>
/// 料箱扫描
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtBox_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . Key = = Key . Enter )
{
txtBarCode . Focus ( ) ;
}
}
/// <summary>
/// 条码扫描
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtBarCode_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . Key = = Key . Enter )
{
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var mesInfo = dbContext . MesBaseBarcodeInfo . Where ( t = > t . barcodeInfo = = txtBarCode . Text ) . FirstOrDefault ( ) ;
if ( mesInfo = = null )
{
MessageBox . Show ( "请扫描正确的条码" ) ;
return ;
}
barcodeinfo barcodeinfo = new barcodeinfo ( ) ;
barcodeinfo . barcode = txtBarCode . Text ;
barcodeinfo . materialId = mesInfo . materialId ;
barcodeinfo . qty = mesInfo . amount ;
barcodeLsit . Add ( barcodeinfo ) ;
txtBarCode . SelectAll ( ) ;
txtBarCode . Focus ( ) ;
txtScan . Text = $"已扫描{barcodeLsit.Count}个" ;
}
}
/// <summary>
/// 确认
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnConfirmBox_Click ( object sender , RoutedEventArgs e )
{
var box = txtBox . Text ;
if ( string . IsNullOrEmpty ( box ) )
{
MessageBox . Show ( "容器号不能为空!" ) ;
return ;
}
if ( barcodeLsit . Count = = 0 )
{
MessageBox . Show ( "未扫描条码!" ) ;
return ;
}
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
if ( cbxType . Text = = "入库" )
{
//写入wms_raw_instock
var wmsRawInstock = new WmsRawInstock ( )
{
rawInstockId = Global . SnowId . NextId ( ) ,
warehouseId = 5 ,
operationType = "3" ,
instockType = "9" ,
materialId = barcodeLsit . FirstOrDefault ( ) . materialId ,
palletInfoCode = txtBox . Text ,
instockAmount = barcodeLsit . Sum ( t = > t . qty ) ,
executeStatus = "0" ,
applyBy = "扫描入库" ,
applyDate = System . DateTime . Now
} ;
dbContext . WmsRawInstock . Add ( wmsRawInstock ) ;
dbContext . SaveChanges ( ) ;
var startEquip = dbContext . BaseEquip . Where ( t = > t . equipNo = = "FL05" ) . FirstOrDefault ( ) ;
var warehouse = dbContext . WmsBaseWarehouse . Where ( t = > t . warehouseId = = 5 ) . FirstOrDefault ( ) ;
//写入wcs任务
var wcsTask = new WcsTask ( )
{
objid = Global . SnowId . NextId ( ) ,
startPointId = startEquip . objid ,
startPointNo = startEquip . agvPositionCode ,
currPointId = startEquip . objid ,
currPointNo = startEquip . agvPositionCode ,
nextPointId = warehouse . warehouseId ,
nextPointNo = warehouse . warehouseCode ,
endPointId = warehouse . warehouseId ,
endPointNo = warehouse . warehouseCode ,
taskType = 4 ,
taskStatus = 0 ,
floorNo = 5 ,
containerNo = txtBox . Text ,
equipmentNo = startEquip . equipNo ,
createBy = "5楼入库任务" ,
createTime = System . DateTime . Now ,
} ;
dbContext . Add ( wcsTask ) ;
dbContext . SaveChanges ( ) ;
}
if ( cbxType . Text = = "出库" )
{
//从料箱里拿出来
}
if ( cbxType . Text = = "回库" )
{
//写入wms_raw_instock
var wmsRawInstock = new WmsRawInstock ( )
{
rawInstockId = Global . SnowId . NextId ( ) ,
warehouseId = 5 ,
operationType = "3" ,
instockType = "9" ,
materialId = barcodeLsit . FirstOrDefault ( ) . materialId ,
palletInfoCode = txtBox . Text ,
instockAmount = barcodeLsit . Sum ( t = > t . qty ) ,
executeStatus = "0" ,
applyBy = "扫描回库" ,
applyDate = System . DateTime . Now
} ;
dbContext . WmsRawInstock . Add ( wmsRawInstock ) ;
dbContext . SaveChanges ( ) ;
var startEquip = dbContext . BaseEquip . Where ( t = > t . equipNo = = "FL05" ) . FirstOrDefault ( ) ;
var warehouse = dbContext . WmsBaseWarehouse . Where ( t = > t . warehouseId = = 5 ) . FirstOrDefault ( ) ;
//写入wcs任务
var wcsTask = new WcsTask ( )
{
objid = Global . SnowId . NextId ( ) ,
startPointId = startEquip . objid ,
startPointNo = startEquip . agvPositionCode ,
currPointId = startEquip . objid ,
currPointNo = startEquip . agvPositionCode ,
nextPointId = warehouse . warehouseId ,
nextPointNo = warehouse . warehouseCode ,
endPointId = warehouse . warehouseId ,
endPointNo = warehouse . warehouseCode ,
taskType = 4 ,
taskStatus = 0 ,
floorNo = 5 ,
containerNo = txtBox . Text ,
equipmentNo = startEquip . equipNo ,
createBy = "5楼回库任务" ,
createTime = System . DateTime . Now ,
} ;
dbContext . Add ( wcsTask ) ;
dbContext . SaveChanges ( ) ;
}
}
}