Exemple #1
0
        private void InitControls()
        {
            lbx_Value.Items.Clear();
            //te_Condition.Text = (this.featureLayer as IFeatureLayerDefinition).DefinitionExpression;
            ITableFields     tableFields = featureLayer as ITableFields;
            IGeoFeatureLayer geoFL       = featureLayer as IGeoFeatureLayer;
            IField           field;

            _dt = new DataTable();
            _dt.Columns.AddRange(new DataColumn[] { new DataColumn("Name"), new DataColumn("AliasName"), new DataColumn("Object", typeof(object)) });
            if (geoFL.Renderer is IUniqueValueRenderer)
            {
                field = tableFields.get_Field(tableFields.FindField((geoFL.Renderer as IUniqueValueRenderer).get_Field(0)));
                AddRowToDT(field);
            }
            else if (geoFL.Renderer is ISimpleRenderer)
            {
                for (int i = 0; i < tableFields.FieldCount; i++)
                {
                    if (tableFields.get_FieldInfo(i).Visible)
                    {
                        field = tableFields.get_Field(i);
                        switch (field.Type)
                        {
                        case esriFieldType.esriFieldTypeOID:
                        case esriFieldType.esriFieldTypeSmallInteger:
                        case esriFieldType.esriFieldTypeInteger:
                        case esriFieldType.esriFieldTypeSingle:
                        case esriFieldType.esriFieldTypeDouble:
                        case esriFieldType.esriFieldTypeDate:
                        case esriFieldType.esriFieldTypeString:
                            AddRowToDT(field);
                            break;
                        }
                    }
                }
            }
            this.gridControl1.DataSource = _dt;
        }
Exemple #2
0
        /// <summary>Returns the index of a particular field given the Name or Alias of a given field.</summary>
        /// <param name="o">Object that could either be a layer, featurelayer, featureclass, feature, row, table, standalone table or tablefields</param>
        /// <param name="FieldName"> Field name to search</param>
        /// <returns>Integer denoting the field index</returns>
        public int FindField(object o, string FieldName)
        {
            try
            {
                if (o is ILayer)
                {
                    ILayer layer = (ILayer)o;
                    if (!(layer == null))
                    {
                        IFeatureLayer featurelayer = (IFeatureLayer)layer;
                        if (!(featurelayer == null))
                        {
                            int i = featurelayer.FeatureClass.Fields.FindField(FieldName);
                            if (i > -1)
                            {
                                return(i);
                            }
                            else
                            {
                                for (int j = 0; j < featurelayer.FeatureClass.Fields.FieldCount; j++)
                                {
                                    if (FieldName.CompareTo(featurelayer.FeatureClass.Fields.get_Field(j).AliasName) == 0)
                                    {
                                        return(j);
                                    }
                                }
                            }
                        }
                    }
                }
                if (o is IFeatureLayer)
                {
                    IFeatureLayer featurelayer = (IFeatureLayer)o;
                    if (!(featurelayer == null))
                    {
                        int i = featurelayer.FeatureClass.Fields.FindField(FieldName);
                        if (i > -1)
                        {
                            return(i);
                        }
                        else
                        {
                            for (int j = 0; j < featurelayer.FeatureClass.Fields.FieldCount; j++)
                            {
                                if (FieldName.CompareTo(featurelayer.FeatureClass.Fields.get_Field(j).AliasName) == 0)
                                {
                                    return(j);
                                }
                            }
                        }
                    }
                }
                if (o is IFeatureClass)
                {
                    IFeatureClass featureclass = (IFeatureClass)o;
                    if (!(featureclass == null))
                    {
                        int i = featureclass.Fields.FindField(FieldName);
                        if (i > -1)
                        {
                            return(i);
                        }
                        else
                        {
                            for (int j = 0; j < featureclass.Fields.FieldCount; j++)
                            {
                                if (FieldName.CompareTo(featureclass.Fields.get_Field(j).AliasName) == 0)
                                {
                                    return(j);
                                }
                            }
                        }
                    }
                }
                if (o is IFeature)
                {
                    IFeature feature = (IFeature)o;
                    if (!(feature == null))
                    {
                        int i = feature.Fields.FindField(FieldName);
                        if (i > -1)
                        {
                            return(i);
                        }
                        else
                        {
                            for (int j = 0; j < feature.Fields.FieldCount; j++)
                            {
                                if (FieldName.CompareTo(feature.Fields.get_Field(j).AliasName) == 0)
                                {
                                    return(j);
                                }
                            }
                        }
                    }
                }
                if (o is IRow)
                {
                    IRow row = (IRow)o;
                    if (!(row == null))
                    {
                        int i = row.Fields.FindField(FieldName);
                        if (i > -1)
                        {
                            return(i);
                        }
                        else
                        {
                            for (int j = 0; j < row.Fields.FieldCount; j++)
                            {
                                if (FieldName.CompareTo(row.Fields.get_Field(j).AliasName) == 0)
                                {
                                    return(j);
                                }
                            }
                        }
                    }
                }
                if (o is ITable)
                {
                    ITable table = (ITable)o;
                    if (!(table == null))
                    {
                        int i = table.FindField(FieldName);
                        if (i > -1)
                        {
                            return(i);
                        }
                        else
                        {
                            for (int j = 0; j < table.Fields.FieldCount; j++)
                            {
                                if (FieldName.CompareTo(table.Fields.get_Field(j).AliasName) == 0)
                                {
                                    return(j);
                                }
                            }
                        }
                    }
                }
                if (o is IStandaloneTable)
                {
                    IStandaloneTable standalonetable = (IStandaloneTable)o;
                    int i = standalonetable.Table.FindField(FieldName);
                    if (i > -1)
                    {
                        return(i);
                    }
                    else
                    {
                        for (int j = 0; j < standalonetable.Table.Fields.FieldCount; j++)
                        {
                            if (FieldName.CompareTo(standalonetable.Table.Fields.get_Field(j).AliasName) == 0)
                            {
                                return(j);
                            }
                        }
                    }
                }
                if (o is ITableFields)
                {
                    ITableFields tablefields = (ITableFields)o;
                    int          i           = tablefields.FindField(FieldName);
                    if (i > -1)
                    {
                        return(i);
                    }
                    else
                    {
                        for (int j = 0; j < tablefields.FieldCount; j++)
                        {
                            if (FieldName.CompareTo(tablefields.get_FieldInfo(j).Alias) == 0)
                            {
                                return(j);
                            }
                        }
                    }
                }
                if (o is IGeoFeatureLayer)
                {
                    IGeoFeatureLayer geofeaturelayer = (IGeoFeatureLayer)o;
                    if (!(geofeaturelayer == null))
                    {
                        IFeatureLayer featurelayer = (IFeatureLayer)geofeaturelayer;
                        if (!(featurelayer == null))
                        {
                            int i = featurelayer.FeatureClass.Fields.FindField(FieldName);
                            if (i > -1)
                            {
                                return(i);
                            }
                            else
                            {
                                for (int j = 0; j < featurelayer.FeatureClass.Fields.FieldCount; j++)
                                {
                                    if (FieldName.CompareTo(featurelayer.FeatureClass.Fields.get_Field(j).AliasName) == 0)
                                    {
                                        return(j);
                                    }
                                }
                            }
                        }
                    }
                }
                if (o is IFields)
                {
                    IFields fields = (IFields)o;
                    if (!(fields == null))
                    {
                        int i = fields.FindField(FieldName);
                        if (i > -1)
                        {
                            return(i);
                        }
                        else
                        {
                            for (int j = 0; j < fields.FieldCount; j++)
                            {
                                if (FieldName.CompareTo(fields.get_Field(j).AliasName) == 0)
                                {
                                    return(j);
                                }
                            }
                        }
                    }
                }

                return(-1);
            }
            catch (Exception ex)
            {
                if (SupressMessaging == false)
                {
                    MessageBox.Show(ex.Message, "Release COM Objects", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(-1);
        }
Exemple #3
0
        /// <summary>
        ///  保存图层属性
        /// </summary>
        /// <returns></returns>
        public bool SaveProperties()
        {
            if (txtLayerName.Text.Trim() == "")
            {
                return(false);
            }
            if (this.rdoGroupScale.SelectedIndex == 1)
            {
                try
                {
                    if (double.Parse(txtScaleMin.Text) <= double.Parse(txtScaleMax.Text))
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            m_FeaLay.Name = txtLayerName.Text;
            if (this.rdoGroupScale.SelectedIndex == 0)
            {
                m_FeaLay.MinimumScale = 0;
                m_FeaLay.MaximumScale = 0;
            }
            else if (this.rdoGroupScale.SelectedIndex == 1)
            {
                m_FeaLay.MinimumScale = double.Parse(txtScaleMin.Text);
                m_FeaLay.MaximumScale = double.Parse(txtScaleMax.Text);
            }

            (m_FeaLay as ILayerGeneralProperties).LayerDescription = txtDescription.Text; //地图描述

            Class.Item item = cboDisplayField.SelectedItem as Class.Item;
            m_FeaLay.DisplayField = item.Value.ToString();                                //主显示字段
            m_FeaLay.Visible      = chkVisible.Checked;                                   //可见性
            (m_FeaLay as ILayerEffects).Transparency = short.Parse(txtTransparency.Text); //透明度

            m_FeaLay.ShowTips = chkShowTip.Checked;                                       //显示主显示字段
            if (m_FeaLay is IGeoFeatureLayer)
            {
                if (chkLabelAll.Checked)
                {
                    ChangeLayerAnno(m_FeaLay);
                }

                (m_FeaLay as IGeoFeatureLayer).DisplayAnnotation = chkLabelAll.Checked; //标注图层中所有要素
            }

            m_FeaLay.ScaleSymbols = chkScaleSymbol.Checked;//符号随比例尺缩放


            ////////字段信息
            m_pTableFields = m_FeaLay as ITableFields;
            for (int i = 0; i < listViewFieldInfo.Nodes.Count; i++)
            {
                int index = m_pTableFields.FindField(listViewFieldInfo.Nodes[i][2].ToString());
                if (index > -1)
                {
                    IFieldInfo pFieldInfo = m_pTableFields.get_FieldInfo(index);
                    pFieldInfo.Visible = listViewFieldInfo.Nodes[i].Checked == true ? true : false;
                }
            }

            if (!CheckCondition(this.m_FeaLay, txtCondition.Text))
            {
                MessageBox.Show("查询条件错误!");
            }
            else
            {
                (this.m_FeaLay as IFeatureLayerDefinition).DefinitionExpression = txtCondition.Text;
                m_MapCtrl.ActiveView.Refresh();
            }

            return(true);
        }