引排水量过程线

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace taihu2
{
    public partial class Form6 : Form
    {
        //string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\JS\\Desktop\\taihu2\\水资源信息.mdb";
        string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\水资源信息.mdb";
        DateTime dt1 = new DateTime();
        DateTime dt2 = new DateTime();
        DateTimeFormatInfo Format = new DateTimeFormatInfo();
        public Form6()
        {
            InitializeComponent();
        }

        private void Form6_Load(object sender, EventArgs e)
        {
            //ComboBox值
            comboBox1.Items.Add("常熟枢纽引排水量");
            comboBox1.Items.Add("望亭枢纽引排水量");
            comboBox1.Items.Add("太浦闸引排水量");
            //可查询日期值 
            string connString = constr;
            OleDbConnection conn = new OleDbConnection(connString);
            int i = 0;
            string queryString = "select 日期 from 引排水量";
            OleDbCommand Command = new OleDbCommand(queryString, conn);
            conn.Open();
            try
            {
                OleDbDataReader DataReader = Command.ExecuteReader();
                while (DataReader.Read())
                {
                    listBox1.Items.Add(DataReader.GetValue(i));                 

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            listBox1.SelectedIndex = 0;
            string fromdate = listBox1.SelectedItem.ToString();
            listBox1.SelectedIndex = listBox1.Items.Count - 1;
            string todate = listBox1.SelectedItem.ToString();
            label1.Text = "可供查询日期范围:" + fromdate + "至" + todate;
            conn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0 || comboBox1.SelectedIndex == 2 || comboBox1.SelectedIndex == 1 )
            {
                if (textBox1.Text.Trim() == string.Empty || textBox2.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入查询日期", "警告", MessageBoxButtons.OK, MessageBoxIcon.Question);

                }
                else
                {
                    string connString = constr;
                    OleDbConnection conn = new OleDbConnection(connString);
                    int i = 0;
                    string queryString = "select 日期 from 引排水量";
                    OleDbCommand Command = new OleDbCommand(queryString, conn);
                    conn.Open();
                    try
                    {
                        OleDbDataReader DataReader = Command.ExecuteReader();
                        while (DataReader.Read())
                        {
                            listBox1.Items.Add(DataReader.GetValue(i));

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    listBox1.SelectedIndex = 0;
                    string fromdate = listBox1.SelectedItem.ToString();
                    listBox1.SelectedIndex = listBox1.Items.Count - 1;
                    string todate = listBox1.SelectedItem.ToString();
                    label1.Text = "可供查询日期范围:" + fromdate + "至" + todate;
        
                    DateTime date3 = Convert.ToDateTime(fromdate);
                    DateTime date4 = Convert.ToDateTime(todate);
                    
                    conn.Close();

                    DateTime date1 = Convert.ToDateTime(this.textBox1.Text);
                    DateTime date2 = Convert.ToDateTime(this.textBox2.Text);

                    
                    if (date1.CompareTo(date3) < 0)
                    {

                        MessageBox.Show("所输日期超出可查询范围", "警告", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    }
                    else
                    {
                        if (date2.CompareTo(date4) > 0)
                        {

                            MessageBox.Show("所输日期超出可查询范围", "警告", MessageBoxButtons.OK, MessageBoxIcon.Question);
                        }
                        else
                        {
                            Format.ShortDatePattern = "yyyy/mm/dd";
                            dt1 = Convert.ToDateTime(textBox1.Text, Format);
                            dt2 = Convert.ToDateTime(textBox2.Text, Format);
                            conn.Open();
                            string queryString1 = "select  日期, " + comboBox1.Text + " from 引排水量  where  日期 between '" + dt1 + "' and '" + dt2 + "' ";
                            OleDbDataAdapter dataAdapter = new OleDbDataAdapter(queryString1, conn);
                            OleDbCommandBuilder builder = new OleDbCommandBuilder(dataAdapter);
                            DataTable table = new DataTable();
                            dataAdapter.Fill(table);
                            chart1.DataSource = table;
                            //x列数据
                            chart1.Series[0].XValueMember = "日期";
                            //y列数据
                            chart1.Series[0].YValueMembers = comboBox1.Text;
                            //数据绑定
                            chart1.DataBind();
                            conn.Close();
                            groupBox2.Visible = true;
                        }
                    }

                }
            }
        }
    }
}

 

posted on 2017-01-11 08:24  水熊虫OK  阅读(119)  评论(0)    收藏  举报

导航