public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            BindingGroup  bindingGroup  = (BindingGroup)value;
            StringBuilder stringBuilder = null;

            foreach (object current in bindingGroup.Items)
            {
                DataRowView dataRowView = current as DataRowView;
                if (dataRowView != null)
                {
                    try
                    {
                        DataRow   row   = dataRowView.Row;
                        DataTable table = row.Table;
                        string    text  = dataRowView.Row["Name"].ToString();
                        if (!CadField.IsValidFieldName(text))
                        {
                            stringBuilder = new StringBuilder();
                            stringBuilder.Append(AfaStrings.InvalidFieldName);
                            ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                            return(result);
                        }
                        foreach (DataRow dataRow in table.Rows)
                        {
                            if (dataRow != row && dataRow["Name"].ToString().Equals(text, StringComparison.CurrentCultureIgnoreCase))
                            {
                                stringBuilder = new StringBuilder();
                                stringBuilder.Append(AfaStrings.DuplicateFieldName);
                                ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                                return(result);
                            }
                        }
                        string text2 = row["Value"].ToString();
                        string text3 = row["Type"].ToString();
                        if (string.IsNullOrEmpty(text3))
                        {
                            row["Type"] = "String";
                        }
                        CadField.GetTypeCode(text3);
                        CadField.CadFieldType cadFieldType = CadField.FieldTypeCode(row["Type"].ToString());
                        if (!string.IsNullOrEmpty(text2) && !CadField.IsValidTypedValue(cadFieldType, text2))
                        {
                            stringBuilder = new StringBuilder();
                            stringBuilder.Append(AfaStrings.ErrorValueNotEqualType);
                            ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                            return(result);
                        }
                        string s   = row["Length"].ToString();
                        int    num = 0;
                        if (cadFieldType == CadField.CadFieldType.String)
                        {
                            if (int.TryParse(s, out num))
                            {
                                if (num < 0)
                                {
                                    stringBuilder = new StringBuilder();
                                    stringBuilder.Append(AfaStrings.InvalidLengthValue);
                                    ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                                    return(result);
                                }
                                if (num == 0)
                                {
                                    row["Length"]         = "255";
                                    dataRowView["Length"] = "255";
                                }
                            }
                            else
                            {
                                row["Length"]         = "255";
                                dataRowView["Length"] = "255";
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(row["Value"].ToString()))
                            {
                                row["Value"]         = "0";
                                dataRowView["Value"] = "0";
                            }
                            row["Length"]         = "0";
                            dataRowView["Length"] = "255";
                        }
                        if (cadFieldType == CadField.CadFieldType.String && num > 0 && text2.Length > num)
                        {
                            stringBuilder = new StringBuilder();
                            stringBuilder.Append(AfaStrings.ValueExceedsFieldLength);
                            ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                            return(result);
                        }
                    }
                    catch
                    {
                        stringBuilder = new StringBuilder();
                        stringBuilder.Append(AfaStrings.ErrorInDXFCode);
                        ValidationResult result = new ValidationResult(false, stringBuilder.ToString());
                        return(result);
                    }
                    if (!string.IsNullOrEmpty(dataRowView.Row.RowError))
                    {
                        if (stringBuilder == null)
                        {
                            stringBuilder = new StringBuilder();
                        }
                        stringBuilder.Append(((stringBuilder.Length != 0) ? ", " : "") + dataRowView.Row.RowError);
                    }
                }
            }
            if (stringBuilder != null)
            {
                return(new ValidationResult(false, stringBuilder.ToString()));
            }
            return(ValidationResult.ValidResult);
        }
예제 #2
0
        public object ESRI_AddFeatureClassFieldDefinition(ResultBuffer rb)
        {
            object result;

            try
            {
                TypedValue[] array = rb.AsArray();
                if (array.Count <TypedValue>() < 2)
                {
                    result = null;
                }
                else
                {
                    TypedValue typedValue = array[0];
                    if (typedValue.TypeCode != 5005)
                    {
                        result = null;
                    }
                    else
                    {
                        string          name = typedValue.Value.ToString();
                        MSCFeatureClass localFeatureClass = this.GetLocalFeatureClass(name);
                        if (localFeatureClass == null)
                        {
                            result = null;
                        }
                        else
                        {
                            string       text   = null;
                            string       strVal = null;
                            object       obj    = null;
                            object       obj2   = null;
                            object       obj3   = null;
                            object       obj4   = null;
                            TypedValue[] array2 = array;
                            for (int i = 0; i < array2.Length; i++)
                            {
                                TypedValue typedValue2 = array2[i];
                                if (typedValue2.TypeCode == 5016)
                                {
                                    obj3 = null;
                                    obj4 = null;
                                }
                                else if (typedValue2.TypeCode == 5017)
                                {
                                    obj3 = null;
                                    obj4 = null;
                                }
                                else if (typedValue2.TypeCode == 5018)
                                {
                                    if (obj3 != null && obj4 != null)
                                    {
                                        TypedValue typedValue3 = (TypedValue)obj3;
                                        TypedValue typedValue4 = (TypedValue)obj4;
                                        string     a           = typedValue3.Value.ToString();
                                        object     value       = typedValue4.Value;
                                        if (string.Equals(a, "NAME", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            text = value.ToString();
                                        }
                                        else if (string.Equals(a, "VALUE", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            obj = value.ToString();
                                        }
                                        else if (string.Equals(a, "TYPE", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            strVal = value.ToString();
                                        }
                                        else if (string.Equals(a, "LENGTH", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            string s = value.ToString();
                                            obj2 = short.Parse(s);
                                        }
                                    }
                                }
                                else if (obj3 == null)
                                {
                                    obj3 = typedValue2;
                                }
                                else
                                {
                                    obj4 = typedValue2;
                                }
                            }
                            if (string.IsNullOrEmpty(text))
                            {
                                result = null;
                            }
                            else
                            {
                                CadField cadField = FeatureClassAPI.FindField(localFeatureClass.Fields, text);
                                if (cadField != null)
                                {
                                    result = null;
                                }
                                else
                                {
                                    CadField cadField2 = new CadField();
                                    cadField2.Name = text;
                                    CadField.CadFieldType cadFieldType = CadField.FieldTypeCode(strVal);
                                    if (obj == null)
                                    {
                                        if (cadFieldType == CadField.CadFieldType.Double)
                                        {
                                            obj = 0.0;
                                        }
                                        if (cadFieldType == CadField.CadFieldType.Integer)
                                        {
                                            obj = 0;
                                        }
                                        if (cadFieldType == CadField.CadFieldType.Short)
                                        {
                                            obj = 0;
                                        }
                                        if (cadFieldType == CadField.CadFieldType.String)
                                        {
                                            obj = "";
                                        }
                                    }
                                    if (obj != null)
                                    {
                                        cadField2.Value = new TypedValue((int)cadFieldType, obj);
                                    }
                                    if (obj2 == null && cadFieldType == CadField.CadFieldType.String)
                                    {
                                        obj2 = 255;
                                    }
                                    if (obj2 != null)
                                    {
                                        short num = short.Parse(obj2.ToString());
                                        if (num > 0 && num < 256)
                                        {
                                            obj2 = num;
                                        }
                                        cadField2.Length = (short)obj2;
                                    }
                                    cadField2.ReadOnly  = false;
                                    cadField2.TypeField = false;
                                    cadField2.Visible   = true;
                                    localFeatureClass.Fields.Add(cadField2);
                                    localFeatureClass.Write(AfaDocData.ActiveDocData.Document);
                                    result = cadField2.Name;
                                }
                            }
                        }
                    }
                }
            }
            catch (SystemException)
            {
                result = null;
            }
            return(result);
        }