Newer
Older
GHFX_REFACTOR / Forms / FrmRanQiQuery.cs
wxn on 2 Nov 2016 5 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Globe;
using System.Collections;

namespace PipeLine.Forms
{
    public partial class FrmRanQiQuery : DevComponents.DotNetBar.Office2007Form
    {
        private GSOGlobeControl globeControl1;
        private DevComponents.DotNetBar.Controls.DataGridViewX dataGridViewX1;
        private string pipeLineName = "燃气管线";
        public FrmRanQiQuery(GSOGlobeControl ctl, DevComponents.DotNetBar.Controls.DataGridViewX d)
        {
            InitializeComponent();
            globeControl1 = ctl;
            dataGridViewX1 = d;
        }

        private void FrmRanQiQuery_Load(object sender, EventArgs e)
        {
            dataGridViewX1.Visible = false;
            dataGridViewX1.ReadOnly = true;

            string sqltype1 = "select distinct 材质 from " + pipeLineName + "";
            DataTable table1 = OledbHelper.QueryTable(sqltype1);
            combMaterial.Items.Add("无");
            for (int j = 0; j < table1.Rows.Count; j++)
            {
                DataRow dr = table1.Rows[j];
                string colString1 = dr[0].ToString();
                if (colString1 == null || colString1.Trim() == "")
                    continue;
                combMaterial.Items.Add(colString1);
            }

            string sqltype2 = "select distinct 埋设方式 from " + pipeLineName + "";
            DataTable table2 = OledbHelper.QueryTable(sqltype2);
            combType.Items.Add("无");
            for (int k = 0; k < table2.Rows.Count; k++)
            {
                DataRow dr = table2.Rows[k];
                string colString1 = dr[0].ToString();
                if (colString1 == null || colString1.Trim() == "")
                    continue;
                combType.Items.Add(colString1);
            }

            string sqltype3 = "select distinct 是否废弃 from " + pipeLineName + "";
            DataTable table3 = OledbHelper.QueryTable(sqltype3);
            combUse.Items.Add("无");
            for (int h = 0; h < table3.Rows.Count; h++)
            {
                DataRow dr = table3.Rows[h];
                string colString1 = dr[0].ToString();
                if (colString1 == null || colString1.Trim() == "")
                    continue;
                combUse.Items.Add(colString1);
            }          
        }

        private void btnSel_Click(object sender, EventArgs e)
        {
            try
            {
                string type = combType.Text.ToString();
                dataGridViewX1.Visible = true;
                string sql = "select " + Utility.Query_Fields["燃气"] + " from " + pipeLineName + "";  //"select 材质,类型,起始埋深,终点埋深,管径,压力,编号 from reli";

                ArrayList filters = new ArrayList();

                if (combType.SelectedIndex > 0)
                {
                    string sql1 = " 埋设方式='" + combType.SelectedItem.ToString() + "'";
                    filters.Add(sql1);
                }

                if (combMaterial.SelectedIndex > 0)
                {
                    string sql2 = " 材质='" + combMaterial.SelectedItem.ToString() + "'";
                    filters.Add(sql2);
                }

                if (txtGuanJing.Text != "")
                {
                    string sql7 = " 管径_毫米>=" + txtGuanJing.Text + "";
                    filters.Add(sql7);
                }

                if (txtYali.Text != "")
                {
                    string sql3 = " 压力=" + txtYali.Text + "";
                    filters.Add(sql3);
                }

                if (txtDeep1.Text != "")
                {
                    string sql4 = " 起始埋深>=" + txtDeep1.Text + "";
                    filters.Add(sql4);
                }

                if (txtDeep1.Text != "")
                {
                    string sql5 = "终止埋深>=" + txtDeep1.Text + "";
                    filters.Add(sql5);
                }

                if (combUse.SelectedIndex > 0)
                {
                    string sql8 = " 是否废弃='" + combUse.SelectedItem.ToString() + "'";
                    filters.Add(sql8);
                }
                if (combBuild1.SelectedIndex > 0 && combBuild2.SelectedIndex > 0)
                {
                    string sql6 = "建设年代 between '" + combBuild1.SelectedItem.ToString() + "' and '" + combBuild2.SelectedItem.ToString() + "'";
                    filters.Add(sql6);
                }


                string[] aa = (string[])(filters.ToArray(typeof(string)));
                if (aa.Length > 0)
                    sql += " where " + string.Join(" and ", aa);


                DataTable table = OledbHelper.QueryTable(sql);
                dataGridViewX1.DataSource = table;
                dataGridViewX1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        private void btnCanel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}