Пример #1
0
 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);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 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;
                     }
                 }
             }
         }
     }
 }