private void ContextOnPostAcquireRequestState(object sender, EventArgs eventArgs) { var context = (HttpApplication)sender; if (string.IsNullOrEmpty(context.Request.QueryString[ControlIDField]) || string.IsNullOrEmpty(context.Request.QueryString[OpTypeField]) || !OpTypeExport.Equals(context.Request.QueryString[OpTypeField], StringComparison.OrdinalIgnoreCase) || !context.Request.Path.Equals("/Reserved.ReportViewerWebControl.axd", StringComparison.OrdinalIgnoreCase)) { return; } var controlID = context.Request.QueryString[ControlIDField]; var dic = (Dictionary <string, Type>)context.Session[SessionList]; if (dic == null || !dic.ContainsKey(controlID)) { return; } var plugin = dic[controlID]; DBDataContext.AddViewReports( User.GetSID(), HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name, ReportInitializerSection.GetReportInitializerSection().ReportPageViewer + "?ClassName=" + plugin.FullName, HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), Environment.MachineName, true, plugin); }
private void StiWebViewer1OnReportExport(object sender, StiExportDataEventArgs stiExportDataEventArgs) { DBDataContext.AddViewReports( Tools.Security.User.GetSID(), HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name, ReportInitializerSection.GetReportInitializerSection().ReportPageViewer + "?ClassName=" + Request.QueryString["reportName"], HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), Environment.MachineName, true, BuildManager.GetType(Request.QueryString["reportName"], true, true)); }
public Stream GetExcelStream(JournalExportEventArgs args) { string docLocation = string.Empty; if (args.ViewJournalUrl != null && args.ViewJournalUrl.Length > 0) { docLocation = args.ViewJournalUrl.ToString(); var startIndex = docLocation.IndexOf("?", StringComparison.Ordinal); var pluginName = startIndex > -1 ? docLocation.Substring(0, startIndex) : docLocation; DBDataContext.AddViewReports( User.GetSID(), HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name, docLocation, HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), Environment.MachineName, true, pluginName, LocalizationHelper.IsCultureKZ ? null : args.Header, LocalizationHelper.IsCultureKZ ? args.Header : null); } var export = new ExporterXslxByArgs(); var stream = export.GetExcel(args); if (args.ExportLog != 0) { args.LogMonitor.Log( args.ExportLog, () => { var message = new StringBuilder(); message.Append(args.Header); if (args.FilterValues != null) { message.Append("; Фильтры: \r\n"); foreach (var value in args.FilterValues) { message.Append(value); message.Append(";\r\n"); } } message.AddHyperLink(docLocation, Resources.SViewJournal, string.Empty); return(new LogMessageEntry(User.GetSID(), args.ExportLog, message.ToString())); }); } return(stream); }
public static Stream GetExcel <TDataContext, TFilterControl, TKey, TTable, TDataSource, TRow, TJournal, TNavigatorControl, TNavigatorValues, TFilter>( BaseJournalUserControl <TDataContext, TFilterControl, TKey, TTable, TDataSource, TRow, TJournal, TNavigatorControl, TNavigatorValues, TFilter> journalControl, RvsSavedProperties properties, ILogMonitor logMonitor, bool checkPermit) where TDataContext : DataContext, new() where TKey : struct where TTable : class where TFilterControl : BaseFilterControl <TKey, TTable>, new() where TDataSource : BaseDataSource <TKey, TTable, TDataContext, TRow> where TRow : BaseRow, new() where TJournal : BaseJournalControl <TKey, TTable, TRow, TDataContext> where TNavigatorControl : BaseNavigatorControl <TNavigatorValues> where TNavigatorValues : BaseNavigatorValues, new() where TFilter : BaseFilter <TKey, TTable, TDataContext>, new() { Stream stream; journalControl.LogMonitor = logMonitor; journalControl.Url = MainPageUrlBuilder.Current.Clone(); if (checkPermit) { journalControl.CheckExportPermit(); } if ("xml".Equals(properties.Format, StringComparison.OrdinalIgnoreCase)) { var exporterXml = new ExporterXml <TDataContext, TFilterControl, TKey, TTable, TDataSource, TRow, TJournal, TNavigatorControl, TNavigatorValues, TFilter> { LogMonitor = logMonitor }; stream = exporterXml.GetExcel(journalControl, properties); } else { var exporterXslx = new ExporterXslx <TDataContext, TFilterControl, TKey, TTable, TDataSource, TRow, TJournal, TNavigatorControl, TNavigatorValues, TFilter> { LogMonitor = logMonitor }; stream = exporterXslx.GetExcel(journalControl, properties); } DBDataContext.AddViewReports( User.GetSID(), HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name, HttpContext.Current.Request.Url.PathAndQuery, HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), Environment.MachineName, true, BuildManager.GetType(properties.ReportPluginName, false, true) ?? GetTypeByReportManager(properties.ReportPluginName)); logMonitor.Log( new LogMessageEntry( User.GetSID(), journalControl.ExportLog, properties.NameRu, journalControl.OnExportNewSavedProperties ? RvsSavedProperties.GetFromJournal(journalControl) : properties)); return(stream); }
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); }
public static Stream GetReport(bool useReturnStream, string pluginName, string guid, StorageValues storageValues, string culture, Page page, string format, string command, LogMonitor logMonitor, ServerReport report, out string fileNameExtention, bool RoleCheck) { fileNameExtention = ""; WebInitializer.Initialize(); report = ReportViewerInitializer(report); var webReportManager = new WebReportManager(new TreeView()); if (string.IsNullOrEmpty(pluginName)) { return(null); } webReportManager.RoleCheck = RoleCheck; webReportManager.Plugin = webReportManager.GetPlugins()[pluginName]; webReportManager.Plugin.InitializeReportCulture(culture); var webReportPlugin = (IWebReportPlugin)webReportManager.Plugin; webReportPlugin.Page = page; webReportManager.CreateView(); webReportManager.InitValues(storageValues, true); var list = new List <ReportParameter>(); foreach (var reportCondition in webReportManager.Plugin.Conditions) { var conditions = reportCondition.GetQueryConditions().ToList(); if (conditions.Count == 0) { list.Add(new ReportParameter(reportCondition.ColumnFilter.GetStorage().Name, (string)null, false)); } else { foreach (var condition in conditions) { if (condition.Parameters.Length == 0) { throw new Exception("Условие без значения не поддерживаются при формировании отчета"); } var values = condition.GetParamValues().Select(r => r.ToString()).ToArray(); list.Add(new ReportParameter(condition.ColumnName, values, false)); } } } if (!string.IsNullOrEmpty(webReportManager.Plugin.CultureParameter)) { if (webReportManager.Plugin.SupportRuKz) { list.Add(new ReportParameter(webReportManager.Plugin.CultureParameter, webReportManager.Plugin.InitializedKzCulture.ToString(), false)); } else { list.Add(new ReportParameter(webReportManager.Plugin.CultureParameter, webReportManager.Plugin.InitializedCulture, false)); } } //+= потому что инициализируется папка в которой лежат отчеты report.ReportPath += ((ISqlReportingServicesPlugin)webReportManager.Plugin).ReportUrl; report.SetParameters(list); Log(logMonitor, guid, webReportManager); var export = !string.IsNullOrEmpty(format) && "render".Equals(command, StringComparison.OrdinalIgnoreCase); DBDataContext.AddViewReports( Tools.Security.User.GetSID(), HttpContext.Current?.User.Identity.Name ?? "anonymous", HttpContext.Current?.User.Identity.Name ?? "anonymous", ReportInitializerSection.GetReportInitializerSection().ReportPageViewer + "?ClassName=" + webReportManager.Plugin.GetType().FullName, HttpContext.Current?.Request.Url.GetLeftPart(UriPartial.Authority) ?? "https://maxat", Environment.MachineName, export, webReportManager.Plugin.GetType()); if (export) { string mimeType; if (useReturnStream) { return(report.Render(format, "", null, out mimeType, out fileNameExtention)); } PageHelper.DownloadFile( report.Render(format, "", null, out mimeType, out fileNameExtention), webReportManager.Plugin.Description + "." + fileNameExtention, HttpContext.Current.Response); } return(null); }