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 System.Data.SqlClient;
namespace Ex12_01
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text != "")
            {
                //生成连接数据库字符串
                string ConStr = "server=(local);user id=myzf;pwd=123456;database=DataServer";
                //定义SqlConnection对象实例  
                SqlConnection con = new SqlConnection(ConStr);
                //定义Select查询语句
                string SqlStr = "select spendprocd as 消费项目,spendMoney as 消费金额, spendDate as 消费日期  from consume where spendMoney >=" + Convert.ToDouble(textBox2.Text);
                SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);
                DataSet ds = new DataSet();    //定义DataSet对象实例
                ada.Fill(ds);
                //连接数据表格，显示数据  
                this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
                con.Close();
                SqlConnection mycon = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=DataServer");
                mycon.Open();
                SqlCommand cmd = new SqlCommand("select sum(spendMoney) from consume where spendMoney >=" + Convert.ToDouble(textBox2.Text), mycon);
                SqlDataReader drr = cmd.ExecuteReader();
                while (drr.Read())
                {
                    textBox1.Text = String.Format(Convert.ToDouble(drr.GetValue(0)).ToString());
                    textBox1.BackColor = Color.GreenYellow;
                }
            }
            else
            {
                MessageBox.Show("请输入最小消费金额！");
            }
        }
    }
}
