[]
        
(Showing Draft Content)

Text Expressions

PrintDocument supports the use of different criteria in the document by specifying expressions. An expression is simply a string, which when parsed and processed, gives some value. It can consist of field names, functions, operators or constants.

When specifying expressions in code, the expression fields are wrapped in square brackets. The expressions can be assigned using the Text property of RenderText and ParagraphText objects.

To work with expressions, use the following object IDs:

  • Document (type C1PrintDocument)

    This variable references the document being generated, and can be used in a number of ways. Refer the following code snippet:

    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText(doc, "Personal information", _captionStyle, _captionStyle);
    doc.Body.Children.Add(rt);
    
  • RenderObject (type RenderObject)

    This variable references the current render object. The following code will print the name of the current render object:

    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText(
      "The object's name is [RenderObject.Name]");
    rt.Name = "MyRenderText";
    doc.Body.Children.Add(rt);
    
  • Page (type C1Page)

    This variable references the current page (object of type C1Page). While the most commonly-used scripts members of the page object are accessible directly,, there is other data that can be accessed via the Page variable, such as the current page settings. For example, the following code will print "Landscape is TRUE" if the current page layout has the landscape orientation, and "Landscape is FALSE" otherwise:

    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("Landscape is " +
      "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")].");
    doc.Body.Children.Add(rt);
    
  • Fields (type FieldCollection)

    This variable references the collection of available database fields, and has the type C1.C1Preview.DataBinding.FieldCollection. It can only be used in data-bound documents. For instance, the following code will print the list of product names contained in the Products table of the C1NWIND database:

    C1PrintDocument doc = new C1PrintDocument();
    DataSource dSrc = new DataSource();
    dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB;
    dSrc.ConnectionProperties.ConnectString =
      @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB";
    C1.C1Preview.DataBinding.DataSet dSet1 =
      new C1.C1Preview.DataBinding.DataSet(dSrc,
      "select * from Products");
    doc.DataSchema.DataSources.Add(dSrc);
    doc.DataSchema.DataSets.Add(dSet1);
    RenderText rt = new RenderText();
    doc.Body.Children.Add(rt);
    rt.DataBinding.DataSource = dSet1;
    rt.Text = "[Fields!ProductName.Value]";
    
  • Aggregates (type AggregateCollection)

    This variable allows access to the collection of aggregates defined in the document. That collection is of the type C1.C1Preview.DataBinding.AggregateCollection, its elements have the type C1.C1Preview.DataBinding.Aggregate. For instance, the following code will print the average unit price after the list of products:

    C1PrintDocument doc = new C1PrintDocument();
    DataSource dSrc = new DataSource();
    dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB;
    dSrc.ConnectionProperties.ConnectString =
      @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB";
    C1.C1Preview.DataBinding.DataSet dSet1 =
      new C1.C1Preview.DataBinding.DataSet(dSrc,  "select * from Products");
    doc.DataSchema.DataSources.Add(dSrc);
    doc.DataSchema.DataSets.Add(dSet1);
    RenderText rt = new RenderText();
    doc.Body.Children.Add(rt);
    rt.DataBinding.DataSource = dSet1;
    rt.Text = "[Fields!ProductName.Value]";
    doc.DataSchema.Aggregates.Add(new Aggregate(
      "AveragePrice", "Fields!UnitPrice.Value",
      rt.DataBinding, RunningEnum.Document,
      AggregateFuncEnum.Average));
    doc.Body.Children.Add(new RenderText(
      "Average price: [Aggregates!AveragePrice.Value]"));
    
  • DataBinding (type C1DataBinding)

    This variable allows accessing the DataBinding property of the current render object, of the type C1.C1Preview.DataBinding.C1DataBinding. For instance, the following code (modified from the sample showing the use of Fields variable) will produce a numbered list of products using the RowNumber member of the render object's DataBinding property in the text expression:

    C1PrintDocument doc = new C1PrintDocument();
    DataSource dSrc = new DataSource();
    dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB;
    dSrc.ConnectionProperties.ConnectString =
      @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB";
    C1.C1Preview.DataBinding.DataSet dSet1 =
      new C1.C1Preview.DataBinding.DataSet(dSrc,
      "select * from Products");
    doc.DataSchema.DataSources.Add(dSrc);
    doc.DataSchema.DataSets.Add(dSet1);
    RenderText rt = new RenderText();
    rt.DataBinding.DataSource = dSet1;
    rt.Text = "[DataBinding.RowNumber]: [Fields!ProductName.Value]";
    doc.Body.Children.Add(rt);
    

type=note

Note: If the expression parser cannot parse the text within square brackets, such text is not interpreted as an expression, instead is inserted in the document as it is.