/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { base.CreateChildControls(); this.reportViewer = new StiWebViewer { ID = "ReportViewer" }; this.Controls.Add(this.reportViewer); }
public static Stream GetReport(bool useReturnStream, string pluginName, string guid, StorageValues storageValues, string culture, Page page, string format, string command, LogMonitor logMonitor, bool expToWord, Dictionary <string, object> constants, StiWebViewer report, out string fileNameExtention, bool RoleCheck) { var originalUICulture = Thread.CurrentThread.CurrentUICulture; var originalCulture = Thread.CurrentThread.CurrentCulture; try { if (string.IsNullOrEmpty(culture)) { culture = "ru-ru"; } Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = new CultureInfo(culture == "ru" ? "ru-ru" : (culture == "kz" ? "kk-kz" : culture)); fileNameExtention = ""; WebInitializer.Initialize(); var webReportManager = new WebReportManager(new TreeView()); if (string.IsNullOrEmpty(pluginName)) { return(null); } webReportManager.RoleCheck = RoleCheck; webReportManager.Plugin = webReportManager.GetPlugins()[pluginName]; if (webReportManager.Plugin != null) { webReportManager.Plugin.InitializeReportCulture(culture); var values = storageValues; var webReportPlugin = (IWebReportPlugin)webReportManager.Plugin; var stiPlugin = (IStimulsoftReportPlugin)webReportPlugin; webReportPlugin.Page = page; webReportManager.CreateView(); if (!string.IsNullOrEmpty(webReportManager.Plugin.CultureParameter)) { values.SetStorageValues( webReportManager.Plugin.CultureParameter, webReportManager.Plugin.InitializedKzCulture); } webReportManager.InitValues(values, webReportPlugin.InitSavedValuesInvisibleConditions); webReportPlugin.Constants = constants; if (!string.IsNullOrEmpty(webReportManager.Plugin.CultureParameter) && stiPlugin.Report.Dictionary.Variables.Contains(webReportManager.Plugin.CultureParameter)) { if (webReportManager.Plugin.SupportRuKz) { stiPlugin.Report[webReportManager.Plugin.CultureParameter] = webReportManager.Plugin.InitializedKzCulture; } else { stiPlugin.Report[webReportManager.Plugin.CultureParameter] = webReportManager.Plugin.InitializedCulture; } } try { webReportManager.ShowReport(); } catch (ConstraintException e) { var allErrors = webReportManager.Plugin.Table.DataSet?.GetAllErrors(); if (!string.IsNullOrEmpty(allErrors)) { throw new Exception(allErrors, e); } var errors = webReportManager.Plugin.Table.GetErrors(); if (errors.Length > 0) { throw new Exception(errors.Select(r => r.RowError).Aggregate((v1, v2) => v1 + "; " + v2), e); } throw; } var section = ReportInitializerSection.GetReportInitializerSection(); if (section != null && !string.IsNullOrEmpty(section.PropSaveDataFile)) { if (webReportManager.Plugin.Table.DataSet != null) { webReportManager.Plugin.Table.DataSet.WriteXml(section.PropSaveDataFile); } else { webReportManager.Plugin.Table.WriteXml(section.PropSaveDataFile); } } if (HttpContext.Current != null && HttpContext.Current.Request.QueryString["GetDataSet"] == "on" && UserRoles.IsInRole(UserRoles.ADMIN)) { using (var stream = new MemoryStream()) { if (webReportManager.Plugin.Table.DataSet != null) { webReportManager.Plugin.Table.DataSet.WriteXml(stream); } else { webReportManager.Plugin.Table.WriteXml(stream); } stream.Position = 0; PageHelper.DownloadFile(stream, "data.xml", HttpContext.Current.Response); } } var autoExport = webReportPlugin as IReportAutoExport; DBDataContext.AddViewReports( Tools.Security.User.GetSID(), HttpContext.Current?.User.Identity.Name ?? "anonymous", HttpContext.Current?.User.Identity.Name ?? "anonymous", ReportInitializerSection.GetReportInitializerSection().ReportPageViewer + "?ClassName=" + pluginName, HttpContext.Current?.Request.Url.GetLeftPart(UriPartial.Authority) ?? "https://maxat", Environment.MachineName, useReturnStream || autoExport != null || expToWord || stiPlugin.AutoExportTo != null, webReportManager.Plugin.GetType()); Log(logMonitor, guid, webReportManager); if (useReturnStream) { StiExportFormat stiExportFormat; try { stiExportFormat = (StiExportFormat)Enum.Parse(typeof(StiExportFormat), format); } catch (Exception) { var stiCustomExportType = (CustomExportType)Enum.Parse(typeof(CustomExportType), format); return(ExportWithoutShow( webReportManager.Report, stiCustomExportType, true, out fileNameExtention)); } fileNameExtention = WebReportManager.GetFileExtension(stiExportFormat); return(ExportWithoutShow(webReportManager.Report, stiExportFormat, true)); } //webReportManager.Report.EndRender += (sender, args) => LogMessages(webReportManager.Report, logMonitor); if (autoExport != null) { autoExport.Export(); } if (!expToWord && stiPlugin.AutoExportTo == null) { report.Report = webReportManager.Report; page.Cache.Insert(report.Report.ReportName, report.Report, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), CacheItemPriority.NotRemovable, null); report.ResetCurrentPage(); } else if (webReportPlugin.CustomExportType != CustomExportType.None) { return(ExportWithoutShow( webReportManager.Report, webReportPlugin.CustomExportType, false, out fileNameExtention)); } else if (stiPlugin.AutoExportTo != null) { return(ExportWithoutShow(webReportManager.Report, stiPlugin.AutoExportTo.Value, false)); } else { return(ExportWithoutShow(webReportManager.Report, StiExportFormat.Word2007, false)); } } } finally { Thread.CurrentThread.CurrentUICulture = originalUICulture; Thread.CurrentThread.CurrentCulture = originalCulture; } return(null); }