Beispiel #1
0
        /// <summary>
        /// iterate though subReports to populate list of documents and fieldnames
        /// </summary>
        /// <param name="sections">Sections of document to walk</param>
        /// <param name="reportDocList">list of inner subreport docs to populate</param>
        /// <param name="fieldNames">hashset of fieldNames to populate</param>
        private void WalkSubReports(Sections sections, List <ReportDocument> reportDocList, HashSet <string> fieldNames)
        {
            foreach (CrystalDecisions.CrystalReports.Engine.Section section in sections)
            {
                // In each section we need to loop through all the reporting objects
                foreach (ReportObject reportObject in section.ReportObjects)
                {
                    if (reportObject is CrystalDecisions.CrystalReports.Engine.FieldObject)
                    {
                        DatabaseFieldDefinition fieldDefn = ((FieldObject)reportObject).DataSource as DatabaseFieldDefinition;

                        if (fieldDefn != null)
                        {
                            fieldNames.Add(string.Format("{0}.{1}", fieldDefn.TableName, fieldDefn.Name));
                        }
                    }

                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subReport   = (SubreportObject)reportObject;
                        ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);
                        reportDocList.Add(subDocument);
                    }
                }
            }
        }
Beispiel #2
0
 private static void ProcessDatabaseFieldDefinition(DatabaseFieldDefinition fld, XmlWriter xmlw)
 {
     xmlw.WriteStartElement("DatabaseFieldDefinition");
     xmlw.WriteAttributeString("FormulaName", fld.FormulaName);
     xmlw.WriteAttributeString("Kind", fld.Kind.ToStringSafe());
     xmlw.WriteAttributeString("Name", fld.Name);
     xmlw.WriteAttributeString("NumberOfBytes", fld.NumberOfBytes.ToStringSafe());
     xmlw.WriteAttributeString("TableName", fld.TableName);
     xmlw.WriteAttributeString("UseCount", fld.UseCount.ToStringSafe());
     xmlw.WriteAttributeString("ValueType", fld.ValueType.ToStringSafe());
     xmlw.WriteEndElement();
 }
Beispiel #3
0
        /// <summary>
        /// get all the fields that the report uses to pass back via the configureArgs returned by ConfigureReport()
        /// </summary>
        /// <param name="report">crystal document to look for fields</param>
        /// <param name="fieldNames">hashset that contain all field names</param>
        private void FindReportFields(ReportDocument report, HashSet <string> fieldNames)
        {
            //loop though the group fields
            foreach (GroupNameFieldDefinition field in report.DataDefinition.GroupNameFields)
            {
                this.FindFieldNames(fieldNames, field.Name);
            }

            //loop through the sortfields
            foreach (SortField field in report.DataDefinition.SortFields)
            {
                DatabaseFieldDefinition dbFieldDefn = field.Field as DatabaseFieldDefinition;

                if (dbFieldDefn != null)
                {
                    fieldNames.Add(string.Format("{0}.{1}", dbFieldDefn.TableName, dbFieldDefn.Name));
                }
                else
                {
                    this.FindFieldNames(fieldNames, field.Field.Name);
                }
            }

            //loop through the summary fields
            foreach (SummaryFieldDefinition field in report.DataDefinition.SummaryFields)
            {
                this.FindFieldNames(fieldNames, field.Name);
            }

            //loop through alll the formulas
            foreach (FormulaFieldDefinition field in report.DataDefinition.FormulaFields)
            {
                this.FindFieldNames(fieldNames, field.Text);
            }

            //loop through all the links (data keys)
            foreach (TableLink tl in report.Database.Links)
            {
                foreach (CrystalDecisions.CrystalReports.Engine.DatabaseFieldDefinition o in tl.DestinationFields)
                {
                    fieldNames.Add(string.Format("{0}.{1}", o.TableName, o.Name));
                }
                foreach (CrystalDecisions.CrystalReports.Engine.DatabaseFieldDefinition o in tl.SourceFields)
                {
                    fieldNames.Add(string.Format("{0}.{1}", o.TableName, o.Name));
                }
            }

            //?might need to loop through sub reports.
        }
        static void Main(string[] args)
        {
            if (args.Count() >= 1 && args[0] == "-s")
            {
                Simplified = true;
                args       = args.Skip(1).ToArray();
            }

            if (args.Count() < 1 || args[0] == "-h")
            {
                Console.WriteLine("CrystalReportReaderFramework [-s]  report_file_name.rpt");
                Console.WriteLine("");
                Console.WriteLine("    -s  : Simplify output by removing numbers from sections and text fields and by removing location information.");
                Console.WriteLine("          Simplified output makes it easier to compare reports where layout is not important.");
                Console.WriteLine("");
                return;
            }

            string fileName = args[0];

            ReportDocument reportDocument = new ReportDocument();

            reportDocument.Load(fileName);

            Database db = reportDocument.Database;

            foreach (var t in db.Tables)
            {
                Table  tbl    = t as Table;
                string prefix = "Database:Table:Name:" + tbl.Name + ":";
                Console.WriteLine(prefix);
                Console.WriteLine(prefix + "Location:" + tbl.Location);
                foreach (var f in tbl.Fields)
                {
                    FieldDefinition fd          = f as FieldDefinition;
                    string          fieldPrefix = prefix + "Field:Name:" + fd.Name + ":";
                    Console.WriteLine(fieldPrefix);
                    Console.WriteLine(fieldPrefix + "Kind:" + fd.Kind);
                    Console.WriteLine(fieldPrefix + "ValueType:" + fd.ValueType);
                }
            }

            foreach (var l in db.Links)
            {
                TableLink lnk        = l as TableLink;
                string    linkPRefix = "Database:TableLink:SourceTable:" + lnk.SourceTable.Name + ":DestinationTable:" + lnk.DestinationTable.Name + ":";
                Console.WriteLine(linkPRefix);
                Console.WriteLine(linkPRefix + "JoinType:" + lnk.JoinType);
                for (int i = 0; i < lnk.SourceFields.Count; i++)
                {
                    DatabaseFieldDefinition sfd = lnk.SourceFields[i] as DatabaseFieldDefinition;
                    DatabaseFieldDefinition dfd = lnk.DestinationFields[i] as DatabaseFieldDefinition;
                    Console.WriteLine(linkPRefix + "SourceField:Name:" + sfd.Name + ":DestinationField:Name:" + dfd.Name);
                }
            }


            var ffs = reportDocument.DataDefinition.FormulaFields;

            foreach (var ff in ffs)
            {
                FormulaFieldDefinition ffd = ff as FormulaFieldDefinition;
                Console.WriteLine("Formula:FormulaName:" + ffd.FormulaName + ":");
                if (ffd.Text != null)
                {
                    Console.WriteLine("Formula:FormulaName:" + ffd.FormulaName + ":Text:'" + MakeSingleLine(ffd.Text));
                }
            }

            var rtfs = reportDocument.DataDefinition.RunningTotalFields;

            foreach (var rtf in rtfs)
            {
                RunningTotalFieldDefinition rtfd = rtf as RunningTotalFieldDefinition;
                Group  rc     = rtfd.ResetCondition as Group;
                string prefix = "RunningTotal:FormulaName:" + rtfd.FormulaName + ":";
                Console.WriteLine(prefix + "Operation:" + rtfd.Operation);
                Console.WriteLine(prefix + "SummarizedField:" + rtfd.SummarizedField.Name + "," + rtfd.SummarizedField.FormulaName);
                Console.WriteLine(prefix + "EvaluationCondition:" + rtfd.EvaluationCondition);
                Console.WriteLine(prefix + "ResetCondition:" + rc.ConditionField.FormulaName);
            }


            var groups = reportDocument.DataDefinition.Groups;

            foreach (var gp in groups)
            {
                Group  gpd    = gp as Group;
                string prefix = "Group:GroupName:" + RemoveNumbersIfSimplified(gpd.ConditionField.FormulaName) + ":";
                Console.WriteLine(prefix);
                Console.WriteLine(prefix + "GroupOptions.Condition:" + gpd.GroupOptions.Condition);
            }



            var parameterFields = reportDocument.DataDefinition.ParameterFields;

            foreach (var pf in parameterFields)
            {
                ParameterFieldDefinition pfd = pf as ParameterFieldDefinition;
                var x = "ParameterFields:FormulaName:" + pfd.FormulaName + ":" +
                        "ParameterFieldName:" + pfd.ParameterFieldName;
                Console.WriteLine(x);
            }


            var sections = reportDocument.ReportDefinition.Sections;

            foreach (var section in sections)
            {
                Section sd     = section as Section;
                string  prefix = "Section:Name:" + RemoveNumbersIfSimplified(sd.Name) + ":";
                Console.WriteLine(prefix);
                Console.WriteLine(prefix + "Kind:" + sd.Kind);
                Console.WriteLine(prefix + "EnableKeepTogether:" + sd.SectionFormat.EnableKeepTogether);
                Console.WriteLine(prefix + "EnableSuppress:" + sd.SectionFormat.EnableSuppress);
                if (!Simplified)
                {
                    Console.WriteLine(prefix + "Height:" + sd.Height);
                    Console.WriteLine(prefix + "Height:" + sd.Height);
                }


                AddReportObjects(prefix, sd.ReportObjects);
            }

            // Console.WriteLine(reportDocument);
            //Console.ReadLine();
        }