public static void CopyRow(IRow pSrcFea, IRow pDestFea, List <int> pSrcField, List <int> pDestField) { for (int i = 0; i < pSrcField.Count; i++) { int num2 = pSrcField[i]; int num3 = pDestField[i]; if ((num2 >= 0) && (num3 >= 0)) { try { object obj2 = pSrcFea.get_Value(num2); IField field = pDestFea.Fields.get_Field(num3); if (((obj2 != null) && !(obj2 is DBNull)) && field.CheckValue(obj2)) { try { pDestFea.set_Value(num3, obj2); } catch { } } } catch (Exception exception) { string message = exception.Message; } } } }
public static void CopyRow(IRow pSrcFea, IRow pDestFea) { try { ITable table = pSrcFea.Table; ITable table2 = pDestFea.Table; IField field = null; IField field2 = null; IField field3 = null; IField field4 = null; if (table is IFeatureClass) { field = (table as IFeatureClass).LengthField; field2 = (table as IFeatureClass).AreaField; } if (table2 is IFeatureClass) { field3 = (table2 as IFeatureClass).LengthField; field4 = (table2 as IFeatureClass).AreaField; } int num = pSrcFea.Fields.FieldCount; for (int i = 0; i < num; i++) { IField field5 = table.Fields.get_Field(i); if ((((field5.Type != esriFieldType.esriFieldTypeOID) && (field5.Type != esriFieldType.esriFieldTypeGeometry)) && (field5 != field)) && (field5 != field2)) { string str = field5.Name.ToUpper(); object obj2 = pSrcFea.get_Value(i); if ((obj2 != null) || (obj2 is DBNull)) { int num3 = table2.Fields.FindField(str); if (num3 >= 0) { IField field6 = table2.Fields.get_Field(num3); if (((((field6.Type != esriFieldType.esriFieldTypeOID) && (field6.Type != esriFieldType.esriFieldTypeGeometry)) && (field6 != field3)) && (field6 != field4)) && (((obj2 != null) && !(obj2 is DBNull)) && field6.CheckValue(obj2))) { try { pDestFea.set_Value(num3, obj2); } catch { } } } } } } pDestFea.Store(); } catch (Exception) { } }
// TODO Consider implementing IValidate //public IFields GetInvalidFields() //{ // return new FieldsClass(); //} //public IEnumRule GetInvalidRules() //{ // throw new NotImplementedException(); //} //public IEnumRule GetInvalidRulesByField(string fieldName) //{ // throw new NotImplementedException(); //} //public bool Validate(out string errorMessage) //{ // errorMessage = string.Empty; // return true; //} #endregion #region IRowSubtypes public void InitDefaultValues() { var subtypes = Class as ISubtypes; if (subtypes != null && subtypes.HasSubtype) { int fieldCount = _fields.FieldCount; for (var i = 0; i < fieldCount; i++) { if (i == subtypes.SubtypeFieldIndex) { continue; // skip, this has already been set } IField field = _fields.Field[i]; if (!field.Editable) { continue; } //if (field.Type == esriFieldType.esriFieldTypeOID) continue; //if (field.Type == esriFieldType.esriFieldTypeGeometry) continue; object value = subtypes.DefaultValue[SubtypeCode, field.Name]; if (value == null || value == DBNull.Value) { continue; // No default value seems to be represented by NULL } if (!field.CheckValue(value)) { continue; } IDomain domain = subtypes.Domain[SubtypeCode, field.Name]; if (domain != null && !domain.MemberOf(value)) { continue; } set_Value(i, value); } } //else: silently ignore (or should we set class default values?) }
public void set_Value(int index, object value) { IField field = _fields.Field[index]; if (!field.Editable) { throw new InvalidOperationException( string.Format("Field {0} is not editable", field.Name)); } if (value == null) { // Empirical: null seems to set field's default value value = GetInitialValue(field); } if (!field.IsNullable && (value == null || value == DBNull.Value)) { throw new InvalidOperationException( string.Format("Field {0} is not nullable", field.Name)); } // IField.CheckValue() catches some bad values, but it's a rather // weak test; for example, shapeField.CheckValue(123) is true if (!field.CheckValue(value)) { throw new ArgumentOutOfRangeException( string.Format("Value [{0}] is not valid for field {1}", value, field.Name)); } try { value = ConvertToFieldType(value, field.Type); } catch (Exception ex) { throw new ArgumentException( string.Format("Field {0}: Cannot convert value '{1}' to {2}: {3}", field.Name, value, field.Type, ex.Message), ex); } _fieldValues[index] = value; }
public static void SetRowValue(IRow pRow, string pField, object pValue) { if ((pRow != null) && (pField != null)) { int num = pRow.Fields.FindField(pField); if (num >= 0) { if ((pValue == null) || (pValue is DBNull)) { pValue = ""; } IField field = pRow.Fields.get_Field(num); if (field.CheckValue(pValue)) { if ((field.Type == esriFieldType.esriFieldTypeInteger) && ((pValue == null) || (pValue.ToString() == ""))) { pRow.set_Value(num, 0); } else if ((field.Type == esriFieldType.esriFieldTypeDouble) && ((pValue == null) || (pValue.ToString() == ""))) { pRow.set_Value(num, 0.0); } else { pRow.set_Value(num, pValue); } } else { try { pRow.set_Value(num, pValue); } catch { } } } } }
public static void CopyFeature(IFeature pSrcFea, IFeature pDestFea, bool pOverwrite) { try { IFeatureClass class2 = pSrcFea.Table as IFeatureClass; IFeatureClass class3 = pDestFea.Table as IFeatureClass; int num = pSrcFea.Fields.FieldCount; for (int i = 0; i < num; i++) { IField field = class2.Fields.get_Field(i); if ((((field.Type != esriFieldType.esriFieldTypeOID) && (field.Type != esriFieldType.esriFieldTypeGeometry)) && (field != class2.LengthField)) && (field != class2.AreaField)) { string str = field.Name.ToUpper(); int num3 = class3.Fields.FindField(str); if (num3 >= 0) { IField field2 = class3.Fields.get_Field(num3); if ((((field2.Type != esriFieldType.esriFieldTypeOID) && (field2.Type != esriFieldType.esriFieldTypeGeometry)) && (field2 != class3.LengthField)) && (field2 != class3.AreaField)) { object obj2 = pSrcFea.get_Value(i); if (pOverwrite) { if ((obj2 == null) || (obj2 is DBNull)) { obj2 = null; } if (field2.CheckValue(obj2)) { try { pDestFea.set_Value(num3, obj2); } catch { } } } else { object obj3 = pDestFea.get_Value(num3); if ((obj3 == null) || (obj3 is DBNull)) { if ((obj2 == null) || (obj2 is DBNull)) { obj2 = null; } if (field2.CheckValue(obj2)) { try { pDestFea.set_Value(num3, obj2); } catch { } } } } } } } } pDestFea.Store(); } catch (Exception) { } }
public static bool ValorValido(IField field, object valor) { return field.CheckValue(valor); }