usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;using MySql.Data.MySqlClient; //引用mysql server命名空间
namespacepay
{public partial classlogin : Form
{public static string ConnectionStr = "Server=127.0.0.1;Port=3306;Database=test;user=root;password=123456789;";//数据库信息
public static stringname;public static stringpassword1;public static stringrole;publiclogin()
{
InitializeComponent();
}private void loginbutton_Click(objectsender, EventArgs e)
{
name=username.Text.Trim();
password1=password.Text.Trim();
role= this.comboBoxrole.SelectedItem.ToString();if (name == "" || password1 == "" || role == "")
{
MessageBox.Show("请将信息输入完整!","提示",MessageBoxButtons.OK);
}else{
MySqlConnection conn= newMySqlConnection(login.ConnectionStr);
conn.Open();if (role=="管理员")
{
String sql= "select EmpId,Password from Employee where ScheduleType='管理员' and EmpId='" + name + "'and Password='" + password1 + "'";//SQL语句实现表数据的读取
MySqlCommand cmd = newMySqlCommand(sql, conn);
MySqlDataReader sqlDataReader=cmd.ExecuteReader();if (sqlDataReader.HasRows) //如果能查到,说明该用户密码存在
{
MessageBox.Show("登陆成功");this.Close();
conn.Close();
}else{
MessageBox.Show("账号或密码错误或未注册","提示",
MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}else if (role=="钟点工")
{
String sql= "select EmpId,Password from Employee where ScheduleType='钟点工' and EmpId='" + name + "'and Password='" + password1 + "'";//SQL语句实现表数据的读取
MySqlCommand cmd = newMySqlCommand(sql, conn);
MySqlDataReader sqlDataReader=cmd.ExecuteReader();if (sqlDataReader.HasRows) //如果能查到,说明该用户密码存在
{
MessageBox.Show("登陆成功");this.Close();
conn.Close();
}else{
MessageBox.Show("账号或密码错误或未注册","提示",
MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}else if (role=="销售员工")
{
String sql= "select EmpId,Password from Employee where ScheduleType='销售员工' and EmpId='" + name + "'and Password='" + password1 + "'";//SQL语句实现表数据的读取
MySqlCommand cmd = newMySqlCommand(sql, conn);
MySqlDataReader sqlDataReader=cmd.ExecuteReader();if (sqlDataReader.HasRows) //如果能查到,说明该用户密码存在
{
MessageBox.Show("登陆成功");this.Close();
conn.Close();
}else{
MessageBox.Show("账号或密码错误或未注册","提示",
MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}else{
String sql= "select EmpId,Password from Employee where ScheduleType='普通职员' and EmpId='" + name + "'and Password='" + password1 + "'";//SQL语句实现表数据的读取
MySqlCommand cmd = newMySqlCommand(sql, conn);
MySqlDataReader sqlDataReader=cmd.ExecuteReader();if (sqlDataReader.HasRows) //如果能查到,说明该用户密码存在
{
MessageBox.Show("登陆成功");this.Close();
conn.Close();
}else{
MessageBox.Show("账号或密码错误或未注册","提示",
MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}
}private void button1_Click(objectsender, EventArgs e)
{this.Close();
}
}
}