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 Ex04_7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
            {
                MessageBox.Show("输入的信息不完整，重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=MysqlData");
                StringBuilder strSQL = new StringBuilder();
                strSQL.Append("insert into 应付账(供应商名, 购入金额,已付款,应付款)");
                strSQL.Append(" values('" + textBox1.Text.Trim().ToString() + "','" + textBox2.Text.Trim().ToString() + "',");
                strSQL.Append("'" + textBox3.Text.Trim().ToString() + "','" + textBox4.Text.Trim().ToString() + "')");

                using (SqlCommand cmd = new SqlCommand(strSQL.ToString(), con))
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    con.Dispose();

                }
                MessageBox.Show("已成功向数据库表中插入一条记录！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            myf.Show();
        }

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