コード例 #1
0
        private void btnReportAnalisys_Click(object sender, EventArgs e)
        {
            ReportDocument ReportDoc   = new ReportDocument();
            string         path        = Meta.GetUsr("localreportdir").ToString();
            string         fName       = txtFile.Text;
            string         repFileName = Path.Combine(path, fName);

            try {
                // Open a temporary copy of the report.
                ReportDoc.Load(repFileName, OpenReportMethod.OpenReportByTempCopy);
            }
            catch (Exception ee) {
                QueryCreator.ShowException(this, "Impossibile caricare il report " + repFileName, ee);
                return;
            }
            //ReportDispatcherClass.setReportLogon(ReportDoc, Conn as Easy_DataAccess);

            CrystalDecisions.CrystalReports.Engine.Database crDatabase;
            CrystalDecisions.CrystalReports.Engine.Tables   crTables;
            crDatabase = ReportDoc.Database;
            crTables   = crDatabase.Tables;

            //Nome SP = spName;
            StringBuilder sbParam = new StringBuilder();

            foreach (ParameterFieldDefinition PF in ReportDoc.DataDefinition.ParameterFields)
            {
                //solo se appartengono al report in elaborazione
                if (PF.ReportName != "")
                {
                    continue;
                }
                if (PF.IsLinked())
                {
                    continue;
                }
                //PF.Name @ayear
                //PF.ValueType Numberfield  StringField
                sbParam.AppendLine($"{PF.Name} type:{PF.ValueType}");
            }
            StringBuilder sbFormula = new StringBuilder();

            foreach (FormulaFieldDefinition FFD in ReportDoc.DataDefinition.FormulaFields)
            {
                sbFormula.AppendLine($"{FFD.FormulaName} kind: {FFD.ValueType}");
            }
            StringBuilder sbSP = new StringBuilder();

            sbSP.AppendLine($"Report principale:  {ReportDoc.FilePath}  Stored Procedure: {getSPName(ReportDoc)}");
            //mi scorro tutti i subreport (se presenti) del report principale
            ReportDefinition repDef = ReportDoc.ReportDefinition;

            foreach (Section sec in repDef.Sections)
            {
                foreach (ReportObject repObj in sec.ReportObjects)
                {
                    if (repObj.Kind != ReportObjectKind.SubreportObject)
                    {
                        continue;
                    }
                    SubreportObject subRep    = (SubreportObject)repObj;
                    ReportDocument  SubReport = subRep.OpenSubreport(subRep.SubreportName);
                    sbSP.AppendLine($"SubReport: {SubReport.Name}  Stored Procedure: {getSPName(SubReport)}");
                    SubReport.Close();
                }
            }

            FrmShowParams p = new FrmShowParams(sbParam.ToString(), sbFormula.ToString(), sbSP.ToString(), Conn, getSPName(ReportDoc));

            ReportDoc.Close();
            p.Show(this);
        }