public int Register(BLL.model.User newUser) { int result; string mysql; mysql = "INSERT INTO Users(Username,Password,Type) VALUES('" + newUser.Username + "','" + newUser.Password + "','" + newUser.Type + "')"; result = mysqlhelper.ExecuteNonQuery(mysql); return(result); }
public DataTable Login(BLL.model.User newUser) { DataTable mytable = new DataTable(); string mysql; mysql = "SELECT * FROM Users WHERE Username='******'"; mytable = mysqlhelper.Exesql(mysql); return(mytable); }
private void btnRegister_Click(object sender, EventArgs e) { if (txRegName.Text == "") { MessageBox.Show("用户名不能为空!", "信息提示", MessageBoxButtons.OKCancel); } else if (txRegPwd1.Text == "" || txRegPwd2.Text == "") { MessageBox.Show("密码或确认密码不能为空!", "信息提示", MessageBoxButtons.OKCancel); } else if (txRegPwd1.Text != txRegPwd2.Text) { MessageBox.Show("两次输入密码不一致!", "信息提示", MessageBoxButtons.OKCancel); } else if (comboBox1.Text == "") { MessageBox.Show("请选择注册类型!", "信息提示", MessageBoxButtons.OKCancel); } else { int result; BLL.model.User newUser = new BLL.model.User(); newUser.Username = txRegName.Text; newUser.Password = txRegPwd1.Text; newUser.Type = comboBox1.Text; BLL.Login.LoginOrRegister newLorR = new BLL.Login.LoginOrRegister(); result = newLorR.Register(newUser); if (result == 1) { MessageBox.Show("注册成功,点击确定返回登录界面!", "信息提示", MessageBoxButtons.OKCancel); this.Close(); } else { MessageBox.Show("注册失败,请联系系统管理员!", "信息提示", MessageBoxButtons.OKCancel); } } }
private void btnLogin_Click(object sender, EventArgs e) { if (txName.Text == "") //判断用户名是否为空 { MessageBox.Show("用户名不能为空!", "信息提示", MessageBoxButtons.OKCancel); } else if (txPwd.Text == "") //判断密码是否为空 { MessageBox.Show("密码不能为空!", "信息提示", MessageBoxButtons.OKCancel); } else { BLL.model.User newUser = new BLL.model.User(); BLL.Login.LoginOrRegister newLorR = new BLL.Login.LoginOrRegister(); DataTable mytable = new DataTable(); newUser.Username = txName.Text; mytable = newLorR.Login(newUser); if (mytable.Rows[0][0].ToString() == txName.Text && mytable.Rows[0][1].ToString() == txPwd.Text) { MessageBox.Show("登录成功!", "信息提示", MessageBoxButtons.OKCancel); if (mytable.Rows[0][2].ToString() == "P1") { UI.FormPermission myform = new FormPermission(); this.Hide(); myform.ShowDialog(); this.Close(); } else if (mytable.Rows[0][2].ToString() == "P2") { UI.FormPayment myform = new FormPayment(); this.Hide(); myform.ShowDialog(); this.Close(); } else if (mytable.Rows[0][2].ToString() == "P3") { UI.FormLeave myform = new FormLeave(); this.Hide(); myform.ShowDialog(); this.Close(); } else if (mytable.Rows[0][2].ToString() == "P4") { UI.FormMedicalRecord myform = new FormMedicalRecord(); this.Hide(); myform.ShowDialog(); this.Close(); } else if (mytable.Rows[0][2].ToString() == "P5") { UI.FormSelect myform = new FormSelect(); this.Hide(); myform.ShowDialog(); this.Close(); } else if (mytable.Rows[0][2].ToString() == "P6") { UI.FormBedManagement myform = new FormBedManagement(); this.Hide(); myform.ShowDialog(); this.Close(); } } else { MessageBox.Show("用户名或密码错误!", "信息提示", MessageBoxButtons.OKCancel); } } }