using FastReport.Table; using FastReport.Matrix; using FastReport.Barcode; using FastReport.Gauge.Linear; using FastReport.Gauge.Simple; using FastReport.Data; #if !CROSSPLATFORM using System.CodeDom.Compiler; #endif namespace FastReport.Import { /// /// The components factory. /// public static partial class ComponentsFactory { #region Private Methods private static bool IsValidIdentifier(string identifier) { #if !CROSSPLATFORM if (!CodeGenerator.IsValidLanguageIndependentIdentifier(identifier)) return false; #endif return true; } #endregion // Private Methods #region Pages /// /// Creates a ReportPage instance in the specified Report. /// /// The Report instance. /// The ReportPage instance. public static ReportPage CreateReportPage(Report report) { ReportPage page = new ReportPage(); report.Pages.Add(page); page.CreateUniqueName(); return page; } /// /// Creates a ReportPage instance in the specified Report with the cpecified name. /// /// The name of page. /// The Report instance. /// The ReportPage instance. public static ReportPage CreateReportPage(string name, Report report) { ReportPage page = new ReportPage(); page.Name = name; report.Pages.Add(page); if (!IsValidIdentifier(page.Name)) page.CreateUniqueName(); return page; } #endregion // Pages #region Bands /// /// Creates a ReportTitleBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The ReportTitleBand instance. public static ReportTitleBand CreateReportTitleBand(ReportPage page) { ReportTitleBand reportTitle = new ReportTitleBand(); page.ReportTitle = reportTitle; reportTitle.CreateUniqueName(); return reportTitle; } /// /// Creates a ReportSummaryBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The ReportSummaryBand instance. public static ReportSummaryBand CreateReportSummaryBand(ReportPage page) { ReportSummaryBand reportSummary = new ReportSummaryBand(); page.ReportSummary = reportSummary; reportSummary.CreateUniqueName(); return reportSummary; } /// /// Creates a PageHeaderBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The PageHeaderBand instance. public static PageHeaderBand CreatePageHeaderBand(ReportPage page) { PageHeaderBand pageHeader = new PageHeaderBand(); page.PageHeader = pageHeader; pageHeader.CreateUniqueName(); return pageHeader; } /// /// Creates a PageFooterBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The PageFooterBand instance. public static PageFooterBand CreatePageFooterBand(ReportPage page) { PageFooterBand pageFooter = new PageFooterBand(); page.PageFooter = pageFooter; pageFooter.CreateUniqueName(); return pageFooter; } /// /// Creates a ColumnHeaderBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The ColumnHeaderBand instance. public static ColumnHeaderBand CreateColumnHeaderBand(ReportPage page) { ColumnHeaderBand columnHeader = new ColumnHeaderBand(); page.ColumnHeader = columnHeader; columnHeader.CreateUniqueName(); return columnHeader; } /// /// Creates a ColumnFooterBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The ColumnFooterBand instance. public static ColumnFooterBand CreateColumnFooterBand(ReportPage page) { ColumnFooterBand columnFooter = new ColumnFooterBand(); page.ColumnFooter = columnFooter; columnFooter.CreateUniqueName(); return columnFooter; } /// /// Creates a DataHeaderBand instance in the specified DataBand. /// /// The DataBand instance. /// The DataHeaderBand instance. public static DataHeaderBand CreateDataHeaderBand(DataBand data) { DataHeaderBand dataHeader = new DataHeaderBand(); data.Header = dataHeader; dataHeader.CreateUniqueName(); return dataHeader; } /// /// Creates a DataBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The DataBand instance. public static DataBand CreateDataBand(ReportPage page) { DataBand band = new DataBand(); page.Bands.Add(band); band.CreateUniqueName(); return band; } /// /// Creates a DataFooterBand instance in the specified DataBand. /// /// The DataBand instance. /// The DataFooterBand instance. public static DataFooterBand CreateDataFooterBand(DataBand data) { DataFooterBand dataFooter = new DataFooterBand(); data.Footer = dataFooter; dataFooter.CreateUniqueName(); return dataFooter; } /// /// Creates a GroupHeaderBand instance in the specified ReportPage. /// /// The ReportPage instance. /// The GroupHeaderBand instance. public static GroupHeaderBand CreateGroupHeaderBand(ReportPage page) { GroupHeaderBand groupHeader = new GroupHeaderBand(); page.Bands.Add(groupHeader); groupHeader.CreateUniqueName(); return groupHeader; } /// /// Creates a GroupFooterBand instance in the cpecified ReportPage. /// /// The ReportPage instance. /// The GroupFooterBand instance. public static GroupFooterBand CreateGroupFooterBand(ReportPage page) { GroupFooterBand groupFooter = new GroupFooterBand(); page.Bands.Add(groupFooter); groupFooter.CreateUniqueName(); return groupFooter; } /// /// Creates a GroupFooterBand instance in the cpecified GroupHeaderBand. /// /// The GroupHeaderBand instance. /// The GroupFooterBand instance. public static GroupFooterBand CreateGroupFooterBand(GroupHeaderBand groupHeaderBand) { GroupFooterBand groupFooter = new GroupFooterBand(); groupHeaderBand.GroupFooter = groupFooter; groupFooter.CreateUniqueName(); return groupFooter; } /// /// Creates a ChildBand instance in the specified BandBase. /// /// The BandBase instance. /// The ChildBand instance. public static ChildBand CreateChildBand(BandBase parent) { ChildBand child = new ChildBand(); parent.AddChild(child); child.CreateUniqueName(); return child; } /// /// Creates an OverlayBand in the specified ReportPage. /// /// The ReportPage instance. /// The OverlayBand instance. public static OverlayBand CreateOverlayBand(ReportPage page) { OverlayBand overlay = new OverlayBand(); page.Overlay = overlay; overlay.CreateUniqueName(); return overlay; } #endregion // Bands #region Objects /// /// Creates a Style instance with specified name. /// /// The name of the Style instance. /// The report to add style to. /// The Style instance. public static Style CreateStyle(string name, Report report) { Style style = new Style(); style.Name = name; report.Styles.Add(style); return style; } /// /// Creates a TextObject instance with specified name and parent. /// /// The name of the TextObject instance. /// The parent of the TextObject instance. /// The TextObject instance. public static TextObject CreateTextObject(string name, Base parent) { TextObject text = new TextObject(); text.Name = name; if ((parent as IParent).CanContain(text)) text.Parent = parent; if (!IsValidIdentifier(text.Name)) text.CreateUniqueName(); return text; } /// /// Creates a PictureObject instance with specified name and parent. /// /// The name of the PictureObject instance. /// The parent of the PictureObject instance. /// The PictureObject instance. public static PictureObject CreatePictureObject(string name, Base parent) { PictureObject picture = new PictureObject(); picture.Name = name; if ((parent as IParent).CanContain(picture)) picture.Parent = parent; if (!IsValidIdentifier(picture.Name)) picture.CreateUniqueName(); return picture; } /// /// Creates a LineObject instance with specified name and parent. /// /// The name of the LineObject instance. /// The parent of the LineObject instance. /// The LineObject instance. public static LineObject CreateLineObject(string name, Base parent) { LineObject line = new LineObject(); line.Name = name; if ((parent as IParent).CanContain(line)) line.Parent = parent; if (!IsValidIdentifier(line.Name)) line.CreateUniqueName(); return line; } /// /// Creates a ShapeObject instance with specified name and parent. /// /// The name of the ShapeObject instance. /// The parent of the ShapeObject instance. /// The ShapeObject instance. public static ShapeObject CreateShapeObject(string name, Base parent) { ShapeObject shape = new ShapeObject(); shape.Name = name; if ((parent as IParent).CanContain(shape)) shape.Parent = parent; if (!IsValidIdentifier(shape.Name)) shape.CreateUniqueName(); return shape; } /// /// Creates a PolyLineObject instance with specified name and parent. /// /// The name of the PolyLineObject instance. /// The parent of the PolyLineObject instance. /// The PolyLineObject instance. public static PolyLineObject CreatePolyLineObject(string name, Base parent) { PolyLineObject polyLine = new PolyLineObject(); polyLine.Name = name; if ((parent as IParent).CanContain(polyLine)) polyLine.Parent = parent; if (!IsValidIdentifier(polyLine.Name)) polyLine.CreateUniqueName(); return polyLine; } /// /// Creates a PolygonObject instance with specified name and parent. /// /// The name of the PolygonObject instance. /// The parent of the PolygonObject instance. /// The PolygonObject instance. public static PolygonObject CreatePolygonObject(string name, Base parent) { PolygonObject polygon = new PolygonObject(); polygon.Name = name; if ((parent as IParent).CanContain(polygon)) polygon.Parent = parent; if (!IsValidIdentifier(polygon.Name)) polygon.CreateUniqueName(); return polygon; } /// /// Creates a SubreportObject instance with specified name and parent. /// /// The name of the SubreportObject instance. /// The parent of the SubreportObject instance. /// The SubreportObject instance. public static SubreportObject CreateSubreportObject(string name, Base parent) { SubreportObject subreport = new SubreportObject(); subreport.Name = name; if ((parent as IParent).CanContain(subreport)) subreport.Parent = parent; if (!IsValidIdentifier(subreport.Name)) subreport.CreateUniqueName(); return subreport; } /// /// Creates a ContainerObject instance with specified name and parent. /// /// The name of the ContainerObject instance. /// The parent of the ContainerObject instance. /// The ContainerObject instance. public static ContainerObject CreateContainerObject(string name, Base parent) { ContainerObject container = new ContainerObject(); container.Name = name; if ((parent as IParent).CanContain(container)) container.Parent = parent; if (!IsValidIdentifier(container.Name)) container.CreateUniqueName(); return container; } /// /// Creates a CheckBoxObject instance with specified name and parent. /// /// The name of the CheckBoxObject instance. /// The parent of the CheckBoxObject instance. /// The CheckBoxObject instance. public static CheckBoxObject CreateCheckBoxObject(string name, Base parent) { CheckBoxObject checkBox = new CheckBoxObject(); checkBox.Name = name; if ((parent as IParent).CanContain(checkBox)) checkBox.Parent = parent; if (!IsValidIdentifier(checkBox.Name)) checkBox.CreateUniqueName(); return checkBox; } /// /// Creates a HtmlObject instance with specified name and parent. /// /// The name of the HtmlObject instance. /// The parent of the HtmlObject instance. /// The HtmlObject instance. public static HtmlObject CreateHtmlObject(string name, Base parent) { HtmlObject html = new HtmlObject(); html.Name = name; if ((parent as IParent).CanContain(html)) html.Parent = parent; if (!IsValidIdentifier(html.Name)) html.CreateUniqueName(); return html; } /// /// Creates a TableObject instance with specified name and parent. /// /// The name of the TableObject instance. /// The parent of the TableObject instance. /// The TableObject instance. public static TableObject CreateTableObject(string name, Base parent) { TableObject table = new TableObject(); table.Name = name; if ((parent as IParent).CanContain(table)) table.Parent = parent; if (!IsValidIdentifier(table.Name)) table.CreateUniqueName(); return table; } /// /// Creates a MatrixObject instance with specified name and parent. /// /// The name of the MatrixObject instance. /// The parent of the MatrixObject instance. /// The MatrixObject instance. public static MatrixObject CreateMatrixObject(string name, Base parent) { MatrixObject matrix = new MatrixObject(); matrix.Name = name; if ((parent as IParent).CanContain(matrix)) matrix.Parent = parent; if (!IsValidIdentifier(matrix.Name)) matrix.CreateUniqueName(); return matrix; } /// /// Creates a BarcodeObject instance with specified name and parent. /// /// The name of the BarcodeObject instance. /// The parent of the BarcodeObject instance. /// The BarcodeObject instance. public static BarcodeObject CreateBarcodeObject(string name, Base parent) { BarcodeObject barcode = new BarcodeObject(); barcode.Name = name; if ((parent as IParent).CanContain(barcode)) barcode.Parent = parent; if (!IsValidIdentifier(barcode.Name)) barcode.CreateUniqueName(); return barcode; } /// /// Creates a ZipCodeObject instance with specified name and parent. /// /// The name of the ZipCodeObject instance. /// The parent of the ZipCodeObject instance. /// The ZipCodeObject instance. public static ZipCodeObject CreateZipCodeObject(string name, Base parent) { ZipCodeObject zipCode = new ZipCodeObject(); zipCode.Name = name; if ((parent as IParent).CanContain(zipCode)) zipCode.Parent = parent; if (!IsValidIdentifier(zipCode.Name)) zipCode.CreateUniqueName(); return zipCode; } /// /// Creates a CellularTextObject instance with specified name and parent. /// /// The name of the CellularTextObject instance. /// The parent ot the CellularTextObject instance. /// The CellularTextObject instance. public static CellularTextObject CreateCellularTextObject(string name, Base parent) { CellularTextObject cellularText = new CellularTextObject(); cellularText.Name = name; if ((parent as IParent).CanContain(cellularText)) cellularText.Parent = parent; if (!IsValidIdentifier(cellularText.Name)) cellularText.CreateUniqueName(); return cellularText; } /// /// Creates a LinearGauge instance with specified name and parent. /// /// The name of the LinearGauge instance. /// The parent of the LinearGauge instance. /// The LinearGauge instance. public static LinearGauge CreateLinearGauge(string name, Base parent) { LinearGauge gauge = new LinearGauge(); gauge.Name = name; if ((parent as IParent).CanContain(gauge)) gauge.Parent = parent; if (!IsValidIdentifier(gauge.Name)) gauge.CreateUniqueName(); return gauge; } /// /// Creates a SimpleGauge instance with specified name and parent. /// /// The name of the SimpleGauge instance. /// The parent of the SimpleGauge instance. /// The SimpleGauge instance. public static SimpleGauge CreateSimpleGauge(string name, Base parent) { SimpleGauge gauge = new SimpleGauge(); gauge.Name = name; if ((parent as IParent).CanContain(gauge)) gauge.Parent = parent; if (!IsValidIdentifier(gauge.Name)) gauge.CreateUniqueName(); return gauge; } /// /// Creates a RadialGauge instance with specified name and parent. /// /// The name of the RadialGauge instance. /// The parent of the RadialGauge instance. /// The RadialGauge instance. public static Gauge.Radial.RadialGauge CreateRadialGauge(string name, Base parent) { Gauge.Radial.RadialGauge gauge = new Gauge.Radial.RadialGauge(); gauge.Name = name; if ((parent as IParent).CanContain(gauge)) gauge.Parent = parent; if (!IsValidIdentifier(gauge.Name)) gauge.CreateUniqueName(); return gauge; } /// /// Creates a SimpleProgressGauge instance with specified name and parent. /// /// The name of the SimpleProgressGauge instance. /// The parent of the SimpleProgressGauge instance. /// The SimpleProgressGauge instance. public static Gauge.Simple.Progress.SimpleProgressGauge CreateSimpleProgressGauge(string name, Base parent) { Gauge.Simple.Progress.SimpleProgressGauge gauge = new Gauge.Simple.Progress.SimpleProgressGauge(); gauge.Name = name; if ((parent as IParent).CanContain(gauge)) gauge.Parent = parent; if (!IsValidIdentifier(gauge.Name)) gauge.CreateUniqueName(); return gauge; } #endregion // Objects #region Dictionary Elements /// /// Creates a Parameter instance with specified name and parent. /// /// The name of the Parameter instance. /// The parent Report for the new Parameter. /// The Parameter instance. public static Parameter CreateParameter(string name, Report report) { Parameter parameter = new Parameter(name); report.Parameters.Add(parameter); return parameter; } #endregion Dictionary Elements } }