Newer
Older
GHFX_REFACTOR / FrmKeywordQuery.cs
xiaowei on 27 Oct 2016 4 KB yxw20161027修改查询功能
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;
using GeoScene.Engine;

namespace Cyberpipe
{
    public partial class FrmKeywordQuery : Office2007Form
    {  
        GSOGlobeControl globeControl1;
        List<string> layerNames = new List<string>();
        GSOFeatureDataset sourcefDataset;

        private MainFrm.DataGridViewDelegate m_InitDataGridViewX1;
        static FrmKeywordQuery frm;
        DataTable table = new DataTable();
        string strLable = "";

        public static void ShowForm(GSOGlobeControl _ctl, List<string> _list, MainFrm.DataGridViewDelegate InitDataGridViewX1)
        {
            if (frm == null)
            {
                frm = new FrmKeywordQuery(_ctl, _list, InitDataGridViewX1);
                frm.Show(_ctl.Parent);
            }
            else
            {
                if (frm.WindowState == FormWindowState.Minimized)
                {
                    frm.WindowState = FormWindowState.Normal;
                }
            }
        }

        private FrmKeywordQuery(GSOGlobeControl _ctl, List<string> _list, MainFrm.DataGridViewDelegate InitDataGridViewX1)
        {
            InitializeComponent();
            globeControl1 = _ctl;
            layerNames = _list;
            m_InitDataGridViewX1 = InitDataGridViewX1;
        }
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmKeywordQuery_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < layerNames.Count; i++)
            {
                cbxLayers.Items.Add(layerNames[i]);
            }
        }
        /// <summary>
        /// 查询按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (cbxLayers.Text != null)
            {
                GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(cbxLayers.Text);
                if (layer == null || comboBoxEx1.SelectedIndex == -1 || textBoxX1.Text.Trim() == "")
                {
                    MessageBox.Show("请选择查询条件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                ClassSearchAnalysis.ResultDataTable(out table, globeControl1, cbxLayers.Text, 
                    comboBoxEx1.SelectedItem.ToString(), textBoxX1.Text.Trim());

                if (table != null && table.Rows.Count > 0)
                {
                    strLable = cbxLayers.Text + " 共有:" + table.Rows.Count + "条";
                    m_InitDataGridViewX1(table, strLable, cbxLayers.Text, true);
                }
                else
                {
                    MessageBox.Show("没有查到符合条件的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
        }
        /// <summary>
        /// 图层下拉框选中项改变事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbxLayers_SelectedIndexChanged(object sender, EventArgs e)
        {            
            comboBoxEx1.Items.Clear();
            GSOLayer m_layer = globeControl1.Globe.Layers.GetLayerByCaption(cbxLayers.SelectedItem.ToString().Trim());//获取当前选择的layer图层
            if (m_layer == null)
                return;
            GSOFeatureLayer flayer = m_layer as GSOFeatureLayer;
            sourcefDataset = m_layer.Dataset as GSOFeatureDataset;
            sourcefDataset.Open();

            for (int j = 0; j < sourcefDataset.FieldCount; j++)
            {
                GSOFieldAttr fieldef = sourcefDataset.GetField(j);
                if (fieldef.Type == EnumFieldType.Text)
                {
                    comboBoxEx1.Items.Add(fieldef.Name);
                }
            }
            //设置当前选择字段为第一个
            if (comboBoxEx1.Items.Count > 0)
            {
                comboBoxEx1.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// 关闭按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void FrmKeywordQuery_FormClosing(object sender, FormClosingEventArgs e)
        {
            m_InitDataGridViewX1(table, strLable, "", false);
            frm = null;
        }

    }
}