public void PrintTTLabel(LabelInfo labelInfo) { // validation if (string.IsNullOrEmpty(labelInfo.Name)) { // username is null RaiseMonitorExceptionEvent(new ExceptionArgs(new FailedInfo() { ErrorCode = (int)EnumErrorCodes.UserNameNull, ErrorMessage = new ErrorInfo().GetErrorMessage(EnumErrorCodes.UserNameNull) })); return; } else if (string.IsNullOrEmpty(labelInfo.NRIC)) { // NRIC is null RaiseMonitorExceptionEvent(new ExceptionArgs(new FailedInfo() { ErrorCode = (int)EnumErrorCodes.NRICNull, ErrorMessage = new ErrorInfo().GetErrorMessage(EnumErrorCodes.NRICNull) })); return; } // print label BarcodePrinterUtil printerUtils = BarcodePrinterUtil.Instance; TTLabelInfo infoTTLabel = new TTLabelInfo { ID = labelInfo.NRIC, Name = labelInfo.Name, MarkingNumber = labelInfo.MarkingNo }; //MessageBox.Show("Call PrintTTLabel"); if (printerUtils.PrintTTLabel_Direction_0(infoTTLabel)) { // raise succeeded event RaisePrintTTLabelSucceededEvent(new PrintMUBAndTTLabelsEventArgs(labelInfo)); } else { // raise failed event RaiseMonitorExceptionEvent(new ExceptionArgs(new FailedInfo() { ErrorCode = (int)EnumErrorCodes.UnknownError, ErrorMessage = new ErrorInfo().GetErrorMessage(EnumErrorCodes.UnknownError) })); } }
/// <summary> /// print TTLabel /// </summary> /// <param name="ttLabelInfo">Id, Name, MarkingNumber must not be null</param> /// <returns>successful</returns> public bool PrintTTLabel_Direction_0(TTLabelInfo ttLabelInfo) { lock (syncRoot) { try { //LogManager.Debug("PrintTTLabel "); // validate if (!ttLabelInfo.IsValid()) { LogManager.Debug("!ttLabelInfo.IsValid"); return(false); } //Open specified printer driver TSCLIB_DLL.openport(EnumDeviceNames.TTLabelPrinter); //Setup the media size and sensor type info // page size 55mm x 30mm // template size 45mm x 30mm (actually 55mm x 32.5mm) //TSCLIB_DLL.setup("55", "32.5", "4", "8", "0", "0", "0"); TSCLIB_DLL.setup("50", "30", "4", "8", "0", "0", "0"); TSCLIB_DLL.sendcommand("GAP 3mm, 0mm"); //TSCLIB_DLL.setup("52.5", "30", "4", "8", "0", "0", "0"); //TSCLIB_DLL.sendcommand("GAP 1.3mm, 0mm"); TSCLIB_DLL.sendcommand("DIRECTION 0"); TSCLIB_DLL.sendcommand("CLS"); //Clear image buffer //TSCLIB_DLL.clearbuffer(); // DPI = 203 => 8px = 1 mm //Draw windows font //int startX = 54; //int startY = 32; int startX = 48; int startY = 16; //int startX = 40; //int startY = 0; string fontName = "ARIAL"; int fontStyle = 2; // Bold int fontHeight = 30; int maxChar = 17; // max char of name at first name line // Name line TSCLIB_DLL.windowsfont(startX, startY, fontHeight, 0, fontStyle, 0, fontName, "Name"); if (ttLabelInfo.Name.Length > maxChar) { TSCLIB_DLL.windowsfont(startX + 70, startY, fontHeight, 0, fontStyle, 0, fontName, " : " + ttLabelInfo.Name.Substring(0, maxChar)); // Add name line if name is too long. Need to improve (split name by space char) TSCLIB_DLL.windowsfont(startX + 100, startY += fontHeight, fontHeight, 0, fontStyle, 0, fontName, ttLabelInfo.Name.Substring(maxChar, ttLabelInfo.Name.Length - maxChar)); } else { TSCLIB_DLL.windowsfont(startX + 70, startY, fontHeight, 0, fontStyle, 0, fontName, " : " + ttLabelInfo.Name); startY += fontHeight; } // ID line TSCLIB_DLL.windowsfont(startX, startY += fontHeight, fontHeight, 0, fontStyle, 0, fontName, "ID"); TSCLIB_DLL.windowsfont(startX + 70, startY, fontHeight, 0, fontStyle, 0, fontName, " : " + ttLabelInfo.ID); //Drawing barcode TSCLIB_DLL.barcode(startX.ToString(), (startY += fontHeight + 8).ToString(), "39", "72", "0", "0", "1", "3", ttLabelInfo.MarkingNumber); // Drawing barcode buildin function do not let us set text size of readable line, so we need to draw a line to display MarkingNumber TSCLIB_DLL.windowsfont(startX, startY += 80, fontHeight, 0, fontStyle, 0, fontName, ttLabelInfo.MarkingNumber); //Print labels TSCLIB_DLL.printlabel("1", "1"); TSCLIB_DLL.closeport(); //LogManager.Debug("Print OK"); return(true); } catch (Exception ex) { //Debug.WriteLine("Print exception: " + ex.ToString()); LogManager.Debug("Print exception: " + ex.ToString()); return(false); } } }