public async Task <Object> InvokeAsync(Int64 UserId, Int32 TenantId, Int64 Id, String Report, String Model, String Schema) { _reportHelper.SetupLicense(); var dm = await _dbContext.LoadModelAsync(String.Empty, $"[{Schema}].[{Model}.Report]", new { UserId, TenantId, Id }); using (var stream = CreateStream(dm, Report)) { var r = StiReportExtensions.CreateReport(stream, String.Empty); r.AddDataModel(dm); using (var ms = new MemoryStream()) { r.Render(); r.ExportDocument(StiExportFormat.Pdf, ms, StiReportExtensions.GetDefaultPdfSettings()); ms.Seek(0, SeekOrigin.Begin); AttachmentUpdateInfo ai = new AttachmentUpdateInfo() { UserId = UserId, TenantId = TenantId, Id = Id, Mime = "application/pdf", Stream = ms, Name = r.ReportName }; if (String.IsNullOrEmpty(ai.Name)) { ai.Name = "Attachment"; } await _dbContext.ExecuteAsync(String.Empty, $"[{Schema}].[{Model}.SaveAttachment]", ai); return(new { ai.Id }); } } }
public async Task <ActionResult> GetReport() { try { var rp = StiMvcViewer.GetRequestParams(); var Rep = rp.HttpContext.Request.Params["Rep"]; var Base = rp.HttpContext.Request.Params["Base"]; var id = rp.Routes["Id"]; var url = $"/_report/{Base}/{Rep}/{id}"; //TODO: profile var token = Profiler.BeginReport("create"); ReportInfo ri = await GetReportInfo(url, id); //TODO: image settings var rm = rm.ImageInfo; if (ri == null) { throw new InvalidProgramException("invalid data"); } var path = ri.ReportPath; var r = StiReportExtensions.CreateReport(path, ri.Name); if (ri.DataModel != null) { var dynModel = ri.DataModel.GetDynamic(); foreach (var x in dynModel) { r.RegBusinessObject(x.Key, x.Value); } } var vars = ri.Variables; if (vars != null) { r.AddVariables(vars); } return(StiMvcViewer.GetReportResult(r)); } catch (Exception ex) { String msg = ex.Message; Int32 x = msg.IndexOf(": error"); if (x != -1) { msg = msg.Substring(x + 7).Trim(); } return(new HttpStatusCodeResult(500, msg)); } }
public async Task <ActionResult> GetReport() { try { var rp = StiMvcViewer.GetRequestParams(); var Rep = rp.HttpContext.Request.Params["Rep"]; var Base = rp.HttpContext.Request.Params["Base"]; var id = rp.Routes["Id"]; var url = $"/_report/{Base.RemoveHeadSlash()}/{Rep}/{id}"; //TODO: profile var token = Profiler.BeginReport("create"); var prms = new ExpandoObject(); prms.Append(_baseController.CheckPeriod(rp.HttpContext.Request.QueryString), toPascalCase: true); prms.RemoveKeys("Rep,rep,Base,base,Format,format"); ReportInfo ri = await GetReportInfo(url, id, prms); //TODO: image settings var rm = rm.ImageInfo; if (ri == null) { throw new InvalidProgramException("invalid data"); } var path = ri.ReportPath; using (var stream = _baseController.Host.ApplicationReader.FileStreamFullPathRO(path)) { var r = StiReportExtensions.CreateReport(stream, ri.Name); r.AddDataModel(ri.DataModel); var vars = ri.Variables; if (vars != null) { r.AddVariables(vars); } return(StiMvcViewer.GetReportResult(r)); } } catch (Exception ex) { String msg = ex.Message; Int32 x = msg.IndexOf(": error"); if (x != -1) { msg = msg.Substring(x + 7).Trim(); } return(new HttpStatusCodeResult(500, msg)); } }
ActionResult ExportStiReport(ReportInfo ri) { var r = StiReportExtensions.CreateReport(ri.ReportPath, ri.Name); if (ri.DataModel != null) { var dynModel = ri.DataModel.GetDynamic(); foreach (var x in dynModel) { r.RegBusinessObject(x.Key, x.Value); } } if (ri.Variables != null) { r.AddVariables(ri.Variables); } var ms = new MemoryStream(); // saveFileDialog: true -> download // saveFileDialog: false -> show return(StiMvcReportResponse.ResponseAsPdf(r, StiReportExtensions.GetPdfExportSettings(), saveFileDialog: true)); }
public async Task <Object> InvokeAsync(Int64 UserId, Int32 TenantId, Int64 Id, String Report, String Model, String Schema) { _reportHelper.SetupLicense(); var dm = await _dbContext.LoadModelAsync(String.Empty, $"[{Schema}].[{Model}.Report]", new { UserId, TenantId, Id }); String path = _host.ApplicationReader.MakeFullPath(Report, String.Empty); path = Path.ChangeExtension(path, ".mrt"); if (!_host.ApplicationReader.FileExists(path)) { throw new FileNotFoundException(path); } var r = StiReportExtensions.CreateReport(_host.ApplicationReader.FileStreamFullPathRO(path), String.Empty); r.AddDataModel(dm); using (var ms = new MemoryStream()) { r.Render(); r.ExportDocument(StiExportFormat.Pdf, ms, StiReportExtensions.GetDefaultPdfSettings()); ms.Seek(0, SeekOrigin.Begin); AttachmentUpdateInfo ai = new AttachmentUpdateInfo() { UserId = UserId, TenantId = TenantId, Id = Id, Mime = "application/pdf", Stream = ms, Name = r.ReportName }; if (String.IsNullOrEmpty(ai.Name)) { ai.Name = "Attachment"; } await _dbContext.ExecuteAsync(String.Empty, $"[{Schema}].[{Model}.SaveAttachment]", ai); return(new { ai.Id }); } }