private void _QueryData_RowChanged(object sender, DataRowChangeEventArgs e) { try { if ((e.Action == DataRowAction.Add || e.Action == DataRowAction.Change) && e.Row["Type"].ToString() == "Color" && !FeatureClassProperties.isUpdating && e.Row["Value"].GetType() != typeof(short)) { short num = DXFCode.TranslateColorString(e.Row["Value"].ToString()); FeatureClassProperties.isUpdating = true; e.Row["Value"] = num; FeatureClassProperties.isUpdating = false; } } catch (Exception) { } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { bool flag1 = value.GetType() == typeof(string); if (!DBNull.Value.Equals(value) && (value != null)) { value.ToString(); DXFCode code = new DXFCode(int.Parse(value.ToString())); return(code.CodeString); } return(""); } catch { return(value); } }
private void BuildColorRow(string selectedValue) { string value = ""; if (selectedValue == AfaStrings.AnyValue) { value = ""; } else if (selectedValue == "Select Color...") { var colorDialog = new Autodesk.AutoCAD.Windows.ColorDialog(); DialogResult dialogResult = colorDialog.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { string text = DXFCode.TranstateColorIndexToString(colorDialog.Color.ColorIndex); if (!this._mColorList.Contains(text)) { this._mColorList.Add(text); this.cbValue.ItemsSource = this._mColorList; } this.cbValue.SelectedValue = text; value = text; } } else { short colorIndex = DXFCode.TranslateColorString(selectedValue); value = DXFCode.TranstateColorIndexToString(colorIndex); } int index; if (this.QueryDataContainsRow(AfaStrings.Color, out index)) { this.QueryData.Rows.RemoveAt(index); } if (!string.IsNullOrEmpty(value)) { DataRow dataRow = this.QueryData.NewRow(); dataRow["Value"] = value; dataRow["Type"] = AfaStrings.Color; this.QueryData.Rows.Add(dataRow); } }
private ResultBuffer BuildQueryResultBuffer() { ResultBuffer resultBuffer = new ResultBuffer(); foreach (DataRow dataRow in this._QueryData.Rows) { DXFCode dXFCode = new DXFCode(dataRow["Type"].ToString()); object obj = dataRow["Value"]; if (dXFCode.Code == 62) { obj = DXFCode.TranslateColorString(obj.ToString()); } if (DXFCode.IsValidTypedValue(dXFCode.Code, obj.ToString())) { TypedValue typedValue = DXFCode.CreateTypedValue(dXFCode.Code, obj.ToString()); resultBuffer.Add(typedValue); } } return(resultBuffer); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { try { value.ToString(); int value2 = int.Parse(value.ToString()); DXFCode dXFCode = new DXFCode(value2); object result = dXFCode.CodeString; return(result); } catch { object result = value; return(result); } } return(""); }
public static bool IsValid(string value, ref string errMessage) { bool result; try { DXFCode dXFCode = new DXFCode(value); if (dXFCode.Code < -5 || dXFCode.Code > 1071) { errMessage = AfaStrings.DXFCodeError; result = false; } else { result = true; } } catch { result = false; } return(result); }
private void SelectValueFromEntity(string propertyType) { Document document = AfaDocData.ActiveDocData.Document; Database database = document.Database; Editor editor = document.Editor; try { using (document.LockDocument((DocumentLockMode)20, null, null, false)) { var transactionManager = database.TransactionManager; using (Transaction transaction = transactionManager.StartTransaction()) { PromptEntityOptions promptEntityOptions = new PromptEntityOptions("\nPick a sample entity: "); promptEntityOptions.SetRejectMessage("Invalid pick: must be AutoCAD entity."); promptEntityOptions.AddAllowedClass(typeof(Entity), false); PromptEntityResult entity = editor.GetEntity(promptEntityOptions); if (entity.Status == (PromptStatus)5100) { Entity entity2 = (Entity)transaction.GetObject(entity.ObjectId, 0); if (propertyType == "Layer") { this.cbValue.SelectedValue = entity2.Layer; } else if (propertyType == "Color") { this.cbValue.SelectedValue = DXFCode.TranstateColorIndexToString(entity2.Color.ColorIndex); } else if (propertyType == "Linetype") { this.cbValue.SelectedValue = entity2.Linetype; } else if (propertyType == "Lineweight") { this.cbValue.SelectedValue = entity2.LineWeight.ToString(); } else if (propertyType == "Text Style") { if (entity2 is DBText) { DBText dBText = (DBText)entity2; string textStyleName = dBText.TextStyleName; this.cbValue.SelectedValue = textStyleName; } else if (entity2 is MText) { MText mText = (MText)entity2; string textStyleName2 = mText.TextStyleName; this.cbValue.SelectedValue = textStyleName2; } } else if (propertyType == "Block Name" && entity2 is BlockReference) { BlockReference blockReference = (BlockReference)entity2; this.cbValue.SelectedValue = blockReference.BlockName; } } transaction.Commit(); } } } catch { } }
public FeatureClassProperties(MSCFeatureClass fc) { try { this._mColorList = this.InitColorList(); this._FC = fc; this._QueryData = new DataTable(); this._QueryData.Columns.Add("Type"); this._QueryData.Columns.Add("Value"); if (fc.Query != null) { TypedValue[] array = fc.Query.AsArray(); TypedValue[] array2 = array; for (int i = 0; i < array2.Length; i++) { TypedValue typedValue = array2[i]; if (typedValue.TypeCode == 62) { this.BuildColorRow(typedValue.Value.ToString()); } else { DataRow dataRow = this._QueryData.NewRow(); dataRow["Type"] = new DXFCode((int)typedValue.TypeCode).CodeString; dataRow["Value"] = typedValue.Value; this._QueryData.Rows.Add(dataRow); } } } this._QueryData.RowChanged += new DataRowChangeEventHandler(this._QueryData_RowChanged); this._FieldData = new DataTable(); this._FieldData.Columns.Add("Name"); this._FieldData.Columns.Add("Type"); this._FieldData.Columns.Add("Value"); this._FieldData.Columns.Add("DisplayValue"); this._FieldData.Columns.Add("Length", typeof(int)); this._FieldData.Columns.Add("ReadOnly", typeof(bool)); this._FieldData.Columns.Add("BaseField", typeof(CadField)); this._FieldData.Columns.Add("CodedValues", typeof(List <MSCCodedValue>)); this._FieldData.Columns.Add("CodedValue", typeof(MSCCodedValue)); this._FieldData.Columns.Add("Domain", typeof(FieldDomain)); this._FieldData.Columns.Add("CanEditType", typeof(bool)); if (fc.Fields != null) { foreach (CadField current in fc.Fields) { if (current != null && current.Visible) { DataRow dataRow2 = this._FieldData.NewRow(); dataRow2["Name"] = current.Name; dataRow2["Value"] = current.Value.Value; dataRow2["DisplayValue"] = dataRow2["Value"]; if (current.Value.TypeCode == 1) { dataRow2["Length"] = current.Length; } else { dataRow2["Length"] = 0; } dataRow2["Type"] = current.GetTypeString(); if (current.ReadOnly) { dataRow2["ReadOnly"] = true; } else { dataRow2["ReadOnly"] = false; } dataRow2["BaseField"] = current; this._FieldData.Rows.Add(dataRow2); if (current.Domain != null) { dataRow2["Domain"] = current.Domain; } dataRow2["CanEditType"] = true; if (current.Domain != null) { dataRow2["CanEditType"] = false; current.Value = current.Domain.CheckValue(current.Value.Value); dataRow2["CodedValues"] = current.Domain.CodedValuesDisplayList; dataRow2["CodedValue"] = current.Domain.GetCodedValue(current.Value.Value); dataRow2["DisplayValue"] = dataRow2["CodedValue"]; } } } } this._FieldData.RowChanged += new DataRowChangeEventHandler(this._FieldData_RowChanged); this.InitializeComponent(); this.lblName.Content = fc.Name; this.lblType.Content = MSCFeatureClass.GetTypeCodeString(fc.GeometryType); this.dgQuery.ItemsSource = this.QueryData.DefaultView; this.BuildQueryPropertyOptions(fc.GeometryType); this.dgFields.ItemsSource = this._FieldData.DefaultView; if (fc.ReadOnly || fc.IsSubType || fc.SubTypes.Count > 0) { this.dgQuery.IsEnabled = false; this.dgFields.IsEnabled = false; this.cbProperty.IsEnabled = false; this.cbAppend.IsEnabled = false; this.cbValue.IsEnabled = false; } } catch (Exception ex) { ErrorReport.ShowErrorMessage(ex.Message); } }
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 value2 = ""; if (!DXFCode.IsValid(dataRowView.Row["Type"].ToString(), ref value2)) { stringBuilder = new StringBuilder(); stringBuilder.Append(value2); ValidationResult result = new ValidationResult(false, stringBuilder.ToString()); return(result); } string text = dataRowView.Row["Type"].ToString(); foreach (DataRow dataRow in table.Rows) { if (dataRow != row && dataRow["Type"].ToString() == text) { stringBuilder = new StringBuilder(); stringBuilder.Append(AfaStrings.DuplicateTypeCode); ValidationResult result = new ValidationResult(false, stringBuilder.ToString()); return(result); } } DXFCode dXFCode = new DXFCode(text); object obj = dataRowView.Row["Value"]; if (dXFCode.Code == 62) { obj = DXFCode.TranslateColorString(obj.ToString()); } if (!DXFCode.IsValidTypedValue(dXFCode.Code, obj.ToString())) { stringBuilder = new StringBuilder(); stringBuilder.Append(AfaStrings.CodeDoesNotMatchType); 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 TypedValue CreateTypedValue(int code, string value) { if (!DXFCode.IsValidTypedValue(code, value)) { return(new TypedValue(3, value)); } TypedValue result; try { if (code >= -5 && code <= 9) { result = new TypedValue(code, value); } else if (code > 9 && code <= 58) { result = new TypedValue(code, double.Parse(value)); } else if (code >= 60 && code <= 99) { result = new TypedValue(code, int.Parse(value)); } else if (code >= 100 && code <= 105) { result = new TypedValue(code, value); } else if (code >= 210 && code <= 230) { result = new TypedValue(code, double.Parse(value)); } else if (code >= 280 && code <= 289) { result = new TypedValue(code, short.Parse(value)); } else if (code >= 290 && code <= 299) { result = new TypedValue(code, bool.Parse(value)); } else if (code >= 300 && code <= 309) { result = new TypedValue(code, value); } else if (code >= 310 && code <= 319) { result = new TypedValue(code, value); } else if (code >= 320 && code <= 329) { result = new TypedValue(code, value); } else if (code >= 330 && code <= 339) { result = new TypedValue(code, value); } else if (code >= 340 && code <= 349) { result = new TypedValue(code, value); } else if (code >= 350 && code <= 359) { result = new TypedValue(code, value); } else if (code >= 360 && code <= 369) { result = new TypedValue(code, value); } else if (code >= 370 && code <= 379) { result = new TypedValue(code, short.Parse(value)); } else if (code >= 380 && code <= 389) { result = new TypedValue(code, short.Parse(value)); } else if (code >= 390 && code <= 399) { result = new TypedValue(code, value); } else if (code >= 400 && code <= 409) { result = new TypedValue(code, short.Parse(value)); } else if (code >= 410 && code <= 319) { result = new TypedValue(code, value); } else if (code >= 999 && code <= 1005) { result = new TypedValue(code, value); } else if (code >= 1010 && code <= 1042) { result = new TypedValue(code, double.Parse(value)); } else if (code == 1070) { result = new TypedValue(code, short.Parse(value)); } else if (code == 1071) { result = new TypedValue(code, int.Parse(value)); } else { result = new TypedValue(3, value); } } catch { result = new TypedValue(3, value); } return(result); }