public override void SetValue(object component, object value)
        {
            IRow pRow = component as IRow;

            if (m_CodedValueDomain != null)
            {
                if (!m_UseCVDomain)
                {
                    if (!((IDomain)m_CodedValueDomain).MemberOf(value))
                    {
                        System.Windows.Forms.MessageBox.Show(string.Format(
                                                                 "Value {0} is not valid for coded value domain {1}", value.ToString(), ((IDomain)m_CodedValueDomain).Name));
                        return;
                    }
                }
                else
                {
                    bool foundMatch = false;
                    for (int i = 0; i < m_CodedValueDomain.CodeCount; i++)
                    {
                        if (value.ToString() == m_CodedValueDomain.get_Name(i))
                        {
                            foundMatch = true;
                            value      = i;
                            break;
                        }
                    }

                    if (!foundMatch)
                    {
                        System.Windows.Forms.MessageBox.Show(string.Format(
                                                                 "Value {0} is not valid for coded value domain {1}", value.ToString(), ((IDomain)m_CodedValueDomain).Name));
                        return;
                    }
                }
            }

            pRow.set_Value(m_FieldIndex, value);
            bool weStartedEditing = false;

            if (m_WorkspaceEdit != null)
            {
                if (!m_WorkspaceEdit.IsBeingEdited())
                {
                    m_WorkspaceEdit.StartEditing(false);
                    weStartedEditing = true;
                }
                m_WorkspaceEdit.StartEditOperation();
                pRow.Store();
                m_WorkspaceEdit.StopEditOperation();

                if (weStartedEditing)
                {
                    m_WorkspaceEdit.StopEditing(true);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a list of all the coded domains: 0 - Value, 1 - Name, 2 - Combined "Value (name)"
        /// </summary>
        /// <param name="feature_layer"></param>
        /// <param name="attribute_field"></param>
        /// <param name="domainitemtype"></param>
        /// <returns></returns>
        public IList <string> GetCodedDomainItems(IFeatureLayer feature_layer, string attribute_field, DomainItemType domainitemtype)
        {
            IList <string> domain_list = new List <string>();


            IFields fields = feature_layer.FeatureClass.Fields;

            if (fields.FieldCount == 0)
            {
                throw new Exception("Feature Class has no fields");
            }

            int field_index = fields.FindField(attribute_field);

            if (field_index > -1)
            {
                IDomain domain = fields.get_Field(field_index).Domain;
                if (domain == null)
                {
                    throw new Exception("Attribute field '" + attribute_field + "' has no domain");
                }

                if (domain.Type == esriDomainType.esriDTCodedValue)
                {
                    ICodedValueDomain codedvaluedomain = (ICodedValueDomain)domain;
                    int codecount = codedvaluedomain.CodeCount;
                    if (domainitemtype == DomainItemType.Name)
                    {
                        for (int i = 0; i < codecount; i++)
                        {
                            domain_list.Add(codedvaluedomain.get_Name(i).ToString());
                        }
                    }
                    if (domainitemtype == DomainItemType.Value)
                    {
                        for (int i = 0; i < codecount; i++)
                        {
                            domain_list.Add(codedvaluedomain.get_Value(i).ToString());
                        }
                    }
                    if (domainitemtype == DomainItemType.Combined)
                    {
                        string name  = String.Empty;
                        string value = String.Empty;
                        for (int i = 0; i < codecount; i++)
                        {
                            name  = codedvaluedomain.get_Name(i).ToString();
                            value = codedvaluedomain.get_Value(i).ToString();
                            domain_list.Add(name + " (" + value + ")");
                        }
                    }
                }
            }

            return(domain_list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method is responsible for translanting between coded domain names
        /// and their values, setting into UnderlyingObject the correct value.
        /// </summary>
        /// <remarks>
        /// Imagine a ICodedDomain like:
        /// 1 = "Alphanumeric"
        /// 2 = "Geographic"
        ///
        /// This method will aways set the value to 1 when passed
        /// "Alphanumeric"
        /// </remarks>
        /// <exception cref="ActiveRecrdAttributeException"></exception>
        /// <param name="wrapper"></param>
        /// <param name="propertyName"></param>
        /// <param name="displayValue"></param>
        /// <returns></returns>
        private static void SetDisplayValue(this IActiveRecord wrapper, FieldAttribute fieldAtt, string displayValue)
        {
            if (wrapper.UnderlyingObject == null)
            {
                FetchUnderlyingObject(wrapper);
            }

            if (!(fieldAtt is DomainFieldAttribute))
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "O atributo não é tipo domínio.");
            }

            DomainFieldAttribute domainField = fieldAtt as DomainFieldAttribute;
            ICodedValueDomain    domain      = wrapper.UnderlyingObject.Fields.get_Field(domainField.Index).Domain as ICodedValueDomain;

            if (domain == null)
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "Não foi possível localizar o domínio.");
            }

            for (var i = 0; i <= domain.CodeCount - 1; i++)
            {
                if (domain.get_Name(i) == displayValue)
                {
                    object codedValue = domain.get_Value(i);
                    wrapper.UnderlyingObject.set_Value(domainField.Index, codedValue);
                }
            }
        }
Ejemplo n.º 4
0
        public static string GetDomainValueOfFieldValue(IFeatureClass pFeatureClass, string strFieldName, string strFieldValue)
        {
            string strValue = strFieldValue;

            try
            {
                // IDataset dataset = pFeatureClass as IDataset;
                //IWorkspace workspace = dataset.Workspace;
                // IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)workspace;
                int               indexfield       = pFeatureClass.Fields.FindField(strFieldName);
                IField            pField           = pFeatureClass.Fields.get_Field(indexfield);
                IDomain           requestDomain    = pField.Domain;
                ICodedValueDomain codedValueDomain = (ICodedValueDomain)requestDomain;
                if (codedValueDomain != null)
                {
                    for (int i = 0; i < codedValueDomain.CodeCount; i++)
                    {
                        string strTmpFieldValue = codedValueDomain.get_Value(i).ToString();
                        if (strTmpFieldValue.Equals(strFieldValue))
                        {
                            strValue = codedValueDomain.get_Name(i);
                            break;
                        }
                    }
                }
            }
            catch
            { }
            return(strValue);
        }
Ejemplo n.º 5
0
        //获得管线的属性字段和信息
        private void GetWaterLineValue(out string var1, out string var2, out string var3, out string var4, out string var5)
        {
            IFields pFields = pFeatureWaterLine.Fields;

            var1 = pFeatureWaterLine.get_Value(pFields.FindField("WATER_ID")).ToString();
            var2 = pFeatureWaterLine.get_Value(pFields.FindField("PIPEUSE_CODE")).ToString();
            var3 = pFeatureWaterLine.get_Value(pFields.FindField("SHAPE_LENGTH")).ToString();
            var4 = pFeatureWaterLine.get_Value(pFields.FindField("PWDIAM")).ToString();
            var5 = pFeatureWaterLine.get_Value(pFields.FindField("PWMATERIAL")).ToString();
            //根据子类型代码获得子类型名称
            ISubtypes    pWaterLineSubtypes = pFeatLayerWaterLines.FeatureClass as ISubtypes;
            IRowSubtypes pRowSubtypes       = pFeatureWaterLine as IRowSubtypes;

            if (pRowSubtypes != null)
            {
                var2 = pWaterLineSubtypes.get_SubtypeName(pRowSubtypes.SubtypeCode);
                //获取属性域
                IDomain pDomain = pWaterLineSubtypes.get_Domain(pRowSubtypes.SubtypeCode, "PWMATERIAL");
                if (pDomain != null)
                {
                    ICodedValueDomain pCodedValDomain = pDomain as ICodedValueDomain;
                    for (int i = 0; i <= pCodedValDomain.CodeCount - 1; i++)
                    {
                        if (pCodedValDomain.get_Value(i) == var5)
                        {
                            var5 = pCodedValDomain.get_Name(i);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public string GetDomainDisplay(string domain, object domainValu)
        {
            List <String>      listDomains = new List <string>();
            IDataset           dataset     = (IDataset)GetWorkspace;
            IWorkspaceDomains2 domains     = (IWorkspaceDomains2)dataset;
            ICodedValueDomain  dom         = null;

            try
            {
                dom = (ICodedValueDomain)domains.get_DomainByName(domain);
                for (int i = 0; i <= dom.CodeCount - 1; i++)
                {
                    if (dom.get_Value(i).Equals(domainValu))
                    {
                        return(dom.get_Name(i));
                    }
                }
            }
            catch (Exception ex)
            {
                //_log.Error("Ocorreu um problema ao tentar carregar os domínios do componente SegmentListComponent.");
            }
            finally
            {
                //if (domains != null)
                //    Marshal.ReleaseComObject(domains);

                //if (dom != null)
                //    Marshal.ReleaseComObject(dom);

                //Marshal.ReleaseComObject(dataset);
            }
            return("");
        }
Ejemplo n.º 7
0
        ///// <summary>
        ///// 批量专题导出Excel
        ///// </summary>
        ///// <param name="pFeatureClass"></param>
        ///// <param name="listFileName"></param>
        ///// <param name="TypeName"></param>
        //public void BatchSubjectExport(IFeatureClass pFeatureClass, IList<string> listFileName, string TypeName, string fieldName)
        //{
        //    flag = 1;
        //    result = folderBrowerDialog.ShowDialog();
        //    for (int i = 0; i < listFileName.Count; i++)
        //    {
        //        Export(pFeatureClass, listFileName[i], TypeName, fieldName);
        //    }
        //    flag = 0;
        //}
        ///// <summary>
        ///// 批量导出该行政去内各种类型Excel
        ///// </summary>
        ///// <param name="ListFeatureClass"></param>
        ///// <param name="VillageName">行政区名称</param>
        ///// <param name="fieldName">统计字段名称</param>
        //public void BatchStatisticalChart(IList<IFeatureClass> ListFeatureClass, string VillageName, string fieldName)
        //{

        //    flag = 1;
        //    result = folderBrowerDialog.ShowDialog();
        //    for (int i = 0; i < ListFeatureClass.Count; i++)
        //    {
        //        ExportByFeartureClassName(ListFeatureClass[i], VillageName, fieldName);
        //    }
        //    flag = 0;
        //}
        ///// <summary>
        ///// 根据FeatureClass别名进行统计导出Excel表
        ///// </summary>
        ///// <param name="pFeatureClass"></param>
        ///// <param name="VillageName"></param>
        ///// <param name="fieldName"></param>
        //private void ExportByFeartureClassName(IFeatureClass pFeatureClass, string VillageName, string fieldName)
        //{
        //    switch (pFeatureClass.AliasName)
        //    {
        //        case "DATASYS.DATONG_LDGH":
        //            string fileName = VillageName + "镇(乡)林地规划统计表";
        //            Export(pFeatureClass, fileName, "林地类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LYYDFB":
        //            fileName = VillageName + "镇(乡)林业用地分布统计表";
        //            Export(pFeatureClass, fileName, "类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_BAOHU_DJ":
        //            fileName = VillageName + "镇(乡)林地保护等级分布统计表";
        //            Export(pFeatureClass, fileName, "林地保护等级级别", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_ZDGNQ":
        //            fileName = VillageName + "镇(乡)林地主导功能区分布统计表";
        //            Export(pFeatureClass, fileName, "主导功能区类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LDLY":
        //            fileName = VillageName + "镇(乡)林地利用现状统计表";
        //            Export(pFeatureClass, fileName, "林地利用现状类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LDJG":
        //            fileName = VillageName + "镇(乡)林地结构现状统计表";
        //            Export(pFeatureClass, fileName, "林地结构类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_ZHILIANG_DJ":
        //            fileName = VillageName + "镇(乡)林地质量等级现状统计表";
        //            Export(pFeatureClass, fileName, "林地质量等级类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LC":
        //            fileName = VillageName + "镇(乡)林场统计表";
        //            Export(pFeatureClass, fileName, "林场名称", fieldName);
        //            fileName = "";
        //            break;
        //    }
        //}
        /// <summary>
        /// 得到属性域的值
        /// </summary>
        /// <param name="TypeName">表字段名称</param>
        /// <param name="pFeatureClass">特征类</param>
        /// <returns>属性域字段</returns>
        private IList <string> GetDomainsName(string fieldName, IFeatureClass pFeatureClass)
        {
            IList <string> newList = new List <string>();

            newList = listString;
            IDataset          dataset          = pFeatureClass as IDataset;
            IWorkspace        workspace        = dataset.Workspace;
            IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)workspace;
            int               indexField       = pFeatureClass.Fields.FindField(fieldName);
            IField            pField           = pFeatureClass.Fields.get_Field(indexField);
            IDomain           domain           = pField.Domain;
            ICodedValueDomain codeDomain       = (ICodedValueDomain)domain;

            for (int i = 0; i < codeDomain.CodeCount; i++)
            {
                for (int j = 0; j < listString.Count; j++)
                {
                    if (listString[j] == codeDomain.get_Value(i).ToString())
                    {
                        newList[j] = codeDomain.get_Name(i).ToString();
                    }
                }
            }
            return(newList);
        }
Ejemplo n.º 8
0
        public static string DecorateWhereClasuse(IFeatureClass fc)
        {
            string fValue = "2";
            int    index  = GetIndex(fc, "Upordown");

            if (index == -1)
            {
                return("");
            }
            IDomain pDomain = fc.Fields.get_Field(index).Domain;

            if (pDomain != null && pDomain.Type == esriDomainType.esriDTCodedValue)
            {
                ICodedValueDomain pCD = pDomain as ICodedValueDomain;
                for (int j = 0; j < pCD.CodeCount; j++)
                {
                    if (pCD.get_Name(j) == "地下")
                    {
                        fValue = pCD.get_Value(j).ToString();
                    }
                }
            }
            string whereClause = "UPORDOWN = " + fValue + " And ";

            return(whereClause);
        }
Ejemplo n.º 9
0
        //获得阀门的属性字段和信息
        private void GetValves(IFeature pFeature, out string var1, out string var2, out string var3)
        {
            IFields   pFields          = pFeature.Fields;
            ISubtypes pWaterPtSubtypes = pFeatLayerValves.FeatureClass as ISubtypes;

            var1 = pFeature.get_Value(pFields.FindField("WATER_ID")).ToString();
            var2 = pFeature.get_Value(pFields.FindField("PWV_TYPE")).ToString();
            var3 = pFeature.get_Value(pFields.FindField("PWSHEETNO")).ToString();
            IRowSubtypes pRowSubtypes = pFeature as IRowSubtypes;

            if (pRowSubtypes != null)
            {
                IDomain pDomain = pWaterPtSubtypes.get_Domain(pRowSubtypes.SubtypeCode, "PWV_TYPE");
                if (pDomain != null)
                {
                    ICodedValueDomain pCodedValDomain = pDomain as ICodedValueDomain;
                    for (int i = 0; i <= pCodedValDomain.CodeCount - 1; i++)
                    {
                        if (pCodedValDomain.get_Value(i).ToString() == var2)
                        {
                            var2 = pCodedValDomain.get_Name(i).ToString();
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private object GetFieldValueByIndex(IFeature feature, int index)
        {
            object obj = null;

            if (index == -1)
            {
                return(null);
            }
            IDomain domain = feature.Fields.get_Field(index).Domain;

            if (domain != null && domain.Type == esriDomainType.esriDTCodedValue)
            {
                ICodedValueDomain pCD = domain as ICodedValueDomain;
                for (int i = 0; i < pCD.CodeCount; i++)
                {
                    if (object.Equals(pCD.get_Value(i), feature.get_Value(index)))
                    {
                        obj = pCD.get_Name(i);
                    }
                }
            }
            else
            {
                obj = feature.get_Value(index).ToString();
            }
            return(obj);
        }
Ejemplo n.º 11
0
 private string method_6(IFeature ifeature_0, int int_0)
 {
     try
     {
         IDomain domain = ifeature_0.Fields.get_Field(int_0).Domain;
         if (domain == null)
         {
             return(ifeature_0.get_Value(int_0).ToString());
         }
         if (domain.Type != esriDomainType.esriDTCodedValue)
         {
             return(ifeature_0.get_Value(int_0).ToString());
         }
         ICodedValueDomain domain2 = domain as ICodedValueDomain;
         int codeCount             = domain2.CodeCount;
         for (int i = 0; i < codeCount; i++)
         {
             if (domain2.get_Value(i) == ifeature_0.get_Value(int_0))
             {
                 return(domain2.get_Name(i));
             }
         }
     }
     catch
     {
     }
     return("");
 }
Ejemplo n.º 12
0
        private void UpdateGrid()
        {
            IFields           fields   = this.m_pObject.Fields;
            ISubtypes         subtypes = this.m_pObject.Class as ISubtypes;
            IDomain           domain   = null;
            ICodedValueDomain domain2  = null;

            for (int i = 0; i < fields.FieldCount; i++)
            {
                IField field = fields.get_Field(i);
                if (((((field.Type != esriFieldType.esriFieldTypeGeometry) &&
                       (field.Type != esriFieldType.esriFieldTypeOID)) &&
                      (field.Type != esriFieldType.esriFieldTypeRaster)) && field.Editable) &&
                    (subtypes.SubtypeFieldName != field.Name))
                {
                    domain = subtypes.get_Domain((this.m_pObject as IRowSubtypes).SubtypeCode, field.Name);
                    if (domain is ICodedValueDomain)
                    {
                        IList list = new ArrayList();
                        domain2 = domain as ICodedValueDomain;
                        if (field.IsNullable)
                        {
                            list.Add("<空>");
                        }
                        for (int j = 0; j < domain2.CodeCount; j++)
                        {
                            list.Add(domain2.get_Name(j));
                        }
                        this.m_pVertXtraGrid.ChangeItem(i,
                                                        (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_COMBOBOX, list, 0.0, 0.0);
                    }
                    else if ((((field.Type == esriFieldType.esriFieldTypeSmallInteger) ||
                               (field.Type == esriFieldType.esriFieldTypeSingle)) ||
                              (field.Type == esriFieldType.esriFieldTypeDouble)) ||
                             (field.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;
                            this.m_pVertXtraGrid.ChangeItem(i,
                                                            (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_SPINEDIT, null, 0.0, 0.0);
                        }
                        else
                        {
                            this.m_pVertXtraGrid.ChangeItem(i,
                                                            (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_TEXTEDIT, null, 0.0, 0.0);
                        }
                    }
                    else
                    {
                        this.m_pVertXtraGrid.ChangeItem(i,
                                                        (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_TEXTEDIT, null, 0.0, 0.0);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the current value of the property on a component.
        /// </summary>
        /// <param name="component">The component (an IRow) with the property for
        /// which to retrieve the value.</param>
        /// <remarks>
        /// This will return the field value for all fields apart from geometry, raster and Blobs.
        /// These fields will return the string equivalent of the geometry type.
        /// </remarks>
        /// <returns>
        /// The value of a property for a given component. This will be the value of
        /// the field this class instance represents in the IRow passed in the component
        /// parameter.
        /// </returns>
        public override object GetValue(object component)
        {
            object retVal = null;

            IRow givenRow = (IRow)component;

            try
            {
                // Get value
                object value = givenRow.get_Value(wrappedFieldIndex);

                if ((null != cvDomain) && useCVDomain)
                {
                    value = cvDomain.get_Name(Convert.ToInt32(value));
                }

                switch (esriType)
                {
                case esriFieldType.esriFieldTypeBlob:
                    retVal = "Blob";
                    break;

                case esriFieldType.esriFieldTypeGeometry:
                    retVal = GetGeometryTypeAsString(value);
                    break;

                case esriFieldType.esriFieldTypeRaster:
                    retVal = "Raster";
                    break;

                default:
                    retVal = value;
                    break;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            return(retVal);
        }
Ejemplo n.º 14
0
        private string GetCodedValueDomainValue(ICodedValueDomain pDomain, string domainDescription)
        {
            string result = "<Null>";

            for (int i = 0; i < pDomain.CodeCount; i++)
            {
                if (pDomain.get_Name(i) == domainDescription)
                {
                    result = pDomain.get_Value(i).ToString();
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 15
0
 //复制工作空间坐标空间域
 private void CreateWorkspaceDomains(IWorkspace pWs1, IWorkspace pWs2)
 {
     try
     {
         WaitForm.SetCaption("正在复制工作空间域,请稍后...");
         IWorkspaceDomains pWsD1       = pWs1 as IWorkspaceDomains;
         IWorkspaceDomains pWsD2       = pWs2 as IWorkspaceDomains;
         IEnumDomain       pEnumDomain = pWsD1.Domains;
         IDomain           pDomain1    = null;
         IDomain           pDomain2    = null;
         if (pEnumDomain == null)
         {
             return;
         }
         while ((pDomain1 = pEnumDomain.Next()) != null)
         {
             if (pDomain1.Type == esriDomainType.esriDTCodedValue)//编码域
             {
                 ICodedValueDomain tempDomain1 = pDomain1 as ICodedValueDomain;
                 ICodedValueDomain tempDomain2 = new CodedValueDomainClass();
                 for (int i = 0; i < tempDomain1.CodeCount; i++)
                 {
                     tempDomain2.AddCode(tempDomain1.get_Value(i), tempDomain1.get_Name(i));
                 }
                 pDomain2             = tempDomain2 as IDomain;
                 pDomain2.Description = pDomain1.Description;
                 pDomain2.FieldType   = pDomain1.FieldType;
                 pDomain2.DomainID    = pDomain1.DomainID;
                 pDomain2.MergePolicy = pDomain1.MergePolicy;
                 pDomain2.Name        = pDomain1.Name;
                 pDomain2.Owner       = pDomain1.Owner;
                 pDomain2.SplitPolicy = pDomain1.SplitPolicy;
                 pWsD2.AddDomain(pDomain2);
             }
             else//范围域
             {
                 IRangeDomain tempDomain1 = pDomain1 as IRangeDomain;
                 IRangeDomain tempDomain2 = new RangeDomainClass();
                 tempDomain2.MaxValue = tempDomain1.MaxValue;
                 tempDomain2.MinValue = tempDomain1.MinValue;
                 pDomain2             = tempDomain2 as IDomain;
                 pWsD2.AddDomain(pDomain2);
             }
         }
     }
     catch (System.Exception ex)
     {
         return;
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// This method is responsible for translating between coded domain values
        /// and their names, returning the correct name.
        /// </summary>
        /// Imagine a ICodedDomain like:
        /// 1 = "Alphanumeric"
        /// 2 = "Geographic"
        ///
        /// This method will always return "Alphanumeric" for the value 1,
        /// fetched from UnderlyingObject
        /// </remarks>
        /// <exception cref="ActiveRecrdAttributeException"></exception>
        /// <param name="wrapper">IActiveRecord</param>
        /// <param name="propertyName">string</param>
        /// <returns>string</returns>
        private static string GetDisplayValue(this IActiveRecord wrapper, FieldAttribute fieldAtt)
        {
            if (wrapper.UnderlyingObject == null)
            {
                FetchUnderlyingObject(wrapper);
            }

            if (!(fieldAtt is DomainFieldAttribute))
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "Não é possível obter o atributo de domínio.");
            }

            DomainFieldAttribute domainField = fieldAtt as DomainFieldAttribute;
            ICodedValueDomain    domain      = wrapper.UnderlyingObject.Fields.get_Field(domainField.Index).Domain as ICodedValueDomain;

            if (domain == null)
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(),
                                                         String.Format("Não foi possível localizar o domínio {0}.", domainField.DomainName));
            }

            string codedValue   = wrapper.UnderlyingObject.get_Value(domainField.Index).ToString();
            string displayValue = String.Empty;

            for (int i = 0; i <= domain.CodeCount - 1; i++)
            {
                if (domain.get_Value(i).ToString() == codedValue)
                {
                    displayValue = domain.get_Name(i);
                    break;
                }
            }

            if (displayValue == String.Empty)
            {
                return(codedValue);
            }
            else
            {
                return(displayValue);
            }
        }
Ejemplo n.º 17
0
        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();
            }
        }
Ejemplo n.º 18
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);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 19
0
        private void ReadFieldInfo()
        {
            IDomain           domain       = null;
            ICodedValueDomain domain2      = null;
            ILayerFields      featureLayer = this.FeatureLayer as ILayerFields;

            for (int i = 0; i < featureLayer.FieldCount; i++)
            {
                string     str;
                IFieldInfo info;
                FieldInfo  info2;
                IField     field = featureLayer.get_Field(i);
                if (field.Required)
                {
                    if ((featureLayer is IFDOGraphicsLayer) && (string.Compare(field.Name, "SymbolID", true) == 0))
                    {
                        str = (field.Type == esriFieldType.esriFieldTypeString)
                            ? string.Format("(长度={0})", field.Length)
                            : "";
                        info  = featureLayer.get_FieldInfo(i);
                        info2 = new FieldInfo
                        {
                            FieldName       = "SymbolID",
                            TypeDescription = RowOperator.GetFieldTypeString(field.Type) + str,
                            IsNull          = field.IsNullable,
                            IsVisible       = info.Visible,
                            LayerFieldAlias = info.Alias
                        };
                        this.m_listInfo.Add(info2);
                        this.m_sortAliaslistInfo.Add(info2.LayerFieldAlias, info2);
                        this.m_sortnamelistInfo.Add(info2.FieldName, info2);
                    }
                }
                else if (field.Editable &&
                         ((((field.Type != esriFieldType.esriFieldTypeGeometry) &&
                            (field.Type != esriFieldType.esriFieldTypeBlob)) &&
                           (field.Type != esriFieldType.esriFieldTypeRaster)) &&
                          (field.Type != esriFieldType.esriFieldTypeOID)))
                {
                    str = (field.Type == esriFieldType.esriFieldTypeString)
                        ? string.Format("(长度={0})", field.Length)
                        : "";
                    info  = featureLayer.get_FieldInfo(i);
                    info2 = new FieldInfo
                    {
                        FieldName       = field.Name,
                        TypeDescription = RowOperator.GetFieldTypeString(field.Type) + str,
                        IsNull          = field.IsNullable,
                        IsVisible       = info.Visible,
                        LayerFieldAlias = info.Alias
                    };
                    domain = field.Domain;
                    if ((domain != null) && (domain is ICodedValueDomain))
                    {
                        domain2 = domain as ICodedValueDomain;
                        List <string> list = new List <string>();
                        if (field.IsNullable)
                        {
                            list.Add("<空>");
                        }
                        for (int j = 0; j < domain2.CodeCount; j++)
                        {
                            list.Add(domain2.get_Name(j));
                        }
                        info2.CodeDomainList = list;
                    }
                    this.m_listInfo.Add(info2);
                    this.m_sortAliaslistInfo.Add(info2.LayerFieldAlias, info2);
                    this.m_sortnamelistInfo.Add(info2.FieldName, info2);
                }
            }
        }
Ejemplo n.º 20
0
        private bool ExportTable(Excel.Workbook ExcelWbk, IMxDocument MxDoc, IStandaloneTable StandTable, ref IProgressDialog2 progressDialog, ref IStepProgressor stepProgressor, ref ITrackCancel trackCancel)
        {
            ITableProperties      TableProperties      = null;
            IEnumTableProperties  EnumTableProperties  = null;
            ITableProperty3       TableProperty        = null;
            ITableCharacteristics TableCharacteristics = null;
            ITableSelection       TabSel       = null;
            IDisplayTable         DisplayTable = null;
            ITable       Table       = null;
            IRow         TabRow      = null;
            IObjectClass ObjectClass = null;
            ISubtypes    Subtypes    = null;
            ITableFields TableFields = null;

            ICursor           Cursor           = null;
            IField            CurField         = null;
            IDomain           Domain           = null;
            ICodedValueDomain CodedValueDomain = null;

            object missing = null;
            object sheet   = null;

            Microsoft.Office.Interop.Excel.Style style = null;


            try
            {
                bool   UseDescriptions;
                int    subtype;
                string SheetName;



                int Col = 0;
                int Row = 0;
                int i;
                int j;



                missing = System.Reflection.Missing.Value;

                sheet = ExcelWbk.Sheets[ExcelWbk.Sheets.Count];
                Excel.Worksheet ExcelSheet;
                Excel.Range     ExcelRange;

                //Add new Excel worksheet
                ExcelSheet = (Excel.Worksheet)ExcelWbk.Sheets.Add(missing, sheet, missing, missing);
                //style = ExcelWbk.Styles.Add("Style1");
                //style.NumberFormat = "@";
                //style.Font.Name = "Arial";
                //style.Font.Bold = True
                //style.Font.Size = 12;
                //style.Interior.Pattern = Microsoft.Office.Interop.Excel.XlPattern.xlPattern Solid
                //style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlighLe ft



                SheetName = StandTable.Name;
                if (SheetName.Length > 30)
                {
                    SheetName = SheetName.Substring(0, 30);
                }
                ExcelSheet.Name = SheetName;


                //Determine whether to use descriptions or codes for domains
                UseDescriptions     = true;
                TableProperties     = MxDoc.TableProperties;
                EnumTableProperties = (IEnumTableProperties)TableProperties;
                EnumTableProperties.Reset();
                TableProperty = (ITableProperty3)EnumTableProperties.Next();

                while (TableProperty != null)
                {
                    if (TableProperty.StandaloneTable != null)
                    {
                        if (TableProperty.StandaloneTable.Equals(StandTable))
                        {
                            TableCharacteristics = (ITableCharacteristics)TableProperty;
                            UseDescriptions      = TableCharacteristics.ShowCodedValueDomainDescriptions;
                            break;
                        }
                    }
                    TableProperty = (ITableProperty3)EnumTableProperties.Next();
                }
                TabSel = (ITableSelection)StandTable;

                DisplayTable = (IDisplayTable)StandTable;
                Table        = (ITable)DisplayTable.DisplayTable;

                //Get subtype info
                ObjectClass = Table as IObjectClass;
                Subtypes    = ObjectClass as ISubtypes;

                //Get TableFields so later we can determine whether that field is visible
                TableFields = (ITableFields)StandTable;


                //loop through each field and write column headings
                Row = 1;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Write field alias name as Excel column header
                        ExcelSheet.Cells[Row, Col] = TableFields.get_FieldInfo(j).Alias;
                        if (CurField.Type == esriFieldType.esriFieldTypeString)
                        {
                            ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[65535, Col]).EntireColumn.NumberFormat = "@";
                        }
                    }
                }

                //Get all selected records for this table (use IDisplayTable to get any joined data)
                DisplayTable.DisplaySelectionSet.Search(null, true, out Cursor);

                //subtype = Subtypes.DefaultSubtypeCode;

                //For each selected record

                TabRow = Cursor.NextRow();
                //stepProgressor.Step();
                //     progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";

                while (TabRow != null)
                {
                    Row += 1;

                    if (Subtypes != null && Subtypes.HasSubtype == true &&
                        (TabRow.get_Value(Subtypes.SubtypeFieldIndex) != null))
                    {
                        subtype = Convert.ToInt32(TabRow.get_Value(Subtypes.SubtypeFieldIndex));
                    }
                    else
                    {
                        subtype = -99999;
                    }


                    //For each column
                    Col = 0;
                    for (j = 0; j < TableFields.FieldCount; j++)
                    {
                        CurField = TableFields.get_Field(j);

                        //skip blob and geometry fields in data also
                        if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                        {
                            Col += 1;
                            ExcelSheet.Cells[Row, Col] = TabRow.get_Value(j);

                            if (UseDescriptions == true && subtype == -99999)
                            {
                                Domain = CurField.Domain;
                                if (Domain != null)
                                {
                                    if (Domain.Type == esriDomainType.esriDTCodedValue)
                                    {
                                        CodedValueDomain = (ICodedValueDomain)CurField.Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (TabRow.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (UseDescriptions == true && subtype != -99999)
                            {
                                if (Subtypes.SubtypeFieldIndex == j)
                                {
                                    ExcelSheet.Cells[Row, Col] = Subtypes.get_SubtypeName(subtype);
                                }
                                else
                                {
                                    Domain = Subtypes.get_Domain(subtype, CurField.Name);
                                    if ((Domain != null) && (Domain.Type == esriDomainType.esriDTCodedValue))
                                    {
                                        CodedValueDomain = (ICodedValueDomain)Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (TabRow.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    stepProgressor.Step();
                    progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";
                    if (!trackCancel.Continue())
                    {
                        return(false);
                    }
                    TabRow = Cursor.NextRow();
                }

                //Hide Columns
                Col = 0;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields in data also
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Autofit
                        ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                        ExcelRange.EntireColumn.AutoFit();

                        //Hide column if invisible in ArcMap
                        if (TableFields.get_FieldInfo(j).Visible == false)
                        {
                            ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                            ExcelRange.EntireColumn.Hidden = true;
                        }
                    }
                }
                return(true);
            }
            catch
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ExportXLError"));
                return(true);
            }
            finally
            {
                TableProperties      = null;
                EnumTableProperties  = null;
                TableProperty        = null;
                TableCharacteristics = null;
                TabSel       = null;
                DisplayTable = null;
                Table        = null;
                TabRow       = null;
                ObjectClass  = null;
                Subtypes     = null;
                TableFields  = null;


                if (Cursor != null)
                {
                    Marshal.ReleaseComObject(Cursor);
                }
                Cursor           = null;
                CurField         = null;
                Domain           = null;
                CodedValueDomain = null;

                missing = null;
                sheet   = null;
                style   = null;
            }
        }
Ejemplo n.º 21
0
        private bool ExportLayer(Excel.Workbook ExcelWbk, IMxDocument MxDoc, IFeatureLayer FLayer, ref IProgressDialog2 progressDialog, ref IStepProgressor stepProgressor, ref ITrackCancel trackCancel)
        {
            IFeatureClass FC       = null;
            ISubtypes     Subtypes = null;

            ITableProperties      TableProperties      = null;
            IEnumTableProperties  EnumTableProperties  = null;
            ITableProperty3       TableProperty        = null;
            ITableCharacteristics TableCharacteristics = null;
            IFeatureSelection     FeatSel      = null;
            IDisplayTable         DisplayTable = null;
            ITable       Table       = null;
            ILayerFields LayerFields = null;
            ITableFields TableFields = null;
            ILayer       LayerTest   = null;

            ICursor           Cursor           = null;
            IFeatureCursor    FCursor          = null;
            IField            CurField         = null;
            IDomain           Domain           = null;
            ICodedValueDomain CodedValueDomain = null;
            IFeature          Feat             = null;
            List <IPoint>     pGeo             = null;

            object missing = null;
            object sheet   = null;

            Excel.Worksheet ExcelSheet = null;
            Excel.Range     ExcelRange = null;
            Microsoft.Office.Interop.Excel.Style style = null;

            try
            {
                int    Col = 0;
                int    Row = 0;
                int    i;
                int    j;
                bool   UseDescriptions;
                int    subtype;
                string SheetName;

                missing = System.Reflection.Missing.Value;
                sheet   = ExcelWbk.Sheets[ExcelWbk.Sheets.Count];

                //Add new Excel worksheet
                ExcelSheet = (Excel.Worksheet)ExcelWbk.Sheets.Add(missing, sheet, missing, missing);
                SheetName  = FLayer.Name;
                if (SheetName.Length > 30)
                {
                    SheetName = SheetName.Substring(0, 30);
                }
                ExcelSheet.Name = SheetName;

                //style = ExcelWbk.Styles.Add("Style1");
                //style.NumberFormat = "@";

                LayerTest = (ILayer)FLayer;

                //Get Subtype info
                FC       = FLayer.FeatureClass;
                Subtypes = FC as ISubtypes;
                //Determine whether to use descriptions or codes for domains and subtypes
                UseDescriptions     = true;
                TableProperties     = MxDoc.TableProperties;
                EnumTableProperties = (IEnumTableProperties)TableProperties;
                EnumTableProperties.Reset();
                TableProperty = (ITableProperty3)EnumTableProperties.Next();
                while (TableProperty != null && TableProperty.Layer != null)  //Fixed
                {
                    if (TableProperty.Layer.Equals(LayerTest))
                    {
                        TableCharacteristics = (ITableCharacteristics)TableProperty;
                        UseDescriptions      = TableCharacteristics.ShowCodedValueDomainDescriptions;
                    }
                    TableProperty = (ITableProperty3)EnumTableProperties.Next();
                }
                FeatSel = (IFeatureSelection)FLayer;

                DisplayTable = (IDisplayTable)FLayer;
                Table        = (ITable)DisplayTable.DisplayTable;

                //Get TableFields so later we can determine whether that field is visible
                LayerFields = (ILayerFields)FLayer;
                TableFields = (ITableFields)FLayer;

                //loop through each field and write column headings
                Row = 1;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Write field alias name as Excel column header
                        ExcelSheet.Cells[Row, Col] = TableFields.get_FieldInfo(j).Alias;
                        if (CurField.Type == esriFieldType.esriFieldTypeString)
                        {
                            ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[65535, Col]).EntireColumn.NumberFormat = "@";
                        }
                    }
                }
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "X_COORD";
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "Y_COORD";
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "Lat";
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "Long";
                IField       pFieldTest       = FLayer.FeatureClass.Fields.get_Field(FLayer.FeatureClass.Fields.FindField(FLayer.FeatureClass.ShapeFieldName));
                IGeometryDef pGeometryDefTest = null;
                pGeometryDefTest = pFieldTest.GeometryDef;
                bool bZAware = false;
                bool bMAware = false;
                //Determine if M or Z aware
                if (pGeometryDefTest.GeometryType == esriGeometryType.esriGeometryPoint)
                {
                    bZAware = pGeometryDefTest.HasZ;
                    bMAware = pGeometryDefTest.HasM;
                }
                if (bZAware)
                {
                    Col += 1;
                    ExcelSheet.Cells[Row, Col] = "Z_COORD";
                }
                pFieldTest       = null;
                pGeometryDefTest = null;
                //Get all selected records for this table (use IDisplayTable to get any joined data)
                DisplayTable.DisplaySelectionSet.Search(null, true, out Cursor);
                FCursor = (IFeatureCursor)Cursor;

                //subtype = Subtypes.DefaultSubtypeCode;

                //For each selected record

                Feat = FCursor.NextFeature();
                //  stepProgressor.Step();
                // progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";

                while (Feat != null)
                {
                    Row += 1;

                    if (Subtypes != null && Subtypes.HasSubtype == true &&
                        (Feat.get_Value(Subtypes.SubtypeFieldIndex) != null))
                    {
                        subtype = Convert.ToInt32(Feat.get_Value(Subtypes.SubtypeFieldIndex));
                    }
                    else
                    {
                        subtype = -99999;
                    }


                    //For each column
                    Col = 0;
                    for (j = 0; j < TableFields.FieldCount; j++)
                    {
                        CurField = TableFields.get_Field(j);

                        //skip blob and geometry fields in data also
                        if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                        {
                            Col += 1;
                            ExcelSheet.Cells[Row, Col] = Feat.get_Value(j);

                            if (UseDescriptions == true && subtype == -99999)
                            {
                                Domain = CurField.Domain;
                                if (Domain != null)
                                {
                                    if (Domain.Type == esriDomainType.esriDTCodedValue)
                                    {
                                        CodedValueDomain = (ICodedValueDomain)CurField.Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (Feat.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (UseDescriptions == true && subtype != -99999)
                            {
                                if (Subtypes.SubtypeFieldIndex == j)
                                {
                                    ExcelSheet.Cells[Row, Col] = Subtypes.get_SubtypeName(subtype);
                                }
                                else
                                {
                                    Domain = Subtypes.get_Domain(subtype, CurField.Name);
                                    if ((Domain != null) && (Domain.Type == esriDomainType.esriDTCodedValue))
                                    {
                                        CodedValueDomain = (ICodedValueDomain)Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (Feat.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (Feat.Shape != null)
                    {
                        if (Feat.Shape.IsEmpty == false)
                        {
                            pGeo = Globals.GetGeomCenter(Feat.Shape);
                            if (pGeo != null)
                            {
                                if (pGeo.Count > 0)
                                {
                                    if (pGeo[0].X != null)
                                    {
                                        ExcelSheet.Cells[Row, Col + 1] = pGeo[0].X;
                                    }
                                    if (pGeo[0].Y != null)
                                    {
                                        ExcelSheet.Cells[Row, Col + 2] = pGeo[0].Y;
                                    }
                                    if (pGeo[0] != null)
                                    {
                                        pGeo[0].Project(srWGS84);

                                        ExcelSheet.Cells[Row, Col + 3] = pGeo[0].Y;
                                        ExcelSheet.Cells[Row, Col + 4] = pGeo[0].X;
                                    }
                                    if (bZAware)
                                    {
                                        ExcelSheet.Cells[Row, Col + 5] = pGeo[0].Z;
                                    }
                                }
                            }
                        }
                    }

                    stepProgressor.Step();
                    progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";
                    if (!trackCancel.Continue())
                    {
                        return(false);
                    }


                    Feat = FCursor.NextFeature();
                }

                //Hide Columns
                Col = 0;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields in data also
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Autofit
                        ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                        ExcelRange.EntireColumn.AutoFit();

                        //Hide column if invisible in ArcMap
                        if (TableFields.get_FieldInfo(j).Visible == false)
                        {
                            ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                            ExcelRange.EntireColumn.Hidden = true;
                        }
                    }
                }
                return(true);
            }
            catch
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ExportXLError"));
                return(true);
            }
            finally
            {
                FC       = null;
                Subtypes = null;

                TableProperties = null;
                if (EnumTableProperties != null)
                {
                    Marshal.ReleaseComObject(EnumTableProperties);
                }

                EnumTableProperties  = null;
                TableProperty        = null;
                TableCharacteristics = null;
                FeatSel      = null;
                DisplayTable = null;
                Table        = null;
                LayerFields  = null;
                TableFields  = null;
                LayerTest    = null;
                if (Cursor != null)
                {
                    Marshal.ReleaseComObject(Cursor);
                }
                Cursor = null;

                if (FCursor != null)
                {
                    Marshal.ReleaseComObject(FCursor);
                }
                FCursor          = null;
                CurField         = null;
                Domain           = null;
                CodedValueDomain = null;
                Feat             = null;
                pGeo             = null;

                missing    = null;
                sheet      = null;
                ExcelSheet = null;
                ExcelRange = null;
                style      = null;
            }
        }
Ejemplo n.º 22
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;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 23
0
 public DataTable GetDataTableByDistrictName()
 {
     try
     {
         FacilityClass fac = FacilityClassManager.Instance.GetFacilityClassByName(_sysFieldName);
         if (fac == null)
         {
             return(null);
         }
         List <FieldInfo> listFI = fac.FieldInfoCollection;
         _dt = new DataTable();
         foreach (FieldInfo fi in listFI)
         {
             if (fi.CanStats)
             {
                 DataColumn dc = new DataColumn(fi.Alias);
                 if (ColumnExist(_dt, fi.Alias))
                 {
                     continue;
                 }
                 _dt.Columns.Add(dc);
             }
         }
         if (_dict != null && _dict.ContainsKey(_disName))
         {
             List <IFeature> listF = _dict[_disName];
             foreach (IFeature fea in listF)
             {
                 DataRow dr = _dt.NewRow();
                 foreach (FieldInfo fi in listFI)
                 {
                     if (fi.CanStats)
                     {
                         int index = fea.Fields.FindField(fi.Name);
                         if (index == -1)
                         {
                             continue;
                         }
                         IDomain pDomain = fea.Fields.get_Field(index).Domain;
                         if (pDomain != null && pDomain.Type == esriDomainType.esriDTCodedValue)
                         {
                             ICodedValueDomain pCD = pDomain as ICodedValueDomain;
                             for (int i = 0; i < pCD.CodeCount; i++)
                             {
                                 if (object.Equals(pCD.get_Value(i), fea.get_Value(index)))
                                 {
                                     dr[fi.Alias] = pCD.get_Name(i);
                                 }
                             }
                         }
                         else if (fi.DataType == "Decimal")
                         {
                             dr[fi.Alias] = Math.Round(Convert.ToDouble(fea.get_Value(index)), 2).ToString();
                         }
                         else
                         {
                             dr[fi.Alias] = fea.get_Value(index).ToString();
                         }
                     }
                 }
                 _dt.Rows.Add(dr);
             }
         }
         return(_dt);
     }
     catch (System.Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 24
0
 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;
     }
 }
Ejemplo n.º 25
0
        private string method_7(IRow irow_0, IField ifield_0, int int_0)
        {
            int               num;
            string            str     = irow_0.get_Value(int_0).ToString();
            ISubtypes         table   = irow_0.Table as ISubtypes;
            ICodedValueDomain domain  = null;
            IList             list    = new ArrayList();
            IDomain           domain2 = null;

            if ((table != null) && table.HasSubtype)
            {
                if (table.SubtypeFieldName == ifield_0.Name)
                {
                    try
                    {
                        str = table.get_SubtypeName((irow_0 as IRowSubtypes).SubtypeCode);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    domain2 = table.get_Domain((irow_0 as IRowSubtypes).SubtypeCode, ifield_0.Name);
                    if (domain2 is ICodedValueDomain)
                    {
                        domain = domain2 as ICodedValueDomain;
                        if (ifield_0.IsNullable)
                        {
                            list.Add("<空>");
                        }
                        num = 0;
                        while (num < domain.CodeCount)
                        {
                            if (str == domain.get_Value(num).ToString())
                            {
                                str = domain.get_Name(num);
                                break;
                            }
                            num++;
                        }
                    }
                }
            }
            domain2 = ifield_0.Domain;
            if (domain2 != null)
            {
                if (domain2 is ICodedValueDomain)
                {
                    domain = domain2 as ICodedValueDomain;
                    num    = 0;
                    while (num < domain.CodeCount)
                    {
                        if (str == domain.get_Value(num).ToString())
                        {
                            return(domain.get_Name(num));
                        }
                        num++;
                    }
                }
                return(str);
            }
            string       name         = (irow_0.Table as IDataset).Name;
            CodeDomainEx codeDomainEx = CodeDomainManage.GetCodeDomainEx(ifield_0.Name, name);

            if (codeDomainEx == null)
            {
                return(str);
            }
            if ((codeDomainEx.ParentIDFieldName == null) || (codeDomainEx.ParentIDFieldName.Length == 0))
            {
                NameValueCollection codeDomain = codeDomainEx.GetCodeDomain();
                for (num = 0; num < codeDomain.Count; num++)
                {
                    string str3 = codeDomain.Keys[num];
                    if (str == codeDomain[str3])
                    {
                        str = str3;
                    }
                }
                return(str);
            }
            return(codeDomainEx.FindName(str));
        }