@ -3,7 +3,6 @@ using System;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Threading ;
using System.Windows.Controls ;
using System.Windows.Input ;
using System.Windows.Media ;
@ -13,22 +12,22 @@ using Masuit.Tools.Logging;
using Microsoft.Extensions.Hosting ;
using Microsoft.Extensions.DependencyInjection ;
using Khd.Core.EntityFramework ;
using Khd.Core.Plc.S7 ;
using Khd.Core.Wpf ;
using Thrift.Server ;
using Thrift.Transport ;
using ThriftService ;
using Thrift.Protocol ;
using Khd.Core.Domain.Models ;
using Z.EntityFramework.Plus ;
using Khd.Core.Wpf.Form ;
using OfficeOpenXml ;
using Microsoft.Win32 ;
using System.IO ;
using AngleSharp.Dom ;
using System.Windows ;
using Masuit.Tools ;
using Microsoft.EntityFrameworkCore ;
using System.Text.RegularExpressions ;
using Khd.Core.Plc.S7 ;
namespace XGL.FormItem
namespace Khd.Core.Wpf.For m
{
/// <summary>
/// FormBoard.xaml 的交互逻辑
@ -36,14 +35,10 @@ namespace XGL.FormItem
public partial class FormBoard : Window
{
private readonly IHost _host ;
private Plc _plc ;
/// <summary>
/// 时间刷新计时器
/// </summary>
private Khd . Core . Plc . S7 . Plc _plc ;
private DispatcherTimer ShowTimer ; //刷新时间
private DispatcherTimer PLCMessage ; //呈现PLC机柜信息
private DispatcherTimer ShowOrderMessage ; //呈现PLC机柜信息
private object order_code ;
private int UpState ; //对应上件站点的状态,0为良好 1为损坏
//FormShowSelect formSelect;
@ -66,21 +61,19 @@ namespace XGL.FormItem
{
try
{
LogManager . Info ( $"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;" ) ;
//设置显示任务栏
if ( WindowState = = WindowState . Normal )
{
MaxHeight = SystemParameters . MaximizedPrimaryScreenHeight ;
WindowState = WindowState . Maximized ;
}
//加载dategrid信息
LoadMaterial_GetMessage ( "" ) ;
//连接PLC判断
var plc = new Khd . Core . Plc . S7 . Plc ( ( CpuType ) PlcConfig . CpuType , PlcConfig . IP , PlcConfig . Port ,
PlcConfig . Rack , PlcConfig . Slot ) ;
plc . Open ( ) ;
// plc.Open();
if ( ! plc . IsConnected )
{
MessageBox . Show ( "PLC连接失败,重新连接" ) ;
@ -90,68 +83,68 @@ namespace XGL.FormItem
this . _plc = plc ;
}
ShowTimer = new System . Windows . Threading . DispatcherTimer ( ) ;
ShowTimer . Tick + = new EventHandler ( ShowCurTimer ) ; //起个Timer一直获取当前时间
ShowTimer . Interval = new TimeSpan ( 0 , 0 , 0 , 1 , 0 ) ;
ShowTimer . Start ( ) ;
//ShowTimer = new System.Windows.Threading.DispatcherTimer() ;
//ShowTimer.Tick += new EventHandler(ShowCurTimer); //起个Timer一直获取当前时间
//ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0) ;
//ShowTimer.Start() ;
#region 测试client, 调用wcs服务端
// #region 测试client, 调用wcs服务端
//TTransport transport = new TSocket("localhost", 9091);
//transport.Open();
//TProtocol protocol = new TBinaryProtocol(transport);
//WcsThrift.Client client = new WcsThrift.Client(protocol);
//client.hello("Sunzy");
// //TTransport transport = new TSocket("localhost", 9091);
// //transport.Open();
// //TProtocol protocol = new TBinaryProtocol(transport);
// //WcsThrift.Client client = new WcsThrift.Client(protocol);
// //client.hello("Sunzy");
# endregion
//# endregion
//启动Thriftserver
Thread ThriftThread = new Thread ( StartThriftServer ) ; //接收服务端的推送信息
ThriftThread . IsBackground = true ;
ThriftThread . Start ( ) ;
// //启动Thriftserver
//Thread ThriftThread = new Thread(StartThriftServer); //接收服务端的推送信息
//ThriftThread.IsBackground = true ;
//ThriftThread.Start() ;
PLCMessage = new DispatcherTimer ( ) ;
PLCMessage . Tick + = new EventHandler ( PLCmessage ) ; //委托获取点位方法
PLCMessage . Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 300 ) ;
PLCMessage . Start ( ) ;
//PLCMessage = new DispatcherTimer() ;
//PLCMessage.Tick += new EventHandler(PLCmessage); //委托获取点位方法
//PLCMessage.Interval = new TimeSpan(0, 0, 0, 0, 300) ;
//PLCMessage.Start() ;
//string result = ThriftConfig.UpSite == "k46" ? " K46" : " K48";
//this.lab_Title.Content = (string)this.lab_Title.Content + result;
// //string result = ThriftConfig.UpSite == "k46" ? " K46" : " K48";
// //this.lab_Title.Content = (string)this.lab_Title.Content + result;
//载具到位状态
this . labzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . imgzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . labzjwdw . Visibility = System . Windows . Visibility . Visible ;
this . imgzjwdw . Visibility = System . Windows . Visibility . Visible ;
// //载具到位状态
//this.labzjydw.Visibility = System.Windows.Visibility.Hidden ;
//this.imgzjydw.Visibility = System.Windows.Visibility.Hidden ;
//this.labzjwdw.Visibility = System.Windows.Visibility.Visible ;
//this.imgzjwdw.Visibility = System.Windows.Visibility.Visible ;
if ( ThriftConfig . UpSite = = "k48" )
{
this . spl_sunhuaizhakoumianban . Visibility = System . Windows . Visibility . Visible ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var getFlagState = dbContext . BaseAmima . Where ( t = > t . name = = "UpState" ) . FirstOrDefault ( ) ;
if ( getFlagState ! = null )
{
int zhuangtai = getFlagState . password = = "2" ? 2 : 1 ;
string quxiang = getFlagState . direction = = 1 ? "直通" : "弯通" ;
if ( zhuangtai = = 2 )
{
this . lab_shangjiandianzhuangtai . Content = "上件点正常!K22按照任务线别方向流转." ;
this . lab_shangjiandianzhuangtai . Foreground = new SolidColorBrush ( Colors . Green ) ;
this . spl_sunhuaizhakouquxiang . Visibility = System . Windows . Visibility . Hidden ;
}
else
{
this . lab_shangjiandianzhuangtai . Content = $"上件点损坏!人工维护去向:{quxiang}" ;
this . lab_shangjiandianzhuangtai . Foreground = new SolidColorBrush ( Colors . Red ) ;
this . spl_sunhuaizhakouquxiang . Visibility = System . Windows . Visibility . Visible ;
}
}
}
else
{
this . spl_sunhuaizhakoumianban . Visibility = System . Windows . Visibility . Hidden ;
}
//if (ThriftConfig.UpSite == "k48" )
// {
// this.spl_sunhuaizhakoumianban.Visibility = System.Windows.Visibility.Visible;
// using var scope = _host.Services.CreateScope();
// using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
// var getFlagState = dbContext.BaseAmima.Where(t => t.name == "UpState").FirstOrDefault();
// if (getFlagState != null)
// {
// int zhuangtai = getFlagState.password == "2" ? 2 : 1;
// string quxiang = getFlagState.direction == 1 ? "直通" : "弯通";
// if (zhuangtai == 2)
// {
// this.lab_shangjiandianzhuangtai.Content = "上件点正常!K22按照任务线别方向流转.";
// this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Green);
// this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Hidden;
// }
// else
// {
// this.lab_shangjiandianzhuangtai.Content = $"上件点损坏!人工维护去向:{quxiang}";
// this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Red);
// this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible;
// }
// }
// }
// else
// {
// this.spl_sunhuaizhakoumianban.Visibility = System.Windows.Visibility.Hidden;
// }
}
catch ( Exception ex )
@ -164,14 +157,14 @@ namespace XGL.FormItem
{
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 ( ) ;
//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 )
{
@ -179,7 +172,7 @@ namespace XGL.FormItem
delegate
{
//设置图片为未到位
this . CarNo . Clear( ) ;
this . CarNo . Text = "Null" ;
this . labzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . imgzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . labzjwdw . Visibility = System . Windows . Visibility . Visible ;
@ -214,6 +207,7 @@ namespace XGL.FormItem
delegate
{
//设置图片为未到位
//this.CarNo.Clear();
this . labzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . imgzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . labzjwdw . Visibility = System . Windows . Visibility . Visible ;
@ -233,8 +227,7 @@ namespace XGL.FormItem
/// </summary>
/// <param name="carlist"></param>
/// <param name="order_code">Vin条码号</param>
/// <param name="amount">三轮车辆长度</param>
public void SendCar ( List < string > carlist , string order_code , string amount )
public void SendCar ( List < string > carlist , string order_code )
{
TTransport transport = new TSocket ( ThriftConfig . ThriftIpAddress , ThriftConfig . TuiSongDuankou ) ;
try
@ -244,37 +237,37 @@ namespace XGL.FormItem
transport . Open ( ) ;
TProtocol protocol = new TBinaryProtocol ( transport ) ;
WcsThrift . Client client = new WcsThrift . Client ( protocol ) ;
var ret = client . SendCar ( carlist , order_code , amount ) ;
if ( ret = = "1" ) //与服务端交互成功发车时
{
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
//发车成功提示反馈
this . lba_ThrifTtitle . Foreground = new SolidColorBrush ( Colors . Green ) ;
this . lba_ThrifTtitle . Content = "发车成功!" ;
//设置为未到位
this . labzjwdw . Visibility = System . Windows . Visibility . Visible ;
this . imgzjwdw . Visibility = System . Windows . Visibility . Visible ;
this . labzjydw . Visibility = System . Windows . Visibility . Hidden ;
this . imgzjydw . Visibility = System . Windows . Visibility . Hidden ;
} ) ) ;
}
else //与服务端交互失败时
{
//var ret = client.SendCar(carlist, order_code, order_code) ;
//if (ret == "1") //与服务端交互成功发车时
// {
// Application.Current.Dispatcher.Invoke(new Action(
// delegate
// {
// //发车成功提示反馈
// this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Green);
// this.lba_ThrifTtitle.Content = "发车成功!";
// //设置为未到位
// this.labzjwdw.Visibility = System.Windows.Visibility.Visible;
// this.imgzjwdw.Visibility = System.Windows.Visibility.Visible;
// this.labzjydw.Visibility = System.Windows.Visibility.Hidden;
// this.imgzjydw.Visibility = System.Windows.Visibility.Hidden;
// }));
// }
//else //与服务端交互失败时
// {
Application . Current . Dispatcher . Invoke ( new Action (
delegate
{
this . lba_ThrifTtitle . Foreground = new SolidColorBrush ( Colors . Red ) ;
this . lba_ThrifTtitle . Content = $"Thrift交互失败!" ;
//发车失败依然显示到位
this . labzjwdw . Visibility = System . Windows . Visibility . Hidden ;
this . imgzjwdw . Visibility = System . Windows . Visibility . Hidden ;
this . labzjydw . Visibility = System . Windows . Visibility . Visible ;
this . imgzjydw . Visibility = System . Windows . Visibility . Visible ;
} ) ) ;
}
// Application.Current.Dispatcher.Invoke(new Action(
// delegate
// {
// this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Red);
// this.lba_ThrifTtitle.Content = $"Thrift交互失败!";
// //发车失败依然显示到位
// this.labzjwdw.Visibility = System.Windows.Visibility.Hidden;
// this.imgzjwdw.Visibility = System.Windows.Visibility.Hidden;
// this.labzjydw.Visibility = System.Windows.Visibility.Visible;
// this.imgzjydw.Visibility = System.Windows.Visibility.Visible;
// }));
// }
}
catch ( Exception ex )
{
@ -316,11 +309,15 @@ namespace XGL.FormItem
/// <param name="e"></param>
private void btnExit_Click ( object sender , RoutedEventArgs e )
{
if ( MessageBox . Show ( "是否确认关闭程序" , "提示信息" , MessageBoxButton . YesNo , MessageBoxImage . Information ) = = MessageBoxResult . No )
{
//if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No )
// {
}
else
//}
//else
//{
// System.Environment.Exit(System.Environment.ExitCode);
//}
if ( MessageBox . Show ( "是否确认关闭程序" , "提示信息" , MessageBoxButton . YesNo , MessageBoxImage . Information ) = = MessageBoxResult . Yes )
{
System . Environment . Exit ( System . Environment . ExitCode ) ;
}
@ -830,8 +827,6 @@ namespace XGL.FormItem
{
}
}
/// <summary>
/// 使用DataTable当做数据传递中介向DataGrid中传输数据源
/// </summary>
@ -850,10 +845,10 @@ namespace XGL.FormItem
IsOver AS isover
FROM base_production_order_split
{ pjsql }
ORDER BY est , IsOver ";
ORDER BY IsOver , est ; ";
var QueryOrder = dbContext . ExecuteSqlQuery < BaseProductionOrderSplit > ( sql ) ;
#region 注释代码折叠
// ($@"SELECT
// string sql = ($@"SELECT
// a.line_code AS lineCode,
@ -871,7 +866,7 @@ namespace XGL.FormItem
// LEFT JOIN base_waitdownline b
// ON a.order_code = b.materiel_no { sql} ORDER BY est ,IsOver ");
// ON a.order_code = b.materiel_no { pj sql} ORDER BY est ,IsOver ");
//var QueryOrder = dbContext.BaseProductionOrderSplit.OrderBy(t => t.est).OrderBy(t => t.isover).ToList();
# endregion
if ( QueryOrder ? . Count > 0 )
@ -892,11 +887,14 @@ namespace XGL.FormItem
dr [ "isover" ] = i . isover . ToString ( ) ;
switch ( i . isover )
{
case 1 :
dr [ "isover" ] = "已完成" ;
break ;
case 0 :
dr [ "isover" ] = "未完成" ;
dr [ "isover" ] = "未上线" ;
break ;
case 1 :
dr [ "isover" ] = "已上线" ;
break ;
case 2 :
dr [ "isover" ] = "已完成" ;
break ;
default :
dr [ "isover" ] = "状态错误!" ;
@ -904,7 +902,7 @@ namespace XGL.FormItem
}
dt . Rows . Add ( dr ) ;
}
this . LoadMaterial . ItemsSource = dt . DefaultView ;
this . LoadMaterial . ItemsSource = dt . DefaultView ;
this . LoadMaterial . Items . Refresh ( ) ;
}
}
@ -944,14 +942,14 @@ namespace XGL.FormItem
/// <param name="e"></param>
private void Btn_shangjiansunhuai_Click ( object sender , RoutedEventArgs e )
{
this . spl_sunhuaizhakouquxiang . Visibility = System . Windows . Visibility . Visible ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
dbContext . BaseAmima . Where ( t = > t . name = = "UpState" ) . Update ( a = > new BaseAmima ( ) { password = "1" } ) ;
var data = dbContext . BaseAmima . Where ( t = > t . name = = "UpState" ) . FirstOrDefault ( ) ;
string quxiang = data . direction = = 1 ? "直通" : "弯通" ;
this . lab_shangjiandianzhuangtai . Content = $"上件点状态:损坏!K22固定去向:" + quxiang ;
this . lab_shangjiandianzhuangtai . Foreground = new SolidColorBrush ( Colors . Red ) ;
//this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible ;
//using var scope = _host.Services.CreateScope() ;
//using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>() ;
//dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { password = "1" }) ;
//var data = dbContext.BaseAmima.Where(t => t.name == "UpState").FirstOrDefault() ;
//string quxiang = data.direction == 1 ? "直通" : "弯通" ;
//this.lab_shangjiandianzhuangtai.Content = $"上件点状态:损坏!K22固定去向:" + quxiang ;
//this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Red) ;
}
/// <summary>
/// 上件点状态良好确认按钮点击事件
@ -965,7 +963,7 @@ namespace XGL.FormItem
this . lab_shangjiandianzhuangtai . Content = $"上件点状态:正常!K22走任务线别去向!" ;
this . lab_shangjiandianzhuangtai . Foreground = new SolidColorBrush ( Colors . Green ) ;
this . spl_sunhuaizhakouquxiang . Visibility = System . Windows . Visibility . Hidden ;
dbContext . BaseAmima . Where ( t = > t . name = = "UpState" ) . Update ( a = > new BaseAmima ( ) { password = "2" } ) ;
// dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { password = "2" });
}
/// <summary>
/// 上件点状态维护损坏后固定K22去向1
@ -974,11 +972,11 @@ namespace XGL.FormItem
/// <param name="e"></param>
private void Btn_K22QuXiang1_Click ( object sender , RoutedEventArgs e )
{
this . spl_sunhuaizhakouquxiang . Visibility = System . Windows . Visibility . Visible ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
dbContext . BaseAmima . Where ( t = > t . name = = "UpState" ) . Update ( a = > new BaseAmima ( ) { direction = 1 } ) ;
Btn_shangjiansunhuai_Click ( null , null ) ;
//this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible ;
//using var scope = _host.Services.CreateScope() ;
//using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>() ;
//dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { direction = 1 }) ;
//Btn_shangjiansunhuai_Click(null, null) ;
}
/// <summary>
@ -991,7 +989,7 @@ namespace XGL.FormItem
this . spl_sunhuaizhakouquxiang . Visibility = System . Windows . Visibility . Visible ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
dbContext . BaseAmima . Where ( t = > t . name = = "UpState" ) . Update ( a = > new BaseAmima ( ) { direction = 2 } ) ;
//dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { direction = 2 }) ;
Btn_shangjiansunhuai_Click ( null , null ) ;
}
/// <summary>
@ -1019,27 +1017,26 @@ namespace XGL.FormItem
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
string VinResult = this . tBoxMessage . Text . Trim ( ) . ToUpper ( ) . ToString ( ) ;
if ( string . IsNullOrWhiteSpace ( VinResult ) )
{
return ;
}
var orderModel = dbContext . BaseProductionOrderSplit . Where ( t = > t . orderCode = = VinResult ) . FirstOrDefault ( ) ;
if ( orderModel = = null )
{
return ;
}
var waitdownlineModel = dbContext . BaseWaitdownline . Where ( t = > t . definefield1 = = orderModel . lineCode ) . ToList ( ) ;
int FlagNum = waitdownlineModel . Count ( ) ;
if ( FlagNum > = FlagConfig . UpFlagNum )
{
//如果上件数量大于等于设置的闸口数量时
SolidColorBrush myBrush = new SolidColorBrush ( ) ;
myBrush . Color = System . Windows . Media . Color . FromRgb ( 255 , 130 , 0 ) ; // 设置RGB值为(255, 0, 0)(红色)
this . lba_ThrifTtitle . Foreground = myBrush ;
this . lba_ThrifTtitle . Content = $"上线数量:{FlagNum}>=缓存数量:{FlagConfig.UpFlagNum},限制发车!" ;
LogManager . Info ( $"当前时间:{DateTime.Now},物料:{orderModel.orderCode},线别:{orderModel.lineCode},数量:{FlagNum} >= 缓存数量:{FlagConfig.UpFlagNum},限制发车操作!" ) ;
return ;
}
//var orderModel = dbContext.BaseProductionOrderSplit.Where(t => t.orderCode == VinResult).FirstOrDefault();
//if (orderModel == null)
//{
// MessageBox.Show($"该VIN条码:{VinResult}未搜索到对应订单!");
// return;
//}
//if (orderModel.isover != 0)
//{
// if (orderModel.isover == 1) MessageBox.Show($"该Vin条码:{VinResult}对应订单已上线!", "发车错误提示!");
// if (orderModel.isover == 2) MessageBox.Show($"该Vin条码:{VinResult}对应订单已下线完成!", "发车错误提示!");
// return;
//}
// var waitdownlineModel = dbContext.BaseWaitdownline.Where(t => t.definefield1 == orderModel.lineCode).ToList();
//int FlagNum = waitdownlineModel.Count();
//if (FlagNum >= FlagConfig.UpFlagNum)
//{
// MessageBox.Show($"已上线数量:{FlagNum}>=缓存闸口设置数量:{FlagConfig.UpFlagNum},限制发车操作!", "发车错误提示!");
// LogManager.Info($"当前时间:{DateTime.Now},物料:{orderModel.orderCode},线别:{orderModel.lineCode},数量:{FlagNum} >= 缓存数量:{FlagConfig.UpFlagNum},限制发车操作!");
// return;
//}
string sqlQuery = @ $ "
SELECT
b1 . material_no AS materialNo ,
@ -1070,26 +1067,37 @@ namespace XGL.FormItem
# endregion
if ( QueryOrder ? . Count = = 0 )
{
MessageBox . Show ( $" Vin:{VinResult}不存在对应车型长度", "发车操作 提示!") ;
MessageBox . Show ( $" 未查找到Vin:{VinResult}对应车型", "发车错误 提示!") ;
return ;
}
string changduText = ThriftConfig . UpSite = = "k46" ? QueryOrder [ 0 ] . k46upLength : QueryOrder [ 0 ] . k48upLength ;
changduText = changduText = = "" ? "Null" : changduText ;
string zhandianText = ThriftConfig . UpSite = = "k46" ? "K46" : "K48" ;
this . tbx_CheLiangChangDu . Text = changduText ;
string CarLengthResult = this . tbx_CheLiangChangDu . Text . Trim ( ) . ToString ( ) ;
if ( ! string . IsNullOrWhiteSpace ( CarLengthResult ) & & ! string . IsNullOrWhiteSpace ( VinResult ) )
if ( string . IsNullOrWhiteSpace ( changduText ) )
{
List < string > carList = new List < string >
{
$"上件站点 >>> {zhandianText}"
} ;
SendCar ( carList , VinResult , CarLengthResult ) ;
LogManager . Info ( $"当前时间;{DateTime.Now},发车方法调用记录 >>> 上件站点:{carList[0]} , Vin条码号:{VinResult},车身长度:{CarLengthResult}" ) ;
carList . Clear ( ) ;
this . LoadMaterial . ItemsSource = null ;
LoadMaterial_GetMessage ( "" ) ;
MessageBox . Show ( $"未查找到Vin:{VinResult}对应车型长度" , "发车错误提示!" ) ;
return ;
}
string carId = this . CarNo . Text ;
if ( string . IsNullOrWhiteSpace ( carId ) )
{
MessageBox . Show ( $"挂具号为空!" , "发车错误提示!" ) ;
return ;
}
string zhandianText = ThriftConfig . UpSite = = "k46" ? "K46" : "K48" ;
List < string > carList = new ( )
{
$"上件站点 >>> {zhandianText}"
} ;
SendCar ( carList , VinResult ) ;
LogManager . Info ( $"当前时间;{DateTime.Now},发车方法调用记录 >>> 挂具ID:{carId},上件站点:{carList[0]} , Vin条码号:{VinResult},车身长度:{changduText}" ) ;
carList . Clear ( ) ;
//this.LoadMaterial.Items.Refresh();
this . LoadMaterial . ItemsSource = null ;
LoadMaterial_GetMessage ( "" ) ;
}
else if ( this . tBoxMessage . Text . Trim ( ) . Length < 17 & & e . Key = = Key . Enter )
{
MessageBox . Show ( $"输入Vin条码:{this.tBoxMessage.Text.Trim()}长度有误!" ) ;
return ;
}
}
catch ( Exception ex )
@ -1107,107 +1115,111 @@ namespace XGL.FormItem
try
{
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 ) ;
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 ) ;
using ( ExcelPackage package = new ExcelPackage ( fileInfo ) )
{
ExcelWorksheet worksheet = package . Workbook . Worksheets . FirstOrDefault ( ) ;
using ( ExcelPackage package = new ExcelPackage ( fileInfo ) )
{
ExcelWorksheet worksheet = package . Workbook . Worksheets . FirstOrDefault ( ) ;
if ( worksheet ! = null )
{
// 获取 Excel 表头
var columnHeaders = worksheet . Cells [ 1 , 1 , 1 , worksheet . Dimension . End . Column ]
. Select ( cell = > cell . Text )
. ToList ( ) ;
BaseProductionOrderSplit orderMoedel = new ( ) ;
// 映射数据库字段,这里需要根据你的实际需求进行调整
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" }
} ;
int ordernum = 0 ;
// 遍历 Excel 数据行
for ( int row = 2 ; row < = worksheet . Dimension . End . Row ; row + + )
{
// 创建 SQL 插入语句
//string insertCommand = $"INSERT INTO YourTableName ({string.Join(", ", columnMappings.Values)}) VALUES (";
List < string > values = new ( ) ;
if ( worksheet ! = null )
{
// 获取 Excel 表头
var columnHeaders = worksheet . Cells [ 1 , 1 , 1 , worksheet . Dimension . End . Column ]
. Select ( cell = > cell . Text )
. ToList ( ) ;
BaseProductionOrderSplit orderMoedel = new ( ) ;
// 映射数据库字段,这里需要根据你的实际需求进行调整
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" }
} ;
int ordernum = 0 ;
// 获取实际的行数和列数
int rowCount = worksheet . Dimension . Rows ;
int colCount = worksheet . Dimension . Columns ;
// 遍历 Excel 数据行
for ( int row = 2 ; row < = rowCount ; row + + )
{
// 创建 SQL 插入语句
//string insertCommand = $"INSERT INTO YourTableName ({string.Join(", ", columnMappings.Values)}) VALUES (";
List < string > values = new ( ) ;
// 遍历 Excel 数据列
for ( int col = 1 ; col < = colCount ; col + + )
{
string columnName = columnHeaders [ col - 1 ] ;
string databaseColumnName ;
// 映射 Excel 列名到数据库列名
if ( columnMappings . TryGetValue ( columnName , out databaseColumnName ) )
{
// 获取 Excel 单元格的值
var cellValue = worksheet . Cells [ row , col ] . Text ;
// 添加值到插入语句
values . Add ( cellValue ) ;
//values.Add($"'{cellValue.Replace("'", "''")}'");
//if (!string.IsNullOrWhiteSpace(cellValue))
//{
// values.Add(cellValue);
//}
}
}
// 使用 LINQ 查询空值
bool containsNull = values . Any ( item = > item = = "" | | item = = null ) ;
if ( containsNull )
{
//MessageBox.Show("Excel表格中存在空值,不执行导入操作!", "订单导入操作提示!");
//LogManager.Info($"订单导入按钮事件错误 >>> Excel表格中存在空值!不执行导入操作!");
break ;
}
// 获得插入语句
//string fullInsertCommand = $"{insertCommand} {string.Join(", ", values)} )";
var xianbiename = Char . GetNumericValue ( values [ 1 ] [ values [ 1 ] . Length - 1 ] ) . ToString ( ) ;
int orderSequence = int . Parse ( values [ 0 ] . Trim ( ) ) ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
// var orderModel = dbContext.BaseProductionOrderSplit.OrderBy(t => t.productionSequence).ToList();
//var data = orderModel.Find(t => t.orderCode == values[4].Trim().ToUpper());
//if (data == null)
//{
// BaseProductionOrderSplit InserOrderModel = new()
// {
// id = Guid.NewGuid().ToString(),
// lineCode = values[1].Trim(),
// lineName = xianbiename == "1" ? "二线" : "一线",
// orderCode = values[4].Trim().ToUpper(),
// prodCode = values[2].Trim(),
// prodDesc = values[2].Trim(),
// productionSequence = orderSequence,
// est = DateTime.Now,
// isover = 0,
// quantity = 1,
// createBy = "ExcelInsert"
// };
// dbContext.Add(InserOrderModel);
// dbContext.SaveChanges();
// ordernum++;
//}
}
// 遍历 Excel 数据列
for ( int col = 1 ; col < = worksheet . Dimension . End . Column ; col + + )
{
string columnName = columnHeaders [ col - 1 ] ;
string databaseColumnName ;
// 映射 Excel 列名到数据库列名
if ( columnMappings . TryGetValue ( columnName , out databaseColumnName ) )
{
// 获取 Excel 单元格的值
var cellValue = worksheet . Cells [ row , col ] . Text ;
// 添加值到插入语句
values . Add ( cellValue ) ;
//values.Add($"'{cellValue.Replace("'", "''")}'");
//if (!string.IsNullOrWhiteSpace(cellValue))
//{
// values.Add(cellValue);
//}
}
}
// 使用 LINQ 查询空值
bool containsNull = values . Any ( item = > item = = "" | | item = = null ) ;
if ( containsNull )
{
MessageBox . Show ( "Excel表格中存在空值,不执行导入操作!" , "订单导入操作提示!" ) ;
LogManager . Info ( $"按钮订单导入事件粗无日志 >>> Excel表格中存在空值!不执行导入操作!" ) ;
continue ;
}
// 获得插入语句
//string fullInsertCommand = $"{insertCommand} {string.Join(", ", values)} )";
var xianbiename = Char . GetNumericValue ( values [ 1 ] [ values [ 1 ] . Length - 1 ] ) . ToString ( ) ;
int orderSequence = int . Parse ( values [ 0 ] . Trim ( ) ) ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
var orderModel = dbContext . BaseProductionOrderSplit . OrderBy ( t = > t . productionSequence ) . ToList ( ) ;
var data = orderModel . Find ( t = > t . orderCode = = values [ 4 ] . Trim ( ) . ToUpper ( ) ) ;
if ( data = = null )
{
BaseProductionOrderSplit InserOrderModel = new ( )
{
id = Guid . NewGuid ( ) . ToString ( ) ,
lineCode = values [ 1 ] . Trim ( ) ,
lineName = xianbiename = = "1" ? "二线" : "一线" ,
orderCode = values [ 4 ] . Trim ( ) . ToUpper ( ) ,
prodCode = values [ 2 ] . Trim ( ) ,
prodDesc = values [ 2 ] . Trim ( ) ,
productionSequence = orderSequence ,
est = DateTime . Now ,
isover = 0 ,
quantity = 1
} ;
dbContext . Add ( InserOrderModel ) ;
dbContext . SaveChanges ( ) ;
ordernum + + ;
}
}
MessageBox . Show ( $"{ordernum}条订单导入系统!" , "订单导入操作提示!" ) ;
this . LoadMaterial . ItemsSource = null ;
LoadMaterial_GetMessage ( "" ) ;
}
}
}
} ) ) ;
MessageBox . Show ( $"{ordernum}条订单导入系统!" , "订单导入操作提示!" ) ;
this . LoadMaterial . ItemsSource = null ;
LoadMaterial_GetMessage ( "" ) ;
}
}
}
} ) ) ;
}
catch ( Exception ex )
{
@ -1231,5 +1243,155 @@ namespace XGL.FormItem
this . lba_ThrifTtitle . Content = string . Empty ;
}
}
/// <summary>
/// 订单清空按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_ClearOrder_Click ( object sender , RoutedEventArgs e )
{
try
{
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}" ) ;
}
}
/// <summary>
/// 查询挂具绑定Vin物料点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_ChaXunByCarNo_Click ( object sender , RoutedEventArgs e )
{
try
{
if ( string . IsNullOrWhiteSpace ( this . tbx_JieBangByCarNo . Text ) )
{
MessageBox . Show ( "上线挂具号输入框为空!" , "查询挂具物料绑定关系操作提示!" ) ;
return ;
}
if ( ! Regex . IsMatch ( this . tbx_JieBangByCarNo . Text , @"^\d+$" ) )
{
MessageBox . Show ( "挂具号输入格式有误!" , "查询挂具物料绑定关系操作提示!" ) ;
this . tbx_JieBangByVin . Clear ( ) ;
return ;
//textBox.Text = textBox.Text.Replace("非数字字符", ""); // 移除非数字字符
}
if ( this . tbx_JieBangByCarNo . Text . Length > = 3 )
{
MessageBox . Show ( "挂具号输入长度有误!" , "查询挂具物料绑定关系操作提示!" ) ;
this . tbx_JieBangByVin . Clear ( ) ;
return ;
}
int ShuRuCarNo = int . Parse ( this . tbx_JieBangByCarNo . Text ) ;
using var scope = _host . Services . CreateScope ( ) ;
using var dbContext = scope . ServiceProvider . GetRequiredService < DefaultDbContext > ( ) ;
//var listWaitDownLine = dbContext.BaseWaitdownline.Where(t => t.isDelete == 0 && t.carNo == ShuRuCarNo).ToList();
//if (string.IsNullOrWhiteSpace(listWaitDownLine[0].materielNo))
//{
// MessageBox.Show($"{ShuRuCarNo}号为空挂具,不存在与Vin绑定信息!", "查询挂具物料绑定关系操作提示!");
// return;
//}
// var listOrder = dbContext.BaseProductionOrderSplit.Where(t => t.orderCode == listWaitDownLine[0].materielNo).ToList();
//var resultOrderList = (from waitdownline in listWaitDownLine
// join order in listOrder on waitdownline.materielNo equals order.orderCode
// select new BaseProductionOrderSplit
// {
// id = order.id,
// lineCode = order.lineCode,
// orderCode = order.orderCode
// }).ToList();
//if (resultOrderList?.Count > 0)
//{
// this.tbx_JieBangByVin.Text = resultOrderList[0].orderCode;
//}
}
catch ( Exception ex )
{
MessageBox . Show ( $"查询挂具物料绑定关系报错 >>> {ex.Message}" ) ;
LogManager . Info ( $"查询挂具物料绑定关系报错 >>> {ex.Message}" ) ;
}
}
/// <summary>
/// 解绑按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_JieBangByCarNo_Click ( object sender , RoutedEventArgs e )
{
try
{
}
catch ( Exception ex )
{
LogManager . Info ( $"解绑载具物料绑定关系操作报错 >>> {ex.Message}" ) ;
}
}
/// <summary>
/// 清空输入框点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_ChaXunByCarNoClear_Click ( object sender , RoutedEventArgs e )
{
try
{
this . tbx_JieBangByCarNo . Clear ( ) ;
this . tbx_JieBangByVin . Clear ( ) ;
}
catch ( Exception )
{
}
}
/// <summary>
/// 一键重置点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_JieBangAll_Click ( object sender , RoutedEventArgs e )
{
try
{
}
catch ( Exception EX )
{
LogManager . Info ( $"一键重置订单、挂具状态方法报错 >>> {EX.Message}" ) ;
}
}
}
}