コード例 #1
0
        public IEnumerable GetNestedItems(RelationDescriptor rd, ChildTable childTable, object[] keys, out object totals)
        {
            if (NestedQueryHandler == null)
            {
                totals = null;
                return(null);
            }

            return(NestedQueryHandler(keys, out totals));
        }
コード例 #2
0
ファイル: Class1.cs プロジェクト: silexcorp/wpf-demos
        RelationDescriptor AddRelation(string name, RelationDescriptorCollection relations)
        {
            RelationDescriptor children = new RelationDescriptor();

            children.RelationKind = RelationKind.UniformChildList;
            children.MappingName  = "Children";
            children.Name         = name;
            relations.Add(children);
            return(children);
        }
コード例 #3
0
        public Class1()
        {
            engine1 = new Engine();

            USStatesCollection  usStates  = USStatesCollection.CreateDefaultCollection();
            CountriesCollection countries = CountriesCollection.CreateDefaultCollection();

            this.engine1.SourceListSet.Add("Countries", countries);
            this.engine1.SourceListSet.Add("USStates", usStates);

            DataTable table = new DataTable();

            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Country", typeof(Country));
            table.Columns.Add("State", typeof(USState));

            // and then add a few rows:
            for (int i = 0; i < 50; i++)
            {
                table.Rows.Add(table.NewRow());
                table.Rows[i][0] = i;
                table.Rows[i][1] = countries[i % 8];
                if (i % 8 == 0)
                {
                    table.Rows[i][2] = usStates[i / 8];
                }
            }

            TableDescriptor mainTd = this.engine1.TableDescriptor;
            //mainTd.Fields.ExpandProperties = false;

            RelationDescriptor usStatesRd = new RelationDescriptor();

            usStatesRd.Name           = "State";
            usStatesRd.MappingName    = "State";           // FieldName in table
            usStatesRd.ChildTableName = "USStates";        // SourceListSet name for lookup
            usStatesRd.RelationKind   = RelationKind.ListItemReference;
            usStatesRd.ChildTableDescriptor.SortedColumns.Add("Name");
            //usStatesRd.ChildTableDescriptor.AllowEdit = false;
            //usStatesRd.ChildTableDescriptor.AllowNew = false;  // users can't modify states.
            mainTd.Relations.Add(usStatesRd);

            RelationDescriptor countriesRd = new RelationDescriptor();

            countriesRd.Name           = "Country";
            countriesRd.MappingName    = "Country";           // FieldName in table
            countriesRd.ChildTableName = "Countries";         // SourceListSet name for lookup
            countriesRd.RelationKind   = RelationKind.ListItemReference;
            countriesRd.ChildTableDescriptor.AllowEdit = true;
            countriesRd.ChildTableDescriptor.AllowNew  = true;             // allow user to add countries (these setting will be overriden by CountriesCollection.IsReadOnly / CountriesCollection.IsFixedSize properties if they are true).
            mainTd.Relations.Add(countriesRd);
            this.engine1.SetSourceList(table.DefaultView);
        }
コード例 #4
0
        public Class1()
        {
            engine1 = new Engine();

            USStatesCollection  usStates  = USStatesCollection.CreateDefaultCollection();
            CountriesCollection countries = CountriesCollection.CreateDefaultCollection();

            this.engine1.SourceListSet.Add("Countries", countries);
            this.engine1.SourceListSet.Add("USStates", usStates);

            DataTable table = new DataTable();

            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Country", typeof(string));
            table.Columns.Add("State", typeof(string));

            // and then add a few rows:
            for (int i = 0; i < 50; i++)
            {
                table.Rows.Add(table.NewRow());
                table.Rows[i][0] = i;
                table.Rows[i][1] = countries[i % 8].CountryCode;
                table.Rows[i][2] = usStates[i % 8].Key;
            }

            TableDescriptor mainTd = this.engine1.TableDescriptor;

            RelationDescriptor usStatesRd = new RelationDescriptor();

            usStatesRd.Name           = "State";
            usStatesRd.RelationKind   = RelationKind.ForeignKeyReference;
            usStatesRd.ChildTableName = "USStates";              // SourceListSet name for lookup
            usStatesRd.RelationKeys.Add("State", "Key");
            usStatesRd.ChildTableDescriptor.SortedColumns.Add("Name");
            usStatesRd.ChildTableDescriptor.AllowEdit = false;
            usStatesRd.ChildTableDescriptor.AllowNew  = false;             // Make pencil icon disappear, users can't modify states.
            mainTd.Relations.Add(usStatesRd);

            RelationDescriptor countriesRd = new RelationDescriptor();

            //countriesRd.Name = "Country";  - default will be ChildTableName = "Countries"
            countriesRd.RelationKind   = RelationKind.ForeignKeyReference;
            countriesRd.ChildTableName = "Countries";              // SourceListSet name for lookup
            countriesRd.RelationKeys.Add("Country", "CountryCode");
            countriesRd.ChildTableDescriptor.AllowEdit = true;
            countriesRd.ChildTableDescriptor.AllowNew  = true;             // Make pencil icon appear, allow user to add countries (these setting will be overriden by CountriesCollection.IsReadOnly / CountriesCollection.IsFixedSize properties if they are true).
            mainTd.Relations.Add(countriesRd);


            this.engine1.SetSourceList(table.DefaultView);
            mainTd.Name = "ForeignKeyReference";
        }
コード例 #5
0
        public void Run()
        {
            foreach (Record r in engine1.Table.FilteredRecords)
            {
                // Print record fields
                Console.WriteLine(r.ToString());

                Console.WriteLine(r.GetValue("State_Name"));

                // Get related record in foreign table.
                RelationDescriptor usStatesRd    = r.ParentTableDescriptor.Relations["State"];
                Record             relatedRecord = r.GetRelatedRecord(usStatesRd);
                Console.WriteLine(relatedRecord.GetValue("Name"));
            }
        }
コード例 #6
0
        //public static void Main()
        //{

        //}

        public void Run()
        {
            foreach (Record r in engine1.Table.FilteredRecords)
            {
                // Print record fields
                Console.WriteLine(r.ToString());

                Console.WriteLine(r.GetValue("State_Name"));

                // Get related record in foreign table.
                RelationDescriptor usStatesRd = r.ParentTableDescriptor.Relations["State"];
                if (!(r.GetValue("State") is DBNull))
                {
                    USState state = (USState)r.GetValue("State");
                    Console.WriteLine(state.Name);
                }
            }
        }
コード例 #7
0
ファイル: Class1.cs プロジェクト: silexcorp/wpf-demos
        public Class1()
        {
            engine1 = new Engine();

            CustomerCollection customers = PopulateCustomers.CreateCustomers();

            this.engine1.SetSourceList(customers);

            RelationDescriptorCollection relations = new RelationDescriptorCollection();

            // First level
            RelationDescriptor rd = AddRelation("Level_0", relations);

            // Subsequent levels
            for (int level = 1; level < 5; level++)
            {
                rd = AddRelation("Level_" + level.ToString(), rd.ChildTableDescriptor.Relations);
            }

            this.engine1.TableDescriptor.Relations.InitializeFrom(relations);

            this.engine1.Table.ExpandAllRecords();
        }
コード例 #8
0
        public Class1()
        {
            engine1 = new Engine();

            DataTable parentTable     = GetParentTable();
            DataTable childTable      = GetChildTable();
            DataTable grandChildTable = GetGrandChildTable();

            // Manually specify relations in grouping engine. The DataSet does not need to have any DataRelations.
            // This is the same approach that should be used if you want to set up relation ships
            // between independent IList.
            RelationDescriptor parentToChildRelationDescriptor = new RelationDescriptor();

            parentToChildRelationDescriptor.ChildTableName = "MyChildTable";                // same as SourceListSetEntry.Name for childTable (see below)
            parentToChildRelationDescriptor.RelationKind   = RelationKind.RelatedMasterDetails;
            parentToChildRelationDescriptor.RelationKeys.Add("parentID", "ParentID");

            // Add relation to ParentTable
            engine1.TableDescriptor.Relations.Add(parentToChildRelationDescriptor);

            RelationDescriptor childToGrandChildRelationDescriptor = new RelationDescriptor();

            childToGrandChildRelationDescriptor.ChildTableName = "MyGrandChildTable";              // same as SourceListSetEntry.Name for grandChhildTable (see below)
            childToGrandChildRelationDescriptor.RelationKind   = RelationKind.RelatedMasterDetails;
            childToGrandChildRelationDescriptor.RelationKeys.Add("childID", "ChildID");

            // Add relation to ChildTable
            parentToChildRelationDescriptor.ChildTableDescriptor.Relations.Add(childToGrandChildRelationDescriptor);

            // Register any DataTable/IList with SourceListSet, so that RelationDescriptor can resolve the name
            this.engine1.SourceListSet.Add("MyParentTable", parentTable);
            this.engine1.SourceListSet.Add("MyChildTable", childTable);
            this.engine1.SourceListSet.Add("MyGrandChildTable", grandChildTable);

            this.engine1.SetSourceList(parentTable.DefaultView);
        }
コード例 #9
0
        /// <summary>
        /// Setting Maual relation to the GridGroupingControl.
        /// </summary>

        private void SampleCustomization()
        {
            #region DataTable

            DataSet ds = new DataSet();
            ReadXml(ds, @"Expand.xml");

            ds.Tables[1].TableName = "Products";
            ds.Tables[2].TableName = "OrderDetails";
            ds.Tables[3].TableName = "Suppliers";

            ds.Relations.Add(
                ds.Tables[0].Columns["CategoryID"],
                ds.Tables[1].Columns["CategoryID"]);
            ds.Relations[0].RelationName = "Category_Products";

            ds.Relations.Add(
                ds.Tables[1].Columns["ProductID"],
                ds.Tables[2].Columns["ProductID"]);
            ds.Relations[1].RelationName = "Products_OrderDetails";

            #endregion

            this.groupingGrid1.DataSource = ds.Tables[0];

            GridEngine engine = this.groupingGrid1.Engine;

            engine.TopLevelGroupOptions.ShowCaption = true;

            // Record summary for Categories Tables

            GridTableDescriptor categoriesTableDescriptor = (GridTableDescriptor)engine.TableDescriptor;

            categoriesTableDescriptor.Columns.Clear();
            categoriesTableDescriptor.Columns.Add("CategoryID");
            categoriesTableDescriptor.Columns.Add("CategoryName");
            categoriesTableDescriptor.Columns.Add("Description");

            categoriesTableDescriptor.Columns["CategoryName"].Width = 200;
            //Creating a new SummaryColumnDescriptor.
            GridSummaryColumnDescriptor countCat = new GridSummaryColumnDescriptor("RecordCount");
            //Setting it's properties.
            countCat.SummaryType = SummaryType.Count;
            countCat.Style       = GridSummaryStyle.FillRow;
            //Initializing it to the Column it is associated with.
            countCat.DataMember = "CategoryID";
            //Mentioning the format of display.
            countCat.Format = "      {Count} Records.";

            //Adding the SummaryColumnDescriptor to the SummaryRowDescriptor.
            GridSummaryRowDescriptor categoriesSummaryRow = new GridSummaryRowDescriptor("RecordCountRow");
            categoriesSummaryRow.SummaryColumns.Add(countCat);
            //Adding the SummaryRowDescriptor to the  TableDesriptor.
            categoriesTableDescriptor.SummaryRows.Add(categoriesSummaryRow);

            // Group Products table by "SupplierID"
            RelationDescriptor  productsRelationDescriptor = categoriesTableDescriptor.Relations["Products"];
            GridTableDescriptor productsTableDescriptor    = (GridTableDescriptor)productsRelationDescriptor.ChildTableDescriptor;
            productsTableDescriptor.GroupedColumns.Add("SupplierID");

            // Group OrderDetails table by "Discount"
            // Add Total = "[UnitPrice]*[Quantity]" expression field
            // Add Summaries for Total and Average for UnitPrice.

            RelationDescriptor  orderDetailsRelationDescriptor = productsTableDescriptor.Relations["OrderDetails"];
            GridTableDescriptor orderDetailsTableDescriptor    = (GridTableDescriptor)orderDetailsRelationDescriptor.ChildTableDescriptor;

            ExpressionFieldDescriptor ed = new ExpressionFieldDescriptor("Total", "[UnitPrice]*[Quantity]");
            ed.DefaultValue = "";
            orderDetailsTableDescriptor.ExpressionFields.Add(ed);
            orderDetailsTableDescriptor.GroupedColumns.Add("Discount");
            //Adding the SummaryColumnDescriptor to the SummaryRowDescriptor.
            GridSummaryRowDescriptor orderDetailsSummaryRow = new GridSummaryRowDescriptor("Total");
            orderDetailsTableDescriptor.SummaryRows.Add(orderDetailsSummaryRow);
            //Creating a new SummaryColumnDescriptor.
            GridSummaryColumnDescriptor totalSum = new GridSummaryColumnDescriptor("Total");
            //Setting it's properties.
            totalSum.SummaryType = SummaryType.DoubleAggregate;
            totalSum.Style       = GridSummaryStyle.Column;
            //Initializing it to the Column it is associated with.
            totalSum.DataMember    = "Total";
            totalSum.DisplayColumn = "Total";
            totalSum.Format        = "Sum={Sum}";
            orderDetailsSummaryRow.SummaryColumns.Add(totalSum);


            orderDetailsTableDescriptor.Columns["Total"].Width = 70;

            //Creating a new SummaryColumnDescriptor.
            GridSummaryColumnDescriptor avgUnitPrice = new GridSummaryColumnDescriptor("AvgUnitPrice");
            //Setting it's properties.
            avgUnitPrice.SummaryType   = SummaryType.DoubleAggregate;
            avgUnitPrice.Style         = GridSummaryStyle.Column;
            avgUnitPrice.DataMember    = "UnitPrice";
            avgUnitPrice.DisplayColumn = "UnitPrice";
            avgUnitPrice.Format        = "Avg={Average:#.0}";
            orderDetailsSummaryRow.SummaryColumns.Add(avgUnitPrice);

            // expand a specific record, search for groups etc.
            Table categoriesTable = engine.Table;//.RelatedTables["Categories"];
            Console.WriteLine(categoriesTable.ToString());

            Table productsTable = categoriesTable.RelatedTables["Products"];
            Console.WriteLine(productsTable.ToString());

            // Get the child table in the products table that is assocuated with category "1"
            ChildTable product1 = (ChildTable)productsTable.TopLevelGroup.Groups["1"];
            Console.WriteLine(product1.ToString());
            Console.WriteLine(product1.Groups[0].ToString());

            // Get the child table in the products table that is assocuated with category "1"
            ChildTable product21 = (ChildTable)productsTable.TopLevelGroup.Groups["8"];
            Console.WriteLine(product21.ToString());
            Console.WriteLine(product21.Groups[0].Records[0].ToString());

            // Show me the associated "NestedTable" element of the categories table (the NestedTable
            // element established the link between parent table and a nested child table)
            Console.WriteLine(product21.Groups[0].Records[0].ParentChildTable.ParentNestedTable);

            // Expand the product for category 8
            product21.IsExpanded = true;
            product21.ParentNestedTable.IsExpanded = true;
            product21.ParentNestedTable.ParentRecord.IsExpanded = true;

            // When you assign a "DataSet" as a datasource, the DataSet is a list with one record (not allowing AddNew) with nested tables.
            // Expand the first record so that tables are shown.
            engine.Table.TopLevelGroup.Records[0].IsExpanded = true;

            // Sort  product table by ProductName
            product21.ParentTable.TableDescriptor.SortedColumns.Add("ProductName");

            // Find group for supplier id 21
            Group supplier21Group = product21.Groups["21"];

            // Find productname Spegesild in that group
            int index = supplier21Group.Records.FindRecord("Spegesild");

            // Print out the row index and record index
            Record r = supplier21Group.Records[index];
            Console.WriteLine("Found: " + r.ToString());
            Console.WriteLine("RowIndex " + engine.Table.NestedDisplayElements.IndexOf(r).ToString());
            Console.WriteLine("Record Index " + engine.Table.Records.IndexOf(r).ToString());

            // Dump out nested display elements to console



            this.groupingGrid1.Table.Records[0].IsExpanded    = true;
            this.groupingGrid1.Table.TopLevelGroup.IsExpanded = true;


            engine.ChildGroupOptions.ShowCaption       = true;
            engine.NestedTableGroupOptions.ShowCaption = true;



            // Adding GroupDropAreas for nested tables.
            groupingGrid1.AddGroupDropArea((GridTable)productsTable);
            groupingGrid1.AddGroupDropArea((GridTable)productsTable.RelatedTables[0]);
            groupingGrid1.ShowGroupDropArea = true;

            //Navigate to other control using tabkey navigation
            groupingGrid1.WantTabKey = false;

            // Make Spegesild current record
            if (r != null)
            {
                r.SetCurrent();

                // Expand record and nested tables
                r.IsExpanded = true;
                r.NestedTables[0].IsExpanded = true;

                Record orderDetailsRecords = r.NestedTables[0].ChildTable.GetFirstRecord();
                // Expand Group record belongs to
                orderDetailsRecords.ParentGroup.IsExpanded = true;

                // Scroll this record in view.
                groupingGrid1.TableControl.ScrollInView(orderDetailsRecords);
                groupingGrid1.TableControl.LeftColIndex = 1;
            }
        }