/// <summary> /// Execute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="validateMe">IWorkspace object that contains the data being validated</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(IWorkspace validateMe, string arguments) { m_ipWorkspace = validateMe; IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Split comma delimited string into array //This is the array of fully qualified feature class/table names string[] arrayOfArguments = arguments.Split(new char[] { ',' }, StringSplitOptions.None); //loop through the feature classes/tables and check for any attributes that violate domain constraints for (int i = 0; i < arrayOfArguments.Length; i++) { string strTableName = arrayOfArguments[i]; if (DatasetExists(validateMe, strTableName)) { ITable ipTable = (validateMe as IFeatureWorkspace).OpenTable(strTableName); bool bHasSubtype = false; ISubtypes ipSubtypes = ipTable as ISubtypes; if (null != ipSubtypes) { bHasSubtype = ipSubtypes.HasSubtype; } if (bHasSubtype) { IEnumSubtype ipEnumSubtype = ipSubtypes.Subtypes; if (null != ipEnumSubtype) { ipEnumSubtype.Reset(); int iSubtypeCode; string strSubtypeName; strSubtypeName = ipEnumSubtype.Next(out iSubtypeCode); while (null != strSubtypeName) { ValidateSubtype(ipRevResultCollection, ipSubtypes, iSubtypeCode); strSubtypeName = ipEnumSubtype.Next(out iSubtypeCode); } } } else { ValidateTable(ipRevResultCollection, ipTable); } } } m_ipWorkspace = null; return(ipRevResultCollection); }
/// <summary> /// Creates an <see cref="IEnumerable{T}" /> from an <see cref="IEnumSubtype" /> /// </summary> /// <param name="source">An <see cref="IEnumSubtype" /> to create an <see cref="IEnumerable{T}" /> from.</param> /// <returns> /// An <see cref="IEnumerable{T}" /> that contains the datasets from the input source. /// </returns> public static IEnumerable <KeyValuePair <int, string> > AsEnumerable(this IEnumSubtype source) { if (source != null) { source.Reset(); int subtypeCode; string subtypeName = source.Next(out subtypeCode); while (!string.IsNullOrEmpty(subtypeName)) { yield return(new KeyValuePair <int, string>(subtypeCode, subtypeName)); subtypeName = source.Next(out subtypeCode); } } }
/// <summary> /// Creates an <see cref="IEnumerable{T}"/> from an <see cref="IEnumSubtype"/> /// </summary> /// <param name="source">An <see cref="IEnumSubtype"/> to create an <see cref="IEnumerable{T}"/> from.</param> /// <returns>An <see cref="IEnumerable{T}"/> that contains the datasets from the input source.</returns> public static IEnumerable <KeyValuePair <string, int> > ToEnumerable(this IEnumSubtype source) { if (source != null) { source.Reset(); int subtypeCode; string subtype = source.Next(out subtypeCode); while (string.IsNullOrEmpty(subtype) == false) { yield return(new KeyValuePair <string, int>(subtype, subtypeCode)); subtype = source.Next(out subtypeCode); } } }
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) { if (this.m_CanDo) { object obj2; ISubtypes featureClass = this.m_pFeatLayer.FeatureClass as ISubtypes; GridEditorItem row = this.gridView1.GetRow(e.RowHandle) as GridEditorItem; int index = this.m_pFeatLayer.FeatureClass.Fields.FindFieldByAliasName(row.Name); IField pField = this.m_pFeatLayer.FeatureClass.Fields.get_Field(index); if ((featureClass != null) && featureClass.HasSubtype) { if (featureClass.SubtypeFieldName == pField.Name) { IEnumSubtype subtypes = featureClass.Subtypes; subtypes.Reset(); int subtypeCode = 0; for (string str = subtypes.Next(out subtypeCode); str != null; str = subtypes.Next(out subtypeCode)) { if (e.Value.ToString() == str) { this.UpdateFieldValue(pField, subtypeCode); break; } } } else if (e.Value.ToString() == "<空>") { obj2 = DBNull.Value; this.UpdateFieldValue(pField, obj2); } else { this.UpdateFieldValue(pField, e.Value); } } else if (e.Value.ToString() == "<空>") { obj2 = DBNull.Value; this.UpdateFieldValue(pField, obj2); } else { this.UpdateFieldValue(pField, e.Value); } } }
private static string GetSubtypeConstaint([NotNull] ISubtypes subtypes, [NotNull] string fieldName) { IEnumSubtype enumSubtypes = subtypes.Subtypes; int subtypeCode; var sb = new StringBuilder(); for (string subtype = enumSubtypes.Next(out subtypeCode); subtype != null; subtype = enumSubtypes.Next(out subtypeCode)) { sb.AppendFormat(", {0}", subtypeCode); } string subtypeConstraint = fieldName + " IN (" + sb.ToString(1, sb.Length - 1) + ")"; return(subtypeConstraint); }
public static List <string> getClassNames(IFeatureClass Anno) { List <string> names = new List <string>(); ISubtypes subtypes = (ISubtypes)Anno; if (subtypes.HasSubtype) { IEnumSubtype enumSubs = subtypes.Subtypes; int subTypeCode; string subTypeName = enumSubs.Next(out subTypeCode); while (subTypeName != null) { names.Add(subTypeName); subTypeName = enumSubs.Next(out subTypeCode); } } names.Sort(); return(names); }
public static int getClassIDByName(IFeatureClass Anno, string name) { ISubtypes subtypes = (ISubtypes)Anno; if (subtypes.HasSubtype) { IEnumSubtype enumSubs = subtypes.Subtypes; int subTypeCode; string subTypeName = enumSubs.Next(out subTypeCode); while (subTypeName != null) { if (subTypeName.ToUpper() == name.ToUpper()) { return(subTypeCode); } subTypeName = enumSubs.Next(out subTypeCode); } } return(-1); }
public static string getClassNameById(IFeatureClass Anno, int id) { ISubtypes subtypes = (ISubtypes)Anno; if (subtypes.HasSubtype) { IEnumSubtype enumSubs = subtypes.Subtypes; int subTypeCode; string subTypeName = enumSubs.Next(out subTypeCode); while (subTypeName != null) { if (subTypeCode == id) { return(subTypeName); } subTypeName = enumSubs.Next(out subTypeCode); } } return(null); }
private void cboConnectivityRule_SelectedIndexChanged(object sender, EventArgs e) { this.listView1.Items.Clear(); if (this.cboConnectivityRule.SelectedIndex != -1) { ListViewItem item; ISubtypes featureClass = (this.cboConnectivityRule.SelectedItem as FeatureClassWrap).FeatureClass as ISubtypes; string[] items = new string[2]; if (featureClass.HasSubtype) { int num; IEnumSubtype subtypes = featureClass.Subtypes; subtypes.Reset(); for (string str = subtypes.Next(out num); str != null; str = subtypes.Next(out num)) { items[0] = str; items[1] = num.ToString(); item = new ListViewItem(items) { Tag = num }; this.listView1.Items.Add(item); } } else { items[0] = this.cboConnectivityRule.Text; items[1] = "0"; item = new ListViewItem(items) { Tag = 0 }; this.listView1.Items.Add(item); } } }
private static KeyValueList <int, string> ReadSubtypeDomainValues(IFeature feature) { ISubtypes subtypes = feature.Class as ISubtypes; IEnumSubtype enumSubtype = subtypes?.Subtypes; if (enumSubtype == null) { return(null); } var result = new KeyValueList <int, string>(); enumSubtype.Reset(); int subtypeCode; string description = enumSubtype.Next(out subtypeCode); while (description != null) { result.AddOrReplace(subtypeCode, description); description = enumSubtype.Next(out subtypeCode); } return(result); }
private void Init() { this.gridControl1.Focus(); this.m_pVertXtraGrid.Clear(); int rowHandle = -1; if (this.m_pObject == null) { this.m_CanDo = true; } else { this.toolStripDropDownButton1.DropDownItemClicked += new ToolStripItemClickedEventHandler(this.toolStripDropDownButton1_DropDownItemClicked); try { ITableAttachments attachments = (ITableAttachments)this.m_pObject.Class; if (attachments != null) { if (attachments.HasAttachments) { this.toolStrip1.Visible = true; this.InitAttachment(); } else { this.toolStrip1.Visible = false; } } } catch { } IFields fields = this.m_pObject.Fields; string[] strArray = new string[2]; ISubtypes subtypes = this.m_pObject.Class as ISubtypes; IDomain domain = null; for (int i = 0; i < fields.FieldCount; i++) { IField pField = fields.get_Field(i); if (this.CheckFieldIsVisible(this.m_pFeatureLayer, pField)) { strArray[0] = pField.AliasName; if (pField.Type == esriFieldType.esriFieldTypeGeometry) { strArray[1] = this.GetShapeString(pField); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else if (pField.Type == esriFieldType.esriFieldTypeOID) { strArray[1] = this.m_pObject.OID.ToString(); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else if (pField.Type == esriFieldType.esriFieldTypeBlob) { strArray[1] = "<二进制数据>"; this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else { int num4; double minValue; double maxValue; object obj2 = this.m_pObject.get_Value(i); ICodedValueDomain domain2 = null; IList list = new ArrayList(); if ((subtypes != null) && subtypes.HasSubtype) { if (subtypes.SubtypeFieldName == pField.Name) { int num3; try { strArray[1] = subtypes.get_SubtypeName((this.m_pObject as IRowSubtypes).SubtypeCode); } catch { strArray[1] = obj2.ToString(); } IEnumSubtype subtype = subtypes.Subtypes; subtype.Reset(); for (string str = subtype.Next(out num3); str != null; str = subtype.Next(out num3)) { list.Add(str); } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list, !this.FieldCanEdit(pField)); } else { domain = subtypes.get_Domain((this.m_pObject as IRowSubtypes).SubtypeCode, pField.Name); if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; if (pField.IsNullable) { list.Add("<空>"); } strArray[1] = obj2.ToString(); num4 = 0; while (num4 < domain2.CodeCount) { list.Add(domain2.get_Name(num4)); if (obj2.ToString() == domain2.get_Value(num4).ToString()) { strArray[1] = domain2.get_Name(num4); } num4++; } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list, !this.FieldCanEdit(pField)); } else if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { minValue = 0.0; maxValue = 0.0; if (domain is IRangeDomain) { minValue = (double)(domain as IRangeDomain).MinValue; maxValue = (double)(domain as IRangeDomain).MaxValue; } if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], obj2, false, minValue, maxValue); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], obj2, true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], obj2, !this.FieldCanEdit(pField)); } else { strArray[1] = obj2.ToString(); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !this.FieldCanEdit(pField)); } } } else { domain = pField.Domain; if (domain != null) { if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; if (pField.IsNullable) { list.Add("<空>"); } strArray[1] = obj2.ToString(); num4 = 0; while (num4 < domain2.CodeCount) { list.Add(domain2.get_Name(num4)); if (obj2.ToString() == domain2.get_Value(num4).ToString()) { strArray[1] = domain2.get_Name(num4); } num4++; } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list, !this.FieldCanEdit(pField)); } else if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { minValue = 0.0; maxValue = 0.0; if (domain is IRangeDomain) { minValue = (double)(domain as IRangeDomain).MinValue; maxValue = (double)(domain as IRangeDomain).MaxValue; } if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], obj2, false, minValue, maxValue); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], obj2, true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], obj2, !this.FieldCanEdit(pField)); } else { strArray[1] = obj2.ToString(); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !this.FieldCanEdit(pField)); } } else { string name = (this.m_pObject.Class as IDataset).Name; CodeDomainEx codeDomainEx = CodeDomainManage.GetCodeDomainEx(pField.Name, name); if (codeDomainEx != null) { if ((codeDomainEx.ParentIDFieldName == null) || (codeDomainEx.ParentIDFieldName.Length == 0)) { NameValueCollection codeDomain = codeDomainEx.GetCodeDomain(); if (pField.IsNullable) { list.Add("<空>"); } strArray[1] = obj2.ToString(); for (num4 = 0; num4 < codeDomain.Count; num4++) { string str3 = codeDomain.Keys[num4]; list.Add(str3); if (obj2.ToString() == codeDomain[str3]) { strArray[1] = str3; } } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list, !this.FieldCanEdit(pField)); } else { strArray[1] = obj2.ToString(); this.m_pVertXtraGrid.AddTreeviewComBoBox(strArray[0], codeDomainEx.FindName(strArray[1]), codeDomainEx, !this.FieldCanEdit(pField)); } } else { if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], obj2, false, 0.0, 0.0); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], obj2, true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], obj2, !this.FieldCanEdit(pField)); } else { strArray[1] = obj2.ToString(); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !this.FieldCanEdit(pField)); } if (strArray[0] == this.m_EditFeildName) { rowHandle = i; } } } } } } } if (rowHandle >= 0) { this.gridView1.SelectRow(rowHandle); } this.gridView1.Focus(); this.m_CanDo = true; base.Parent.Focus(); } }
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) { if (this.m_CanDo && (this.m_pObject != null)) { object obj2; IDomain domain; ICodedValueDomain domain2; int num3; ISubtypes subtypes = this.m_pObject.Class as ISubtypes; GridEditorItem row = this.gridView1.GetRow(e.RowHandle) as GridEditorItem; int index = this.m_pObject.Fields.FindFieldByAliasName(row.Name); IField pField = this.m_pObject.Fields.get_Field(index); this.m_EditFeildName = pField.AliasName; if ((subtypes != null) && subtypes.HasSubtype) { if (subtypes.SubtypeFieldName == pField.Name) { IEnumSubtype subtype = subtypes.Subtypes; subtype.Reset(); int subtypeCode = 0; for (string str = subtype.Next(out subtypeCode); str != null; str = subtype.Next(out subtypeCode)) { if (e.Value.ToString() == str) { this.UpdateFieldValue(pField, subtypeCode); break; } } } else if (e.Value.ToString() == "<空>") { obj2 = DBNull.Value; this.UpdateFieldValue(pField, obj2); } else { domain = subtypes.get_Domain((this.m_pObject as IRowSubtypes).SubtypeCode, pField.Name); if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; for (num3 = 0; num3 < domain2.CodeCount; num3++) { if (domain2.get_Name(num3) == e.Value.ToString()) { this.UpdateFieldValue(pField, domain2.get_Value(num3)); break; } } } else { this.UpdateFieldValue(pField, e.Value); } } } else if (e.Value.ToString() == "<空>") { obj2 = DBNull.Value; this.UpdateFieldValue(pField, obj2); } else { string name = (this.m_pObject.Class as IDataset).Name; CodeDomainEx codeDomainEx = CodeDomainManage.GetCodeDomainEx(pField.Name, name); if (codeDomainEx != null) { if ((codeDomainEx.ParentIDFieldName == null) || (codeDomainEx.ParentIDFieldName.Length == 0)) { NameValueCollection codeDomain = codeDomainEx.GetCodeDomain(); for (num3 = 0; num3 < codeDomain.Count; num3++) { string str3 = codeDomain.Keys[num3]; if (str3 == e.Value.ToString()) { this.UpdateFieldValue(pField, codeDomain[str3]); break; } } } else { this.UpdateFieldValue(pField, codeDomainEx.GetCodeByName(e.Value.ToString())); } } else { domain = pField.Domain; if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; for (num3 = 0; num3 < domain2.CodeCount; num3++) { if (domain2.get_Name(num3) == e.Value.ToString()) { this.UpdateFieldValue(pField, domain2.get_Value(num3)); break; } } } else if (this.UpdateFieldValue(pField, e.Value)) { this.m_CanDo = false; row.Value = this.m_pObject.get_Value(index); this.m_CanDo = true; } } } } }
private void AddDataset(XmlWriter writer, IDatasetName datasetName) { // Check Parameters if (writer == null) { return; } if (datasetName == null) { return; } // Open Dataset IName name = datasetName as IName; if (name == null) { return; } object o = null; try { o = name.Open(); } catch { } if (o == null) { return; } IDataset dataset = o as IDataset; if (dataset == null) { return; } IFeatureClass featureClass = dataset as IFeatureClass; // <Dataset> writer.WriteStartElement("Dataset"); // <Dataset><Name> writer.WriteStartElement("Name"); writer.WriteValue(dataset.Name); writer.WriteEndElement(); // <Dataset><Type> string type = string.Empty; switch (dataset.Type) { case esriDatasetType.esriDTFeatureClass: if (featureClass == null) { type += "Unknown"; break; } switch (featureClass.FeatureType) { case esriFeatureType.esriFTAnnotation: case esriFeatureType.esriFTDimension: case esriFeatureType.esriFTSimple: type += GeodatabaseUtility.GetDescription(esriDatasetType.esriDTFeatureClass); break; default: type += GeodatabaseUtility.GetDescription(featureClass.FeatureType); break; } break; default: type += GeodatabaseUtility.GetDescription(dataset.Type); break; } writer.WriteStartElement("Type"); writer.WriteValue(type); writer.WriteEndElement(); // <Dataset><Geometry> string geometry = "-"; if (featureClass != null) { switch (featureClass.FeatureType) { case esriFeatureType.esriFTAnnotation: case esriFeatureType.esriFTDimension: geometry = GeodatabaseUtility.GetDescription(featureClass.FeatureType); break; default: geometry = GeodatabaseUtility.GetDescription(featureClass.ShapeType); break; } } writer.WriteStartElement("Geometry"); writer.WriteValue(geometry); writer.WriteEndElement(); //if (dataset is IFeatureClass) { // IFeatureClass featureClass = (IFeatureClass)dataset; // // <Dataset><FeatureType> // writer.WriteStartElement("FeatureType"); // writer.WriteValue(GeodatabaseUtility.GetDescription(featureClass.FeatureType)); // writer.WriteEndElement(); // // Add ...<Dataset><ShapeType> // switch (featureClass.FeatureType) { // case esriFeatureType.esriFTAnnotation: // case esriFeatureType.esriFTDimension: // break; // default: // writer.WriteStartElement("ShapeType"); // writer.WriteValue(GeodatabaseUtility.GetDescription(featureClass.ShapeType)); // writer.WriteEndElement(); // break; // } //} // Get Row Count ITable table = dataset as ITable; int intRowCount = -1; if (table != null) { try { intRowCount = table.RowCount(null); } catch { } } // <Dataset><RowCount> writer.WriteStartElement("RowCount"); switch (intRowCount) { case -1: writer.WriteValue("Error"); break; case 0: default: writer.WriteValue(intRowCount.ToString()); break; } writer.WriteEndElement(); if (intRowCount > 0) { if (dataset is IGeoDataset) { IGeoDataset geoDataset = (IGeoDataset)dataset; IEnvelope envelope = geoDataset.Extent; if (envelope != null && !envelope.IsEmpty) { // <Dataset><Extent> writer.WriteStartElement("Extent"); // <Dataset><Extent><XMax> writer.WriteStartElement("XMax"); writer.WriteValue(envelope.XMax.ToString()); writer.WriteEndElement(); // <Dataset><Extent><XMin> writer.WriteStartElement("XMin"); writer.WriteValue(envelope.XMin.ToString()); writer.WriteEndElement(); // <Dataset><Extent><YMax> writer.WriteStartElement("YMax"); writer.WriteValue(envelope.YMax.ToString()); writer.WriteEndElement(); // <Dataset><Extent><YMin> writer.WriteStartElement("YMin"); writer.WriteValue(envelope.YMin.ToString()); writer.WriteEndElement(); // <Dataset></Extent> writer.WriteEndElement(); // <Dataset><SmallImage> if (DataReportSettings.Default.ShowSmallImage) { string smallImage = System.IO.Path.GetTempFileName(); writer.WriteStartElement("SmallImage"); writer.WriteValue(smallImage); writer.WriteEndElement(); GeodatabaseUtility.CreateBitmap( dataset, DataReportSettings.Default.SmallImageType, DataReportSettings.Default.SmallImageSize, DataReportSettings.Default.SmallImageResolution, DataReportSettings.Default.SmallImageBackgroundColor, smallImage); } // <Dataset><LargeImage> if (DataReportSettings.Default.ShowLargeImage) { string largeImage = System.IO.Path.GetTempFileName(); writer.WriteStartElement("LargeImage"); writer.WriteValue(largeImage); writer.WriteEndElement(); GeodatabaseUtility.CreateBitmap( dataset, DataReportSettings.Default.LargeImageType, DataReportSettings.Default.LargeImageSize, DataReportSettings.Default.LargeImageResolution, DataReportSettings.Default.LargeImageBackgroundColor, largeImage); } } } } ISubtypes subtypes = dataset as ISubtypes; if (subtypes != null && subtypes.HasSubtype) { int subtypeCode = 0; IEnumSubtype enumSubtype = subtypes.Subtypes; string subtypeName = enumSubtype.Next(out subtypeCode); while (subtypeName != null) { // <Dataset><Sybtype> writer.WriteStartElement("Subtype"); // <Dataset><Sybtype><Name> writer.WriteStartElement("Name"); writer.WriteValue(subtypeName); writer.WriteEndElement(); // Get Row Count IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = string.Format("{0} = {1}", subtypes.SubtypeFieldName, subtypeCode.ToString()); int rowCount = table.RowCount(queryFilter); // <Dataset><Sybtype><RowCount> writer.WriteStartElement("RowCount"); writer.WriteValue(rowCount.ToString()); writer.WriteEndElement(); // <Dataset></Sybtype> writer.WriteEndElement(); // Get Next Subtype subtypeName = enumSubtype.Next(out subtypeCode); } } // </Dataset> writer.WriteEndElement(); }
private void Init() { this.m_pVertXtraGrid.Clear(); if (this.m_pFeatLayer == null) { this.m_CanDo = true; } else { IFields fields = this.m_pFeatLayer.FeatureClass.Fields; string[] strArray = new string[2]; ISubtypes featureClass = this.m_pFeatLayer.FeatureClass as ISubtypes; IDomain domain = null; for (int i = 0; i < fields.FieldCount; i++) { IField pField = fields.get_Field(i); strArray[0] = pField.AliasName; if (pField.Type == esriFieldType.esriFieldTypeGeometry) { strArray[1] = this.GetShapeString(pField); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else if (pField.Type == esriFieldType.esriFieldTypeBlob) { strArray[1] = "<二进制数据>"; this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else { ICodedValueDomain domain2 = null; IList list = new ArrayList(); if ((featureClass != null) && featureClass.HasSubtype) { if (featureClass.SubtypeFieldName == pField.Name) { int num2; strArray[1] = "<空>"; IEnumSubtype subtypes = featureClass.Subtypes; subtypes.Reset(); for (string str = subtypes.Next(out num2); str != null; str = subtypes.Next(out num2)) { list.Add(str); } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list, !pField.Editable); } else { strArray[1] = "<空>"; this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !pField.Editable); } } else { domain = pField.Domain; if (domain != null) { if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; if (pField.IsNullable) { list.Add("<空>"); } strArray[1] = "<空>"; for (int j = 0; j < domain2.CodeCount; j++) { list.Add(domain2.get_Name(j)); } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list, !pField.Editable); } else { strArray[1] = "<空>"; if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { double minValue = 0.0; double maxValue = 0.0; if (domain is IRangeDomain) { minValue = (double)(domain as IRangeDomain).MinValue; maxValue = (double)(domain as IRangeDomain).MaxValue; } if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], strArray[1], false, minValue, maxValue); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], strArray[1], !pField.Editable); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !pField.Editable); } } } else { strArray[1] = "<空>"; if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], strArray[1], false, 0.0, 0.0); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], strArray[1], !pField.Editable); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !pField.Editable); } } } } } this.m_CanDo = true; } }
private void cboLayer_SelectedIndexChanged(object sender, EventArgs e) { this.m_pVertXtraGrid.Clear(); if (this.cboLayer.SelectedIndex != -1) { LayerObject selectedItem = this.cboLayer.SelectedItem as LayerObject; IFeatureLayer pLayer = selectedItem.Layer as IFeatureLayer; this.m_pFeatLayer = pLayer; if (pLayer != null) { ICursor cursor; (pLayer as IFeatureSelection).SelectionSet.Search(null, false, out cursor); IList <IRow> pLists = new List <IRow>(); for (IRow row = cursor.NextRow(); row != null; row = cursor.NextRow()) { pLists.Add(row); } ComReleaser.ReleaseCOMObject(cursor); IFields fields = pLayer.FeatureClass.Fields; string[] strArray = new string[2]; ISubtypes featureClass = pLayer.FeatureClass as ISubtypes; IDomain domain = null; for (int i = 0; i < fields.FieldCount; i++) { IField pField = fields.get_Field(i); if (this.CheckFieldIsVisible(pLayer, pField)) { strArray[0] = pField.AliasName; if (pField.Type == esriFieldType.esriFieldTypeGeometry) { strArray[1] = this.GetShapeString(pField); this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else if (pField.Type == esriFieldType.esriFieldTypeBlob) { strArray[1] = "<二进制数据>"; this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } else if ((pField.Type != esriFieldType.esriFieldTypeOID) && pField.Editable) { int num3; double minValue; double maxValue; ICodedValueDomain domain2 = null; IList list2 = new ArrayList(); if ((featureClass != null) && featureClass.HasSubtype) { if (featureClass.SubtypeFieldName == pField.Name) { int num2; if (this.CheckValueIsEqual(pLists, i)) { object obj4 = pLists[0].get_Value(i); if (obj4 is DBNull) { strArray[1] = "<空>"; } else { try { strArray[1] = featureClass.get_SubtypeName( (pLists[0] as IRowSubtypes).SubtypeCode); } catch { strArray[1] = obj4.ToString(); } } } else { strArray[1] = "<空>"; } IEnumSubtype subtypes = featureClass.Subtypes; subtypes.Reset(); for (string str = subtypes.Next(out num2); str != null; str = subtypes.Next(out num2)) { list2.Add(str); } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list2, !pField.Editable); } else { domain = featureClass.get_Domain((pLists[0] as IRowSubtypes).SubtypeCode, pField.Name); if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; if (pField.IsNullable) { list2.Add("<空>"); } if (this.CheckValueIsEqual(pLists, i)) { strArray[1] = pLists[0].get_Value(i).ToString(); } else { strArray[1] = "<空>"; } num3 = 0; while (num3 < domain2.CodeCount) { list2.Add(domain2.get_Name(num3)); if (strArray[1] == domain2.get_Value(num3).ToString()) { strArray[1] = domain2.get_Name(num3); } num3++; } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list2, !pField.Editable); } else { if (this.CheckValueIsEqual(pLists, i)) { strArray[1] = pLists[0].get_Value(i).ToString(); } else { strArray[1] = "<空>"; } if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { minValue = 0.0; maxValue = 0.0; if (domain is IRangeDomain) { minValue = (double)(domain as IRangeDomain).MinValue; maxValue = (double)(domain as IRangeDomain).MaxValue; } if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], strArray[1], false, minValue, maxValue); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], strArray[1], !pField.Editable); } else { if (this.CheckValueIsEqual(pLists, i)) { strArray[1] = pLists[0].get_Value(i).ToString(); } else { strArray[1] = "<空>"; } this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !pField.Editable); } } } } else { domain = pField.Domain; if (domain != null) { if (domain is ICodedValueDomain) { domain2 = domain as ICodedValueDomain; if (pField.IsNullable) { list2.Add("<空>"); } if (this.CheckValueIsEqual(pLists, i)) { strArray[1] = pLists[0].get_Value(i).ToString(); } else { strArray[1] = "<空>"; } num3 = 0; while (num3 < domain2.CodeCount) { list2.Add(domain2.get_Name(num3)); if (strArray[1] == domain2.get_Value(num3).ToString()) { strArray[1] = domain2.get_Name(num3); } num3++; } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list2, !pField.Editable); } else { if (this.CheckValueIsEqual(pLists, i)) { strArray[1] = pLists[0].get_Value(i).ToString(); } else { strArray[1] = "<空>"; } if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { minValue = 0.0; maxValue = 0.0; if (domain is IRangeDomain) { minValue = (double)(domain as IRangeDomain).MinValue; maxValue = (double)(domain as IRangeDomain).MaxValue; } if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], strArray[1], false, minValue, maxValue); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], strArray[1], !pField.Editable); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !pField.Editable); } } } else { if (this.CheckValueIsEqual(pLists, i)) { strArray[1] = pLists[0].get_Value(i).ToString(); } else { strArray[1] = "<空>"; } string name = (pLayer.FeatureClass as IDataset).Name; NameValueCollection codeDomain = CodeDomainManage.GetCodeDomain(pField.Name, name); if (codeDomain.Count > 0) { if (pField.IsNullable) { list2.Add("<空>"); } for (num3 = 0; num3 < codeDomain.Count; num3++) { string str3 = codeDomain.Keys[num3]; list2.Add(str3); if (strArray[1] == codeDomain[str3]) { strArray[1] = str3; } } this.m_pVertXtraGrid.AddComBoBox(strArray[0], strArray[1], list2, !pField.Editable); } else if ((((pField.Type == esriFieldType.esriFieldTypeSmallInteger) || (pField.Type == esriFieldType.esriFieldTypeSingle)) || (pField.Type == esriFieldType.esriFieldTypeDouble)) || (pField.Type == esriFieldType.esriFieldTypeInteger)) { if (pField.Editable) { this.m_pVertXtraGrid.AddSpinEdit(strArray[0], strArray[1], false, 0.0, 0.0); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], true); } } else if (pField.Type == esriFieldType.esriFieldTypeDate) { this.m_pVertXtraGrid.AddDateEdit(strArray[0], strArray[1], !pField.Editable); } else { this.m_pVertXtraGrid.AddTextEdit(strArray[0], strArray[1], !pField.Editable); } } } } } } } } }
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) { if (this.m_CanDo) { if (this.m_pFeatLayer == null) { LayerObject selectedItem = this.cboLayer.SelectedItem as LayerObject; IFeatureLayer layer = selectedItem.Layer as IFeatureLayer; this.m_pFeatLayer = layer; } if (this.m_pFeatLayer != null) { object obj3; ISubtypes featureClass = this.m_pFeatLayer.FeatureClass as ISubtypes; GridEditorItem row = this.gridView1.GetRow(e.RowHandle) as GridEditorItem; int index = this.m_pFeatLayer.FeatureClass.Fields.FindFieldByAliasName(row.Name); IField pField = this.m_pFeatLayer.FeatureClass.Fields.get_Field(index); if ((featureClass != null) && featureClass.HasSubtype) { if (featureClass.SubtypeFieldName == pField.Name) { IEnumSubtype subtypes = featureClass.Subtypes; subtypes.Reset(); int subtypeCode = 0; for (string str = subtypes.Next(out subtypeCode); str != null; str = subtypes.Next(out subtypeCode)) { if (e.Value.ToString() == str) { this.UpdateFieldValue(pField, subtypeCode); break; } } } else if (e.Value.ToString() == "<空>") { obj3 = DBNull.Value; this.UpdateFieldValue(pField, obj3); } else { this.UpdateFieldValue(pField, e.Value); } } else if (e.Value.ToString() == "<空>") { obj3 = DBNull.Value; this.UpdateFieldValue(pField, obj3); } else { int num3; string name = (this.m_pFeatLayer.FeatureClass as IDataset).Name; NameValueCollection codeDomain = CodeDomainManage.GetCodeDomain(pField.Name, name); if (codeDomain.Count > 0) { for (num3 = 0; num3 < codeDomain.Count; num3++) { string str3 = codeDomain.Keys[num3]; if (str3 == e.Value.ToString()) { this.UpdateFieldValue(pField, codeDomain[str3]); break; } } } else { IDomain domain = pField.Domain; if (domain is ICodedValueDomain) { ICodedValueDomain domain2 = domain as ICodedValueDomain; for (num3 = 0; num3 < domain2.CodeCount; num3++) { if (domain2.get_Name(num3) == e.Value.ToString()) { this.UpdateFieldValue(pField, domain2.get_Value(num3)); break; } } } else if (this.UpdateFieldValue(pField, e.Value)) { this.m_CanDo = false; this.m_CanDo = true; } } } } } }