public JsonResult ViewReportPage(string reportPath, int?page = 0)
        {
            var model = this.GetReportViewerModel(Request);

            model.ViewMode   = ReportViewModes.View;
            model.ReportPath = reportPath;

            var contentData = ReportServiceHelpers.ExportReportToFormat(model, ReportFormats.Html4_0, page, page);
            var content     = model.Encoding.GetString(contentData.ReportData);

            if (model.UseCustomReportImagePath && model.ReportImagePath.HasValue())
            {
                content = ReportServiceHelpers.ReplaceImageUrls(model, content);
            }

            var jsonResult = Json(
                new
            {
                CurrentPage = contentData.CurrentPage,
                Content     = content,
                TotalPages  = contentData.TotalPages
            },
                new Newtonsoft.Json.JsonSerializerSettings()
            {
                ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver()
            }
                );

            return(jsonResult);
        }
        public ActionResult PrintReport(string reportPath)
        {
            var model = this.GetReportViewerModel(Request);

            model.ViewMode   = ReportViewModes.Print;
            model.ReportPath = reportPath;

            var contentData = ReportServiceHelpers.ExportReportToFormat(model, ReportFormats.Html4_0);
            var content     = model.Encoding.GetString(contentData.ReportData);

            content = ReportServiceHelpers.ReplaceImageUrls(model, content);

            var sb = new System.Text.StringBuilder();

            sb.AppendLine("<html>");
            sb.AppendLine("	<body>");
            //sb.AppendLine($"		<img src='data:image/tiff;base64,{Convert.ToBase64String(contentData.ReportData)}' />");
            sb.AppendLine($"		{content}");
            sb.AppendLine("		<script type='text/javascript'>");
            sb.AppendLine("			(function() {");

            /*
             * sb.AppendLine("				var beforePrint = function() {");
             * sb.AppendLine("					console.log('Functionality to run before printing.');");
             * sb.AppendLine("				};");
             */
            sb.AppendLine("				var afterPrint = function() {");
            sb.AppendLine("					window.onfocus = function() { window.close(); };");
            sb.AppendLine("					window.onmousemove = function() { window.close(); };");
            sb.AppendLine("				};");

            sb.AppendLine("				if (window.matchMedia) {");
            sb.AppendLine("					var mediaQueryList = window.matchMedia('print');");
            sb.AppendLine("					mediaQueryList.addListener(function(mql) {");
            sb.AppendLine("						if (mql.matches) {");
            //sb.AppendLine("							beforePrint();");
            sb.AppendLine("						} else {");
            sb.AppendLine("							afterPrint();");
            sb.AppendLine("						}");
            sb.AppendLine("					});");
            sb.AppendLine("				}");

            //sb.AppendLine("				window.onbeforeprint = beforePrint;");
            sb.AppendLine("				window.onafterprint = afterPrint;");

            sb.AppendLine("			}());");
            sb.AppendLine("			window.print();");
            sb.AppendLine("		</script>");
            sb.AppendLine("	</body>");

            sb.AppendLine("<html>");

            return(Content(sb.ToString(), "text/html"));
        }
예제 #3
0
        public JsonResult Execute(string reportPath, [FromBody] Dictionary <string, string[]> parameters, int page = 0)
        {
            try
            {
                var model = this.GetReportViewerModel(Request);

                model.ViewMode   = ReportViewModes.View;
                model.ReportPath = reportPath;

                if (parameters.Any())
                {
                    model.Parameters = parameters;
                }

                var contentData = ReportServiceHelpers.ExportReportToFormat(model, ReportFormats.Html4_0, page, page);
                var content     = model.Encoding.GetString(contentData.ReportData ?? new byte[] { });
                if (model.UseCustomReportImagePath && model.ReportImagePath.HasValue())
                {
                    content = ReportServiceHelpers.ReplaceImageUrls(model, content);
                }

                var jsonResult = Json(
                    new
                {
                    contentData.CurrentPage,
                    content,
                    contentData.Parameters,
                    contentData.TotalPages
                },
                    new Newtonsoft.Json.JsonSerializerSettings()
                {
                    ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
                }
                    );

                return(jsonResult);
            }
            catch (Exception exception)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new
                {
                    ExceptionMessage = exception.Message,
                }));
            }
        }