Example #1
0
        private static void PrintDocumentThread(Object document)
        {
            //Report File exists
            string reportPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), WmsSetupValues.RdlTemplateDir + "\\" + curTemplate.Header);

            if (!File.Exists(reportPath))
            {
                return;
            }

            //Rendering Report
            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           = reportPath;


            DataSet ds;

            //Document

            ds = ReportMngr.ProcessDocument(((Document)document).DocID, new WMSServiceClient(), curTemplate.Header);
            if (ds == null)
            {
                return;
            }

            localReport.DataSources.Add(new ReportDataSource("Header", ds.Tables["ReportHeaderFormat"]));
            localReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["ReportDetailFormat"]));



            //Print Report
            //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(printer.PrinterName);

            Print(usePrinter.PrinterName);
        }
        public static void Export(LocalReport report, string printername, string jobname)
        {
            string deviceInfo =
                @"<DeviceInfo>
                <OutputFormat>EMF</OutputFormat>
                <PageWidth>210mm</PageWidth>
                <PageHeight>297mm</PageHeight>
                <MarginTop>0</MarginTop>
                <MarginLeft>0</MarginLeft>
                <MarginRight>0</MarginRight>
                <MarginBottom>0</MarginBottom>
            </DeviceInfo>";

            Warning[] warnings;
            m_streams = new List <Stream>();
            /* my very own https://stackoverflow.com/questions/40545540/asp-net-localreport-render-invalid-token-for-impersonation/51106487#51106487 */
            report.ExecuteReportInCurrentAppDomain(Assembly.GetExecutingAssembly().Evidence);
            report.Render("Image", deviceInfo, CreateStream, out warnings);
            foreach (Stream stream in m_streams)
            {
                stream.Position = 0;
            }
            Print(printername, jobname);
        }
        private void PrintDocumentThread(Object document)
        {

            //Report File exists
            string reportPath = Path.Combine(AppPath, WmsSetupValues.RdlTemplateDir + "\\" + curTemplate.Header);

            if (!File.Exists(reportPath))
                throw new Exception("Report file does not exists.");


            try
            {
                //Rendering Report
                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 = reportPath;


                //Obteniendo la informacion del Reporte (DataSet)
                ReportHeaderFormat rptHdr = GetReportInformation((Document)document, curTemplate.Header);
                DataSet ds = GetReportDataset(rptHdr);

                localReport.DataSources.Add(new ReportDataSource("Header", ds.Tables["ReportHeaderFormat"]));
                localReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["ReportDetailFormat"]));
            }
            catch { return; }


            //Print Report
            //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);
        }
Example #4
0
        private static void PrintLabelByTemplate(LabelTemplate template, List <Label> listOfLabels)
        {
            if (listOfLabels == null || listOfLabels.Count == 0)
            {
                return;
            }

            listLabels = listOfLabels;

            try
            {
                //Si viene una impresora definida utiliza esa, si no utiliza la del template
                if (template != null)
                {
                    curTemplate = template;
                }
                else
                {
                    curTemplate = (new WMSProcessClient()).GetLabelTemplate(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 (template.IsPL == true)
            {
                PrintLabelByPL(template, listOfLabels, usePrinter);
                return;
            }


            try
            {
                string labelPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                WmsSetupValues.RdlTemplateDir + "\\" + template.Header);

                if (!File.Exists(labelPath))
                {
                    throw new Exception("Label template " + template.Header + " does not exists.\n");
                }


                //Definicion de Reporte
                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
                curTemplate = template;
                m_streams.Add(curTemplate, new List <Stream>());
                m_currentPageIndex.Add(curTemplate, 0);

                Export(localReport, curTemplate, "IMAGE");  //1 - Document, 2 -  Label


                m_currentPageIndex[curTemplate] = 0;
                Thread th = new Thread(new ParameterizedThreadStart(Print));
                th.Start(usePrinter.PrinterName);
                //Print(usePrinter.PrinterName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        private static void PrintDocumentThread(Object document)
        {

            //Report File exists
            string reportPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), WmsSetupValues.RdlTemplateDir + "\\" + curTemplate.Header);

            if (!File.Exists(reportPath))
                return;

            //Rendering Report
            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 = reportPath;


            DataSet ds;
            //Document

            ds = ReportMngr.ProcessDocument(((Document)document).DocID, new WMSServiceClient(), curTemplate.Header);
            if (ds == null)
                return;

            localReport.DataSources.Add(new ReportDataSource("Header", ds.Tables["ReportHeaderFormat"]));
            localReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["ReportDetailFormat"]));



            //Print Report
            //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(printer.PrinterName);

            Print(usePrinter.PrinterName);

        }