using FrmPrint ;
using Mesnac.Compressor.Data ;
using Mesnac.Compressor.Entity ;
using Mesnac.Compressor.Unity ;
using Mesnac.HighWay.ATC.Common ;
using Mesnac.HighWay.ATC.SqlSugar.serviceImpl ;
using SqlSugar ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Linq.Expressions ;
using System.Text ;
using System.Threading.Tasks ;
namespace BarTenderPrint
{
public class PrintManager
{
public delegate void ShowMessageEvent ( string barcode ) ;
public event ShowMessageEvent RefreshShowMessageEvent ;
private static INIFile iNIFile = new INIFile ( System . AppDomain . CurrentDomain . SetupInformation . ApplicationBase + "App.InI" ) ;
public async void Print ( Print Print , List < TBDProductInfo > TBDProductInfo )
{
MLable mlb = new MLable ( ) ;
BoxLable boxlb = new BoxLable ( ) ;
barcodLable barcodelb = new barcodLable ( ) ;
string printType = "" ;
string Serialnum = "" ;
string type = "" ;
//查询机种信息
string ShiftNo = Print . Shift ;
#region 从数据库获取打印数据
try
{
if ( TBDProductInfo ! = null & & TBDProductInfo . Count > 0 )
{
//0表示正常品1表示试制品
type = TBDProductInfo [ 0 ] . ProductType ;
//打印那种标签
printType = TBDProductInfo [ 0 ] . PrintType ;
//车间字段
mlb . ShopID = TBDProductInfo [ 0 ] . ShopID ;
//日期前面是否+A
mlb . HasA = Convert . ToInt16 ( TBDProductInfo [ 0 ] . HasA ) = = 1 ;
//是否有另一处需要+时间的地方
mlb . HasDate = Convert . ToInt16 ( TBDProductInfo [ 0 ] . HasDate ) = = 1 ;
//名牌模板位置
mlb . TempName = TBDProductInfo [ 0 ] . MPTemplate . ToString ( ) ;
boxlb . MachineNam = TBDProductInfo [ 0 ] . ProductName . ToString ( ) ;
//barcodelb.ZJWeight = ZJweight;
//前缀
barcodelb . PreString = TBDProductInfo [ 0 ] . Prefix . ToString ( ) ;
barcodelb . EndString = TBDProductInfo [ 0 ] . Suffix . ToString ( ) ;
//条码模板位置
barcodelb . TempName = TBDProductInfo [ 0 ] . TMTemplate . ToString ( ) ;
//铭牌编码方式
barcodelb . codeType = TBDProductInfo [ 0 ] . CodeType . ToString ( ) ;
}
else
{
Console . WriteLine ( "未找到该机种信息" ) ;
//没绑定托盘说明70工位未绑定上线机壳
//生成
}
}
catch ( Exception ex )
{
Console . WriteLine ( "未找到该机种信息" + ex ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
#region 获取序列号
Serialnum = Print . Serialnum ;
# endregion
barcodelb . PrintType = printType ;
barcodelb . SerialNum = Serialnum ;
barcodelb . ShiftNo = ShiftNo ;
//barcodelb.Date = DateTime.Now;
//barcodelb.Date = Convert.ToDateTime(Print.starttime);
mlb . PrintType = printType ;
mlb . serialNum = Serialnum ;
mlb . ShiftNO = getShift ( ShiftNo ) ;
//mlb.Date = DateTime.Now;
//mlb.Date = Convert.ToDateTime(Print.starttime);
int itype = 0 ;
if ( ! string . IsNullOrEmpty ( printType ) )
{
itype = Convert . ToInt32 ( printType ) ;
}
//判断是否需要打印铭牌
if ( ! string . IsNullOrEmpty ( mlb . TempName ) )
{
#region 打印铭牌
try
{
//这些每个机种应该都谁确定的,在数据库里保存,以后可以一个存储过程去获取
//if (true)
//{
// ExitRePrint();
// RefreshShowMessageEvent?.Invoke(Print.barcode + "铭牌打印成功!");
// LogHelper.Info(Print.barcode + "铭牌打印成功!");
// //插库存储条码及序列号
// baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo();
// BarcodePrintInfo.ID = Guid.NewGuid().ToString("N");
// BarcodePrintInfo.ProductBarcode = Print.barcode;
// BarcodePrintInfo.ProductID = Print.Machine.ToString();
// BarcodePrintInfo.SerialNo = DateTime.Parse(Print.starttime.ToString()).ToString("yyMMdd") + "D" + Print.Shift + Serialnum;
// BarcodePrintInfo.IsRestart = Print.isRestart.ToString();
// BarcodePrintInfo.ShiftID = ShiftNo;
// BarcodePrintInfo.InsertTime = DateTime.Now;
// await new BaseServices<baseBarcodePrintInfo>().Add(BarcodePrintInfo);
// RefreshShowMessageEvent?.Invoke(Print.barcode + "铭牌打印记录存储完成!");
// LogHelper.Info(Print.barcode + "铭牌打印记录存储完成!");
// iNIFile.IniWriteValue("SystemConfig", "PrintState", "2");
// return;
//}
LogHelper . Info ( Print . barcode + "开始打印铭牌" ) ;
PrintEquip Smallequip = new NamePlatePrintEquip ( ) ;
Smallequip . tempPath = mlb . TempName ;
Smallequip . ParaClass = mlb ;
Smallequip . Open ( ) ;
bool bflag = Smallequip . print ( ) ;
if ( bflag )
{
ExitRePrint ( ) ;
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "铭牌打印成功!" ) ;
LogHelper . Info ( Print . barcode + "铭牌打印成功!" ) ;
//插库存储条码及序列号
baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo ( ) ;
BarcodePrintInfo . ID = Guid . NewGuid ( ) . ToString ( "N" ) ;
BarcodePrintInfo . ProductBarcode = Print . barcode ;
BarcodePrintInfo . ProductID = Print . Machine . ToString ( ) ;
BarcodePrintInfo . SerialNo = DateTime . Parse ( Print . starttime . ToString ( ) ) . ToString ( "yyMMdd" ) + "D" + Print . Shift + Serialnum ;
BarcodePrintInfo . IsRestart = Print . isRestart . ToString ( ) ;
BarcodePrintInfo . ShiftID = ShiftNo ;
BarcodePrintInfo . InsertTime = DateTime . Now ;
await new BaseServices < baseBarcodePrintInfo > ( ) . Add ( BarcodePrintInfo ) ;
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "铭牌打印记录存储完成!" ) ;
LogHelper . Info ( Print . barcode + "铭牌打印记录存储完成!" ) ;
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
}
else
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
}
Smallequip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
if ( ! string . IsNullOrEmpty ( barcodelb . TempName ) )
{
//0打印条码, 1打印纸箱标签
if ( itype = = 1 )
{
#region 纸箱标签
try
{
Console . WriteLine ( "开始打印纸箱标签" ) ;
PrintEquip equip = new CartonPrintEquip ( ) ;
equip . tempPath = "" ;
equip . ParaClass = boxlb ;
equip . Open ( ) ;
equip . print ( ) ;
equip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
else if ( itype = = 0 )
{
#region 条码标签
try
{
Console . WriteLine ( "开始打印条码标签" ) ;
//if (true)
//{
// iNIFile.IniWriteValue("SystemConfig", "PrintState", "2");
// RefreshShowMessageEvent?.Invoke(Print.barcode + "条码标签打印成功!");
// LogHelper.Info(Print.barcode + "条码标签打印成功!");
// //插库存储条码及序列号
// baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo();
// BarcodePrintInfo.ID = Guid.NewGuid().ToString("N");
// BarcodePrintInfo.ProductBarcode = Print.barcode;
// BarcodePrintInfo.ProductID = Print.Machine.ToString();
// BarcodePrintInfo.SerialNo = DateTime.Now.ToString("yyMMdd") + Serialnum;
// BarcodePrintInfo.IsRestart = Print.isRestart.ToString();
// BarcodePrintInfo.ShiftID = ShiftNo;
// BarcodePrintInfo.InsertTime = DateTime.Now;
// await new BaseServices<baseBarcodePrintInfo>().Add(BarcodePrintInfo);
// RefreshShowMessageEvent?.Invoke(Print.barcode + "条码打印记录存储完成!");
// LogHelper.Info(Print.barcode + "条码打印记录存储完成!");
//}
PrintEquip equip = new barcodePrintEquip ( ) ;
equip . tempPath = barcodelb . TempName ;
equip . ParaClass = barcodelb ;
equip . Open ( ) ;
bool bflag = equip . print ( ) ;
if ( bflag )
{
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "条码标签打印成功!" ) ;
LogHelper . Info ( Print . barcode + "条码标签打印成功!" ) ;
//插库存储条码及序列号
baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo ( ) ;
BarcodePrintInfo . ID = Guid . NewGuid ( ) . ToString ( "N" ) ;
BarcodePrintInfo . ProductBarcode = Print . barcode ;
BarcodePrintInfo . ProductID = Print . Machine . ToString ( ) ;
BarcodePrintInfo . SerialNo = DateTime . Parse ( Print . starttime . ToString ( ) ) . ToString ( "yyMMdd" ) + "D" + Print . Shift + Serialnum ;
BarcodePrintInfo . IsRestart = Print . isRestart . ToString ( ) ;
BarcodePrintInfo . ShiftID = ShiftNo ;
BarcodePrintInfo . InsertTime = DateTime . Now ;
await new BaseServices < baseBarcodePrintInfo > ( ) . Add ( BarcodePrintInfo ) ;
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "条码打印记录存储完成!" ) ;
LogHelper . Info ( Print . barcode + "条码打印记录存储完成!" ) ;
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
}
equip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
else if ( itype = = 2 )
{
#region 二维码标签
try
{
//if (true)
//{
// iNIFile.IniWriteValue("SystemConfig", "PrintState", "2");
// RefreshShowMessageEvent?.Invoke(Print.barcode + "二维码标签打印成功!");
// LogHelper.Info(Print.barcode + "二维码标签打印成功!");
// //插库存储条码及序列号
// baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo();
// BarcodePrintInfo.ID = Guid.NewGuid().ToString("N");
// BarcodePrintInfo.ProductBarcode = Print.barcode;
// BarcodePrintInfo.ProductID = Print.Machine.ToString();
// BarcodePrintInfo.SerialNo = DateTime.Parse(Print.starttime.ToString()).ToString("yyMMdd") + Serialnum;
// BarcodePrintInfo.IsRestart = Print.isRestart.ToString();
// BarcodePrintInfo.ShiftID = ShiftNo;
// BarcodePrintInfo.InsertTime = DateTime.Now;
// await new BaseServices<baseBarcodePrintInfo>().Add(BarcodePrintInfo);
// RefreshShowMessageEvent?.Invoke(Print.barcode + "二维码打印记录存储完成!");
// LogHelper.Info(Print.barcode + "二维码打印记录存储完成!");
//}
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "开始打印二维码标签" ) ;
LogHelper . Info ( Print . barcode + "开始打印二维码标签" ) ;
PrintEquip equip = new QRCodePrintEquip ( ) ;
equip . tempPath = barcodelb . TempName ;
equip . ParaClass = barcodelb ;
equip . Open ( ) ;
bool bflag = equip . print ( ) ;
if ( bflag )
{
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "二维码标签打印成功!" ) ;
LogHelper . Info ( Print . barcode + "二维码标签打印成功!" ) ;
//插库存储条码及序列号
baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo ( ) ;
BarcodePrintInfo . ID = Guid . NewGuid ( ) . ToString ( "N" ) ;
BarcodePrintInfo . ProductBarcode = Print . barcode ;
BarcodePrintInfo . ProductID = Print . Machine . ToString ( ) ;
BarcodePrintInfo . SerialNo = DateTime . Parse ( Print . starttime . ToString ( ) ) . ToString ( "yyMMdd" ) + "D" + Print . Shift + Serialnum ;
BarcodePrintInfo . IsRestart = Print . isRestart . ToString ( ) ;
BarcodePrintInfo . ShiftID = ShiftNo ;
BarcodePrintInfo . InsertTime = DateTime . Now ;
await new BaseServices < baseBarcodePrintInfo > ( ) . Add ( BarcodePrintInfo ) ;
RefreshShowMessageEvent ? . Invoke ( Print . barcode + "二维码打印记录存储完成!" ) ;
LogHelper . Info ( Print . barcode + "二维码打印记录存储完成!" ) ;
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
}
equip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
//else if (itype == 3)
//{
// #region 打印铭牌
// try
// {
// //这些每个机种应该都谁确定的,在数据库里保存,以后可以一个存储过程去获取
// Console.WriteLine("开始打印铭牌");
// PrintEquip Smallequip = new NamePlatePrintEquip();
// Smallequip.tempPath = mlb.TempName;
// Smallequip.ParaClass = mlb;
// Smallequip.Open();
// Smallequip.print();
// Smallequip.Colse();
// }
// catch (Exception e)
// {
// Console.WriteLine(e.ToString());
// }
// #endregion
//}
}
}
private void ExitRePrint ( )
{
try
{
if ( iNIFile . IniReadValue ( "SystemConfig" , "UserName" ) ! = "用户名" )
{
RefreshShowMessageEvent ? . Invoke ( "退出管理员模式成功!" ) ;
LogHelper . Info ( "退出管理员模式成功!" ) ;
iNIFile . IniWriteValue ( "SystemConfig" , "UserName" , "用户名" ) ;
}
}
catch ( Exception ex )
{
}
}
public async void Print ( string barcode , int Machine , string ShiftID , string starttime , string endtime )
{
MLable mlb = new MLable ( ) ;
BoxLable boxlb = new BoxLable ( ) ;
barcodLable barcodelb = new barcodLable ( ) ;
string printType = "" ;
string Serialnum = "" ;
string type = "" ;
DbHandler db = new DbHandler ( ) ;
string machine = Machine . ToString ( ) ;
//查询机种信息
DataTable dt = GetProductList ( machine ) ;
//string ZJweight = db.GetZJWeightProductInfoByBarCode(barcode);
string Mbarcode = "" ;
//ShiftInfo shift = db.GetShiftInfo();
string ShiftNo = ShiftID ;
#region 从数据库获取打印数据
try
{
if ( dt ! = null & & dt . Rows . Count > 0 )
{
//0表示正常品1表示试制品
type = dt . Rows [ 0 ] [ "ProductType" ] . ToString ( ) ;
//打印那种标签
printType = dt . Rows [ 0 ] [ "PrintType" ] . ToString ( ) ;
//车间字段
mlb . ShopID = dt . Rows [ 0 ] [ "ShopID" ] . ToString ( ) ;
//日期前面是否+A
mlb . HasA = Convert . ToInt16 ( dt . Rows [ 0 ] [ "HasA" ] ) = = 1 ;
//是否有另一处需要+时间的地方
mlb . HasDate = Convert . ToInt16 ( dt . Rows [ 0 ] [ "HasDate" ] ) = = 1 ;
//名牌模板位置
mlb . TempName = dt . Rows [ 0 ] [ "MPTemplate" ] . ToString ( ) ;
boxlb . MachineNam = dt . Rows [ 0 ] [ "ProductName" ] . ToString ( ) ;
//barcodelb.ZJWeight = ZJweight;
//前缀
barcodelb . PreString = dt . Rows [ 0 ] [ "Prefix" ] . ToString ( ) ;
barcodelb . EndString = dt . Rows [ 0 ] [ "Suffix" ] . ToString ( ) ;
//条码模板位置
barcodelb . TempName = dt . Rows [ 0 ] [ "TMTemplate" ] . ToString ( ) ;
//铭牌编码方式
barcodelb . codeType = dt . Rows [ 0 ] [ "CodeType" ] . ToString ( ) ;
}
else
{
Console . WriteLine ( "未找到该机种信息" ) ;
//没绑定托盘说明70工位未绑定上线机壳
//生成
}
}
catch ( Exception ex )
{
Console . WriteLine ( "未找到该机种信息" + ex ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
//Console.WriteLine("整机净重:"+ZJweight);
//Console.WriteLine("机种ID:" + Machine.ToString() + "打印类别:" + printType+"");
#region 获取序列号
//开启补码功能
if ( iNIFile . IniReadValue ( "SystemConfig" , "UserName" ) = = "管理员" )
{
RefreshShowMessageEvent ? . Invoke ( "补码功能开启,查询到当前用户名管理员" ) ;
List < baseBarcodePrintInfo > baseBarcodePrintInfo = await SelectPrintInfoAsync ( "" , ShiftID , Machine . ToString ( ) , starttime , endtime ) ;
if ( baseBarcodePrintInfo ! = null & & baseBarcodePrintInfo . Count > 0 )
{
//查询最大序列号生成
var max = baseBarcodePrintInfo . Max ( x = > x . SerialNo ) ;
RefreshShowMessageEvent ? . Invoke ( "查询当前最大序列号" + max ) ;
Serialnum = Convert . ToInt32 ( Convert . ToInt32 ( max . Substring ( max . Length - 4 , 4 ) ) + 1 ) . ToString ( ) . PadLeft ( 4 , '0' ) ;
RefreshShowMessageEvent ? . Invoke ( "生成新序列号" + Serialnum ) ;
}
else
{
//序列号0001
Serialnum = "0001" ;
RefreshShowMessageEvent ? . Invoke ( "生成新序列号" + Serialnum ) ;
}
}
else
{
//现根据条码查询是否重码
//List<baseBarcodePrintInfo> baseBarcodePrintInfos = await SelectPrintInfoAsync(barcode, ShiftID, Machine.ToString(), starttime, endtime);
//if (baseBarcodePrintInfos != null && baseBarcodePrintInfos.Count > 0)
//{
// foreach (var item in baseBarcodePrintInfos)
// {
// RefreshShowMessageEvent?.Invoke("查询" + barcode + "存在历史记录,序列号:" + item.SerialNo);
// return;
// }
//}
//先根据班次时间查询最大序列号,如果不存在则从0001生成
List < baseBarcodePrintInfo > baseBarcodePrintInfo = await SelectPrintInfoAsync ( "" , ShiftID , Machine . ToString ( ) , starttime , endtime ) ;
if ( baseBarcodePrintInfo ! = null & & baseBarcodePrintInfo . Count > 0 )
{
//查询最大序列号生成
var max = baseBarcodePrintInfo . Max ( x = > x . SerialNo ) ;
RefreshShowMessageEvent ? . Invoke ( "查询当前最大序列号" + max ) ;
Serialnum = Convert . ToInt32 ( Convert . ToInt32 ( max . Substring ( max . Length - 4 , 4 ) ) + 1 ) . ToString ( ) . PadLeft ( 4 , '0' ) ;
RefreshShowMessageEvent ? . Invoke ( "生成新序列号" + Serialnum ) ;
}
else
{
//序列号0001
Serialnum = "0001" ;
RefreshShowMessageEvent ? . Invoke ( "生成新序列号" + Serialnum ) ;
}
}
//这个需要在系统内进行获取早中晚班分别用A,B,C表示
//string beginTime = "";
//DateTime time = DateTime.Now;
//if (string.IsNullOrEmpty(barcode))
//{
// Serialnum = "0001";
// beginTime = DateTime.Now.ToString();
// Console.WriteLine("半部件条码为空");
//}
//else
//{
// //通过壳体条码搜索系统M条码, 以M条码的后四位作为流水号号
// Mbarcode = db.GetMbarcode(barcode);
// if (string.IsNullOrEmpty(Mbarcode))
// {
// RefreshShowMessageEvent?.Invoke("未查询到"+ barcode + "条码流水号,请手动补码!");
// return;
// }
// Serialnum = Mbarcode.Substring(Mbarcode.Length - 4, 4);
//}
# endregion
#region 获取生产日期
//Console.WriteLine("半部件条码:"+ Mbarcode);
//try
//{
// beginTime = getDateString(Mbarcode);
// time = Convert.ToDateTime(beginTime);
//}
//catch (Exception e)
//{
// time = DateTime.Now;
// ICSharpCode.Core.LoggingService.Debug(e.ToString());
//}
# endregion
barcodelb . PrintType = printType ;
barcodelb . SerialNum = Serialnum ;
barcodelb . ShiftNo = ShiftNo ;
barcodelb . Date = DateTime . Now ;
mlb . PrintType = printType ;
mlb . serialNum = Serialnum ;
mlb . ShiftNO = getShift ( ShiftNo ) ;
mlb . Date = DateTime . Now ;
int itype = 0 ;
if ( ! string . IsNullOrEmpty ( printType ) )
{
itype = Convert . ToInt32 ( printType ) ;
}
//判断是否需要打印铭牌
if ( ! string . IsNullOrEmpty ( mlb . TempName ) )
{
#region 打印铭牌
try
{
//这些每个机种应该都谁确定的,在数据库里保存,以后可以一个存储过程去获取
RefreshShowMessageEvent ? . Invoke ( "开始打印铭牌,请等待..." ) ;
PrintEquip Smallequip = new NamePlatePrintEquip ( ) ;
Smallequip . tempPath = mlb . TempName ;
Smallequip . ParaClass = mlb ;
Smallequip . Open ( ) ;
bool bflag = Smallequip . print ( ) ;
if ( bflag )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
RefreshShowMessageEvent ? . Invoke ( "铭牌打印成功!" ) ;
//插库存储条码及序列号
baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo ( ) ;
BarcodePrintInfo . ID = Guid . NewGuid ( ) . ToString ( "N" ) ;
BarcodePrintInfo . ProductBarcode = barcode ;
BarcodePrintInfo . ProductID = machine ;
BarcodePrintInfo . SerialNo = DateTime . Now . ToString ( "yyMMdd" ) + Serialnum ;
BarcodePrintInfo . IsRestart = "0" ;
BarcodePrintInfo . ShiftID = ShiftNo ;
BarcodePrintInfo . InsertTime = DateTime . Now ;
await new BaseServices < baseBarcodePrintInfo > ( ) . Add ( BarcodePrintInfo ) ;
RefreshShowMessageEvent ? . Invoke ( "铭牌打印记录存储完成!" ) ;
}
Smallequip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
if ( ! string . IsNullOrEmpty ( barcodelb . TempName ) )
{
//0打印条码, 1打印纸箱标签
if ( itype = = 1 )
{
#region 纸箱标签
try
{
Console . WriteLine ( "开始打印纸箱标签" ) ;
PrintEquip equip = new CartonPrintEquip ( ) ;
equip . tempPath = "" ;
equip . ParaClass = boxlb ;
equip . Open ( ) ;
equip . print ( ) ;
equip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
else if ( itype = = 0 )
{
#region 条码标签
try
{
Console . WriteLine ( "开始打印条码标签" ) ;
PrintEquip equip = new barcodePrintEquip ( ) ;
equip . tempPath = barcodelb . TempName ;
equip . ParaClass = barcodelb ;
equip . Open ( ) ;
bool bflag = equip . print ( ) ;
if ( bflag )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
RefreshShowMessageEvent ? . Invoke ( "二维码标签打印成功!" ) ;
//插库存储条码及序列号
baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo ( ) ;
BarcodePrintInfo . ID = Guid . NewGuid ( ) . ToString ( "N" ) ;
BarcodePrintInfo . ProductBarcode = barcode ;
BarcodePrintInfo . ProductID = machine ;
BarcodePrintInfo . SerialNo = DateTime . Now . ToString ( "yyMMdd" ) + Serialnum ;
BarcodePrintInfo . IsRestart = "0" ;
BarcodePrintInfo . ShiftID = ShiftNo ;
BarcodePrintInfo . InsertTime = DateTime . Now ;
await new BaseServices < baseBarcodePrintInfo > ( ) . Add ( BarcodePrintInfo ) ;
RefreshShowMessageEvent ? . Invoke ( "打印记录存储完成!" ) ;
}
equip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
else if ( itype = = 2 )
{
#region 二维码标签
try
{
Console . WriteLine ( "开始打印二维码标签" ) ;
PrintEquip equip = new QRCodePrintEquip ( ) ;
equip . tempPath = barcodelb . TempName ;
equip . ParaClass = barcodelb ;
equip . Open ( ) ;
bool bflag = equip . print ( ) ;
if ( bflag )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
RefreshShowMessageEvent ? . Invoke ( "二维码标签打印成功!" ) ;
//插库存储条码及序列号
baseBarcodePrintInfo BarcodePrintInfo = new baseBarcodePrintInfo ( ) ;
BarcodePrintInfo . ID = Guid . NewGuid ( ) . ToString ( "N" ) ;
BarcodePrintInfo . ProductBarcode = barcode ;
BarcodePrintInfo . ProductID = machine ;
BarcodePrintInfo . SerialNo = DateTime . Now . ToString ( "yyMMdd" ) + Serialnum ;
BarcodePrintInfo . IsRestart = "0" ;
BarcodePrintInfo . ShiftID = ShiftNo ;
BarcodePrintInfo . InsertTime = DateTime . Now ;
await new BaseServices < baseBarcodePrintInfo > ( ) . Add ( BarcodePrintInfo ) ;
RefreshShowMessageEvent ? . Invoke ( "打印记录存储完成!" ) ;
}
equip . Colse ( ) ;
}
catch ( Exception ex )
{
iNIFile . IniWriteValue ( "SystemConfig" , "PrintState" , "2" ) ;
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
}
# endregion
}
//else if (itype == 3)
//{
// #region 打印铭牌
// try
// {
// //这些每个机种应该都谁确定的,在数据库里保存,以后可以一个存储过程去获取
// Console.WriteLine("开始打印铭牌");
// PrintEquip Smallequip = new NamePlatePrintEquip();
// Smallequip.tempPath = mlb.TempName;
// Smallequip.ParaClass = mlb;
// Smallequip.Open();
// Smallequip.print();
// Smallequip.Colse();
// }
// catch (Exception e)
// {
// Console.WriteLine(e.ToString());
// }
// #endregion
//}
}
}
private string getDateString ( string semiBarcode )
{
string datestring = "20" ;
if ( string . IsNullOrEmpty ( semiBarcode ) )
{
datestring = DateTime . Now . ToString ( ) ;
}
else
{
string year = semiBarcode . Substring ( 2 , 2 ) ;
string month = semiBarcode . Substring ( 4 , 2 ) ;
string date = semiBarcode . Substring ( 6 , 2 ) ;
datestring + = year + "-" + month + "-" + date ;
}
return datestring ;
}
private string getShift ( string shift )
{
string shiftA = "A" ;
switch ( shift )
{
case "01" :
shiftA = "A" ;
break ;
case "02" :
shiftA = "B" ;
break ;
case "03" :
shiftA = "C" ;
break ;
default :
break ;
}
return shiftA ;
}
public async Task < List < baseBarcodePrintInfo > > SelectPrintInfoAsync ( String BarCode , string ShiftID , string ProductID , string starttime , string endtime )
{
try
{
DateTime start = Convert . ToDateTime ( starttime ) ;
DateTime end = Convert . ToDateTime ( endtime ) ;
Expression < Func < baseBarcodePrintInfo , bool > > exp = ( baseBarcodePrintInfo s1 ) = > true ;
if ( ! string . IsNullOrEmpty ( BarCode ) )
{
exp = ExpressionExtensions . And < Func < baseBarcodePrintInfo , bool > > ( exp , ( Expression < Func < baseBarcodePrintInfo , bool > > ) ( ( baseBarcodePrintInfo s1 ) = > s1 . ProductBarcode = = BarCode ) ) ;
}
else
{
//exp = ExpressionExtensions.And<Func<baseBarcodePrintInfo, bool>>(exp, (Expression<Func<baseBarcodePrintInfo, bool>>)((baseBarcodePrintInfo s1) => s1.ShiftID == ShiftID && s1.ProductID == ProductID && s1.InsertTime > start && s1.InsertTime <= end));
exp = ExpressionExtensions . And < Func < baseBarcodePrintInfo , bool > > ( exp , ( Expression < Func < baseBarcodePrintInfo , bool > > ) ( ( baseBarcodePrintInfo s1 ) = > s1 . ShiftID = = ShiftID & & s1 . ProductID = = ProductID ) ) ;
}
return await new BaseServices < baseBarcodePrintInfo > ( ) . Query ( exp ) ;
}
catch ( Exception ex )
{
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
return null ;
}
}
//public List<baseBarcodePrintInfo> GetLocal_Mchilsurface__DetailInfoList(string ShiftID, string ProductID, string starttime, string endtime)
//{
// List<baseBarcodePrintInfo> result;
// try
// {
// string sql = "SELECT [ID],[ProductBarcode],[SerialNo],[IsRestart],[ProductID],[ShiftID],[InsertTime] FROM [base_Barcode_PrintInfo] WHERE 1 = 1 AND [ShiftID]=@ShiftID AND [ProductID]=@ProductID AND [InsertTime] > @starttime AND InsertTime < @endtime "
// ;
// List<baseBarcodePrintInfo> MaterialTypeList = new BaseServices<baseBarcodePrintInfo>().QueryBySql1<baseBarcodePrintInfo>(sql, new List<SugarParameter>
// {
// new SugarParameter("@ShiftID", ShiftID),
// new SugarParameter("@ProductID", ProductID),
// new SugarParameter("@starttime", starttime),
// new SugarParameter("@endtime", endtime)
// });
// result = MaterialTypeList;
// }
// catch (Exception ex)
// {
// result = new List<baseBarcodePrintInfo>();
// }
// return result;
//}
public DataTable GetProductList ( string ProductID )
{
DataTable result = null ;
try
{
Expression < Func < TBDProductInfo , bool > > exp = ( TBDProductInfo s1 ) = > true ;
exp = exp . And ( ( TBDProductInfo s1 ) = > s1 . ProductID = = ProductID ) ;
result = new BaseServices < TBDProductInfo > ( ) . QueryDatatable ( exp ) ;
return result ;
}
catch ( Exception ex )
{
LogHelper . Error ( "空间名:" + ex . Source + "; " + '\n' +
"方法名:" + ex . TargetSite + '\n' +
"故障点:" + ex . StackTrace . Substring ( ex . StackTrace . LastIndexOf ( "\\" ) + 1 , ex . StackTrace . Length - ex . StackTrace . LastIndexOf ( "\\" ) - 1 ) + '\n' +
"错误提示:" + ex . Message ) ;
return result ;
}
}
}
}