Ejemplo n.º 1
0
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>
        /// The value to be passed to the target dependency property.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null || parameter.ToString() == "" || string.IsNullOrEmpty(LookupField))
            {
                return(value);
            }

            DynamicCodedValueSource dynamicCodedValueSource = parameter as DynamicCodedValueSource;

            return(DynamicCodedValueSource.GetCodedValueSources(LookupField, Field, value, dynamicCodedValueSource, NullableSources));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a DynamicCodedValueSource object used to lookup display value.
        /// </summary>
        /// <param name="field">The field to build DynamicCodedValueSource for</param>
        /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param>
        /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns>
        internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo)
        {
            DynamicCodedValueSource dynamicCodedValueSource = null;

            foreach (object key in layerInfo.FeatureTypes.Keys)
            {
                FeatureType featureType = layerInfo.FeatureTypes[key];
                if (featureType.Domains.ContainsKey(field.Name))
                {
                    if (dynamicCodedValueSource == null)
                    {
                        dynamicCodedValueSource = new DynamicCodedValueSource();
                    }

                    CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain;
                    if (codedValueDomain != null)
                    {
                        CodedValueSources codedValueSources = null;
                        foreach (KeyValuePair <object, string> kvp in codedValueDomain.CodedValues)
                        {
                            if (codedValueSources == null)
                            {
                                codedValueSources = new CodedValueSources();
                                if (field.Nullable)
                                {
                                    CodedValueSource nullableSource = new CodedValueSource()
                                    {
                                        Code = null, DisplayName = " "
                                    };
                                    codedValueSources.Add(nullableSource);
                                }
                            }

                            codedValueSources.Add(new CodedValueSource()
                            {
                                Code = kvp.Key, DisplayName = kvp.Value
                            });
                        }
                        if (codedValueSources != null)
                        {
                            if (dynamicCodedValueSource == null)
                            {
                                dynamicCodedValueSource = new DynamicCodedValueSource();
                            }

                            dynamicCodedValueSource.Add(featureType.Id, codedValueSources);
                        }
                    }
                }
            }
            return(dynamicCodedValueSource);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>
        /// The value to be passed to the target dependency property.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null || parameter.ToString() == "" ||
                string.IsNullOrEmpty(LookupField) || string.IsNullOrEmpty(Field))
            {
                return("");
            }
#if SILVERLIGHT
            DynamicCodedValueSource dynamicCodedValueSource = parameter as DynamicCodedValueSource;
#else
            object[] array = parameter as object[];
            DynamicCodedValueSource dynamicCodedValueSource = array[0] as DynamicCodedValueSource;
            value = (array[1] as FrameworkElement).DataContext;
#endif
            string name = DynamicCodedValueSource.CodedValueNameLookup(LookupField, Field, value, dynamicCodedValueSource);

            if (!string.IsNullOrEmpty(name))
            {
                return(name);
            }

            return("");
        }
Ejemplo n.º 4
0
        internal static string CodedValueNameLookup(string lookupField, string field, object generic, DynamicCodedValueSource dynamicCodedValueSource)
        {
            if (dynamicCodedValueSource != null && generic != null && !string.IsNullOrEmpty(field))
            {
#if SILVERLIGHT
                PropertyInfo lookupFieldProperty = generic.GetType().GetProperty(lookupField);
                if (lookupFieldProperty == null)
                {
                    return(null);
                }

                var key = lookupFieldProperty.GetValue(generic, null);
#else
                var key = generic is Graphic ? (generic as Graphic).Attributes[lookupField] : null;
#endif
                if (key == null)
                {
                    return(CodedValueSources.CodedValueNameLookup(field, generic, new CodedValueSources()));
                }

                if (dynamicCodedValueSource.ContainsKey(key))
                {
                    CodedValueSources codedValueSources = dynamicCodedValueSource[key];
                    if (codedValueSources != null)
                    {
                        string name = CodedValueSources.CodedValueNameLookup(field, generic, codedValueSources);
                        if (!string.IsNullOrEmpty(name))
                        {
                            return(name);
                        }
                    }
                }
                else if (dynamicCodedValueSource.ContainsKey(key.ToString()))
                {
                    CodedValueSources codedValueSources = dynamicCodedValueSource[key.ToString()];
                    if (codedValueSources != null)
                    {
                        string name = CodedValueSources.CodedValueNameLookup(field, generic, codedValueSources);
                        if (!string.IsNullOrEmpty(name))
                        {
                            return(name);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        internal static CodedValueSources GetCodedValueSources(string lookupField, Field field, object generic, DynamicCodedValueSource dynamicCodedValueSource, CodedValueSources nullableSources)
        {
            if (dynamicCodedValueSource != null && generic != null && !string.IsNullOrEmpty(lookupField))
            {
#if SILVERLIGHT
                PropertyInfo lookupFieldProperty = generic.GetType().GetProperty(lookupField);
                if (lookupFieldProperty == null)
                {
                    return(null);
                }

                var key = lookupFieldProperty.GetValue(generic, null);
#else
                var key = (generic is Graphic) ? (generic as Graphic).Attributes[lookupField] : null;
#endif
                if (key == null)
                {
                    object code = CodedValueSources.CodedValueCodeLookup(field.Name, generic, new CodedValueSources());
                    nullableSources.Clear();
                    if (field.Nullable)
                    {
                        CodedValueSource nullableSource = new CodedValueSource()
                        {
                            Code = null, DisplayName = " "
                        };
                        nullableSources.Add(nullableSource);
                    }
                    if (code != null)
                    {
                        CodedValueSource currentSource = new CodedValueSource()
                        {
                            Code = code, DisplayName = code.ToString()
                        };
                        nullableSources.Add(currentSource);
                    }
                    return(nullableSources);
                }

                CodedValueSources codedValueSoruces = null;
                if (dynamicCodedValueSource.ContainsKey(key))
                {
                    codedValueSoruces = dynamicCodedValueSource[key];
                }
                else if (dynamicCodedValueSource.ContainsKey(key.ToString()))
                {
                    codedValueSoruces = dynamicCodedValueSource[key.ToString()];
                }

                CodedValueSource tempSource = codedValueSoruces.FirstOrDefault(x => x.Temp == true);
                if (tempSource != null)
                {
                    codedValueSoruces.Remove(tempSource);
                }
#if SILVERLIGHT
                object value = CodedValueSources.CodedValueNameLookup(field.Name, generic, new CodedValueSources());
                if (string.IsNullOrEmpty(value as string))
                {
                    value = null;
                }
#else
                object value = (generic as Graphic).Attributes[field.Name];
#endif
                if (value != null)
                {
                    CodedValueSource source = codedValueSoruces.FirstOrDefault(x => x.Code != null && x.Code.ToString() == value.ToString());
                    if (source == null)
                    {
                        CodedValueSource currentSource = new CodedValueSource()
                        {
                            Code = value, DisplayName = value.ToString(), Temp = true
                        };
                        if (field.Nullable)
                        {
                            codedValueSoruces.Insert(1, currentSource);
                        }
                        else
                        {
                            codedValueSoruces.Insert(0, currentSource);
                        }
                    }
                }
                return(codedValueSoruces);
            }
            return(null);
        }