private void Default_PreviewTextInput(object sender, TextCompositionEventArgs e) { try { System.Windows.Controls.TextBox textBox = (System.Windows.Controls.TextBox)sender; if (textBox.Tag != null) { CadField.CadFieldType fType = (CadField.CadFieldType)textBox.Tag; DataRowView dataRowView = (DataRowView)((FrameworkElement)sender).DataContext; string text = textBox.Text + e.Text; string s = dataRowView.Row["FieldLength"].ToString(); int num = int.Parse(s); e.Handled = !this.IsValidText(fType, num, text); if (!e.Handled) { CadField cadField = (CadField)dataRowView.Row["BaseField"]; FieldDomain domain = cadField.Domain; if (domain != null) { bool flag = domain.IsWithinRangeValue(text); if (!flag) { e.Handled = true; } } } } } catch { e.Handled = false; } }
private static CadField.CadFieldType GetCadFieldType(esriFieldType t) { CadField.CadFieldType result = CadField.CadFieldType.String; if (t == esriFieldType.esriFieldTypeDouble) { result = CadField.CadFieldType.Double; } else if (t == esriFieldType.esriFieldTypeSingle) { result = CadField.CadFieldType.Double; } else if (t == esriFieldType.esriFieldTypeInteger) { result = CadField.CadFieldType.Integer; } else if (t == esriFieldType.esriFieldTypeOID) { result = CadField.CadFieldType.Integer; } else if (t == esriFieldType.esriFieldTypeSmallInteger) { result = CadField.CadFieldType.Short; } else if (t == esriFieldType.esriFieldTypeString) { result = CadField.CadFieldType.String; } return(result); }
private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(string))) { string testString = (string)e.DataObject.GetData(typeof(string)); System.Windows.Controls.TextBox textBox = (System.Windows.Controls.TextBox)sender; if (textBox.Tag == null) { return; } CadField.CadFieldType fType = (CadField.CadFieldType)textBox.Tag; DataRowView dataRowView = (DataRowView)((FrameworkElement)sender).DataContext; string s = dataRowView.Row["FieldLength"].ToString(); int num = int.Parse(s); if (!this.IsValidText(fType, num, testString)) { e.CancelCommand(); return; } } else { e.CancelCommand(); } }
public FieldDomain(string name, CadField.CadFieldType fieldType, string domainType) { this.DisplayName = name; this.Name = DocUtil.FixSymbolName(name); this.FieldType = fieldType; this.DomainType = domainType; this.CodedValues = new ObservableDictionary <string, MSCCodedValue>(); this.FauxNull = null; this.MinValue = 0; this.MaxValue = 0; }
private bool IsValidText(CadField.CadFieldType fType, int fieldLength, string testString) { if (string.IsNullOrEmpty(testString)) { return(true); } if (fType == CadField.CadFieldType.Integer) { int num = 0; return(int.TryParse(testString, out num) || this.IsPossibleNumericInteger(testString)); } if (fType == CadField.CadFieldType.Short) { short num2 = 0; return(short.TryParse(testString, out num2) || this.IsPossibleNumericInteger(testString)); } if (fType == CadField.CadFieldType.Double) { double num3 = 0.0; return(double.TryParse(testString, out num3) || this.IsPossibleNumericDouble(testString)); } return(fType != CadField.CadFieldType.String || testString.Length <= fieldLength); }
private static bool AreEquivalent(FieldDomain a, Domain b) { if (string.Compare(a.DisplayName, b.DomainName, true) != 0) { return(false); } CadField.CadFieldType cadFieldType = FieldDomain.GetCadFieldType(b.FieldType); if (cadFieldType != a.FieldType) { return(false); } if (b is CodedValueDomain) { if (a.DomainType != "CodedValueDomain") { return(false); } } else if (b is RangeDomain && a.DomainType != "RangeDomain") { return(false); } return(true); }
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); }
public static FieldDomain GetDomain(Domain fs_domain) { FieldDomain result; try { ObservableDictionary <string, FieldDomain> domains = AfaDocData.ActiveDocData.DocDataset.Domains; string key = DocUtil.FixSymbolName(fs_domain.DomainName); FieldDomain fieldDomain = null; if (domains.TryGetValue(key, out fieldDomain) && FieldDomain.AreEquivalent(fieldDomain, fs_domain)) { result = fieldDomain; } else { string domainType = ""; if (fs_domain is CodedValueDomain) { domainType = "CodedValueDomain"; } else if (fs_domain is RangeDomain) { domainType = "RangeDomain"; } CadField.CadFieldType cadFieldType = FieldDomain.GetCadFieldType(fs_domain.FieldType); fieldDomain = new FieldDomain(fs_domain.DomainName, cadFieldType, domainType); if (fs_domain is CodedValueDomain) { CodedValueDomain codedValueDomain = (CodedValueDomain)fs_domain; if (codedValueDomain.CodedValues.Length <= 0) { goto IL_129; } CodedValue[] array = codedValueDomain.CodedValues.ToArray <CodedValue>(); try { CodedValue[] array2 = array; for (int i = 0; i < array2.Length; i++) { CodedValue codedValue = array2[i]; fieldDomain.CodedValues.Add(DocUtil.FixSymbolName(codedValue.Name), new MSCCodedValue(codedValue.Name, cadFieldType, codedValue.Code)); } goto IL_129; } catch (SystemException ex) { string arg_FC_0 = ex.Message; goto IL_129; } } if (fs_domain is RangeDomain) { RangeDomain rangeDomain = (RangeDomain)fs_domain; fieldDomain.MinValue = rangeDomain.MinValue; fieldDomain.MaxValue = rangeDomain.MaxValue; } IL_129: AfaDocData.ActiveDocData.DocDataset.Domains.Add(fieldDomain.Name, fieldDomain); result = fieldDomain; } } catch { result = null; } return(result); }
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 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); }
public MSCCodedValue(string name, CadField.CadFieldType type, object value) { this.DisplayName = name; this.Value = CadField.CreateTypedValue(type, value.ToString()).Value; }