public void Initialize()
        {
            // инициализация ColumnFilterFactory
            ColumnFilterFactory columnFilterFactory = null;

            try
            {
                columnFilterFactory = SpecificInstances.ColumnFilterFactory;
            }
            catch (NullReferenceException)
            {
            }

            if (columnFilterFactory == null)
            {
                var section = ReportInitializerSection.GetReportInitializerSection();
                var type    = Type.GetType(section.ColumnFilterFactoryType, false, true)
                              ?? BuildManager.GetType(section.ColumnFilterFactoryType, false, true)
                              ?? typeof(WebColumnFilterFactory);
                SpecificInstances.ColumnFilterFactory = (ColumnFilterFactory)Activator.CreateInstance(type);
            }

            var rm = new WebReportManager(null);

            rm.GetPlugins();
        }
        public static bool HasConfiguration()
        {
            var reportSection = ReportInitializerSection.GetReportInitializerSection();

            return(!string.IsNullOrEmpty(reportSection.ReportingServicesUserName) &&
                   !string.IsNullOrEmpty(reportSection.ReportingServicesPassword));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Сформировать ссылку на отчет
        /// </summary>
        /// <param name="idrec">Передача параметров атчету</param>
        /// <param name="pluginType">Тип плагина отчета</param>
        /// <param name="backText">Текст для кнопки вернуться</param>
        /// <param name="backUrl">Адрес кнопки "вернуться"</param>
        /// <param name="export">Сразу выполнить экспорт</param>
        /// <returns>Адрес отчета</returns>
        public static string GetReportUrl(string idrec, string pluginType, string backText, string backUrl, bool export)
        {
            var reportUrl = ReportInitializerSection.GetReportInitializerSection().ReportPageViewer;

            idrec      = idrec == "{0}" ? idrec : HttpUtility.UrlEncode(idrec);
            pluginType = HttpUtility.UrlEncode(pluginType);
            if (export)
            {
                return($@"{reportUrl}?expword=1&idrec={idrec}&ClassName={pluginType}");
            }
            return($@"{reportUrl}?idrec={idrec}&ClassName={pluginType}&text={HttpUtility.UrlEncode(backText)}&backPath={HttpUtility.UrlEncode(backUrl)}");
        }
Exemplo n.º 4
0
        private void Page_OnLoadComplete(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["backPath"]) &&
                !string.IsNullOrEmpty(Request.QueryString["text"]) &&
                bBack != null)
            {
                bBack.Visible = true;
                bBack.Text    = Request.QueryString["text"];
            }

            if (IsPostBack)
            {
                return;
            }

            string guid          = Request.QueryString["values"];
            var    storageValues = (StorageValues)Session[guid];

            if (storageValues == null)
            {
                Response.Redirect(ReportInitializerSection.GetReportInitializerSection().ReportPageViewer + "?open=off&setDefaultParams=on&ClassName=" + Request.QueryString["reportName"]);
                return;
            }

            var    expToWord = !string.IsNullOrEmpty(Request.QueryString["expword"]);
            string fileNameExtention;

            GetReport(
                false,
                Request.QueryString["reportName"],
                guid,
                storageValues,
                Request.QueryString["culture"],
                Page,
                Request.QueryString["rs:format"],
                Request.QueryString["rs:command"],
                LogMonitor.LogMonitor,
                expToWord,
                (Dictionary <string, object>)Session["constants" + guid],
                StiWebViewer1,
                out fileNameExtention,
                true);

            if (this.StiWebViewer1.Report != null &&
                this.StiWebViewer1.Report.ReportRenderingMessages != null &&
                this.StiWebViewer1.Report.ReportRenderingMessages.Count > 0)
            {
                foreach (var renderingMessage in this.StiWebViewer1.Report.ReportRenderingMessages)
                {
                    this.Trace.WarnExt("ReportRendering", renderingMessage);
                }
            }
        }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 6
0
        protected override void OnLoadComplete(EventArgs e)
        {
            base.OnLoadComplete(e);

            if (!string.IsNullOrEmpty(Request.QueryString["backPath"]) &&
                !string.IsNullOrEmpty(Request.QueryString["text"]) &&
                bBack != null)
            {
                bBack.Visible = true;
                bBack.Text    = Request.QueryString["text"];
            }

            if (!Page.IsPostBack)
            {
                string guid          = Request.QueryString["values"];
                var    storageValues = (StorageValues)Session[guid];
                if (storageValues == null)
                {
                    Response.Redirect(
                        ReportInitializerSection.GetReportInitializerSection().ReportPageViewer + "?open=off&setDefaultParams=on&ClassName="
                        + Request.QueryString["reportName"]);
                    return;
                }

                string fileNameExtention;
                GetReport(
                    false,
                    Request.QueryString["reportName"],
                    guid,
                    storageValues,
                    Request.QueryString["culture"],
                    Page,
                    Request.QueryString["rs:format"],
                    Request.QueryString["rs:command"],
                    LogMonitor.LogMonitor,
                    rv.ServerReport,
                    out fileNameExtention,
                    true);

                var property = rv.GetType().GetProperty(
                    "InstanceIdentifier",
                    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                if (property != null)
                {
                    var instanceIdentifier = Convert.ToString(property.GetValue(rv, null));
                    if (!string.IsNullOrEmpty(instanceIdentifier))
                    {
                        var type = BuildManager.GetType(Request.QueryString["reportName"], true, true);
                        SqlReportViewerLogExportModule.SetPlugin(instanceIdentifier, type);
                    }
                }
            }
        }
Exemplo n.º 7
0
        private static ServerReport ReportViewerInitializer(ServerReport report)
        {
            var reportSection = ReportInitializerSection.GetReportInitializerSection();

            if (ReportServerCredentials.HasConfiguration())
            {
                report.ReportServerCredentials = new ReportServerCredentials();
            }
            //report.ReportServerUrl = new Uri(@"http://stendnat/ReportServer/");
            report.ReportServerUrl = new Uri(reportSection.ReportingServicesUrl);
            report.ReportPath      = reportSection.ReportingServicesReportsFolder;
            return(report);
        }
Exemplo n.º 8
0
        public static IReportPlugin GetPlugin(string reportPluginName)
        {
            var section = ReportInitializerSection.GetReportInitializerSection();
            var errors  = new StringBuilder();
            var tPlugin = typeof(IWebReportPlugin);
            IWebReportPlugin reportPlugin = null;

            try
            {
                var types = section.ReprotPlugins.GetReportPlugins();
                foreach (var type in types.Where(tPlugin.IsAssignableFrom))
                {
                    try
                    {
                        if (type.FullName.Equals(reportPluginName))
                        {
                            reportPlugin = (IWebReportPlugin)Activator.CreateInstance(type);
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        errors.AppendLine("Can't create '" + type.FullName + "':");
                        errors.AppendLine(e.ToString());
                        errors.AppendLine();
                        errors.AppendLine();
                    }
                }
            }
            catch (Exception e)
            {
                errors.AppendLine(e.ToString());
                errors.AppendLine();
                errors.AppendLine();
            }

            if (errors.Length > 0)
            {
                var errorsStr  = errors.ToString();
                var sid        = HttpContext.Current.User == null ? "Nat.Initializer" : User.GetSID();
                var logMonitor = InitializerSection.GetSection().LogMonitor;
                logMonitor.Init();
                logMonitor.Log(
                    LogConstants.SystemErrorInApp,
                    () => new LogMessageEntry(sid, LogMessageType.SystemErrorInApp, errorsStr));
                TraceContextExt.WarnExt(HttpContext.Current.Trace, errorsStr);
            }

            return(reportPlugin);
        }
Exemplo n.º 9
0
        public override void ShowNewReport(string reportUrl, QueryConditionList conditionList)
        {
            var parameters = conditionList.GetFilterParameters();
            var sb         = new StringBuilder();

            sb.Append(ReportInitializerSection.GetReportInitializerSection().ReportingServicesPageViewer);
            sb.Append("?");
            sb.Append(reportUrl);
            foreach (var parameter in parameters)
            {
                sb.Append("&");
                sb.Append(parameter.Key);
                sb.Append("=");
                sb.Append(parameter.Value);
            }
            HttpContext.Current.Response.Redirect(sb.ToString());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Сформировать ссылку на отчет
        /// </summary>
        /// <param name="idrec">Передача параметров атчету</param>
        /// <param name="pluginType">Тип плагина отчета</param>
        /// <param name="backText">Текст для кнопки вернуться</param>
        /// <param name="backUrl">Адрес кнопки "вернуться"</param>
        /// <param name="export">Сразу выполнить экспорт</param>
        /// <returns>Адрес отчета</returns>
        public static string GetReportUrl(string idrec, string pluginType, string backText, string backUrl, string culture, bool export)
        {
            var reportPageViewer = ReportInitializerSection.GetReportInitializerSection().ReportPageViewer;

            idrec      = idrec == "{0}" ? idrec : HttpUtility.UrlEncode(idrec);
            pluginType = HttpUtility.UrlEncode(pluginType);
            if (export)
            {
                return($@"{reportPageViewer}?expword=1&idrec={idrec}&ClassName={pluginType}&culture={culture}");
            }
            return(string.Format(
                       @"{0}?idrec={1}&ClassName={2}&text={3}&culture={5}&backPath={4}",
                       reportPageViewer,
                       idrec,
                       pluginType,
                       HttpUtility.UrlEncode(backText),
                       HttpUtility.UrlEncode(backUrl),
                       culture));
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }