示例#1
0
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(NewTableName) || string.IsNullOrWhiteSpace(NewColumnName) || projectionDims.SelectedItems.Count == 0)
            {
                return;
            }

            CsSchema schema = SourceTable.Top;

            // Initialize a list of selected dimensions (from the whole list of all greater dimensions
            List <CsColumn> projDims = new List <CsColumn>();

            foreach (var item in projectionDims.SelectedItems)
            {
                projDims.Add((CsColumn)item);
            }

            // Remove all existing greater dims (clean the target table before defining new structure)
            foreach (CsColumn dim in TargetTable.GreaterDims.ToList())
            {
                if (dim.IsSuper)
                {
                    continue;
                }
                dim.Remove();
            }

            // 1. Create a mapping object from the selected projection dimensions
            // 2. Create identity dimensions for the extracted set and their mapping to the projection dimensions
            Mapping mapping = new Mapping(SourceTable, TargetTable);

            foreach (CsColumn projDim in projDims)
            {
                CsTable  idSet = projDim.GreaterSet;
                CsColumn idDim = schema.CreateColumn(projDim.Name, TargetTable, idSet, true);
                idDim.Add();

                mapping.AddMatch(new PathMatch(new DimPath(projDim), new DimPath(idDim)));
            }
            Column.Definition.DefinitionType = ColumnDefinitionType.LINK;
            Column.Definition.Mapping        = mapping;
            Column.Definition.IsGenerating   = true;
            Column.Name = NewColumnName;

            TargetTable.Definition.DefinitionType = TableDefinitionType.PROJECTION;

            TargetTable.Name = NewTableName;

            // If new then add objects to the schema (or do it outside?)
            if (IsNew)
            {
                schema.AddTable(TargetTable, SourceTable.SuperSet, null);
                Column.Add();
            }

            this.DialogResult = true;
        }