Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

How to print a Crystal Report locally when App is published on Server?

$
0
0

Hi 

I am using the below method. How can I print the report automatically?

 public ActionResult GenerateLoanSlip(int patronId)
        {

            var patron = _patronService.GetBy(patronId);

            var loans = _circulationService.GetLoansByPatron(patronId, true);

            int locationId = 0;
            string header;
            string footer;

            foreach (var item in loans)
            {
                locationId = item.location;
                LocationService locationservice = new LocationService(DataContext);
                var locationresult = locationservice.GetTopLocation(locationId);

                if (locationresult.LocationId != null)
                {
                    var toplocationresult = locationservice.GetTopLocation(locationresult.LocationId.Value);
                    if (toplocationresult.LocationId == null)
                    {
                        locationId = toplocationresult.Id;
                    }
                    else
                    {
                        var location = locationservice.GetTopLocation(toplocationresult.LocationId.Value);
                        locationId = location.Id;
                    }
                    break;
                }

            }

            PrintTemplateService printtemplateservice = new PrintTemplateService(DataContext);
            var printtemplatetype = printtemplateservice.GetByLocationID(locationId);
            if (printtemplatetype != null)
            {
                header = printtemplatetype.Header;
                footer = printtemplatetype.Footer;
            }
            else
            {
                GlobalSettingsService globalservice = new GlobalSettingsService(DataContext);
                var reporttype = globalservice.GetBy("Receipt Template");
                var templatetype = printtemplateservice.GetBy(Convert.ToInt32(reporttype.Value));
                header = templatetype.Header;
                footer = templatetype.Footer;

            }

            IList<LoanSlipViewModel> loanViewModels = GenerateLoanSlipViewModel(loans, patron, header, footer);
            //IList<LoanSlipViewModel> loanViewModels = new List<LoanSlipViewModel>();

            var rpt = new Services.Report.ReportService("LoanSlip", null);
            rpt.ReportDocument.SetDataSource(loanViewModels);
            rpt.ReportDocument.PrintToPrinter(1, true, 0, 0);
            return ReturnPDF(rpt.GetPDFStream(), "LoanSlip");


        }

The below line doesn't seem to be working when published.

rpt.ReportDocument.PrintToPrinter(1, true, 0, 0); 

Thanks


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>