Example #1
0
        private CadField CreateAttributeValue(MSCFeatureClass fc, string fieldName, object value)
        {
            CadField result;

            try
            {
                CadField cadField = FeatureClassAPI.FindField(fc.Fields, fieldName);
                if (cadField == null)
                {
                    result = null;
                }
                else if (cadField.ReadOnly || !cadField.Visible)
                {
                    result = null;
                }
                else
                {
                    TypedValue value2 = CadField.CreateTypedValue(cadField.FieldType, value.ToString());
                    result = new CadField(cadField)
                    {
                        Value = value2
                    };
                }
            }
            catch
            {
                result = null;
            }
            return(result);
        }
Example #2
0
        public bool IsWithinRangeValue(object newValue)
        {
            bool result;

            try
            {
                TypedValue  typedValue  = CadField.CreateTypedValue(this.FieldType, newValue.ToString());
                TypedValue  typedValue2 = CadField.CreateTypedValue(this.FieldType, this.MinValue.ToString());
                TypedValue  typedValue3 = CadField.CreateTypedValue(this.FieldType, this.MaxValue.ToString());
                IComparable comparable  = (IComparable)typedValue.Value;
                if (comparable.CompareTo(typedValue2.Value) < 0)
                {
                    result = false;
                }
                else if (comparable.CompareTo(typedValue3.Value) > 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch
            {
                result = true;
            }
            return(result);
        }
        public ResultBuffer CreateResultBuffer()
        {
            ResultBuffer resultBuffer = new ResultBuffer();

            resultBuffer.Add(new TypedValue(5005, this.DisplayName));
            resultBuffer.Add(CadField.CreateTypedValue(this.Value));
            return(resultBuffer);
        }
Example #4
0
        public TypedValue CheckValue(object testValue)
        {
            MSCCodedValue mSCCodedValue = this.GetCodedValue(testValue);

            if (mSCCodedValue == null)
            {
                if (this.FauxNull == null)
                {
                    this.SetFauxNull(testValue);
                }
                mSCCodedValue = this.FauxNull;
            }
            return(CadField.CreateTypedValue(this.FieldType, mSCCodedValue.Value));
        }
Example #5
0
        private CadField CreateAttributeValue(MSCFeatureClass fc, ref object firstValue, ref object secondValue)
        {
            TypedValue typedValue  = (TypedValue)firstValue;
            TypedValue typedValue2 = (TypedValue)secondValue;
            string     text        = typedValue.Value.ToString();
            object     value       = typedValue2.Value;
            string     fieldName   = text.ToString();
            CadField   cadField    = FeatureClassAPI.FindField(fc.Fields, fieldName);

            if (cadField == null)
            {
                firstValue  = null;
                secondValue = null;
                return(null);
            }
            if (cadField.ReadOnly || !cadField.Visible)
            {
                return(null);
            }
            TypedValue value2 = CadField.CreateTypedValue(cadField.FieldType, typedValue2.Value.ToString());

            if (value2.TypeCode != cadField.Value.TypeCode)
            {
                firstValue  = null;
                secondValue = null;
                return(null);
            }
            CadField cadField2 = new CadField(cadField);

            cadField2.Value = value2;
            if (cadField2.Value.TypeCode == 1)
            {
                string text2 = cadField2.Value.Value.ToString();
                if (text2.Length > (int)cadField.Length)
                {
                    firstValue  = null;
                    secondValue = null;
                    return(null);
                }
            }
            firstValue  = null;
            secondValue = null;
            return(cadField2);
        }
Example #6
0
 public void Write(Database db, Transaction t)
 {
     try
     {
         DBDictionary dBDictionary  = this.ParentDataset.Open(db, t, FieldDomain.DictionaryName, (OpenMode)1);
         DBDictionary dBDictionary2 = new DBDictionary();
         this.Id = dBDictionary.SetAt(this.Name, dBDictionary2);
         dBDictionary2.DisableUndoRecording(true);
         t.AddNewlyCreatedDBObject(dBDictionary2, true);
         this.WriteTypedValue(db, t, dBDictionary2, "KeyName", new TypedValue(1, this.Name));
         this.WriteTypedValue(db, t, dBDictionary2, "DisplayName", new TypedValue(1, this.DisplayName));
         this.WriteTypedValue(db, t, dBDictionary2, "DomainType", new TypedValue(1, this.DomainType));
         this.WriteTypedValue(db, t, dBDictionary2, "DomainFieldType", new TypedValue(90, this.FieldType));
         if (this.DomainType == "RangeDomain")
         {
             this.WriteTypedValue(db, t, dBDictionary2, "DomainMinimum", CadField.CreateTypedValue(this.MinValue));
             this.WriteTypedValue(db, t, dBDictionary2, "DomainMaximum", CadField.CreateTypedValue(this.MaxValue));
         }
         if (this.DomainType == "CodedValueDomain")
         {
             List <TypedValue> list = new List <TypedValue>();
             foreach (KeyValuePair <string, MSCCodedValue> keyValuePair in this.CodedValues)
             {
                 MSCCodedValue value = keyValuePair.Value;
                 list.Add(CadField.CreateTypedValue(value.DisplayName));
                 list.Add(CadField.CreateTypedValue(value.Value));
             }
             try
             {
                 ResultBuffer rb = new ResultBuffer(list.ToArray());
                 this.WriteResultBuffer(db, t, dBDictionary2, "CodedValues", rb);
             }
             catch (System.Exception)
             {
             }
         }
     }
     catch
     {
     }
 }
Example #7
0
        private void OnClickOK(object sender, RoutedEventArgs e)
        {
            if (null == Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument)
            {
                ErrorReport.ShowErrorMessage(AfaStrings.ErrorWritingFeatureClass);
                return;
            }
            ResultBuffer resultBuffer = this.BuildQueryResultBuffer();

            if (resultBuffer.AsArray().Count <TypedValue>() == 0)
            {
                this._FC.Query = new ResultBuffer(new TypedValue[]
                {
                    new TypedValue(8, "*")
                });
            }
            else
            {
                this._FC.Query = resultBuffer;
            }
            List <CadField> list = new List <CadField>();

            foreach (DataRow dataRow in this._FieldData.Rows)
            {
                CadField cadField = new CadField();
                cadField.Name = CadField.FixFieldName(dataRow["Name"].ToString());
                CadField.CadFieldType code = CadField.TypeCodeFromString(dataRow["Type"].ToString());
                cadField.ExtendedType = CadField.ExtendedTypeFromString(dataRow["Type"].ToString());
                cadField.Value        = CadField.CreateTypedValue(code, dataRow["Value"].ToString());
                if (dataRow["Domain"] is FieldDomain)
                {
                    cadField.Domain = (FieldDomain)dataRow["Domain"];
                }
                else
                {
                    cadField.Domain = null;
                }
                CadField.CadFieldType arg_142_0 = cadField.FieldType;
                if (cadField.Value.TypeCode == 1)
                {
                    string text = dataRow["Length"].ToString();
                    if (!string.IsNullOrEmpty(text))
                    {
                        short length;
                        if (short.TryParse(text, out length))
                        {
                            cadField.Length = length;
                        }
                        else
                        {
                            cadField.Length = 254;
                        }
                    }
                    else
                    {
                        cadField.Length = 254;
                    }
                }
                list.Add(cadField);
            }
            this._FC.Fields = list;
            Database database = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database;

            try
            {
                using (Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    var transactionManager = database.TransactionManager;
                    using (Transaction transaction = transactionManager.StartTransaction())
                    {
                        this._FC.Write(database, transaction);
                        transaction.Commit();
                    }
                }
                base.Close();
            }
            catch
            {
                ErrorReport.ShowErrorMessage(AfaStrings.ErrorWritingFeatureClass);
            }
        }
 public MSCCodedValue(string name, CadField.CadFieldType type, object value)
 {
     this.DisplayName = name;
     this.Value       = CadField.CreateTypedValue(type, value.ToString()).Value;
 }