//需添加自定义的一个类,此类的源代码已加至本博客中了,可自行进行封装成DLL后引用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TSB_Print.Class
{
///
/// UPC 打印类
///
class UpcBarCode
{
#region 属性
private int _Left;
///
/// 贴纸起始点距离左边距离
///
public int Left
{
get { return _Left; }
set { _Left = value; }
}
private int _Top;
///
/// 贴纸起始点距离上边距离
///
public int Top
{
get { return _Top; }
set { _Top = value; }
}
private string _strPrintName;
///
/// 打印机名称
///
public string strPrintName
{
get { return _strPrintName; }
set { _strPrintName = value; }
}
#endregion
//*********常量定义
private string strMN = "M/N";
private string strPN = "P/N";
private string strSN = "S/N";
private string strWeb = "www.toshibastorage.com";
private string strMade = "Made in China";
private string strEAN1 = "EAN:";
private string strUPC1 = "UPC:";
private string strCons = "Consumo de energia";
private string strCons1 = "Consumo de energia: 1.6 Wh";
private string strCons2 = "Consumo de energia: 2.5 Wh";
private string strEn_Mode1 = "en mode de espera: 1.1 Wh";
private string strEn_Mode2 = "en mode de espera: 1.3 Wh";
private string str1 = "UAE TRA No,";
private string str2="REGISTERED NO:";
private string str3="ER35579/14";
private string str4="DEALER NO:";
private string str5="DA35871/14";
///
/// UpcTypeId = 1 or UpcTypeId = 20 (无EAN,有UPC或无UPC)
///
///
///
///
public void PrintBar1(ProductInfo newProductInfo, BatchInfo newBatchInfo, string strHDDSN)
{
string StrBoard = "";
StringBuilder sb = new StringBuilder(10240);
StrBoard = "^XA^MD12" + "^LH" + Left.ToString() + "," + Top.ToString() + "^LL350^PW1000";
BarCode.BarCode.GETFONTHEX(strPN + " " + newProductInfo.strPN, "Arial", "temp1", 0, 25, 10, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO0,10^XGtemp1,1,1^FS"; //PartNumber
BarCode.BarCode.GETFONTHEX(strMN + " " + newProductInfo.strModelNumber, "Arial", "temp2", 0, 26, 10, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO0,40^XGtemp2,1,1^FS"; //ModelNumber
BarCode.BarCode.GETFONTHEX(strWeb, "Arial", "temp3", 0, 24, 10, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO0,65^XGtemp3,1,1^FS"; //strWeb
BarCode.BarCode.GETFONTHEX(newProductInfo.strBottomLabel, "Arial", "temp4", 0, 28, 12, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO0,90^XGtemp4,1,1^FS"; //BottomLabel
BarCode.BarCode.GETFONTHEX(strSN + " " + strHDDSN, "Arial", "temp5", 0, 28, 10, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO30,160^XGtemp5,1,1^FS"; //SN
BarCode.BarCode.GETFONTHEX(strCons1, "Arial", "temp7", 0, 23, 8, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO245,10^XGtemp7,1,1^FS"; //1.6Wh
BarCode.BarCode.GETFONTHEX(strCons, "Arial", "temp8", 0, 23, 8, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO245,30^XGtemp8,1,1^FS"; //
BarCode.BarCode.GETFONTHEX(strEn_Mode1, "Arial", "temp9", 0, 23, 8, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO245,50^XGtemp9,1,1^FS"; //en mode de espera:1.1Wh
if (newProductInfo.strUPCCode != "")
{
string strTmpUPC = newProductInfo.strUPCCode.Substring(0, 1) + " " + newProductInfo.strUPCCode.Substring(1, 5)
+ " " + newProductInfo.strUPCCode.Substring(6, 5) + " " + newProductInfo.strUPCCode.Substring(11, 1);
BarCode.BarCode.GETFONTHEX(strTmpUPC, "Arial", "temp6", 0, 38, 15, 0, 0, sb);
StrBoard = StrBoard + sb.ToString() + "^FO485,145^XGtemp6,1,1^FS"; //UPC
StrBoard = StrBoard + "^FO505,10^BY3,3.0^BUN,135,N,N^FD" + newProductInfo.strUPCCode + "^FS";
}
//********************条码部分
StrBoard = StrBoard + "^FO0,120^BY2,2^BAN,40,N,N,N^FD" + strHDDSN + "^FS";
StrBoard = StrBoard + "^PQ1^XZ";
SendStringToPrinter(StrBoard);
}
private void SendStringToPrinter(string strPrint)
{
BarCode.BarCodeNew.SendStringToPrinter(strPrintName, strPrint);
}
}