Exemplo n.º 1
0
        protected override object GetDialogResult()
        {
            if (this.SelectedNode != null
                &&
                (this.SelectedNode is TableExpressionViewModel ||
                 this.SelectedNode is QueryExpressionViewModel))
            {
                return(null);
            }

            if (this.SelectedNode is ParameterExpressionViewModel)
            {
                return(((ParameterExpressionViewModel)this.SelectedNode).GetParameterReferenceViewModel(this.SelectedNode.Parent));
            }

            HermesViewModel parentVM = this.Caller as ComparisonOperatorViewModel;

            if (parentVM == null)
            {
                parentVM = this.Caller as PropertyExpressionViewModel;
            }
            PropertyReferenceViewModel selectedVM = this.SelectedNode as PropertyReferenceViewModel;
            PropertyReference          source     = selectedVM.Model as PropertyReference;

            if (parentVM != null && selectedVM != null && source != null)
            {
                PropertyReference model = new PropertyReference(parentVM.Model, source.Table, source.Property);
                return(new PropertyReferenceViewModel(parentVM, selectedVM.Table, model));
            }
            else
            {
                return(null);
            }
        }
        private void InitializeViewModel(ComparisonOperator model)
        {
            QueryExpressionViewModel query  = this.GetQueryExpressionViewModel(this);
            SelectStatementViewModel select = this.GetSelectStatementViewModel(this);

            if (select == null)
            {
                return;
            }

            if (model.LeftExpression is PropertyReference)
            {
                PropertyReference          property   = (PropertyReference)model.LeftExpression;
                TableExpressionViewModel   tableVM    = select.Tables.Where(t => t.Alias == property.Table.Alias).FirstOrDefault();
                PropertyReferenceViewModel propertyVM = new PropertyReferenceViewModel(this, tableVM, (PropertyReference)model.LeftExpression);

                this.LeftExpression     = propertyVM;
                this.LeftExpressionView = new PropertyReferenceView(propertyVM);
            }
            else if (model.LeftExpression is ParameterExpression)
            {
                if (query != null)
                {
                    ParameterExpression          expression = (ParameterExpression)model.LeftExpression;
                    ParameterExpressionViewModel vm         = query.QueryParameters.Where(p => p.Name == expression.Name).FirstOrDefault();
                    if (vm != null)
                    {
                        this.LeftExpression     = vm.GetParameterReferenceViewModel(this);
                        this.LeftExpressionView = new ParameterReferenceView((ParameterReferenceViewModel)this.LeftExpression);
                    }
                }
            }

            if (model.RightExpression is PropertyReference)
            {
                PropertyReference          property   = (PropertyReference)model.RightExpression;
                TableExpressionViewModel   tableVM    = select.Tables.Where(t => t.Alias == property.Table.Alias).FirstOrDefault();
                PropertyReferenceViewModel propertyVM = new PropertyReferenceViewModel(this, tableVM, (PropertyReference)model.RightExpression);

                this.RightExpression     = propertyVM;
                this.RightExpressionView = new PropertyReferenceView(propertyVM);
            }
            else if (model.RightExpression is ParameterExpression)
            {
                if (query != null)
                {
                    ParameterExpression          expression = (ParameterExpression)model.RightExpression;
                    ParameterExpressionViewModel vm         = query.QueryParameters.Where(p => p.Name == expression.Name).FirstOrDefault();
                    if (vm != null)
                    {
                        this.RightExpression     = vm.GetParameterReferenceViewModel(this);
                        this.RightExpressionView = new ParameterReferenceView((ParameterReferenceViewModel)this.RightExpression);
                    }
                }
            }
        }
 private void IntializeViewModel(PropertyExpression model)
 {
     if (model.Expression == null)
     {
         return;
     }
     if (model.Expression is PropertyReference)
     {
         SelectStatementViewModel parent = this.Parent as SelectStatementViewModel;
         if (parent != null)
         {
             PropertyReference          property   = (PropertyReference)model.Expression;
             TableExpressionViewModel   tableVM    = parent.Tables.Where(t => t.Alias == property.Table.Alias).FirstOrDefault();
             PropertyReferenceViewModel propertyVM = new PropertyReferenceViewModel(this, tableVM, (PropertyReference)model.Expression);
             this.OnExpressionSelected(propertyVM);
         }
     }
 }
 public PropertyReferenceView(PropertyReferenceViewModel viewModel) : this()
 {
     this.DataContext = viewModel;
 }