using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 小型宾馆管理系统
{
    public partial class 登录 : Form
    {
        public 登录()
        {
            InitializeComponent();
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                textBox3.Focus();
        }

        private void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                button1_Click(sender, e);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet ds = new DataSet();
                database db = new database();
                string sqlStr = "select UserName ,UserPassword from tbl_User where UserName='" + textBox2 .Text.Trim() + " '";
                ds = db.GetDataFromDB(sqlStr);
                if (ds.Tables[0].Rows[0].ItemArray[1].ToString() ==textBox3.Text.Trim())
                {
                    mainform Mainf = new mainform();
                    
                    Mainf.Show();
                    this.Hide();
                    
                    
                }
                else
                {
                    MessageBox.Show("用户名或密码错误，请重新输入！");
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox2.Focus();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
       
    }
}