Ejemplo n.º 1
0
        private void OkCommand_Executed(object state)
        {
            DcSchema schema = Column.Input.Schema;

            // Column name
            Column.Name = newColumnName.Text;

            // Column type
            DcTable targetTable = null;

            if (AggregationFunction == "COUNT")
            {
                targetTable = schema.GetPrimitive("Integer");;
            }
            else
            {
                targetTable = MeasurePath.Output; // The same as the measure path
            }
            Column.Output = targetTable;

            // Column definition
            Column.Definition.DefinitionType = DcColumnDefinitionType.AGGREGATION;
            Column.Definition.FactTable      = FactTable;
            Column.Definition.GroupPaths.Clear();
            Column.Definition.GroupPaths.Add(GroupingPath);
            Column.Definition.MeasurePaths.Clear();
            Column.Definition.MeasurePaths.Add(MeasurePath);
            Column.Definition.Updater = AggregationFunction;

            this.DialogResult = true;
        }
Ejemplo n.º 2
0
        private void OkCommand_Executed(object state)
        {
            DcSchema schema = Column.Input.Schema;

            // Column name
            if (IsWhere)
            {
                SourceTable.Name = sourceTableName.Text;
            }
            else
            {
                Column.Name = newColumnName.Text;
            }

            ExprNode expr = null;

            if (ExpressionModel == null || ExpressionModel.Count == 0)
            {
                expr = null;
            }
            else
            {
                expr = ExpressionModel[0];
            }

            if (IsWhere) // Expression is part of the table Where definition
            {
                if (expr != null)
                {
                    expr.OutputVariable.TypeName  = "Boolean";
                    expr.OutputVariable.TypeTable = schema.GetPrimitive("Boolean");
                }

                SourceTable.Definition.WhereExpr = expr;
            }
            else // Expression belongs to the column definition
            {
                // Column type
                // Derive output type of the expression and use it to set the type of the column.
                // Alternatively, the type could be chosen by the user precisely as it is done for link columns.
                expr.Resolve(schema.Workspace, new List <DcVariable>()
                {
                    new Variable(SourceTable, "this")
                });
                Column.Output = expr.OutputVariable.TypeTable;

                Column.Definition.FormulaExpr = expr;
            }

            this.DialogResult = true;
        }
Ejemplo n.º 3
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.º 4
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();
        }