InitForExecution() public method

public InitForExecution ( ) : void
return void
        public void ViewReport(Report report, Repository repository, bool render, string viewGUID, string outputGUID, string originalFilePath)
        {
            Show();
            Text = Path.GetFileNameWithoutExtension(originalFilePath) + " - " + Repository.SealRootProductName + " Report Viewer";
            BringToFront();

            Report previousReport = _report;

            _report = report;
            _report.ExecutionContext = ReportExecutionContext.DesignerReport;
            if (string.IsNullOrEmpty(_report.DisplayName)) _report.DisplayName = Path.GetFileNameWithoutExtension(originalFilePath);
            _report.CurrentViewGUID = _report.ViewGUID;

            //execute to output
            if (!string.IsNullOrEmpty(outputGUID))
            {
                _report.OutputToExecute = _report.Outputs.FirstOrDefault(i => i.GUID == outputGUID);
                _report.ExecutionContext = ReportExecutionContext.DesignerOutput;
                if (_report.OutputToExecute != null) _report.CurrentViewGUID = _report.OutputToExecute.ViewGUID;
            }

            //execute with custom view
            if (!string.IsNullOrEmpty(viewGUID)) _report.CurrentViewGUID = viewGUID;

            if (previousReport != null && render)
            {
                //force execution
                var parameter = _report.ExecutionView.Parameters.FirstOrDefault(i => i.Name == "force_execution");
                if (parameter != null) parameter.BoolValue = true;

                //set previous data tables and restrictions
                foreach (var model in _report.Models)
                {
                    ReportModel previousModel = previousReport.Models.FirstOrDefault(i => i.GUID == model.GUID);
                    if (previousModel != null)
                    {
                        model.ResultTable = previousModel.ResultTable;
                        model.Restrictions = previousModel.Restrictions;
                        model.RestrictionText = previousModel.RestrictionText;
                        model.Sql = previousModel.Sql;
                    }
                }
                _report.RenderOnly = true;
            }

            _execution = new ReportExecution() { Report = _report };
            _report.InitForExecution();
            _execution.RenderHTMLDisplayForViewer();
            _url = "file:///" + _report.HTMLDisplayFilePath;
            webBrowser.Navigate(_url);
        }
        private bool processAction(string action)
        {
            bool cancelNavigation = false;
            try
            {
                switch (action)
                {
                    case ReportExecution.ActionExecuteReport:
                        cancelNavigation = true;
                        _reportDone = false;
                        if (webBrowser.Document != null)
                        {
                            _report.InputRestrictions.Clear();
                            if (HeaderForm != null)
                            {
                                foreach (HtmlElement element in HeaderForm.All)
                                {
                                    if (element.Id != null)
                                    {
                                        _report.InputRestrictions.Add(element.Id, element.TagName.ToLower() == "option" ? element.GetAttribute("selected") : element.GetAttribute("value"));
                                        Debug.WriteLine("{0} {1} {2} {3}", element.Id, element.Name, element.GetAttribute("value"), element.GetAttribute("selected"));
                                    }
                                }
                            }
                        }
                        _report.IsNavigating = false;
                        Execute();
                        break;

                    case ReportExecution.ActionRefreshReport:
                        if (_report.IsExecuting)
                        {
                            cancelNavigation = true;
                            HtmlElement message = webBrowser.Document.All[ReportExecution.HtmlId_processing_message];
                            if (message != null) message.SetAttribute("innerHTML", _report.ExecutionHeader);
                            HtmlElement messages = webBrowser.Document.All[ReportExecution.HtmlId_execution_messages];
                            if (messages != null) messages.SetAttribute("innerHTML", Helper.ToHtml(_report.ExecutionMessages));
                        }
                        else if (!_reportDone)
                        {
                            //Set last drill path if any
                            if (_report.NavigationLinks.Count > 0) _report.NavigationLinks.Last().Href = _report.ResultFilePath;

                            cancelNavigation = true;
                            _reportDone = true;
                            _report.IsNavigating = false;
                            _url = "file:///" + _report.HTMLDisplayFilePath;
                            webBrowser.Navigate(_url);
                        }
                        break;

                    case ReportExecution.ActionCancelReport:
                        _execution.Report.LogMessage(_report.Translate("Cancelling report..."));
                        cancelNavigation = true;
                        _report.Cancel = true;
                        break;

                    case ReportExecution.ActionUpdateViewParameter:
                        cancelNavigation = true;
                        _report.UpdateViewParameter(GetFormValue(ReportExecution.HtmlId_parameter_view_id), GetFormValue(ReportExecution.HtmlId_parameter_view_name), GetFormValue(ReportExecution.HtmlId_parameter_view_value));
                        break;

                    case ReportExecution.ActionViewHtmlResult:
                        string resultPath = _execution.GenerateHTMLResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewPrintResult:
                        resultPath = _execution.GeneratePrintResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewPDFResult:
                        resultPath = _execution.GeneratePDFResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewExcelResult:
                        resultPath = _execution.GenerateExcelResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionNavigate:
                        string nav = HeaderForm.GetAttribute(ReportExecution.HtmlId_navigation_attribute_name);
                        string sre = HttpUtility.ParseQueryString(nav).Get("sre");
                        bool navigationDone = false;
                        Report lastReport = _report;
                        ReportExecution lastExecution = _execution;
                        string destLabel = "", srcRestriction = "";

                        if (!string.IsNullOrEmpty(sre))
                        {
                            //Sub-Report
                            string path = sre.Replace(Repository.SealRepositoryKeyword, _report.Repository.RepositoryPath);
                            _report = Report.LoadFromFile(path, _report.Repository);
                            _report.NavigationLinks.AddRange(lastReport.NavigationLinks);

                            /*        if (!File.Exists(path))
                                    {
                                        cancelNavigation = true;
                                        break;
                                    }
                                    */
                            int index = 1;
                            while (true)
                            {
                                string res = HttpUtility.ParseQueryString(nav).Get("res" + index.ToString());
                                string val = HttpUtility.ParseQueryString(nav).Get("val" + index.ToString());
                                if (string.IsNullOrEmpty(res) || string.IsNullOrEmpty(val)) break;
                                foreach (var model in _report.Models)
                                {
                                    foreach (var restriction in model.Restrictions.Where(i => i.MetaColumnGUID == res && i.Prompt == PromptType.Prompt))
                                    {
                                        if (restriction.IsEnum)
                                        {
                                            restriction.EnumValues.Clear();
                                            restriction.EnumValues.Add(val);
                                        }
                                        else restriction.Value1 = val;
                                    }
                                }
                                index++;
                            }
                            _canRender = false;
                            _execution = new ReportExecution() { Report = _report };
                            _report.InitForExecution();
                            navigationDone = true;
                        }
                        else
                        {
                            //Drill
                            string src = HttpUtility.ParseQueryString(nav).Get("src");
                            string dst = HttpUtility.ParseQueryString(nav).Get("dst");
                            string val = HttpUtility.ParseQueryString(nav).Get("val");

                            foreach (var model in _report.Models)
                            {
                                ReportElement element = model.Elements.FirstOrDefault(i => i.MetaColumnGUID == src);
                                if (element != null)
                                {
                                    navigationDone = true;
                                    //If the dest element is already in the model, we can remove it
                                    if (model.Elements.Exists(i => i.MetaColumnGUID == dst && i.PivotPosition == element.PivotPosition)) model.Elements.Remove(element);
                                    else element.ChangeColumnGUID(dst);
                                    destLabel = element.DisplayNameElTranslated;
                                    if (val != null)
                                    {
                                        destLabel = "> " + destLabel;
                                        //Add restriction
                                        ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                                        restriction.Source = model.Source;
                                        restriction.Model = model;
                                        restriction.MetaColumnGUID = src;
                                        restriction.SetDefaults();
                                        restriction.Operator = Operator.Equal;
                                        if (restriction.IsEnum) restriction.EnumValues.Add(val);
                                        else restriction.Value1 = val;
                                        model.Restrictions.Add(restriction);
                                        if (!string.IsNullOrEmpty(model.Restriction)) model.Restriction = string.Format("({0}) AND ", model.Restriction);
                                        model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

                                        srcRestriction = restriction.DisplayText;
                                    }
                                    else
                                    {
                                        destLabel = "< " + destLabel;
                                        var restrictions = model.Restrictions.Where(i => i.MetaColumnGUID == dst).ToList();
                                        foreach (var restr in restrictions)
                                        {
                                            model.Restrictions.Remove(restr);
                                            model.Restriction = model.Restriction.Replace(ReportRestriction.kStartRestrictionChar + restr.GUID + ReportRestriction.kStopRestrictionChar, "1=1");
                                        }
                                    }
                                }
                            }
                        }

                        if (navigationDone)
                        {
                            NavigationLink lastLink = null;
                            if (_report.NavigationLinks.Count == 0)
                            {
                                lastLink = new NavigationLink();
                                _report.NavigationLinks.Add(lastLink);
                            }
                            else lastLink = _report.NavigationLinks.Last();

                            //create HTML result for navigation -> NavigationLinks must have one link to activate the button
                            _report.IsNavigating = true;
                            _canRender = false;

                            if (lastReport != _report)
                            {
                                lastReport.IsNavigating = true;
                                if (lastReport.NavigationLinks.Count == 0) lastReport.NavigationLinks.Add(lastLink);
                            }

                            lastLink.Href = lastExecution.GenerateHTMLResult();
                            if (string.IsNullOrEmpty(lastLink.Text)) lastLink.Text = lastReport.ExecutionName;

                            string linkText = string.Format("{0} {1}", _report.ExecutionName, destLabel);
                            if (!string.IsNullOrEmpty(srcRestriction)) linkText += string.Format(" [{0}]", srcRestriction);
                            _report.NavigationLinks.Add(new NavigationLink() { Href = "#", Text = linkText });
                        }

                        cancelNavigation = true;
                        _reportDone = false;
                        Execute();

                        break;

                    case ReportExecution.ActionGetNavigationLinks:
                        cancelNavigation = true;
                        HtmlElement navMenu = webBrowser.Document.All[ReportExecution.HtmlId_navigation_menu];
                        if (navMenu != null)
                        {
                            string links = "";
                            foreach (var link in _report.NavigationLinks)
                            {
                                links += string.Format("<li><a href='{0}'>{1}</a></li>", link.Href, HttpUtility.HtmlEncode(link.Text));
                            }
                            navMenu.SetAttribute("innerHTML", links);
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                cancelNavigation = true;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return cancelNavigation;
        }