Beispiel #1
0
 private void m_pDataTable_ColumnChanged(object sender, DataColumnChangeEventArgs e)
 {
     if (this.m_InEditing && this.m_CanDo)
     {
         object[] itemArray = e.Row.ItemArray;
         try
         {
             IRow           row;
             int            num;
             IField         field;
             int            num2;
             IWorkspaceEdit workspace = (this.m_pTable as IDataset).Workspace as IWorkspaceEdit;
             if (itemArray[0] is DBNull)
             {
                 if (!(this.m_pTable is IFeatureClass))
                 {
                     workspace.StartEditOperation();
                     row = this.m_pTable.CreateRow();
                     num = row.Fields.FindFieldByAliasName(e.Column.ColumnName);
                     if (num != -1)
                     {
                         field = row.Fields.get_Field(num);
                         if (field.Domain is ICodedValueDomain)
                         {
                             for (num2 = 0; num2 < (field.Domain as ICodedValueDomain).CodeCount; num2++)
                             {
                                 if (e.ProposedValue.ToString() ==
                                     (field.Domain as ICodedValueDomain).get_Name(num2))
                                 {
                                     row.set_Value(num, (field.Domain as ICodedValueDomain).get_Value(num2));
                                     break;
                                 }
                             }
                         }
                         else
                         {
                             string       name         = (row.Table as IDataset).Name;
                             CodeDomainEx codeDomainEx = CodeDomainManage.GetCodeDomainEx(field.Name, name);
                             if (codeDomainEx != null)
                             {
                                 row.set_Value(num, codeDomainEx.GetCodeByName(e.ProposedValue.ToString()));
                             }
                             else
                             {
                                 row.set_Value(num, e.ProposedValue);
                             }
                         }
                         row.Store();
                     }
                     workspace.StopEditOperation();
                     this.m_CanDo = false;
                     e.Row[this.m_pTable.OIDFieldName] = row.OID;
                     this.m_CanDo = true;
                 }
             }
             else
             {
                 int          num3        = Convert.ToInt32(itemArray[0]);
                 IQueryFilter queryFilter = new QueryFilterClass
                 {
                     WhereClause = this.m_pTable.OIDFieldName + " = " + num3.ToString()
                 };
                 ICursor o = this.m_pTable.Search(queryFilter, false);
                 row = o.NextRow();
                 if (row != null)
                 {
                     workspace.StartEditOperation();
                     num = row.Fields.FindFieldByAliasName(e.Column.ColumnName);
                     if (num != -1)
                     {
                         field = row.Fields.get_Field(num);
                         if (field.Domain is ICodedValueDomain)
                         {
                             for (num2 = 0; num2 < (field.Domain as ICodedValueDomain).CodeCount; num2++)
                             {
                                 if (e.ProposedValue.ToString() ==
                                     (field.Domain as ICodedValueDomain).get_Name(num2))
                                 {
                                     row.set_Value(num, (field.Domain as ICodedValueDomain).get_Value(num2));
                                     break;
                                 }
                             }
                         }
                         else
                         {
                             row.set_Value(num, e.ProposedValue);
                         }
                     }
                     row.Store();
                     workspace.StopEditOperation();
                 }
                 row = null;
                 ComReleaser.ReleaseCOMObject(o);
                 o = null;
             }
         }
         catch (COMException exception)
         {
             if (exception.ErrorCode == -2147467259)
             {
                 MessageBox.Show("输入数据大于字段长度");
             }
             else
             {
                 MessageBox.Show(exception.Message);
             }
             e.Row.CancelEdit();
         }
         catch (Exception exception2)
         {
             MessageBox.Show(exception2.Message);
             e.Row.CancelEdit();
         }
     }
 }
Beispiel #2
0
 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;
                 }
             }
         }
     }
 }