using System; using System.Data; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; namespace Cyberpipe { public partial class FrmBasicQuery : Office2007Form { private GSOGlobeControl globeControl1; GSOFeatureDataset sourcefDataset; private GSODataset ds; static FrmBasicQuery frm; private MainFrm.DataGridViewDelegate m_InitDataGridViewX1; DataTable table = new DataTable(); // string strLable = ""; private MainFrm.PageControlStuct _pageControl; /// <summary> /// 单例模式 创建并显示窗体 /// </summary> /// <param name="_ctl"></param> /// <param name="_dataGirdView"></param> /// <param name="p"></param> /// <param name="t1"></param> /// <param name="t2"></param> public static void ShowForm(GSOGlobeControl _ctl, MainFrm.DataGridViewDelegate InitDataGridViewX1, MainFrm.PageControlStuct pageControl) { if (frm == null) { frm = new FrmBasicQuery(_ctl, InitDataGridViewX1,pageControl); frm.Show(_ctl.Parent); } else { if (frm.WindowState == FormWindowState.Minimized) { frm.WindowState = FormWindowState.Normal; } } } public FrmBasicQuery(GSOGlobeControl _ctl, MainFrm.DataGridViewDelegate InitDataGridViewX1, MainFrm.PageControlStuct pageControl) { InitializeComponent(); globeControl1 = _ctl; m_InitDataGridViewX1 = InitDataGridViewX1; _pageControl = pageControl; } private void comboBoxEx1_SelectedIndexChanged(object sender, EventArgs e) { checkBoxX1.Enabled = true; checkBoxX2.Enabled = false; checkBoxX3.Enabled = false; checkBoxX4.Enabled = false; checkBoxX5.Enabled = false; checkBoxX6.Enabled = false; cbxFields.Items.Clear();//字段 lbxFieldValues.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; ds = m_layer.Dataset; sourcefDataset = ds as GSOFeatureDataset; sourcefDataset.Open(); for (int j = 0; j < sourcefDataset.FieldCount; j++) { GSOFieldAttr fieldef = sourcefDataset.GetField(j); cbxFields.Items.Add(fieldef.Name); } cbxFields.SelectedIndex = 0; } string str1; string str2; /// <summary> /// 字段名列表选中项改变事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbxFields_SelectedIndexChanged(object sender, EventArgs e) { checkBoxX1.Enabled = true; checkBoxX2.Enabled = false; checkBoxX3.Enabled = false; checkBoxX4.Enabled = false; checkBoxX5.Enabled = false; checkBoxX6.Enabled = false; lbxFieldValues.Items.Clear(); for (int j = 0; j < sourcefDataset.FieldCount; j++) { GSOFieldAttr fieldef = sourcefDataset.GetField(j); if (cbxFields.SelectedItem.ToString() == fieldef.Name && fieldef.Type == EnumFieldType.Text) { str1 = "'"; str2 = "'"; } } GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(cbxLayers.Text.Trim()); if (layer == null) { MessageBox.Show("图层不存在", "提示"); return; } ClassSearchAnalysis.ResultDistinctDataTable(out table, cbxLayers.Text.Trim(), cbxFields.Text); for (int i = 0; i < table.Rows.Count; i++) { DataRow dr = table.Rows[i]; string colString1 = dr[0].ToString(); if (colString1.Trim() == "") { continue; } string col = str1 + colString1 + str2; lbxFieldValues.Items.Add(col); } string strFiled = cbxFields.SelectedItem.ToString(); if (table.Rows[0][strFiled] is string) { checkBoxX1.Enabled = true; checkBoxX2.Enabled = false; checkBoxX3.Enabled = false; checkBoxX4.Enabled = false; checkBoxX5.Enabled = false; checkBoxX6.Enabled = true; } else if (table.Rows[0][strFiled] is int || table.Rows[0][strFiled] is float || table.Rows[0][strFiled] is double) { checkBoxX1.Enabled = true; checkBoxX2.Enabled = true; checkBoxX3.Enabled = true; checkBoxX4.Enabled = true; checkBoxX5.Enabled = true; checkBoxX6.Enabled = true; } else if (table.Rows[0][strFiled] is decimal) { checkBoxX1.Enabled = true; checkBoxX2.Enabled = true; checkBoxX3.Enabled = true; checkBoxX4.Enabled = true; checkBoxX5.Enabled = true; checkBoxX6.Enabled = false; } str1 = ""; str2 = ""; } /// <summary> /// 窗体初始化事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmBasicQuery_Load(object sender, EventArgs e) { for (int i = 0; i < globeControl1.Globe.Layers.Count; i++)//获取树节点后中所有的layer图层 { GSOLayer layer = globeControl1.Globe.Layers[i]; if (layer != null && layer.Dataset != null && layer.Dataset.IsFeatureDataset) { string name = layer.Name; if (layer.Type == EnumLayerType.FeatureLayer && !name.Contains("\\")&&!name.Contains("施工")) { if(name.EndsWith("管线")||name.EndsWith("附属物")||name.EndsWith("管点")) cbxLayers.Items.Add(name); } } } } /// <summary> /// 查询按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { if (cbxLayers.SelectedIndex == -1 || cbxFields.SelectedIndex == -1) { MessageBox.Show("请选择图层和字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (lbxFieldValues.SelectedItem != null) { try { string s = GetMathStr(); GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(cbxLayers.Text.Trim()); if (layer == null) { MessageBox.Show("图层不存在", "提示"); return; } // ClassSearchAnalysis.ResultDataTable(out table, globeControl1, cbxLayers.Text, // cbxFields.Text + s + lbxFieldValues.SelectedItem); // // if (table != null && table.Rows.Count > 0) // { // strLable = cbxLayers.Text + " 共有:" + table.Rows.Count + "个"; // m_InitDataGridViewX1(table, strLable, cbxLayers.Text, true); // } PaginationUtil.ResetPagination(); int total = PaginationUtil.CountSql(cbxLayers.Text,cbxFields.Text + s + lbxFieldValues.SelectedItem); if (total > 0) { string strLable = cbxLayers.Text + " 共有:" + total + "个"; string sql = PaginationUtil.GetQuerySql(globeControl1, cbxLayers.Text,cbxFields.Text + s + lbxFieldValues.SelectedItem); PaginationUtil pagination = PaginationUtil.InitPagination(sql, total, _pageControl, m_InitDataGridViewX1, strLable, cbxLayers.Text); pagination.FillDataGridView(); } else { MessageBox.Show("没有查找到符合条件的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch(Exception ex) { LogHelper.Error(ex.Message); } } else { MessageBox.Show("请选择字段值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private string GetMathStr() { string mathStr = ""; if (checkBoxX1.Checked) { mathStr = "="; } else if (checkBoxX2.Checked) { mathStr = "<"; } else if (checkBoxX3.Checked) { mathStr = ">"; } else if (checkBoxX4.Checked) { mathStr = "<="; } else if (checkBoxX5.Checked) { mathStr = ">="; } else if (checkBoxX6.Checked) { mathStr = "<>"; } return mathStr; } /// <summary> /// 窗体关闭事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmBasicQuery_FormClosing(object sender, FormClosingEventArgs e) { m_InitDataGridViewX1(null, "", "", false); frm = null; } /// <summary> /// 取消按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX3_Click(object sender, EventArgs e) { Close(); } } }