Exemplo n.º 1
0
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var    token             = Request.QueryString["token"];
            var    sessionId         = Request.QueryString["session"];
            string reportDocumentKey = "ReportDocument_" + token;

            // set the page hidden variable.
            hiddenToken.Value     = token;
            hiddenSessionId.Value = sessionId;

            var report = GetReport(token, sessionId);

            if (report == null)
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            CommonUtil.SetCulture(report.Context.Language);

            // Check whether this report belongs to the same user. If not don't do anything.
            if (report.Context.SessionId != sessionId)
            {
                errorLabel.Text = CommonResx.NotAuthorizedMesage;
                return;
            }

            report.Context.Container = ConfigurationHelper.Container;

            bool isNew;

            var reportDocument = InMemoryCacheProvider.Instance.Get <SageWebReportDocument>(reportDocumentKey);

            if (reportDocument == null)
            {
                using (var watcher = new WADLogWatcher("ReportWatcher"))
                {
                    var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew);

                    watcher.Print("Session Created.");

                    // Throw an exception if the Crystal Reports template file is not found
                    var output       = GetReportTemplatePath(report.Name, session.UserLanguage);
                    var reportPath   = output.Item1;
                    var filenameOnly = output.Item2;
                    if (!File.Exists(reportPath))
                    {
                        //
                        // Security Consideration:
                        //    Do not use the full path in the message. Use only the filename
                        //
                        var msg = string.Format(CommonResx.Template_ReportCouldNotBeLocated, filenameOnly);
                        throw new MissingFileException(msg);
                    }

                    ACCPAC.Advantage.Report accpacReport = session.SelectReport(report.Name, report.ProgramId, report.MenuId);
                    foreach (var parameter in report.Parameters)
                    {
                        var value = GetValue(parameter);
                        accpacReport.SetParam(parameter.Id, value);
                    }

                    var userId = session.GetSession().UserID;
                    EvictUserWatcher.AddUserIdToPauseEviction(userId);

                    try
                    {
                        // Use lock to fix CRM multiple users concurrency printing issues.
                        lock (Lock)
                        {
                            var doc = accpacReport.GetReportDocument();
                            reportDocument = new SageWebReportDocument(doc, session, accpacReport);
                        }
                    }
                    finally
                    {
                        // Make sure we remove that from EvictUserWatcher no matter what happen
                        EvictUserWatcher.RemoveUserIdFromPauseEviction(userId);
                    }

                    watcher.Print("Report Document Created.");

                    // store the report object in the memory
                    InMemoryCacheProvider.Instance.Set(reportDocumentKey,
                                                       reportDocument,
                                                       ConfigurationHelper.ReportCacheExpirationInMinutes);
                }
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument.CrystalReportDocument;
                CrystalReportViewerSage300.DataBind();
                SetLogoPath(reportDocument, report);
            }

            if (!IsPostBack && report.ReportProcessType.HasFlag(ReportProcessType.OnLoad))
            {
                Process(report);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var    token             = Request.QueryString["token"];
            string reportDocumentKey = "ReportDocument_" + token;

            // set the page hidden variable.
            hiddenToken.Value = token;

            var report = GetReport(token);

            if (report == null)
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            CommonUtil.SetCulture(report.Context.Language);

            //Check whether this report belongs to the same user.If not don't do anything.
            if (report.Context.SessionId != Session.SessionID)
            {
                errorLabel.Text = CommonResx.NotAuthorizedMesage;
                return;
            }

            report.Context.Container = ConfigurationHelper.Container;

            bool isNew;

            var reportDocument = InMemoryCacheProvider.Instance.Get <ReportDocument>(reportDocumentKey);

            if (reportDocument == null)
            {
                using (var watcher = new WADLogWatcher("ReportWatcher"))
                {
                    using (var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew))
                    {
                        watcher.Print("Session Created.");
                        var accpacReport = session.SelectReport(report.Name, report.ProgramId, report.MenuId);
                        foreach (var parameter in report.Parameters)
                        {
                            var value = GetValue(parameter);
                            accpacReport.SetParam(parameter.Id, value);
                        }

                        reportDocument = accpacReport.GetReportDocument();
                        watcher.Print("Report Document Created.");

                        // store the report object in the memory
                        InMemoryCacheProvider.Instance.Set(reportDocumentKey, reportDocument);
                    }
                }
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument;
                CrystalReportViewerSage300.DataBind();
                SetLogoPath(reportDocument, report);
            }

            if (!IsPostBack && report.ReportProcessType.HasFlag(ReportProcessType.OnLoad))
            {
                Process(report);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var    token             = Request.QueryString["token"];
            var    sessionId         = Request.QueryString["session"];
            string reportDocumentKey = "ReportDocument_" + token;

            // set the page hidden variable.
            hiddenToken.Value     = token;
            hiddenSessionId.Value = sessionId;

            var report = GetReport(token, sessionId);

            if (report == null)
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            CommonUtil.SetCulture(report.Context.Language);

            //Check whether this report belongs to the same user.If not don't do anything.
            if (report.Context.SessionId != sessionId)
            {
                errorLabel.Text = CommonResx.NotAuthorizedMesage;
                return;
            }

            report.Context.Container = ConfigurationHelper.Container;

            bool isNew;

            var reportDocument = InMemoryCacheProvider.Instance.Get <SageWebReportDocument>(reportDocumentKey);

            if (reportDocument == null)
            {
                using (var watcher = new WADLogWatcher("ReportWatcher"))
                {
                    using (var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew))
                    {
                        watcher.Print("Session Created.");
                        var accpacReport = session.SelectReport(report.Name, report.ProgramId, report.MenuId);
                        foreach (var parameter in report.Parameters)
                        {
                            var value = GetValue(parameter);
                            accpacReport.SetParam(parameter.Id, value);
                        }

                        var userId = session.GetSession().UserID;
                        EvictUserWatcher.AddUserIdToPauseEviction(userId);

                        try
                        {
                            //Use lock to fix CRM multiple users concurrency printing issues.
                            lock (Lock)
                            {
                                reportDocument = new SageWebReportDocument(accpacReport.GetReportDocument());
                            }
                        }
                        finally
                        {
                            // make sure we remove that from EvictUserWatcher no matter what happen
                            EvictUserWatcher.RemoveUserIdFromPauseEviction(userId);
                        }

                        watcher.Print("Report Document Created.");

                        // store the report object in the memory
                        InMemoryCacheProvider.Instance.Set(reportDocumentKey, reportDocument);
                    }
                }
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument.CrystalReportDocument;
                CrystalReportViewerSage300.DataBind();
                SetLogoPath(reportDocument, report);
            }

            if (!IsPostBack && report.ReportProcessType.HasFlag(ReportProcessType.OnLoad))
            {
                Process(report);
            }
        }