Exemple #1
0
        public UserControl Build(HermesViewModel parent, BooleanFunction model)
        {
            if (model == null)
            {
                return(null);
            }

            if (model is ComparisonOperator)
            {
                ComparisonOperatorViewModel viewModel = new ComparisonOperatorViewModel(parent, (ComparisonOperator)model);
                _View = new ComparisonOperatorView(viewModel);
            }
            else if (model is BooleanOperator)
            {
                BooleanOperator                 bo        = (BooleanOperator)model;
                BooleanOperatorViewModel        viewModel = new BooleanOperatorViewModel(parent, bo);
                List <BooleanFunctionViewModel> ovms      = new List <BooleanFunctionViewModel>();
                foreach (BooleanFunction f in bo.Operands)
                {
                    ComparisonOperatorViewModel covm = new ComparisonOperatorViewModel(viewModel, (ComparisonOperator)f);
                    ovms.Add(covm);
                }
                viewModel.Operands = new ObservableCollection <BooleanFunctionViewModel>(ovms);
                _View = new BooleanOperatorView(viewModel);
            }

            return(_View);
        }
Exemple #2
0
        private void AddInnerBooleanOperator()
        {
            BooleanOperator model = this.Model as BooleanOperator;

            if (model == null)
            {
                return;
            }

            if (model.IsLeaf)
            {
                AddOuterBooleanOperator();
            }
            else
            {
                BooleanOperator operand = new BooleanOperator(model)
                {
                    Name = BooleanFunction.OR
                };
                model.AddChild(operand);
                ComparisonOperator child = new ComparisonOperator(operand);
                operand.AddChild(child);
                BooleanOperatorViewModel    viewModel = new BooleanOperatorViewModel(this, operand);
                ComparisonOperatorViewModel childVM   = new ComparisonOperatorViewModel(viewModel, child);
                if (viewModel.Operands == null)
                {
                    viewModel.Operands = new ObservableCollection <BooleanFunctionViewModel>()
                    {
                        childVM
                    };
                }
                else
                {
                    viewModel.Operands.Add(childVM);
                }
                if (this.Operands == null)
                {
                    this.Operands = new ObservableCollection <BooleanFunctionViewModel>()
                    {
                        viewModel
                    };
                }
                else
                {
                    this.Operands.Add(viewModel);
                }
            }
        }
        private void AddNewCondition()
        {
            if (this.Parent is SelectStatementViewModel)
            {
                if (((SelectStatementViewModel)this.Parent).Tables.Count == 0)
                {
                    Z.Notify(new Notification {
                        Title = "Hermes", Content = "Предложение FROM не содержит ни одной таблицы!"
                    });
                    return;
                }
            }

            if (_Model == null)
            {
                _Model = new ComparisonOperator(this.Parent.Model);
                SetModelToParent();
                ComparisonOperatorViewModel viewModel = new ComparisonOperatorViewModel(this, (ComparisonOperator)_Model);
                this.View = new ComparisonOperatorView(viewModel);
            }
            else if (_Model is ComparisonOperator)
            {
                ComparisonOperatorViewModel currentVM = this.View.DataContext as ComparisonOperatorViewModel;

                BooleanOperator substitute = new BooleanOperator(this.Parent.Model);
                substitute.AddChild(_Model);
                BooleanOperatorViewModel substituteVM = new BooleanOperatorViewModel(this, substitute);

                ComparisonOperator child = new ComparisonOperator(substitute);
                substitute.AddChild(child);
                ComparisonOperatorViewModel childVM = new ComparisonOperatorViewModel(substituteVM, child);

                currentVM.Parent      = substituteVM;
                substituteVM.Operands = new ObservableCollection <BooleanFunctionViewModel>()
                {
                    currentVM, childVM
                };

                BooleanOperatorView substituteView = new BooleanOperatorView(substituteVM);

                _Model = substitute;
                SetModelToParent();
                this.IsCommandPanelVisible = false;
                this.View = substituteView;
            }
        }
        private void RemoveComparisonOperator()
        {
            ComparisonOperator model = this.Model as ComparisonOperator;

            if (model == null)
            {
                return;
            }

            if (model.IsRoot)
            {
                if (this.Parent is BooleanExpressionViewModel)
                {
                    ((BooleanExpressionViewModel)this.Parent).ClearBooleanExpression();
                }
            }
            else
            {
                BooleanOperatorViewModel parent = this.Parent as BooleanOperatorViewModel;
                if (parent == null)
                {
                    return;
                }

                BooleanOperator consumer = model.Consumer as BooleanOperator;
                if (consumer == null)
                {
                    return;
                }

                if (consumer.Operands.Count == 0)
                {
                    return;
                }

                if (consumer.Operands.Count > 1)
                {
                    consumer.Operands.Remove(model);
                    parent.RemoveChildOperator(this);
                }
                else
                {
                    parent.RemoveBooleanOperatorCommand.Execute(null);
                }
            }
        }
Exemple #5
0
 public BooleanOperatorView(BooleanOperatorViewModel viewModel) : this()
 {
     this.DataContext = viewModel;
 }
Exemple #6
0
        private void RemoveBooleanOperator()
        {
            BooleanOperator model = this.Model as BooleanOperator;

            if (model == null)
            {
                return;
            }

            if (model.IsRoot)
            {
                if (this.Parent is BooleanExpressionViewModel)
                {
                    ((BooleanExpressionViewModel)this.Parent).ClearBooleanExpression();
                }
            }
            else
            {
                BooleanOperatorViewModel parent = this.Parent as BooleanOperatorViewModel;
                if (parent == null)
                {
                    return;
                }

                BooleanOperator consumer = model.Consumer as BooleanOperator;
                if (consumer == null)
                {
                    return;
                }

                if (consumer.Operands.Count == 0)
                {
                    return;
                }

                consumer.Operands.Remove(model);
                parent.RemoveChildOperator(this);

                if (parent.Operands.Count == 1)
                {
                    BooleanFunctionViewModel orphan = parent.Operands[0];

                    if (parent.Parent is BooleanExpressionViewModel)
                    {
                        orphan.Name = parent.Name;
                        ((BooleanExpressionViewModel)parent.Parent).SetBooleanExpression(orphan);
                    }
                    else if (parent.Parent is BooleanOperatorViewModel)
                    {
                        orphan.Parent         = parent.Parent;
                        orphan.Model.Consumer = parent.Parent.Model;

                        int index_to_replace = ((BooleanOperator)consumer.Consumer).Operands.IndexOf(consumer);
                        ((BooleanOperator)consumer.Consumer).Operands.RemoveAt(index_to_replace);
                        ((BooleanOperator)consumer.Consumer).Operands.Insert(index_to_replace, (BooleanOperator)orphan.Model);

                        index_to_replace = ((BooleanOperatorViewModel)parent.Parent).Operands.IndexOf(parent);
                        ((BooleanOperatorViewModel)parent.Parent).Operands.RemoveAt(index_to_replace);
                        ((BooleanOperatorViewModel)parent.Parent).Operands.Insert(index_to_replace, orphan);
                    }
                }
            }
        }
Exemple #7
0
        private void AddOuterBooleanOperator()
        {
            BooleanOperator model = this.Model as BooleanOperator;

            if (model == null)
            {
                return;
            }

            // 0. Remember the parent of this node
            HermesModel     consumer         = model.Consumer;
            HermesViewModel parentVM         = this.Parent;
            int             index_to_replace = -1;

            if (consumer is BooleanOperator)
            {
                index_to_replace = ((BooleanOperator)consumer).Operands.IndexOf(model);
                if (index_to_replace == -1)
                {
                    throw new ArgumentOutOfRangeException("Model is broken!");
                }
            }

            // 1. Create new node and it's VM which will substitute this current node
            BooleanOperator substitute = new BooleanOperator(consumer)
            {
                Name = BooleanFunction.OR
            };

            substitute.AddChild(model);
            BooleanOperatorViewModel substituteVM = new BooleanOperatorViewModel(parentVM, substitute);

            this.Parent = substituteVM;

            // 2. Create new child and it's VM consumed by substitute
            BooleanOperator child = new BooleanOperator(substitute);

            substitute.AddChild(child);
            BooleanOperatorViewModel childVM = new BooleanOperatorViewModel(substituteVM, child);

            // 3. Add new comparison operator and it's VM to new born child
            ComparisonOperator gift = new ComparisonOperator(child);

            child.AddChild(gift);
            ComparisonOperatorViewModel giftVM = new ComparisonOperatorViewModel(childVM, gift);

            childVM.Operands = new ObservableCollection <BooleanFunctionViewModel>()
            {
                giftVM
            };

            // 4. Fill substitute VM with operands
            substituteVM.Operands = new ObservableCollection <BooleanFunctionViewModel>()
            {
                this,
                childVM
            };

            // 5. Substitute this current node at parent VM and it's model
            if (consumer is BooleanOperator)
            {
                ((BooleanOperator)consumer).Operands.RemoveAt(index_to_replace);
                ((BooleanOperator)consumer).Operands.Insert(index_to_replace, substitute);
                index_to_replace = ((BooleanOperatorViewModel)parentVM).Operands.IndexOf(this);
                if (index_to_replace > -1)
                {
                    ((BooleanOperatorViewModel)parentVM).Operands.RemoveAt(index_to_replace);
                    ((BooleanOperatorViewModel)parentVM).Operands.Insert(index_to_replace, substituteVM);
                }
            }
            else if (parentVM is BooleanExpressionViewModel)
            {
                ((BooleanExpressionViewModel)parentVM).SetBooleanExpression(substituteVM);
            }
        }