Newer
Older
GHFX_REFACTOR / Backup / FrmMaterialSel.cs
wxn on 2 Nov 2016 9 KB 提交
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 FrmMaterialSel : Office2007Form
    {
        GSOGlobeControl globeControl1;
        List<string> layerNames = new List<string>();
        DevComponents.DotNetBar.Controls.DataGridViewX dataGridView1;
        PanelEx panel;
        ToolStripStatusLabel toolStripNumbers;
        ToolStripStatusLabel toolStripFeatureLength;

        static FrmMaterialSel 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 FrmMaterialSel(_ctl, _list, _datagridview, p, t1, t2);
                frm.Show(_ctl.Parent);
            }
            else
            {
                if (frm.WindowState == FormWindowState.Minimized)
                {
                    frm.WindowState = FormWindowState.Normal;
                }
            }
        }

        public FrmMaterialSel(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 FrmMaterialSel_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < layerNames.Count; i++)
            {
                if (!comboBoxEx1.Items.Contains(layerNames[i]))
                {
                    comboBoxEx1.Items.Add(layerNames[i]);
                }
            }
        }
        /// <summary>
        /// 下拉框选中项事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBoxEx1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxEx1.Text.Trim());
            if (layer == null)
            {
                MessageBox.Show("图层不存在", "提示");
                return;
            }
            string sql = "select distinct 材质 from " + layer.Name;
            DataTable table = OledbHelper.QueryTable(sql);
            if (table.Rows.Count > 0)
            {
                listBox1.Items.Clear();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (table.Rows[i][0].ToString() == "")
                    {
                        listBox1.Items.Add("无");
                    }
                    else
                    {
                        listBox1.Items.Add(table.Rows[i][0].ToString());
                    }
                }
            }

            listBox2.Items.Clear();
        }
        /// <summary>
        /// 将所有材质类型列表中的选中项添加到查询材质类型列表中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count>0)
            {
                for (int i = 0; i < listBox1.SelectedItems.Count; i++)
                {
                    for (int j = 0; j < listBox2.Items.Count; j++)
                    {
                        if (listBox1.SelectedItems[i].ToString() == listBox2.Items[j].ToString())
                        {
                            listBox2.Items.RemoveAt(j);
                            break;
                        }                       
                    }
                    listBox2.Items.Add(listBox1.SelectedItems[i]);
                }
            }
            else
            {
                MessageBox.Show("请选中一种所有材质类型!");
            }
        }
        /// <summary>
        /// 查询按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (listBox2.Items.Count > 0)
            {
                string type = "";
                if (comboBoxEx1.Text.IndexOf("燃气") > -1)
                {
                    type = "燃气";
                }
                else if (comboBoxEx1.Text.IndexOf("污水") > -1 || comboBoxEx1.Text.IndexOf("雨水") > -1)
                {
                    type = "排水";
                }
                //string sql = "select " + Utility.Query_Fields[type] + " from " + comboBoxEx1.Text + " where 材质='";
                GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxEx1.Text.Trim());
                if (layer == null)
                {
                    MessageBox.Show("图层不存在", "提示");
                    return;
                }
                string sql = "select " + getpipeLineFields.getFields(comboBoxEx1.Text, globeControl1) + " from " + layer.Name + " where 材质='";
                for (int i = 0; i < listBox2.Items.Count; i++)
                {
                    if (i == 0)
                    {
                        if (listBox2.Items[i].ToString() == "无")
                        {
                            sql += "' ";
                        }
                        else
                        {
                            sql += listBox2.Items[i].ToString() + "' ";
                        }
                    }
                    else
                    {
                        if (listBox2.Items[i].ToString() == "无")
                        {
                            sql += " or 材质=''";
                        }
                        else
                        {
                            sql += " or 材质='" + listBox2.Items[i].ToString() + "'";
                        }
                    }
                }
                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;
                }

            }
            else
            {
                MessageBox.Show("请选择要查询的材质类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// 删除按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem!=null)
            {
                listBox2.Items.RemoveAt(listBox2.SelectedIndex);
            }
            else
            {
                MessageBox.Show("请选择要删除的项!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }
        /// <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 FrmMaterialSel_FormClosing(object sender, FormClosingEventArgs e)
        {
            dataGridView1.DataSource = null;
            dataGridView1.Refresh();
            panel.Visible = false;
            toolStripNumbers.Text = " 类型:";
            toolStripFeatureLength.Text = " 管线里程:";

            frm = null;
        }
        /// <summary>
        /// 删除查询材质类型列表中的选中项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX4_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedItems.Count > 0)
            {
                for (int i = 0; i < listBox2.SelectedItems.Count; i++)
                {
                    listBox2.Items.Remove(listBox2.SelectedItems[i]);
                    i--;
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的查询材质类型!");    
            }
        }
    }
}