You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
9.1 KiB
C#

using Mesnac.Compressor.Data;
using Mesnac.Compressor.Entity;
using Mesnac.Compressor.Unity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace BarTenderPrint
{
public class PrintManager
{
public void Print(string barcode, int Machine, string ShiftID)
{
MLable mlb = new MLable();
BoxLable boxlb = new BoxLable();
barcodLable barcodelb = new barcodLable();
string printType = "";
string Serialnum = "";
string type = "";
DbHandler db = new DbHandler();
string machine = db.GetProductInfoByBarCode(barcode);
DataTable dt = db.GetCurrentMachine(int.Parse(machine));
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.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("未找到该机种信息");
}
}
catch
{
}
#endregion
Console.WriteLine("机种ID:" + Machine.ToString() + "打印类别:" + printType+"");
#region 获取序列号
//这个需要在系统内进行获取早中晚班分别用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);
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 = time;
mlb.PrintType = printType;
mlb.serialNum = Serialnum;
mlb.ShiftNO = getShift(ShiftNo) ;
mlb.Date = time;
int itype = 0;
if (!string.IsNullOrEmpty(printType))
{
itype = Convert.ToInt32(printType);
}
//判断是否需要打印铭牌
if (!string.IsNullOrEmpty(mlb.TempName))
{
#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
}
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 e)
{
Console.WriteLine(e.ToString());
}
#endregion
}
else if (itype == 0)
{
#region 条码标签
try
{
Console.WriteLine("开始打印条码标签");
PrintEquip equip = new barcodePrintEquip();
equip.tempPath = barcodelb.TempName;
equip.ParaClass = barcodelb;
equip.Open();
equip.print();
equip.Colse();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
#endregion
}
else if (itype == 2)
{
#region 二维码标签
try
{
Console.WriteLine("开始打印二维码标签");
PrintEquip equip = new QRCodePrintEquip();
equip.tempPath = barcodelb.TempName;
equip.ParaClass = barcodelb;
equip.Open();
equip.print();
equip.Colse();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
#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(1, 2);
string month = semiBarcode.Substring(3, 2);
string date = semiBarcode.Substring(5, 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;
}
}
}