public async Task Show(String Base, String Rep, String id)
        {
            _reportHelper.SetupLicense();
            try
            {
                var          url = $"/_report/{Base.RemoveHeadSlash()}/{Rep}/{id}";
                RequestModel rm  = await RequestModel.CreateFromBaseUrl(_baseController.Host, false, url);

                var rep = rm.GetReport();

                MvcHtmlString result = null;
                using (var pr = Profiler.CurrentRequest.Start(ProfileAction.Report, $"render: {Rep}"))
                {
                    var view = new EmptyView();
                    var vc   = new ViewContext(ControllerContext, view, ViewData, TempData, Response.Output);
                    var hh   = new HtmlHelper(vc, view);
                    result = hh.Stimulsoft().StiMvcViewer("A2v10StiMvcViewer", ViewerOptions);
                }

                var sb = new StringBuilder(ResourceHelper.StiReportHtml);
                sb.Replace("$(StiReport)", result.ToHtmlString());
                sb.Replace("$(Lang)", _baseController.CurrentLang);
                sb.Replace("$(Title)", _baseController.Localize(rep.name ?? Rep));

                Response.Output.Write(sb.ToString());
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Response.Write(ex.Message);
            }
        }
Exemple #2
0
        public async Task Show(String Base, String Rep, String id)
        {
            try
            {
                var url = $"/_report/{Base.RemoveHeadSlash()}/{Rep}/{id}";


                RequestModel rm = await RequestModel.CreateFromBaseUrl(_baseController.Host, url);

                var rep = rm.GetReport();
                switch (rep.type)
                {
                case RequestReportType.stimulsoft:
                    ShowStimulsoft(rep, Rep);
                    break;

                case RequestReportType.pdf:
                    ReportInfo ri = await GetReportInfo(url, id, CreateParamsFromQueryString());
                    await ShowPdf(ri, Rep);

                    break;
                }
            }
            catch (Exception ex)
            {
                Response.ContentType     = "text/html";
                Response.ContentEncoding = Encoding.UTF8;
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Response.Write(ex.Message);
            }
        }
Exemple #3
0
        public async Task <ReportInfo> GetReportInfo(ReportContext context, String url, String id, ExpandoObject prms)
        {
            var          appReader = _host.ApplicationReader;
            var          ri        = new ReportInfo();
            RequestModel rm        = await RequestModel.CreateFromBaseUrl(_host, false, url);

            var rep = rm.GetReport();

            ri.Type = rep.type;
            if (rep.HasPath)
            {
                ri.ReportPath = appReader.MakeFullPath(rep.Path, rep.ReportName + ".mrt");
            }
            if (rep.type == RequestReportType.xml)
            {
                if (rep.xmlSchemas != null)
                {
                    ri.XmlSchemaPathes = new List <String>();
                    foreach (var schema in rep.xmlSchemas)
                    {
                        ri.XmlSchemaPathes.Add(appReader.MakeFullPath(rep.Path, schema + ".xsd"));
                    }
                }

                ri.Encoding = rep.encoding;
                ri.Validate = rep.validate;
            }

            prms.Set("UserId", context.UserId);
            if (_host.IsMultiTenant)
            {
                prms.Set("TenantId", context.TenantId);
            }
            prms.Set("Id", id);
            prms.AppendIfNotExists(rep.parameters);

            ri.DataModel = await _dbContext.LoadModelAsync(rep.CurrentSource, rep.ReportProcedure, prms);

            // after query
            ExpandoObject vars = rep.variables;

            if (vars == null)
            {
                vars = new ExpandoObject();
            }
            vars.Set("UserId", context.UserId);
            if (_host.IsMultiTenant)
            {
                vars.Set("TenantId", context.TenantId);
            }
            vars.Set("Id", id);
            ri.Variables = vars;
            var repName = _localizer.Localize(null, String.IsNullOrEmpty(rep.name) ? rep.ReportName : rep.name);

            if (ri.DataModel != null && ri.DataModel.Root != null)
            {
                repName = ri.DataModel.Root.Resolve(repName);
            }
            ri.Name = repName;
            return(ri);
        }
Exemple #4
0
        public async Task <ReportInfo> GetReportInfo(ReportContext context, String url, String id, ExpandoObject prms)
        {
            var          appReader = _host.ApplicationReader;
            var          ri        = new ReportInfo();
            RequestModel rm        = await RequestModel.CreateFromBaseUrl(_host, url);

            var rep = rm.GetReport();

            rep.CheckPermissions(_userStateManager?.GetUserPermissions(), _host.IsDebugConfiguration);

            ri.Type = rep.type;

            if (rep.type == RequestReportType.xml)
            {
                if (rep.xmlSchemas != null)
                {
                    ri.XmlSchemaPathes = new List <String>();
                    foreach (var schema in rep.xmlSchemas)
                    {
                        ri.XmlSchemaPathes.Add(appReader.MakeFullPath(rep.Path, schema + ".xsd"));
                    }
                }

                ri.Encoding = rep.encoding;
                ri.Validate = rep.validate;
            }

            prms.Set("UserId", context.UserId);
            if (_host.IsMultiTenant || context.TenantId != 0 /*hack for desktop*/)
            {
                prms.Set("TenantId", context.TenantId);
            }
            if (_host.IsMultiCompany)
            {
                prms.Set("CompanyId", context.CompanyId);
            }
            prms.Set("Id", id);
            prms.AppendIfNotExists(rep.parameters);

            ri.DataModel = await _dbContext.LoadModelAsync(rep.CurrentSource, rep.ReportProcedure, prms);

            CheckTypes(rep.Path, rep.checkTypes, ri.DataModel);

            // after query
            ExpandoObject vars = rep.variables;

            if (vars == null)
            {
                vars = new ExpandoObject();
            }
            vars.Set("UserId", context.UserId);
            if (_host.IsMultiTenant)
            {
                vars.Set("TenantId", context.TenantId);
            }
            if (_host.IsMultiCompany)
            {
                vars.Set("CompanyId", context.CompanyId);
            }
            vars.Set("Id", id);
            ri.Variables = vars;
            var repName = _localizer.Localize(null, String.IsNullOrEmpty(rep.name) ? rep.ReportName : rep.name);

            if (ri.DataModel != null && ri.DataModel.Root != null)
            {
                repName = ri.DataModel.Root.Resolve(repName);
            }
            ri.Name = repName;

            if (rep.ReportFromDataModel)
            {
                ri.ReportStream = ri.DataModel.Eval <Byte[]>(rep.ReportExpression);
                if (ri.ReportStream == null)
                {
                    throw new InvalidDataException($"Expression '{rep.ReportName}'  is null");
                }
            }
            else if (rep.HasPath)
            {
                ri.ReportPath = appReader.MakeFullPath(rep.Path, rep.ReportName + rep.GetExtension());
            }

            return(ri);
        }