示例#1
0
        /// <summary>
        /// Gets a string representing a new clause using the information defined in the FieldAttributeInfo
        /// </summary>
        /// <param name="fieldAttribute"></param>
        private string GetFormattedExpression(FieldAttributeInfo fieldAttribute)
        {
            switch (fieldAttribute.FieldType)
            {
            case FieldType.Double:
            case FieldType.Integer:
            case FieldType.Single:
            case FieldType.SmallInteger:
            case FieldType.OID:
                if (fieldAttribute.FieldValue == null)
                {
                    return(string.Format("{0} is NULL", fieldAttribute.FieldName));
                }
                else
                {
                    return(string.Format("{0} = {1}", fieldAttribute.FieldName, fieldAttribute.FieldValue));
                }

            case FieldType.String:
                if (fieldAttribute.FieldValue == null)
                {
                    return(string.Format("{0} is NULL", fieldAttribute.FieldName));
                }
                else
                {
                    return(string.Format("{0} = {1}", fieldAttribute.FieldName, string.Format("'{0}'", fieldAttribute.FieldValue)));
                }

            default:
                return(null);
            }
        }
        private Task ShowAttributes()
        {
            return(QueuedTask.Run(() =>
            {
                try
                {
                    _fieldAttributes.Clear();
                    if (SelectedLayer == null || SelectedOID == null)
                    {
                        return;
                    }

                    var oidField = SelectedLayer.GetTable().GetDefinition().GetObjectIDField();
                    var qf = new ArcGIS.Core.Data.QueryFilter()
                    {
                        WhereClause = string.Format("{0} = {1}", oidField, SelectedOID)
                    };
                    var cursor = SelectedLayer.Search(qf);
                    Row row = null;

                    if (cursor.MoveNext())
                    {
                        row = cursor.Current;
                    }

                    if (row == null)
                    {
                        return;
                    }

                    var fields = row.GetFields();
                    lock (_lock)
                    {
                        foreach (ArcGIS.Core.Data.Field field in fields)
                        {
                            if (field.FieldType == FieldType.Geometry)
                            {
                                continue;
                            }
                            var val = row[field.Name];
                            FieldAttributeInfo fa = new FieldAttributeInfo(field, (val is DBNull || val == null) ? null : val.ToString());
                            _fieldAttributes.Add(fa);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }));
        }
    /// <summary>
    /// Gets a string representing a new clause using the information defined in the FieldAttributeInfo
    /// </summary>
    /// <param name="fieldAttribute"></param>
    private string GetFormattedExpression(FieldAttributeInfo fieldAttribute)
    {
      switch (fieldAttribute.FieldType)
	    {
        case FieldType.Double:
        case FieldType.Integer:
        case FieldType.Single:
        case FieldType.SmallInteger:
        case FieldType.OID:
          if (fieldAttribute.FieldValue == null)
            return string.Format("{0} is NULL", fieldAttribute.FieldName);
          else
            return string.Format("{0} = {1}", fieldAttribute.FieldName, fieldAttribute.FieldValue);
        case FieldType.String:
          if (fieldAttribute.FieldValue == null)
            return string.Format("{0} is NULL", fieldAttribute.FieldName);
          else
            return string.Format("{0} = {1}", fieldAttribute.FieldName, string.Format("'{0}'", fieldAttribute.FieldValue));
        default:
          return null;
	    }
    }
    private Task ShowAttributes()
    {
      return QueuedTask.Run(() =>
      {
        try
        {
          _fieldAttributes.Clear();
          if (SelectedLayer == null || SelectedOID == null)
            return;

          var oidField = SelectedLayer.GetTable().GetDefinition().GetObjectIDField();
          var qf = new ArcGIS.Core.Data.QueryFilter() { WhereClause = string.Format("{0} = {1}", oidField, SelectedOID) };
          var cursor = SelectedLayer.Search(qf);
          Row row = null;

          if (cursor.MoveNext())
            row = cursor.Current;

          if (row == null)
            return;

          var fields = row.GetFields();
          lock (_lock)
          {
            foreach (ArcGIS.Core.Data.Field field in fields)
            {
              if (field.FieldType == FieldType.Geometry)
                continue;
              var val = row[field.Name];
              FieldAttributeInfo fa = new FieldAttributeInfo(field, (val is DBNull || val == null) ? null : val.ToString());
              _fieldAttributes.Add(fa);
            }
          }
        }
        catch (Exception ex)
        {
        }
      });
    }