Ejemplo n.º 1
0
        public AggregationBox(DcColumn column, DcColumn measureColumn)
        {
            this.okCommand = new DelegateCommand(this.OkCommand_Executed, this.OkCommand_CanExecute);

            InitializeComponent();

            if (column.Input.Columns.Contains(column))
            {
                IsNew = false;
            }
            else
            {
                IsNew = true;
            }

            Column      = column;
            SourceTable = column.Input;

            newColumnName.Text = Column.Name;

            // Initialize all possible fact tables (lesser tables)
            FactTables = MappingModel.GetPossibleLesserSets(SourceTable);
            if (!IsNew)
            {
                FactTable = Column.Definition.FactTable;
            }
            else
            {
                if (FactTables.Count == 1)
                {
                    FactTable = FactTables[0];
                }
            }
            // By setting a fact table here we trigger item selection event where two controls will be filled: grouping paths and measure paths.

            // Use additional parameter for selecting desired measure
            if (IsNew && measureColumn != null)
            {
                // Find at least one fact table that has a measure path to this measure column
                foreach (DcTable table in FactTables)
                {
                    var pathEnum = new PathEnumerator(
                        table,
                        measureColumn.Output,
                        DimensionType.IDENTITY_ENTITY
                        );

                    var paths = pathEnum.ToList();
                    if (paths.Count() == 0)
                    {
                        continue;
                    }

                    FactTable   = table; // Here the list of measure paths has to be filled automatically
                    MeasurePath = paths[0];
                }
            }

            // Initialize aggregation functions
            AggregationFunctions = new List <string>(new string[] { "COUNT", "SUM", "MUL" });
            if (!IsNew)
            {
                AggregationFunction = Column.Definition.Updater;
            }
            else
            {
                AggregationFunction = "SUM";
            }

            RefreshAll();
        }
Ejemplo n.º 2
0
        private void FactTables_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var lv        = (ListView)e.Source; // or sender
            var factTable = lv.SelectedItem;    // or SelectedValue

            if (factTable == null)
            {
                return;
            }

            //
            // Initialize grouping paths. Paths from the fact set to the source set
            //
            var grPaths = new PathEnumerator((DcTable)factTable, SourceTable, DimensionType.IDENTITY_ENTITY);

            GroupingPaths = grPaths.ToList <DimPath>();

            // Select some grouping path item
            if (!IsNew && factTable == Column.Definition.FactTable) // If the fact table as defined then grouping path also as defined (i.e., show the current definition)
            {
                foreach (var p in GroupingPaths)                    // Definition can store a different instance of the same path (so either override Equals for DimPath or compare manually)
                {
                    if (!p.SamePath(Column.Definition.GroupPaths[0]))
                    {
                        continue;
                    }
                    GroupingPath = p;
                    break;
                }
            }
            else // Recommend best grouping path: single choise, shortest path etc.
            {
                if (GroupingPaths.Count == 1)
                {
                    GroupingPath = GroupingPaths[0];
                }
            }

            //
            // Initialize measure paths. Paths from the fact set to numeric sets
            //
            DcSchema schema  = ((DcTable)factTable).Schema;
            var      mePaths = new PathEnumerator(
                new List <DcTable>(new DcTable[] { (DcTable)factTable }),
                new List <DcTable>(new DcTable[] { schema.GetPrimitive("Integer"), schema.GetPrimitive("Double") }),
                false,
                DimensionType.IDENTITY_ENTITY
                );

            MeasurePaths = mePaths.ToList <DimPath>();

            // Select some measure path item
            if (!IsNew && factTable == Column.Definition.FactTable)
            {
                foreach (var p in MeasurePaths) // Definition can store a different instance of the same path (so either override Equals for DimPath or compare manually)
                {
                    if (!p.SamePath(Column.Definition.MeasurePaths[0]))
                    {
                        continue;
                    }
                    MeasurePath = p;
                    break;
                }
            }
            else
            {
                if (MeasurePaths.Count == 1)
                {
                    MeasurePath = MeasurePaths[0];
                }
            }

            RefreshAll();
        }
Ejemplo n.º 3
0
        public ArithmeticBox(DcColumn column, bool whereExpression)
        {
            this.okCommand = new DelegateCommand(this.OkCommand_Executed, this.OkCommand_CanExecute);

            IsWhere = whereExpression;

            if (column.Input.Columns.Contains(column))
            {
                IsNew = false;
            }
            else
            {
                IsNew = true;
            }

            Column = column;
            DcTable  sourceTable = column.Input;
            DcSchema schema      = sourceTable.Schema;

            SourceTable = sourceTable;

            ExpressionModel = new ObservableCollection <ExprNode>(); // This contains what we will create/edit
            if (IsWhere)
            {
                if (SourceTable.Definition.WhereExpr != null)
                {
                    ExpressionModel.Add(SourceTable.Definition.WhereExpr);
                }
            }
            else
            {
                if (Column.Definition.FormulaExpr != null)
                {
                    ExpressionModel.Add(Column.Definition.FormulaExpr);
                }
            }

            InitializeComponent();

            newColumnName.Text = Column.Name;

            // Initialize a list of possible operations
            ActionType[] ops;
            if (whereExpression)
            {
                // Other ways: to collapse a grid row: http://stackoverflow.com/questions/2502178/wpf-hide-grid-row
                Controls.RowDefinitions[0].Height = new GridLength(0);
                sourceTableName.IsReadOnly        = false;

                ops = new ActionType[]
                {
                    ActionType.MUL, ActionType.DIV, ActionType.ADD, ActionType.SUB,
                    ActionType.LEQ, ActionType.GEQ, ActionType.GRE, ActionType.LES,
                    ActionType.EQ, ActionType.NEQ,
                    ActionType.AND, ActionType.OR,
                };
            }
            else
            {
                Controls.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Auto);
                sourceTableName.IsReadOnly        = true;

                ops = new ActionType[] { ActionType.MUL, ActionType.DIV, ActionType.ADD, ActionType.SUB };
            }
            operations.ItemsSource = ops;

            // Initialize a list of possible column accesses
            var paths = new PathEnumerator(
                new List <DcTable>(new DcTable[] { SourceTable }),
                new List <DcTable>(new DcTable[] { schema.GetPrimitive("Integer"), schema.GetPrimitive("Double") }),
                false,
                DimensionType.IDENTITY_ENTITY
                );

            SourcePaths = paths.ToList();

            // If we edit an existing column then we do not want to use it in the definition as an operand
            DimPath columnPath = SourcePaths.FirstOrDefault(p => p.FirstSegment == column);

            if (columnPath != null)
            {
                SourcePaths.Remove(columnPath);
            }

            RefreshAll();
        }