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; namespace Cyberpipe { public partial class FrmDiameterQuery : Office2007Form { GSOGlobeControl globeControl1; List<string> layerNames = new List<string>(); DevComponents.DotNetBar.Controls.DataGridViewX dataGridView1; PanelEx panel; ToolStripStatusLabel toolStripNumbers; ToolStripStatusLabel toolStripFeatureLength; int value = 0; static FrmDiameterQuery 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 FrmDiameterQuery(_ctl, _list, _datagridview, p, t1, t2); frm.Show(_ctl.Parent); } else { if (frm.WindowState == FormWindowState.Minimized) { frm.WindowState = FormWindowState.Normal; } } } public FrmDiameterQuery(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 FrmDiameterSel_Load(object sender, EventArgs e) { for (int i = 0; i < layerNames.Count; i++) { comboBoxEx1.Items.Add(layerNames[i]); } //if (comboBoxEx2.Items.Count > 0) //{ // comboBoxEx2.SelectedIndex = -1; //} value = comboBoxEx2.Location.X - textBoxX2.Location.X; textBoxX2.Visible = false; textBoxX2.Text = ""; labelX4.Visible = false; if (!isBetween) { textBoxX1.Location = new Point(textBoxX1.Location.X - value, textBoxX1.Location.Y); labelX3.Location = new Point(labelX3.Location.X - value, textBoxX1.Location.Y); comboBoxEx2.Location = new Point(comboBoxEx2.Location.X - value, comboBoxEx2.Location.Y); isBetween = true; } } /// <summary> /// 键盘按键按下事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBoxX1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8) { e.Handled = true;//屏蔽 } } bool isBetween = false; /// <summary> /// 下拉框选中项改变事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBoxEx2_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxEx2.SelectedIndex == 3) { textBoxX2.Visible = true; labelX4.Visible = true; if (isBetween) { textBoxX1.Location = new Point(textBoxX1.Location.X + value, textBoxX1.Location.Y); labelX3.Location = new Point(labelX3.Location.X + value, textBoxX1.Location.Y); comboBoxEx2.Location = new Point(comboBoxEx2.Location.X + value, comboBoxEx2.Location.Y); isBetween = false; } } else { textBoxX2.Visible = false; textBoxX2.Text = ""; labelX4.Visible = false; if (!isBetween) { textBoxX1.Location = new Point(textBoxX1.Location.X - value, textBoxX1.Location.Y); labelX3.Location = new Point(labelX3.Location.X - value, textBoxX1.Location.Y); comboBoxEx2.Location = new Point(comboBoxEx2.Location.X - value, comboBoxEx2.Location.Y); isBetween = true; } } } /// <summary> /// 确定按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { if (comboBoxEx1.SelectedIndex == -1) { MessageBox.Show("请选择管线图层!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); return; } GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxEx1.Text.Trim()); if (layer == null) { MessageBox.Show("图层不存在", "提示"); return; } if (textBoxX1.Text == "" || (textBoxX2.Visible == true && textBoxX2.Text == "")) { MessageBox.Show("请输入管径范围!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (textBoxX2.Visible == true && textBoxX2.Text != "") { try { if (Convert.ToInt32(textBoxX2.Text) > Convert.ToInt32(textBoxX1.Text)) { MessageBox.Show("管径范围最小值大于最大值,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (Exception ex) { LogError.PublishError(ex); MessageBox.Show("请输入正确的管径范围!"); return; } } string type = ""; if(comboBoxEx1.Text.IndexOf("燃气")>-1) { type = "燃气"; } else if(comboBoxEx1.Text.IndexOf("污水")>-1 || comboBoxEx1.Text.IndexOf("雨水")>-1) { type = "排水"; } string sql = "select " + getpipeLineFields.getFields(comboBoxEx1.Text, globeControl1) + " from " + layer.Name + " where 管径_毫米"; if (comboBoxEx2.SelectedIndex == 0) { sql += ">" +textBoxX1.Text; } else if (comboBoxEx2.SelectedIndex == 1) { sql += "<" + textBoxX1.Text; } else if (comboBoxEx2.SelectedIndex == 2) { sql += "=" + textBoxX1.Text; } else if (comboBoxEx2.SelectedIndex == 3) { sql += ">" + textBoxX2.Text + "and 管径_毫米<"+ textBoxX1.Text; } DataTable table = OledbHelper.QueryTable(sql); if (table!=null && table.Rows.Count>0) { MainFrm.m_CurrentQueryLayer = comboBoxEx1.Text; dataGridView1.DataSource = table; panel.Visible = true; toolStripNumbers.Text = " 类型:" + comboBoxEx1.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 buttonX3_Click(object sender, EventArgs e) { Close(); } /// <summary> /// 窗体关闭事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmDiameterQuery_FormClosing(object sender, FormClosingEventArgs e) { dataGridView1.DataSource = null; dataGridView1.Refresh(); panel.Visible = false; toolStripNumbers.Text = " 类型:"; toolStripFeatureLength.Text = " 管线里程:"; frm = null; } } }