示例#1
0
        public void TableOfAuthorityCategories()
        {
            //ExStart
            //ExFor:FieldOptions.ToaCategories
            //ExFor:ToaCategories
            //ExFor:ToaCategories.Item(Int32)
            //ExFor:ToaCategories.DefaultCategories
            //ExSummary:Shows how to specify a set of categories for TOA fields.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // TOA fields can filter their entries by categories defined in this collection.
            ToaCategories toaCategories = new ToaCategories();

            doc.FieldOptions.ToaCategories = toaCategories;

            // This collection of categories comes with default values, which we can overwrite with custom values.
            Assert.AreEqual("Cases", toaCategories[1]);
            Assert.AreEqual("Statutes", toaCategories[2]);

            toaCategories[1] = "My Category 1";
            toaCategories[2] = "My Category 2";

            // We can always access the default values via this collection.
            Assert.AreEqual("Cases", ToaCategories.DefaultCategories[1]);
            Assert.AreEqual("Statutes", ToaCategories.DefaultCategories[2]);

            // Insert 2 TOA fields. TOA fields create an entry for each TA field in the document.
            // Use the "\c" switch to select the index of a category from our collection.
            //  With this switch, a TOA field will only pick up entries from TA fields that
            // also have a "\c" switch with a matching category index. Each TOA field will also display
            // the name of the category that its "\c" switch points to.
            builder.InsertField("TOA \\c 1 \\h", null);
            builder.InsertField("TOA \\c 2 \\h", null);
            builder.InsertBreak(BreakType.PageBreak);

            // Insert TOA entries across 2 categories. Our first TOA field will receive one entry,
            // from the second TA field whose "\c" switch also points to the first category.
            // The second TOA field will have two entries from the other two TA fields.
            builder.InsertField("TA \\c 2 \\l \"entry 1\"");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertField("TA \\c 1 \\l \"entry 2\"");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertField("TA \\c 2 \\l \"entry 3\"");

            doc.UpdateFields();
            doc.Save(ArtifactsDir + "FieldOptions.TOA.Categories.docx");
            //ExEnd

            doc = new Document(ArtifactsDir + "FieldOptions.TOA.Categories.docx");

            Assert.Null(doc.FieldOptions.ToaCategories);

            TestUtil.VerifyField(FieldType.FieldTOA, "TOA \\c 1 \\h", "My Category 1\rentry 2\t3\r", doc.Range.Fields[0]);
            TestUtil.VerifyField(FieldType.FieldTOA, "TOA \\c 2 \\h",
                                 "My Category 2\r" +
                                 "entry 1\t2\r" +
                                 "entry 3\t4\r", doc.Range.Fields[1]);
        }
示例#2
0
        public void FieldOptionsToaCategories()
        {
            //ExStart
            //ExFor:FieldOptions.ToaCategories
            //ExFor:ToaCategories
            //ExFor:ToaCategories.Item(Int32)
            //ExFor:ToaCategories.DefaultCategories
            //ExSummary:Shows how to specify a table of authorities categories for a document.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // There are default category values we can use, or we can make our own like this
            ToaCategories toaCategories = new ToaCategories();

            doc.FieldOptions.ToaCategories = toaCategories;

            toaCategories[1] = "My Category 1"; // Replaces default value "Cases"
            toaCategories[2] = "My Category 2"; // Replaces default value "Statutes"

            // Even if we changed the categories in the FieldOptions object, the default categories are still available here
            Assert.AreEqual("Cases", ToaCategories.DefaultCategories[1]);
            Assert.AreEqual("Statutes", ToaCategories.DefaultCategories[2]);

            // Insert 2 tables of authorities, one per category
            builder.InsertField("TOA \\c 1 \\h", null);
            builder.InsertField("TOA \\c 2 \\h", null);
            builder.InsertBreak(BreakType.PageBreak);

            // Insert TOA entries across 2 categories
            builder.InsertField("TA \\c 2 \\l \"entry 1\"");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertField("TA \\c 1 \\l \"entry 2\"");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertField("TA \\c 2 \\l \"entry 3\"");

            doc.UpdateFields();
            doc.Save(ArtifactsDir + "FieldOptions.TOA.Categories.docx");
            //ExEnd

            doc = new Document(ArtifactsDir + "FieldOptions.TOA.Categories.docx");

            Assert.Null(doc.FieldOptions.ToaCategories);

            TestUtil.VerifyField(FieldType.FieldTOA, "TOA \\c 1 \\h", "My Category 1\rentry 2\t3\r", doc.Range.Fields[0]);
            TestUtil.VerifyField(FieldType.FieldTOA, "TOA \\c 2 \\h",
                                 "My Category 2\r" +
                                 "entry 1\t2\r" +
                                 "entry 3\t4\r", doc.Range.Fields[1]);
        }