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 Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            try
            {
                //生成连接数据库字符串
                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";
                SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);
                DataSet ds = new DataSet();    //定义DataSet对象实例
                ada.Fill(ds);
                //连接数据表格，显示数据  
                this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
            }
            catch
            {
                return;
            }
        }

        private void 消费信息浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //生成连接数据库字符串
            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";
            SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);
            DataSet ds = new DataSet();    //定义DataSet对象实例
            ada.Fill(ds);
            //连接数据表格，显示数据  
            this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

        private void 按消费项目查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form3 myf3 = new Form3();
            myf3.Show();            //显示按消费项目查询界面
        }

        private void 按消费金额查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4 myf4 = new Form4();
            myf4.Show();          //显示按消费金额查询界面
        }

        private void 按消费日期查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5 myf5 = new Form5();
            myf5.Show();        //显示按消费日期查询界面      
        }

      private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void 添加消费信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form6 myf6 = new Form6();
            myf6.Show();         //显示添加消费信息界面
        }

        private void 修改消费信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form7 myf7 = new Form7();
            myf7.Show();         //显示修改消费信息界面
        }

        private void 删除消费信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form8 myf8 = new Form8();
            myf8.Show();       //显示删除消费信息界面
        }

        private void 退出系统ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void 报表输出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form9 myf9 = new Form9();
            myf9.Show();     //显示报表输出界面
        }
    }
}
