Exemple #1
0
            private void Initialize()
            {
                isDynamicCodedValue     = false;
                isCodedValue            = false;
                isTypeIDField           = false;
                dynamicCodedValueSource = null;
                codedValueSources       = null;
                TypeIDField             = string.Empty;

                if (string.IsNullOrEmpty(_field) || _layerInfo == null)
                {
                    return;
                }

                TypeIDField = _layerInfo.TypeIdField;

                Field field = _layerInfo.Fields.FirstOrDefault(x => x.Name == _field);

                isDynamicCodedValue = FieldDomainUtils.IsDynamicDomain(field, LayerInfo);
                isCodedValue        = (field.Domain is CodedValueDomain);
                isTypeIDField       = (field.Name == TypeIDField);

                if (isDynamicCodedValue)
                {
                    dynamicCodedValueSource = FieldDomainUtils.BuildDynamicCodedValueSource(field, _layerInfo);
                }
                else if (isTypeIDField)
                {
                    codedValueSources = FieldDomainUtils.BuildTypeIDCodedValueSource(field, _layerInfo);
                }
                else if (isCodedValue)
                {
                    codedValueSources = FieldDomainUtils.BuildCodedValueSource(field);
                }
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="CodedValueDomainColumn"/> class.
 /// </summary>
 public CodedValueDomainColumn()
     : base()
 {
     CodedValueSources = new CodedValueSources();
     nameConverter = new CodedValueSourceConverter();
     lookupConverter = new CodedValueSourceLookupConverter();
     selectedConverter = new CodedValueSourceSelectedItemConverter();
 }
            internal int Compare(Graphic x, Graphic y)
            {
                var o1 = x.Attributes[Field];                 // get primitive value
                var o2 = y.Attributes[Field];                 // get primitive value

                if (isDynamicCodedValue)
                {
                    o1 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, x, dynamicCodedValueSource);
                    o2 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, y, dynamicCodedValueSource);
                }
                if (isCodedValue || isTypeIDField)
                {
                    o1 = CodedValueSources.CodedValueNameLookup(Field, x, codedValueSources);
                    o2 = CodedValueSources.CodedValueNameLookup(Field, y, codedValueSources);
                }

                return(comparer.Compare(o1, o2));                // compare primitives
            }
		/// <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;
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicCodedValueDomainColumn"/> class.
        /// </summary>
        public DynamicCodedValueDomainColumn()
            : base()
        {
            dateTimeConverter = new DateTimeFormatConverter();
            nameConverter = new DynamicCodedValueSourceConverter();
            lookupConverter = new DynamicCodedValueSourceLookupConverter();
            selectedConverter = new DynamicCodedValueSourceSelectedItemConverter();

            nullableSources = new CodedValueSources();
            #if !SILVERLIGHT
            stringToPrimitiveTypeConverter = new StringToPrimitiveTypeConverter();
            #else
            emptyStringToNullConverter = new EmptyStringToNullConverter();
            #endif
        }
Exemple #6
0
            internal int Compare(Graphic x, Graphic y)
            {
                var o1 = x.Attributes[Field];                 // get primitive value
                var o2 = y.Attributes[Field];                 // get primitive value

                if (o1 == null && o2 == null)
                {
                    return(0);
                }
                else if (o1 != null && o2 == null)
                {
                    return(1);
                }
                else if (o1 == null && o2 != null)
                {
                    return(-1);
                }

                var type = NonNullableType(DataType);

                var t1 = o1.GetType();
                var t2 = o2.GetType();

                if (type == typeof(DateTime))
                {
                    if (t1 != type && t2 != type)
                    {
                        return(0);
                    }
                    if (t1 != type && t2 == type)
                    {
                        return(-1);
                    }
                    if (t1 == type && t2 != type)
                    {
                        return(1);
                    }
                }
                else
                {
                    if (t1 != type)
                    {
                        o1 = Convert.ChangeType(o1, type);
                    }
                    if (t2 != type)
                    {
                        o2 = Convert.ChangeType(o2, type);
                    }
                }

                if (isDynamicCodedValue)
                {
                    o1 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, x, dynamicCodedValueSource);
                    o2 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, y, dynamicCodedValueSource);
                }
                else if (isCodedValue || isTypeIDField)
                {
                    o1 = CodedValueSources.CodedValueNameLookup(Field, x, codedValueSources);
                    o2 = CodedValueSources.CodedValueNameLookup(Field, y, codedValueSources);
                }

                return(comparer.Compare(o1, o2));                // compare primitives
            }
		/// <summary>
		/// Returns CodedValueSources that make up the display text of each value of the TypeIDField.
		/// </summary>
		/// <param name="field">TypeIDField</param>
		/// <param name="layerInfo">FeatureLayerInof used to construct the CodedValueSources from the FeatureTypes.</param>
		/// <returns>CodedValueSoruces that contain code an value matches to all possible TypeIDField values.</returns>
		internal static CodedValueSources BuildTypeIDCodedValueSource(Field field, FeatureLayerInfo layerInfo)
		{
			CodedValueSources codedValueSources = null;
			foreach (KeyValuePair<object, FeatureType> kvp in layerInfo.FeatureTypes)
			{
				if (kvp.Key == null) continue;
				string name = (kvp.Value != null && kvp.Value.Name != null) ? kvp.Value.Name : "";
				CodedValueSource codedValueSource = new CodedValueSource() { Code = kvp.Key, DisplayName = name };
				if (codedValueSources == null)
				{
					codedValueSources = new CodedValueSources();
					if (field.Nullable)
					{
						CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " };
						codedValueSources.Add(nullableSource);
					}
				}
				codedValueSources.Add(codedValueSource);
			}
			return codedValueSources;
		}
		/// <summary>
		/// Returns a CodedValueSources object constructed form the CodedValueDomain value.
		/// </summary>
		/// <param name="field">The field to make a CodedValueSource from.</param>
		/// <returns>The CodedValueSources object used for a code to value lookup.</returns>
		internal static CodedValueSources BuildCodedValueSource(Field field)
		{
			CodedValueDomain codedValueDomain = field.Domain as CodedValueDomain;
			CodedValueSources codedValueSources = null;
			if (codedValueDomain != null)
			{
				foreach (KeyValuePair<object, string> codedValue 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 = codedValue.Key, DisplayName = codedValue.Value });
				}
			}
			return codedValueSources;
		}