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);
        }
Example #2
0
        private LocalReport PrintReportSilently(string ReportPath)
        {
            LocalReport lrep = new LocalReport();

            Stream s = new FileStream(ReportPath, FileMode.Open);

            lrep.LoadReportDefinition(RecalcPrescriptionLayout(ChangeMargins(s, this.PageWidth, this.PageHeight + 0.25, 0, 0), (double)this.numHCProvider.Maximum, (double)this.numHCProvider.Value, (double)this.numMedList.Maximum, (double)this.numMedList.Value, (double)this.numDateFields.Minimum, (double)this.numDateFields.Value));

            int RpWidth = 85;                                          // odczytywać z raportu!
            int MedHMax = 75 - (20 - (int)this.numMedList.Value * 10); // odczytać z raportu!

            #region Budowanie listy leków
            Medicines med = new Medicines(RpWidth, MedHMax, -1, this.NormalFont, this.BoldFont, this.g);
            this.LoadData(med);

            lrep.DataSources.Clear();
            lrep.DataSources.Add(med.GetDataSource());
            #endregion

            #region Ustawienie parametrów
            Update_danePacjent();
            Update_danePrzychodni();
            ReportParameter PrintWireframe          = new ReportParameter("PrintWireframe", this.cbPrintFrames.Checked.ToString());
            ReportParameter PrintLabels             = new ReportParameter("PrintLabels", this.cbPrintLabels.Checked.ToString());
            ReportParameter PrintPrescriptionNumber = new ReportParameter("PrintPrescriptionNumber", this.cbPrintPrescNum.Checked.ToString());
            ReportParameter PrintHCProvider         = new ReportParameter("PrintHCProvider", this.cbPrintHCProvider.Checked.ToString());

            ReportParameter HCP  = new ReportParameter("HealthcareProvider", this.danePrzychodni);
            ReportParameter PNum = new ReportParameter("PrescriptionNumber", this.GenerateRandomRpNumber());

            ReportParameter PESEL            = new ReportParameter("PESEL", "12345678901");
            ReportParameter PatientData      = new ReportParameter("PatientData", "Joanna Kołodziejczyk-Krasnodębska" + Environment.NewLine + "90-110 Łódź, Prosta 6 m. 2");
            ReportParameter PrescriptionDate = new ReportParameter("PrescriptionDate", DateTime.Now.ToString("dd-MM-yyyy"));
            ReportParameter FromDate         = new ReportParameter("FromDate", DateTime.Now.ToString("dd-MM-yyyy"));

            lrep.SetParameters(new ReportParameter[] { PrintWireframe, PrintLabels, HCP, PNum, PESEL, PatientData, PrescriptionDate, FromDate, PrintPrescriptionNumber, PrintHCProvider });
            #endregion

            lrep.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            lrep.AddTrustedCodeModuleInCurrentAppDomain("I25, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

            return(lrep);
        }
        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);

        }
Example #7
0
        private static string PrepareAndGetDeviceInfo(LocalReport report, ReportSettings settings)
        {
            /*
             * برای افزایش سرعت در حالت سندباکس کارهای زیاد انجام دادیم ولی نشد.
             * توجه!!!!! خیلی جالب آنکه اجرا در لوکال از سرور های تست
             * خیلی سریعتیر است اما بعد از پابلیش در سرور همچنان کند است
             *
             * کارهای زیر انجام شد :
             *
             * ----------------------------- کار 1 --------------------------------------------------------------
             *
             * کد زیر دقیقا در همین تابع و در همین ابندای آن قرار داده شد. کد کار می کند ولی تاثیری در سرعت نداشت :
             *
             *
             *  PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
             *  permissions.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
             *  permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags));
             *  permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
             *  permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
             *
             *  report.SetBasePermissionsForSandboxAppDomain(permissions);
             *
             *  var customAssembly = typeof(ReportsLoader).Assembly;// "Greewf.Reporting, Culture=neutral, PublicKeyToken=ebf2eb006a1f561b";
             *  StrongName assemblyStrongName = CreateStrongName(customAssembly);
             *  report.AddFullTrustModuleInSandboxAppDomain(assemblyStrongName);
             *
             *
             *
             * ----------------------------- کار 2 --------------------------------------------------------------
             *
             * همچنین تنظیمات زیر را هم در وب کانفیگ پروژه اجرایی گذاشتیم ولی باز تاثیری نداشت :
             * این موارد طبق این پست ها بود : https://stackoverflow.com/a/26733816/790811 & https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ee191568(v=vs.100)
             *
             * در بخش configuration:
             *
             * <startup uselegacyv2runtimeactivationpolicy="true">
             * </startup>
             *
             * و در بخش runtime:
             *  <NetFx40_LegacySecurityPolicy enabled="true" />
             *
             *
             * همچنین در اینجا یک پست هست که توضیح با بالاترین ووت هم خواندنی است : https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6d89e2ce-3528-465f-9740-7e22aa7b7aae/slow-performance-with-dynamic-grouping-and-reportviewer-in-local-mode?forum=sqlreportingservices
             *
             *
             *
             * ----------------------------- کار 3 --------------------------------------------------------------
             * در کانفیگ این کار را هم طبق پست روبرو انجام دادیم. سرعت به طرز وحشتناکی خوب شد : https://social.msdn.microsoft.com/Forums/en-US/b35bf409-4d73-4506-b13b-2629b1216773/reportviewer-in-net-4-even-possible-legacycasmodelquottruequot-causes-problems?forum=vsreportcontrols
             * اما محدودیت آن فراوان است
             *
             * در بخش system.web :
             *  <trust legacyCasModel="true" level="Full"/>
             * البته در صورتیکه برنامه شما یک وب سایت نیست از طریق این تنظیم runtime: (طبق لینک روبرو این تگ با NetFx40_LegacySecurityPolicy تفاوتی ندارد : https://blogs.msdn.microsoft.com/shawnfa/2009/06/12/temporarily-re-enabling-cas-policy-during-migration/)
             *  <legacyCasPolicy enabled="true" />
             *
             * در تنظیمات اسمبلی همین اسمبلی باید خط زیر را اضافه کنید : https://stackoverflow.com/a/2504341/790811
             * برای همین کار مجبور هستیم کل پروژه را جدا کنیم چراکه برای بخش های دیگر دچار مشکل می کند
             *  [assembly: AllowPartiallyTrustedCallers]
             *
             * و در کد دقیقا در همین محل عملیات زیر انجام شد :
             * var customAssembly = typeof(ReportsLoader).Assembly;
             * report.AddTrustedCodeModuleInCurrentAppDomain(customAssembly.FullName);
             *
             *
             */

            //این کد در صورتی اثر می کند که در کانفیگ برنامه تنظیم گفته شده در توضیحات انجام شده باشد
            //توجه: اسمبلی را دستی نوشتیم. دقت کنید که اگر از خود اسمبلی می گرفتیم ورژن هم داشت و ما نباید
            //در این نام آنرا به ورژن وابسته کنیم

            if (RunInLegacyCasModel)
            {
                report.AddTrustedCodeModuleInCurrentAppDomain("Greewf.Reporting, Culture=neutral, PublicKeyToken=ebf2eb006a1f561b");
            }
            else
            {
                var assembly = typeof(ReportsLoader).Assembly;
                report.AddFullTrustModuleInSandboxAppDomain(CreateStrongName(assembly));
            }


            var defaults = report.GetDefaultPageSettings();

            var marginTop    = settings.TopMargin.HasValue ? (settings.TopMargin * (1 / 2.54)) : defaults.Margins.Top / 100.0;
            var marginBottom = settings.BottomMargin.HasValue ? (settings.BottomMargin * (1 / 2.54)) : defaults.Margins.Bottom / 100.0;
            var marginLeft   = settings.LeftMargin.HasValue ? (settings.LeftMargin * (1 / 2.54)) : defaults.Margins.Left / 100.0;
            var marginRight  = settings.RightMargin.HasValue ? (settings.RightMargin * (1 / 2.54)) : defaults.Margins.Right / 100.0;

            settings.EndPage = settings.EndPage ?? settings.StartPage;

            //The DeviceInfo settings should be changed based on the reportType
            // http://msdn2.microsoft.com/en-us/library/ms155397.aspx
            // http://msdn.microsoft.com/en-us/library/hh231593.aspx
            string deviceInfo =
                "<DeviceInfo>" +
                ((settings.DpiX > 0) ? "  <DpiX>" + settings.DpiX + "</DpiX>" : "") +
                ((settings.DpiY > 0) ? "  <DpiY>" + settings.DpiY + "</DpiY>" : "") +
                "  <OutputFormat>" + settings.OutputType + "</OutputFormat>" +
                "  <PageWidth>" + (defaults.IsLandscape ? defaults.PaperSize.Height : defaults.PaperSize.Width) / 100.0 + "in</PageWidth>" +
                "  <PageHeight>" + (defaults.IsLandscape ? defaults.PaperSize.Width : defaults.PaperSize.Height) / 100.0 + "in</PageHeight>" +
                "  <MarginTop>" + marginTop + "in</MarginTop>" +
                "  <MarginLeft>" + marginLeft + "in</MarginLeft>" +
                "  <MarginRight>" + marginRight + "in</MarginRight>" +
                "  <MarginBottom>" + marginBottom + "in</MarginBottom>" +
                "  <StartPage>" + (settings.StartPage ?? 0) + "</StartPage>" +
                "  <EndPage>" + (settings.EndPage ?? 0) + "</EndPage>" +
                "  <PageBreaksMode>OnEachPage</PageBreaksMode>" +
                "  <HumanReadablePDF>" + settings.HumanReadablePdf.ToString() + "</HumanReadablePDF>";

            if (!settings.EmbedFontsInPdf)
            {
                deviceInfo += "  <EmbedFonts>None</EmbedFonts>";
            }

            deviceInfo += "</DeviceInfo>";

            return(deviceInfo);
        }