public void SelectLoadReport()

in sqlnexus/fmNexus.cs [1384:1522]


        public void SelectLoadReport(string report, bool master, ReportParameter[] parameters)
        {

            NexusInfo nInfo = new NexusInfo(Globals.credentialMgr.ConnectionString, this);
            nInfo.SetAttribute("Nexus Report Version", Application.ProductVersion);

            Cursor save = StartWaiting();
            try
            {
                try
                {
                    LogMessage(sqlnexus.Properties.Resources.Msg_LoadingReport+report, MessageOptions.Silent);

                    bool fullpath = false;
                    string filename;
                    if ("" == Path.GetExtension(report))
                    {
                        filename = GetFullReportPath(report, (master ? RDL_EXT : RDLC_EXT));
                        Util.Logger.LogMessage("Loading report from: " + filename);
                    }
                    else  //Assume full path to file
                    {
                        fullpath = true;
                        filename = report;
                        report = ExtractReportName(report);
                    }

                    int i = tcReports.TabPages.IndexOfKey(report);
                    // This report isn't currently open; create a new tab and associated ReporterViewer instance. 
                    if (-1 == i) 
                    {

                        ReportViewer rv = new ReportViewer();
                        rv.Name = "rv" + report;

                        //rv.LocalReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence);
                        //fixing error related to System.InvalidOperationException: Report execution in the current AppDomain requires Code Access Security policy, which is off by default in .NET 4.0 and later.  Enable legacy CAS policy or execute the report in the sandbox AppDomain.

                        rv.LocalReport.ExecuteReportInSandboxAppDomain();
                        //rv.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
                        Globals.ListOfReports.Add(rv);

                        AddCustomAssemblies(filename, rv);

                        //rv.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
                        //rv.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("RenderBitmap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); 

                        rv.LocalReport.ReportPath = filename;


                        rv.LocalReport.EnableHyperlinks = true;
                        rv.LocalReport.EnableExternalImages = true;
                        rv.LocalReport.DisplayName = report;
                        if (null != parameters)
                        {
                            rv.LocalReport.SetParameters(parameters);
                        }
                        SetReportQueryParameters(rv.LocalReport);
                        SetReportUserProvidedParameters(rv.LocalReport);

                        FixupDataSources(filename, report, rv.LocalReport.DataSources, rv.LocalReport.GetParameters());

                        TabPage p = new TabPage(report);
                        p.Name = report;
                        p.Controls.Add(rv);

                        rv.Dock = DockStyle.Fill;

                        rv.ShowContextMenu = false;

                        rv.ContextMenuStrip = cmReport;
                        rv.ShowToolBar = false;

                        tcReports.TabPages.Add(p);
                        tcReports.SelectTab(tcReports.TabPages.Count - 1);

                        //Hide the damned tabs!
                        if (!this.tsiShowReportTabs.Checked)
                        {
                            tcReports.ItemSize = new Size(0, 1);
                        }

                        //Hook up event syncs
                        rv.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ProcessSubreport);

                        rv.ReportRefresh += new System.ComponentModel.CancelEventHandler(this.rvTemplate_ReportRefresh);
                        rv.Hyperlink += new Microsoft.Reporting.WinForms.HyperlinkEventHandler(this.rvTemplate_Hyperlink);
                        rv.Back += new Microsoft.Reporting.WinForms.BackEventHandler(this.rvTemplate_Back);
                        rv.Drillthrough += new Microsoft.Reporting.WinForms.DrillthroughEventHandler(this.rvTemplate_Drillthrough);
                        rv.Toggle += new System.ComponentModel.CancelEventHandler(this.rvTemplate_Toggle);
                        rv.RenderingBegin += new System.ComponentModel.CancelEventHandler(this.rvTemplate_RenderingBegin);
                        rv.RenderingComplete += new Microsoft.Reporting.WinForms.RenderingCompleteEventHandler(this.rvTemplate_RenderingComplete);
                        rv.ReportError += new Microsoft.Reporting.WinForms.ReportErrorEventHandler(this.rvTemplate_ReportError);
                        rv.Click += new System.EventHandler(this.rvTemplate_Click);

                        if ((master) && (fmReportParameters.HasReportParameters(rv.LocalReport, true)))
                            fmNexus.GetReportParameters(false,"");

                        rv.RefreshReport();
                        toolbarReport.Visible = reportToolStripMenuItem.Checked;
                        TreeNode n = AddFindReportNode(report, null);
                        n.ImageIndex = 1;
                        n.SelectedImageIndex = 1;
                        
                        this.tvReports.AfterSelect -= new System.Windows.Forms.TreeViewEventHandler(this.tvReports_AfterSelect);
                        tvReports.SelectedNode = n;
                        this.tvReports.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvReports_AfterSelect);

                        if (fullpath)
                            n.Tag = 1;

                        paTasksBody.Enabled = true;

                    }
                    else
                    {   // This report is already open -- select the tab and refresh the report. 
                        tcReports.SelectTab(i);
                        if (!master)
                        {
                            if (null != parameters)
                                CurrentReport.SetParameters(parameters);
                            SetReportQueryParameters(CurrentReport);
                            RefreshReport(CurrentReport, CurrentReportViewer);
                        }
                    }
                    LogMessage(sqlnexus.Properties.Resources.Msg_Loaded);
                    UpdateTitle();
                    UpdateReportButtons();
                }
                catch (Exception ex)
                {
                    Globals.HandleException(ex, this, this);
                }
            }
            finally
            {
                StopWaiting(save);
            }
        }