Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            DateTimeFieldValue other = obj as DateTimeFieldValue;

            if (other != null)
            {
                return(other.Value == Value && other.FormattedValue == FormattedValue);
            }
            return(base.Equals(obj));
        }
Exemplo n.º 2
0
        private void writeDateTimeFieldValue(DateTimeFieldValue dateTimeFieldValue)
        {
            if (dateTimeFieldValue == null)
            {
                return;
            }

            writer.WriteStartElement("DateTimeFieldValue", Namespaces[Constants.esriMappingPrefix]);
            if (!string.IsNullOrEmpty(dateTimeFieldValue.FormattedValue))
            {
                writer.WriteAttributeString("FormattedValue", dateTimeFieldValue.FormattedValue);
            }
            if (dateTimeFieldValue.Value != null)
            {
                writer.WriteAttributeString("Value", dateTimeFieldValue.Value.ToString());
            }
            writer.WriteEndElement();
        }
        public static object GetFieldValue(PopupItem popupItem, string fieldName)
        {
            if (string.IsNullOrEmpty(fieldName) || popupItem == null || popupItem.Graphic == null || popupItem.Graphic.Attributes == null ||
                popupItem.FieldInfos == null)
            {
                return(null);
            }

            Layer        layer        = popupItem.Layer;
            FeatureLayer featureLayer = layer as FeatureLayer;
            Collection <LayerInformation> layerInfos = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetLayerInfos(layer);

            // Try to find feature layer from layer info
            foreach (LayerInformation item in layerInfos)
            {
                if (item.ID == popupItem.LayerId)
                {
                    featureLayer = item.FeatureLayer;
                    break;
                }
            }

            // Try to find field information from field settings collection (which are FieldInfo objects)
            FieldInfo fldInfo = null;

            foreach (FieldSettings fld in popupItem.FieldInfos)
            {
                if (fld.Name.ToLower().Equals(fieldName.ToLower()))
                {
                    fldInfo = fld as FieldInfo;
                    break;
                }
            }

            if (fldInfo == null)
            {
                return(null);
            }

            // Create local variable for attributes to improve performance since collection is referenced multiple
            // times in logic below.
            IDictionary <string, object> attributes = popupItem.Graphic.Attributes;

            // If the field is a subdomain type, then lookup the value and return
            if (FieldInfo.GetDomainSubTypeLookup(featureLayer, fldInfo) != DomainSubtypeLookup.None)
            {
                return(GetDomainValue(featureLayer, attributes, fldInfo));
            }

            // Try to extract value from field using Name and then DisplayName
            object fieldValue = null;

            if (!attributes.TryGetValue(fldInfo.Name, out fieldValue))
            {
                if (!attributes.TryGetValue(fldInfo.DisplayName, out fieldValue))
                {
                    return(null);
                }
            }

            // Special formatting if the field type is Currency or Date/Time
            if (fldInfo.FieldType == FieldType.Currency)
            {
                CurrencyFieldValue currencyFieldValue = fieldValue as CurrencyFieldValue;
                if (currencyFieldValue != null)
                {
                    fieldValue = currencyFieldValue.FormattedValue;
                }
            }
            else if (fldInfo.FieldType == FieldType.DateTime)
            {
                DateTimeFieldValue dateFieldValue = fieldValue as DateTimeFieldValue;
                if (dateFieldValue != null)
                {
                    fieldValue = dateFieldValue.FormattedValue;
                }
            }

            return(fieldValue);
        }
Exemplo n.º 4
0
        private void writeUniqueValueObj(object uniqueValueInfo)
        {
            if (uniqueValueInfo == null)
            {
                return;
            }

            NumericFieldValue numericFieldValue = uniqueValueInfo as NumericFieldValue;

            if (numericFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeNumericFieldValue(numericFieldValue);
                writer.WriteEndElement();
                return;
            }

            AttachmentFieldValue attFieldValue = uniqueValueInfo as AttachmentFieldValue;

            if (attFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeAttachmentFieldValue(attFieldValue);
                writer.WriteEndElement();
                return;
            }

            CurrencyFieldValue currFieldValue = uniqueValueInfo as CurrencyFieldValue;

            if (currFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeCurrencyFieldValue(currFieldValue);
                writer.WriteEndElement();
                return;
            }

            EntityFieldValue entityFieldValue = uniqueValueInfo as EntityFieldValue;

            if (entityFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeEntityFieldValue(entityFieldValue);
                writer.WriteEndElement();
                return;
            }

            HyperlinkFieldValue hyperlinkFieldValue = uniqueValueInfo as HyperlinkFieldValue;

            if (hyperlinkFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeHyperlinkFieldValue(hyperlinkFieldValue);
                writer.WriteEndElement();
                return;
            }

            HyperlinkImageFieldValue hyperlinkImageFieldValue = uniqueValueInfo as HyperlinkImageFieldValue;

            if (hyperlinkImageFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeHyperlinkImageFieldValue(hyperlinkImageFieldValue);
                writer.WriteEndElement();
                return;
            }

            LookupFieldValue lookupFieldValue = uniqueValueInfo as LookupFieldValue;

            if (lookupFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeLookupFieldValue(lookupFieldValue);
                writer.WriteEndElement();
                return;
            }

            DateTimeFieldValue dateTimeFieldValue = uniqueValueInfo as DateTimeFieldValue;

            if (dateTimeFieldValue != null)
            {
                writer.WriteStartElement("UniqueValueInfoObj.SerializedValue", Namespaces[Constants.esriMappingPrefix]);
                writeDateTimeFieldValue(dateTimeFieldValue);
                writer.WriteEndElement();
                return;
            }

            if (uniqueValueInfo is double)
            {
                writer.WriteAttributeString("SerializedValue", ((double)uniqueValueInfo).ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                writer.WriteAttributeString("SerializedValue", uniqueValueInfo.ToString());
            }
        }
        private void writeDateTimeFieldValue(DateTimeFieldValue dateTimeFieldValue)
        {
            if (dateTimeFieldValue == null)
                return;

            writer.WriteStartElement("DateTimeFieldValue", Namespaces[Constants.esriMappingPrefix]);
            if (!string.IsNullOrEmpty(dateTimeFieldValue.FormattedValue))
                writer.WriteAttributeString("FormattedValue", dateTimeFieldValue.FormattedValue);
            if (dateTimeFieldValue.Value != null)
                writer.WriteAttributeString("Value", dateTimeFieldValue.Value.ToString());
            writer.WriteEndElement();
        }