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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("输入登录信息不完整，请重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);            //提示对话框
            }
            else
            {
                //生成连接数据库字符串
                string ConStr = "server=(local);user id=myzf;pwd=123456;database=DataServer";
                //定义SqlConnection对象实例  
                SqlConnection con = new SqlConnection(ConStr);
                //动态模糊查询 
                string SqlStr = "select * from login where sname = '" + textBox1.Text + "' and  spwd = '" + textBox2.Text + "'";
                SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);
                DataTable dt = new DataTable();     //创建DataTable对象实例
                ada.Fill(dt);
                int i = dt.Rows.Count;            //提出数据表记录的行数
                if (i >= 1)
                {
                    Form2 myf = new Form2();
                    myf.Show();
                }
                else
                {
                    MessageBox.Show("用户名或密码不正确，请重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);            //提示对话框
                }
            }
        }

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

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