www.pudn.com > MyVR.rar > QueryForm.cs, change:2008-06-05,size:7984b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
 
using ESRI.ArcGIS.esriSystem; 
using ESRI.ArcGIS.SystemUI; 
using ESRI.ArcGIS.Geometry; 
using ESRI.ArcGIS.Display; 
using ESRI.ArcGIS.Geodatabase; 
using ESRI.ArcGIS.Carto; 
using ESRI.ArcGIS.Controls; 
using ESRI.ArcGIS.Analyst3D; 
 
namespace MyVR 
{ 
    public partial class QueryForm : Form 
    { 
        //public IMap pMap; 
        //public int iLayerIndex; 
        //public int iFieldIndex; 
        //public FrmQuery(IMapControl2 pFMapControl) 
        //{ 
        //    InitializeComponent(); 
        //    pMapControl = pFMapControl; 
        //    pMap = pFMapControl.Map; 
 
        //} 
        public ISceneControl pS;//q3 
        public IBasicMap pBM; 
        public  IScene pScene; 
        public int iLayerIndex; 
        public int iFieldIndex; 
 
         
        public QueryForm() 
        { 
            InitializeComponent(); 
        } 
        public QueryForm(ISceneControl pSceneControl)//q4 
        { 
            InitializeComponent(); 
            pS = pSceneControl; 
           // pScene = GetScene() ; 
            pScene = pS.SceneGraph.Scene;  
            
  
        } 
        private void QueryForm_Load(object sender, EventArgs e) 
        { 
            //ILayer pLayer; 
            //for (int i = 0; i < pMap.LayerCount; i++) 
            //{ 
            //    pLayer = pMap.get_Layer(i); 
            //    cmbLayers.Items.Add(pLayer.Name); 
            //} 
            ILayer pLayer; 
            for (int i = 0; i < pScene.LayerCount; i++) 
            { 
                pLayer = pScene.get_Layer(i); 
                cmbLayers.Items.Add(pLayer.Name); 
            } 
 
        } 
 
        private void cmbLeyers_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            iLayerIndex = cmbLayers.Items.IndexOf(cmbLayers.Text); 
            cmbFields.Items.Clear(); 
        } 
 
        
 
        private void txtValue_TextChanged(object sender, EventArgs e) 
        { 
 
        } 
 
        private void btnQuery_Click(object sender, EventArgs e) 
        { 
             
            //IActiveView pActiveView; 
            //pActiveView = (IActiveView)pMap; 
            //pMap.ClearSelection(); 
            //pActiveView.Refresh(); 
 
            //IQueryFilter pQueryFilter = new QueryFilterClass();          
 
            //IFeatureLayer pFeatureLayer; 
            //pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex); 
            IActiveView pActiveView; 
            pActiveView = (IActiveView)pScene; 
            pScene.ClearSelection(); 
       //     pActiveView.Refresh();////////////////////////////////////////modify 
            IQueryFilter pQueryFilter = new QueryFilterClass(); 
            IFeatureLayer pFeatureLayer; 
            pFeatureLayer = (IFeatureLayer)pScene.get_Layer(iLayerIndex); 
            
            //IFields pFields; 
            //pFields = pFeatureLayer.FeatureClass.Fields; 
            //IField pField; 
            //pField=pFields.get_Field(iFieldIndex); 
            IFields pFields; 
            pFields = pFeatureLayer.FeatureClass.Fields; 
            IField pField; 
            pField = pFields.get_Field(iFieldIndex); 
 
            //switch (pField.Type) 
            //{ 
            //    case esriFieldType.esriFieldTypeString: 
            //        pQueryFilter.WhereClause = cmbFields.Text + " = '" + txtValue.Text + "'"; 
            //        break; 
            //    case esriFieldType.esriFieldTypeDouble: 
            //    case esriFieldType.esriFieldTypeInteger: 
            //    case esriFieldType.esriFieldTypeSingle: 
            //    case esriFieldType.esriFieldTypeSmallInteger: 
            //        pQueryFilter.WhereClause = cmbFields.Text + " = " + txtValue.Text; 
            //        break; 
            //} 
            switch (pField.Type) 
            { 
                case esriFieldType.esriFieldTypeString : 
                    pQueryFilter.WhereClause = cmbFields.Text + "='" + txtValue.Text + "'"; 
                    break; 
                case esriFieldType .esriFieldTypeDouble : 
                case esriFieldType .esriFieldTypeInteger : 
                case esriFieldType .esriFieldTypeSingle : 
                case esriFieldType .esriFieldTypeSmallInteger : 
                    pQueryFilter.WhereClause = cmbFields.Text + "=" + txtValue.Text; 
                    break; 
 
            } 
 
            IFeatureCursor pFeatureCursor; 
            pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false); 
 
            IFeature pFeature; 
            pFeature = pFeatureCursor.NextFeature(); 
            while (pFeature != null) 
            { 
                pScene.SelectFeature(pFeatureLayer, pFeature); 
                pFeature = pFeatureCursor.NextFeature(); 
            } 
 
 
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); 
        } 
 
        private void btnCancle_Click(object sender, EventArgs e) 
        { 
            this.Close(); 
        } 
 
        private void cmbFields_TextChanged(object sender, EventArgs e) 
        { 
            iFieldIndex = cmbFields.Items.IndexOf(cmbFields.Text); 
        } 
 
        private void cmbFields_DropDown(object sender, EventArgs e) 
        { 
        //    cmbFields.Items.Clear(); 
        //    IFeatureLayer pFeatureLayer; 
        //    pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex); 
 
        //    IFields pFields; 
        //    pFields = pFeatureLayer.FeatureClass.Fields; 
 
 
        //    for (int i = 0; i < pFields.FieldCount; i++) 
        //    { 
        //        string fieldName; 
        //        fieldName = pFields.get_Field(i).Name; 
        //        cmbFields.Items.Add(fieldName); 
        //    } 
            cmbFields.Items.Clear(); 
            IFeatureLayer pFeatureLayer; 
            pFeatureLayer = (IFeatureLayer)pScene.get_Layer(iLayerIndex); 
            IFields pFields; 
            pFields = pFeatureLayer.FeatureClass.Fields; 
            for (int i = 0; i < pFields.FieldCount; i++) 
            { 
                string fieldName; 
                fieldName = pFields.get_Field(i).Name; 
                cmbFields.Items.Add(fieldName); 
            } 
        } 
 
        private void btnShowAllValue_Click(object sender, EventArgs e) 
        { 
            if (cmbFields.Text == "") 
            { 
                MessageBox.Show("请选择字段名", "提升", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
                return; 
            } 
            listBoxValue.Items.Clear(); 
            IFeatureLayer pFeatureLayer; 
            pFeatureLayer = (IFeatureLayer)pScene.get_Layer(iLayerIndex); 
 
            IFeatureCursor pFeatureCursor; 
            pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false); 
             
            IFeature pFeature; 
            pFeature = pFeatureCursor.NextFeature(); 
            while (pFeature != null) 
            { 
                string fldValue; 
                if (cmbFields.Text == "Shape") 
                { 
                    fldValue = Convert.ToString(pFeature.Shape.GeometryType); 
                } 
                else 
                    fldValue = Convert.ToString(pFeature.get_Value(iFieldIndex)); 
 
                listBoxValue.Items.Add(fldValue); 
                pFeature = pFeatureCursor.NextFeature(); 
            } 
 
        } 
 
        private void listBoxValue_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            txtValue.Text = Convert.ToString(listBoxValue.SelectedItem); 
        } 
 
        private void btnTables_Click(object sender, EventArgs e) 
        { 
            TableForm tbf = new TableForm(pS, cmbLayers.Text); 
            tbf.Show (); 
        } 
 
 
         
 
    } 
}