private void PrintMUBLabel(PrinterMonitor printerMonitor, LabelInfo labelInfo) { BarcodePrinterUtil barcodeScannerUtils = BarcodePrinterUtil.Instance; // Check status of Barcode printer //MessageBox.Show(EnumDeviceNames.MUBLabelPrinter); EnumDeviceStatus[] mubLabelPrinterStatuses = barcodeScannerUtils.GetDeviceStatus(EnumDeviceNames.MUBLabelPrinter); if (mubLabelPrinterStatuses.Contains(EnumDeviceStatus.Connected)) { printerMonitor.PrintMUBLabel(labelInfo); } else { // Printer disconnect, get list status of the causes disconnected string causeOfPrintMUBFailure = string.Empty; foreach (var item in mubLabelPrinterStatuses) { causeOfPrintMUBFailure = causeOfPrintMUBFailure + CommonUtil.GetDeviceStatusText(item) + "; "; } labelInfo.PrintStatus = EnumPrintStatus.Failed; labelInfo.Message = causeOfPrintMUBFailure; RaisePrintMUBLabelsFailedEvent(new Trinity.Common.PrintMUBAndTTLabelsEventArgs(labelInfo)); } }
internal void StartPrintTT(LabelInfo labelInfo) { try { _web.SetLoading(false); this._web.LoadPageHtml("MUBAndTTLabel.html"); //this._web.RunScript("$('.status-text').css('color','#000').text('Please wait');"); //System.Threading.Thread.Sleep(1000); PrinterMonitor printerMonitor = PrinterMonitor.Instance; printerMonitor.OnPrintTTLabelSucceeded += OnPrintTTLabelsSucceeded; printerMonitor.OnMonitorException += OnPrintMUBAndTTLabelsException; BarcodePrinterUtil barcodeScannerUtils = BarcodePrinterUtil.Instance; Session session = Session.Instance; if (session.IsAuthenticated) { #region Print TTLabel // Check status of Barcode printer string ttLabelPrinterName = ConfigurationManager.AppSettings["TTLabelPrinterName"]; var ttLabelPrinterStatus = barcodeScannerUtils.GetDeviceStatus(ttLabelPrinterName); if (ttLabelPrinterStatus.Contains(EnumDeviceStatus.Connected)) { printerMonitor.PrintTTLabel(labelInfo); } else { // Printer disconnect, get list status of the causes disconnected string causeOfPrintFailure = ""; foreach (var item in ttLabelPrinterStatus) { causeOfPrintFailure = causeOfPrintFailure + CommonUtil.GetDeviceStatusText(item) + "; "; } RaisePrintTTLabelsFailedEvent(new PrintMUBAndTTLabelsEventArgs("TTLabel Printer have problem: " + causeOfPrintFailure)); return; } #endregion } } catch (Exception ex) { RaisePrintMUBAndTTLabelsExceptionEvent(new ExceptionArgs(new FailedInfo() { ErrorCode = (int)EnumErrorCodes.UnknownError, ErrorMessage = new ErrorInfo().GetErrorMessage(EnumErrorCodes.UnknownError) })); } }
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) })); } }
private void btnPrint_Click(object sender, EventArgs e) { BarcodePrinterUtil printerUtil = BarcodePrinterUtil.Instance; //printerUtil.Test(); return; Trinity.Common.LabelInfo labelInfo = new Trinity.Common.LabelInfo() { Date = "07-04-1982", NRIC = "022234343", Name = "minhdq" }; //printerUtil.PrintBarcodeUserInfo(labelInfo); //if (documentLoaded) //{ // webBrowserAppointmentDetails.Print(); // //webBrowserAppointmentDetails.ShowPrintPreviewDialog(); //} }
public void PrintMUBLabel(LabelInfo labelInfo) { // Validate 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; // create image file to print //string filePath = string.Empty; //string fileName = string.Empty; //using (var ms = new System.IO.MemoryStream(labelInfo.BitmapLabel)) //{ // Bitmap bitmap = new System.Drawing.Bitmap(System.Drawing.Image.FromStream(ms)); // // Rotate bitmap // bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); // string curDir = Directory.GetCurrentDirectory(); // // create directory // if (!Directory.Exists(curDir + "\\Temp")) // { // Directory.CreateDirectory(curDir + "\\Temp"); // } // // set file path // filePath = curDir + "\\Temp\\mublabel.bmp"; // // create image file (bit depth must be 8) // Bitmap target = Convertor1.ConvertTo8bppFormat(bitmap); // target.Save(filePath, ImageFormat.Bmp); //} // Print mub label try { // qr code string: 91 chars string qrCodeString = string.Format("{0}*{1}*{2}", labelInfo.MarkingNo, labelInfo.NRIC, labelInfo.Name).PadRight(91, '*'); MUBLabelInfo mubLabelInfo = new MUBLabelInfo() { ID = labelInfo.NRIC, Name = labelInfo.Name, MarkingNumber = labelInfo.MarkingNo, QRCodeString = qrCodeString }; //if (printerUtils.PrintMUBLabel(filePath)) if (printerUtils.PrintMUBLabel(mubLabelInfo)) { // raise succeeded event RaisePrintMUBLabelSucceededEvent(new PrintMUBAndTTLabelsEventArgs(labelInfo)); } else { //MessageBox.Show("Failed to print"); // raise failed event RaiseMonitorExceptionEvent(new ExceptionArgs(new FailedInfo() { ErrorCode = (int)EnumErrorCodes.UnknownError, ErrorMessage = new ErrorInfo().GetErrorMessage(EnumErrorCodes.UnknownError) })); } } catch (Exception ex) { MessageBox.Show("Error while printing MUB Label, details: " + ex.Message); } }