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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("请填写消费项目");
                return;
            }
            if (textBox2.Text == "")
            {
                MessageBox.Show("请填写消费金额");
                return;
            }
            SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=DataServer");
            con.Open();
            SqlCommand com = new SqlCommand();
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "spendInsert";
            com.Connection = con;
            com.Parameters.Add("@spendprocd", SqlDbType.VarChar, 100);
            com.Parameters["@spendprocd"].Value = textBox1.Text;
            com.Parameters.Add("@spendMoney", SqlDbType.Money);
            com.Parameters["@spendMoney"].Value = textBox2.Text;
            com.Parameters.Add("@spendDate", SqlDbType.DateTime, 8);
            com.Parameters["@spendDate"].Value = Convert.ToDateTime(dateTimePicker1.Value);
            SqlParameter sqlp = com.Parameters.Add("@return", SqlDbType.VarChar, 1);
            sqlp.Direction = ParameterDirection.Output;
            com.ExecuteNonQuery();
            if (com.Parameters["@return"].Value.ToString() == "1")
            {
                MessageBox.Show("添加消费信息成功！");
                textBox1.Text = "";
                textBox2.Text = "";
            }
            else
            {
                MessageBox.Show("添加消费信息失败！");
                textBox1.Text = "";
                textBox2.Text = "";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }
    }
}
