Exemple #1
0
        /// <summary>
        /// Creates a ChildBand instance in the specified BandBase.
        /// </summary>
        /// <param name="parent">The BandBase instance.</param>
        /// <returns>The ChildBand instance.</returns>
        public static ChildBand CreateChildBand(BandBase parent)
        {
            ChildBand child = new ChildBand();

            parent.AddChild(child);
            child.CreateUniqueName();
            return(child);
        }
Exemple #2
0
        static Report GetSubreportReport()
        {
            Report report = new Report();

            // load nwind database
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(inFolder + "\\nwind.xml");

            // register all data tables and relations
            report.RegisterData(dataSet);

            // enable the "Products" and "Suppliers" tables to use it in the report
            report.GetDataSource("Products").Enabled  = true;
            report.GetDataSource("Suppliers").Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create two title text objects
            TextObject titleText1 = new TextObject();

            titleText1.Parent = page.ReportTitle;
            titleText1.CreateUniqueName();
            titleText1.Bounds    = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 1);
            titleText1.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText1.Text      = "Products";
            titleText1.HorzAlign = HorzAlign.Center;

            TextObject titleText2 = new TextObject();

            titleText2.Parent = page.ReportTitle;
            titleText2.CreateUniqueName();
            titleText2.Bounds    = new RectangleF(Units.Centimeters * 9, 0, Units.Centimeters * 8, Units.Centimeters * 1);
            titleText2.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText2.Text      = "Suppliers";
            titleText2.HorzAlign = HorzAlign.Center;

            // create report title's child band that will contain subreports
            ChildBand childBand = new ChildBand();

            page.ReportTitle.Child = childBand;
            childBand.CreateUniqueName();
            childBand.Height = Units.Centimeters * 0.5f;

            // create the first subreport
            SubreportObject subreport1 = new SubreportObject();

            subreport1.Parent = childBand;
            subreport1.CreateUniqueName();
            subreport1.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);

            // create subreport's page
            ReportPage subreportPage1 = new ReportPage();

            report.Pages.Add(subreportPage1);
            // connect subreport to page
            subreport1.ReportPage = subreportPage1;

            // create report on the subreport's page
            DataBand dataBand = new DataBand();

            subreportPage1.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource("Products");
            dataBand.Height     = Units.Centimeters * 0.5f;

            TextObject productText = new TextObject();

            productText.Parent = dataBand;
            productText.CreateUniqueName();
            productText.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);
            productText.Text   = "[Products.ProductName]";


            // create the second subreport
            SubreportObject subreport2 = new SubreportObject();

            subreport2.Parent = childBand;
            subreport2.CreateUniqueName();
            subreport2.Bounds = new RectangleF(Units.Centimeters * 9, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);

            // create subreport's page
            ReportPage subreportPage2 = new ReportPage();

            report.Pages.Add(subreportPage2);
            // connect subreport to page
            subreport2.ReportPage = subreportPage2;

            // create report on the subreport's page
            DataBand dataBand2 = new DataBand();

            subreportPage2.Bands.Add(dataBand2);
            dataBand2.CreateUniqueName();
            dataBand2.DataSource = report.GetDataSource("Suppliers");
            dataBand2.Height     = Units.Centimeters * 0.5f;

            // create supplier name text
            TextObject supplierText = new TextObject();

            supplierText.Parent = dataBand2;
            supplierText.CreateUniqueName();
            supplierText.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);
            supplierText.Text   = "[Suppliers.CompanyName]";

            return(report);
        }