public void PrintLabelsFromDevice(string printer, string rdlTemplateName, IList<Label> listOfLabels, string appPath) { LabelTemplate defTemplate = null; Printer objPrinter = null; //Si el path viene Empty. if (string.IsNullOrEmpty(appPath)) appPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), WmsSetupValues.WebServer); try { if (printer.Equals(WmsSetupValues.DEFAULT)) objPrinter = new Printer { PrinterName = printer }; else { Connection cnnPrinter = Factory.DaoConnection().Select(new Connection { Name = printer }).First(); objPrinter = new Printer { PrinterName = cnnPrinter.Name, PrinterPath = cnnPrinter.CnnString }; } } catch { } try { if (!string.IsNullOrEmpty(rdlTemplateName)) defTemplate = Factory.DaoLabelTemplate().Select( new LabelTemplate { Header = rdlTemplateName }).First(); } catch { } ReportMngr.PrintLabelsFromFacade(objPrinter, defTemplate, listOfLabels, appPath); }
public void PrintDocument(Document document, LabelTemplate report, string appPath, CustomProcess process) { curTemplate = report; try { if (curTemplate.DefPrinter == null) throw new Exception("No printer defined for report " + report.Name +"."); //Save the File printed for Document to show Later. //Solo si no existe. try { Factory.DaoProcessEntityResource().Save( new ProcessEntityResource { Entity = new ClassEntity { ClassEntityID = EntityID.Document }, EntityRowID = document.DocID, CreatedBy = WmsSetupValues.SystemUser, CreationDate = DateTime.Now, Process = process, Status = new Status { StatusID = EntityStatus.Active }, Template = report }); } catch { } //Usa la default Printer del template usePrinter = new Printer { PrinterName = curTemplate.DefPrinter.Name, PrinterPath = curTemplate.DefPrinter.CnnString }; //Ejecutar la impresion global en un Hilo //Thread th = new Thread(new ParameterizedThreadStart(PrintDocumentThread)); //th.Start(document); PrintDocumentThread(document); } catch (Exception ex) { //throw new Exception("Report could not be printed: " + report.Name + ", " + ex.Message); ExceptionMngr.WriteEvent("Report could not be printed: " + report.Name + ", " + ex.Message, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection); } }
//Imprime en impresora mandando la lineas de comando PCL private static void PrintLabelByPL(LabelTemplate template, IList<Label> listLabels, Printer printer ) { LabelMngr lblMngr = new LabelMngr(); string templateReplaced = lblMngr.GetReplacedTemplateForLabels(listLabels, template, ""); if (string.IsNullOrEmpty(templateReplaced)) { //throw new Exception("Error creating Printer Template."); ExceptionMngr.WriteEvent("Error creating Printer Template. " + template.Header, ListValues.EventType.Fatal, null, null, ListValues.ErrorCategory.Printer); } PrintLabels(templateReplaced, printer.PrinterPath); }
public static void PrintLabelsFromFacade(Printer printer, LabelTemplate defTemplate, IList<Label> listOfLabels, string appPath) { usePrinter = null; if (listOfLabels == null || listOfLabels.Count == 0) return; //if (string.IsNullOrEmpty(printer)) //throw new Exception("Printer not found"); if (printer != null && printer.PrinterName != WmsSetupValues.DEFAULT) usePrinter = printer; AppPath = appPath; m_streams = new Dictionary<LabelTemplate, IList<Stream>>(); m_currentPageIndex = new Dictionary<LabelTemplate, int>(); //1. Si viene un template imprime los labes con ese template if (defTemplate != null) { try { if (listOfLabels[0].LabelType.DocTypeID == LabelType.ProductLabel) PrintLabelByTemplate(defTemplate, listOfLabels.Where(f => f.Product.PrintLabel != false).ToList()); else PrintLabelByTemplate(defTemplate, listOfLabels); UpdateLabelPrintStatus(); return; } catch { throw; } } //Agrupa a los diferentes tipos de label y a los null y los manda por aparte. //Filtra los que no imprime label (double check) IList<LabelTemplate> templateList = new List<LabelTemplate>(); //Si el lable es de producto busca las templates del producto. if (listOfLabels[0].LabelType.DocTypeID == LabelType.ProductLabel) templateList = listOfLabels.Where(f => f.Product.DefaultTemplate != null) .Select(f => f.Product.DefaultTemplate).Distinct().ToList(); string error = ""; //Para cada template mandando la impresion foreach (LabelTemplate template in templateList) { try { if (listOfLabels[0].LabelType.DocTypeID == LabelType.ProductLabel) PrintLabelByTemplate(template, listOfLabels.Where(f => f.Product.DefaultTemplate.RowID == template.RowID && f.Product.PrintLabel != false) .ToList()); else PrintLabelByTemplate(template, listOfLabels); UpdateLabelPrintStatus(); //tl = new Thread(new ThreadStart(UpdateLabelPrintStatus)); //tl.Start(); } catch (Exception ex) { error += ex.Message; } } //Mandando las labels con template en Null try { defTemplate = (new DaoFactory()).DaoLabelTemplate().Select(new LabelTemplate { Header = WmsSetupValues.DefaultLabelTemplate}).First(); List<Label> labelsWoTemplate = null; if (listOfLabels[0].LabelType.DocTypeID == LabelType.ProductLabel) labelsWoTemplate = listOfLabels.Where(f => f.Product.DefaultTemplate == null && f.Product.PrintLabel != false).ToList(); else labelsWoTemplate = listOfLabels.ToList(); PrintLabelByTemplate(defTemplate, labelsWoTemplate); //tl = new Thread(new ThreadStart(UpdateLabelPrintStatus)); //tl.Start(); UpdateLabelPrintStatus(); } catch (Exception ex) { error += ex.Message; } //Final Error if (!string.IsNullOrEmpty(error)) throw new Exception(error); }
public int PrintPackageLabels(Document shipment, string printer, string appPath, string labelcode) { IList<Label> labelsToPrint = null; LabelTemplate defTemplate = null; if (shipment != null && shipment.DocID != 0) { labelsToPrint = Factory.DaoDocumentPackage().Select( new DocumentPackage { PostingDocument = shipment } ).Select(f => f.PackLabel).ToList(); try { defTemplate = Factory.DaoLabelTemplate().Select( new LabelTemplate { Header = WmsSetupValues.DefaultPackLabelTemplate }).First(); } catch { } } else if (!string.IsNullOrEmpty(labelcode)) { labelsToPrint = Factory.DaoDocumentPackage().Select( new DocumentPackage { PackLabel = new Label { LabelCode = labelcode } } ).Select(f => f.PackLabel).ToList(); try { if (labelsToPrint[0].Package.PackageType == "P" || labelsToPrint[0].Package.Level == 0) // || labelsToPrint[0].Package.ParentPackage == null defTemplate = Factory.DaoLabelTemplate().Select( new LabelTemplate { Header = WmsSetupValues.DefaultPalletTemplate }).First(); else if (labelsToPrint[0].Package.PackageType == "B") defTemplate = Factory.DaoLabelTemplate().Select( new LabelTemplate { Header = WmsSetupValues.DefaultPackLabelTemplate }).First(); } catch { } } if (labelsToPrint == null || labelsToPrint.Count == 0) return 0; Printer objPrinter = null; //Printer - Default for the Template objPrinter = new Printer { PrinterName = WmsSetupValues.DEFAULT }; ReportMngr.PrintLabelsFromFacade(objPrinter, defTemplate, labelsToPrint, appPath); return labelsToPrint.Count; }
private static void PrintLabelByTemplate(LabelTemplate rdlTemplateName, IList<Label> listOfLabels) { try { if (listOfLabels == null || listOfLabels.Count == 0) return; sListLabels = listOfLabels; try { //Si viene una impresora definida utiliza esa, si no utiliza la del template if (rdlTemplateName != null) curTemplate = rdlTemplateName; else curTemplate = (new DaoFactory()).DaoLabelTemplate().Select(new LabelTemplate { Header = WmsSetupValues.ProductLabelTemplate }).First(); usePrinter = (usePrinter == null) ? new Printer { PrinterName = curTemplate.DefPrinter.Name, PrinterPath = curTemplate.DefPrinter.CnnString } : usePrinter; } catch { throw new Exception("Printer not defined for template " + curTemplate.Name); } if (usePrinter == null) throw new Exception("Printer not defined for template " + curTemplate.Name); //Revisa si el label imprime por comandos y lo manda a esa ruta. if (rdlTemplateName.IsPL == true) { PrintLabelByPL(rdlTemplateName, listOfLabels, usePrinter); return; } string labelPath = Path.Combine(AppPath, WmsSetupValues.RdlTemplateDir + "\\" + rdlTemplateName.Header); if (!File.Exists(labelPath)) throw new Exception("Label template " + labelPath + " does not exists.\n"); localReport = new LocalReport(); localReport.EnableExternalImages = true; localReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence); localReport.AddTrustedCodeModuleInCurrentAppDomain("Barcode, Version=1.0.5.40001, Culture=neutral, PublicKeyToken=6dc438ab78a525b3"); localReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); localReport.EnableExternalImages = true; localReport.ReportPath = labelPath; DataSet ds = ProcessLabels(listOfLabels); localReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["Details"])); //Proceso de Creacion de archivos m_streams.Add(curTemplate, new List<Stream>()); m_currentPageIndex.Add(curTemplate, 0); Export(localReport, curTemplate, "IMAGE"); //1 - Document, 2 - Label m_currentPageIndex[curTemplate] = 0; //Ejecutar la impresion global en un Hilo Thread th = new Thread(new ParameterizedThreadStart(Print)); th.Start(curTemplate.DefPrinter.CnnString); //Print(curTemplate.DefPrinter.CnnString); } catch (Exception ex) { ExceptionMngr.WriteEvent("PrintLabelByTemplate:" + rdlTemplateName.Name, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.Business); throw new Exception(ex.Message); } }