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>(); DevComponents.DotNetBar.Controls.DataGridViewX dataGridView1; GSOFeatureDataset sourcefDataset; PanelEx panel; ToolStripStatusLabel toolStripNumbers; ToolStripStatusLabel toolStripFeatureLength; static FrmKeywordQuery frm; public static void ShowForm(GSOGlobeControl _ctl, List<string> _list, DevComponents.DotNetBar.Controls.DataGridViewX _datagridview, PanelEx p, ToolStripStatusLabel t1, ToolStripStatusLabel t2) { if (frm == null) { frm = new FrmKeywordQuery(_ctl, _list, _datagridview, p, t1, t2); frm.Show(_ctl.Parent); } else { if (frm.WindowState == FormWindowState.Minimized) { frm.WindowState = FormWindowState.Normal; } } } private FrmKeywordQuery(GSOGlobeControl _ctl, List<string> _list, DevComponents.DotNetBar.Controls.DataGridViewX _datagridview, PanelEx p, ToolStripStatusLabel t1, ToolStripStatusLabel t2) { InitializeComponent(); globeControl1 = _ctl; layerNames = _list; dataGridView1 = _datagridview; panel = p; toolStripNumbers = t1; toolStripFeatureLength = t2; } /// <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) { MessageBox.Show("请选择图层!"); return; } if (comboBoxEx1.SelectedIndex == -1) { MessageBox.Show("请选择字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (textBoxX1.Text.Trim() == "") { MessageBox.Show("请输入关键字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } sourcefDataset = layer.Dataset as GSOFeatureDataset; sourcefDataset.Open(); string sql = "select " + getpipeLineFields.getFields(cbxLayers.SelectedItem.ToString(), globeControl1) + " from " +layer.Name+" where " + comboBoxEx1.SelectedItem.ToString() + " like '%" + textBoxX1.Text.Trim() + "%'"; DataTable table = OledbHelper.QueryTable(sql); if (table != null && table.Rows.Count > 0) { MainFrm.m_CurrentQueryLayer = cbxLayers.Text; dataGridView1.DataSource = table; panel.Visible = true; toolStripNumbers.Text = " 类型:" + cbxLayers.Text; toolStripFeatureLength.Text = " 共有:" + table.Rows.Count + "条"; } else { MessageBox.Show("没有查到符合条件的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView1.DataSource = null; toolStripNumbers.Text = " 类型:"; toolStripFeatureLength.Text = " 管线里程:"; panel.Visible = false; } } } /// <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) { dataGridView1.DataSource = null; dataGridView1.Refresh(); panel.Visible = false; toolStripNumbers.Text = " 类型:"; toolStripFeatureLength.Text = " 管线里程:"; frm = null; } } }