Esempio n. 1
0
        private void btnAddExpression_Click(object sender, RoutedEventArgs e)
        {
            //get the actual field name from the map here
            string fieldName = "";

            Model.Expression.fieldType ft = Model.Expression.fieldType.Unknown;

            if (cboFieldNames.SelectedValue.ToString() == _FieldNameAliasMap[cboFieldNames.SelectedIndex].value[0])
            {
                fieldName = _FieldNameAliasMap[cboFieldNames.SelectedIndex].key;
                ft        = _FieldNameAliasMap[cboFieldNames.SelectedIndex].FieldType;
            }
            else
            {
                for (int i = 0; i < cboFieldNames.Items.Count; i++)
                {
                    if (_FieldNameAliasMap[i].value[0] == cboFieldNames.SelectedValue.ToString())
                    {
                        fieldName = _FieldNameAliasMap[i].key;
                        ft        = _FieldNameAliasMap[i].FieldType;
                    }
                }
            }

            string op    = cboOperators.SelectedValue as string;
            string value = txtSimpleExpression.Text;

            bool validValue = validateValue(ft, value);

            if (validValue)
            {
                Model.Expression exp = new Model.Expression(fieldName, op, value);

                foreach (StringItems2 item in FieldNameAliasMap)
                {
                    if (item.key == fieldName)
                    {
                        exp.FieldType = item.FieldType;
                        break;
                    }
                }

                if (expressions == null)
                {
                    expressions = new ObservableCollection <Model.Expression>();
                    lvExpressions.ItemsSource = expressions;
                    //TODO...may want to clean this up between when the diag is opened and closed
                    expressions.CollectionChanged += expressions_CollectionChanged;
                }

                expressions.Add(exp);

                if (lvExpressions.Visibility == System.Windows.Visibility.Hidden)
                {
                    lvExpressions.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }
Esempio n. 2
0
        //returns true for any fields that query is supported on for this addin
        private bool validateValue(Model.Expression.fieldType ft, string value)
        {
            switch (ft)
            {
            case Model.Expression.fieldType.Blob:
                MessageBox.Show("Query not supported on BLOB field type.");
                return(false);

            case Model.Expression.fieldType.Date:
                DateTime dt;
                if (DateTime.TryParse(value, out dt))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for Date field type.");
                    return(false);
                }

            case Model.Expression.fieldType.Double:
                Double d;
                if (Double.TryParse(value, out d))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for Double field type.");
                    return(false);
                }

            case Model.Expression.fieldType.GUID:
                Guid g;
                if (Guid.TryParse(value, out g))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for GUID field type.");
                    return(false);
                }

            case Model.Expression.fieldType.Geometry:
                MessageBox.Show("Query not supported on GEOMETRY field type.");
                return(false);

            case Model.Expression.fieldType.GlobalID:
                Guid guid;
                if (Guid.TryParse(value, out guid))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for GlobalID field type.");
                    return(false);
                }

            case Model.Expression.fieldType.Integer:
                Int32 i;
                if (Int32.TryParse(value, out i))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for Integer field type.");
                    return(false);
                }

            case Model.Expression.fieldType.OID:
                Int32 oid;
                if (Int32.TryParse(value, out oid))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for OID field type.");
                    return(false);
                }

            case Model.Expression.fieldType.Raster:
                MessageBox.Show("Query not supported on RASTER field type.");
                return(false);

            case Model.Expression.fieldType.Single:
                Int16 ii;
                if (Int16.TryParse(value, out ii))
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Cannot add Expression.\nUnable to parse value: " + value + " for Single Integer field type.");
                    return(false);
                }

            case Model.Expression.fieldType.SmallInteger:
                Int16 iii;
                if (Int16.TryParse(value, out iii))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case Model.Expression.fieldType.String:
                return(true);

            case Model.Expression.fieldType.Unknown:
                MessageBox.Show("Query not supported on UNKNOWN field type.");
                return(false);

            case Model.Expression.fieldType.XML:
                MessageBox.Show("Query not supported on XML field type.");
                return(false);

            default:
                return(false);
            }
        }