示例#1
0
        private void AddOperand_Click(object sender, RoutedEventArgs e)
        {
            //
            // Determine parent expression
            //
            ExprNode parentExpr;

            parentExpr = (ExprNode)expressionModel.ExprTreeView.SelectedItem;
            if (parentExpr == null && ExpressionModel.Count != 0)
            {
                return;                                                   // Nothing is selected
            }
            //
            // Determine dimension (function) and create child expression
            //
            DimPath path = (DimPath)operands.SelectedItem;

            if (path == null)
            {
                return;
            }

            var expr = ExprNode.CreateReader(path, false);

            expr = (ExprNode)expr.Root;

            //
            // Insert new child expression
            //
            if (parentExpr == null) // First exprssion node
            {
                ExpressionModel.Add(expr);
            }
            else
            {
                parentExpr.AddChild(expr);
            }

            RefreshAll();
        }
示例#2
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();
        }