//登录 private void btn_enter_Click(object sender, System.EventArgs e) { bool isLogin = false; if (SubjectRegister.IsUserNameUsed(userCombox.Text) == false) { MessageBox.Show(this, "数据库中找不到这样的账号", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (userCombox.Text.Length == 0 || pwd.Text.Length == 0) { MessageBox.Show(this, "账户名称及密码不能为空", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OleDbConnection oleDB = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dac.accdb"); oleDB.Open(); OleDbCommand conn = new OleDbCommand(); conn.Connection = oleDB; conn.CommandText = "select * from [主体信息表] where 主体名称=" + "'" + userCombox.Text.ToLower() + "'"; OleDbDataReader dr = conn.ExecuteReader(); if (dr.HasRows == true) { while (dr.Read()) { if (dr[1].ToString().CompareTo(pwd.Text.GetHashCode().ToString()) == 0)//找到相应的记录,置登录标志为真 { isLogin = true; } } } dr.Close(); oleDB.Close(); if (isLogin == false) { MessageBox.Show(this, "密码错误"+pwd.Text.GetHashCode().ToString(), "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show(this, "登录成功,按确定进入", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Visible = false; switch (this.userCombox.Text.ToLower())//选择不同的窗口 { case "admin": { Admin a = new Admin(); a.ShowDialog(); break; } case "security_officer": { Security_Officer s= new Security_Officer(); s.ShowDialog(); break; } default: { CommonUser c = new CommonUser(); c.GetUserName = this.userCombox.Text.ToLower(); c.ShowDialog(); break; } } this.Visible = true; }
//登录 private void btn_enter_Click(object sender, System.EventArgs e) { bool isLogin = false; if (SubjectRegister.IsUserNameUsed(userCombox.Text) == false) { MessageBox.Show(this, "数据库中找不到这样的账号", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (userCombox.Text.Length == 0 || pwd.Text.Length == 0) { MessageBox.Show(this, "账户名称及密码不能为空", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OleDbConnection oleDB = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dac.accdb"); oleDB.Open(); OleDbCommand conn = new OleDbCommand(); conn.Connection = oleDB; conn.CommandText = "select * from [主体信息表] where 主体名称=" + "'" + userCombox.Text.ToLower() + "'"; OleDbDataReader dr = conn.ExecuteReader(); if (dr.HasRows == true) { while (dr.Read()) { if (dr[1].ToString().CompareTo(pwd.Text.GetHashCode().ToString()) == 0)//找到相应的记录,置登录标志为真 { isLogin = true; } } } dr.Close(); oleDB.Close(); if (isLogin == false) { MessageBox.Show(this, "密码错误" + pwd.Text.GetHashCode().ToString(), "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show(this, "登录成功,按确定进入", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Visible = false; switch (this.userCombox.Text.ToLower())//选择不同的窗口 { case "admin": { Admin a = new Admin(); a.ShowDialog(); break; } case "security_officer": { Security_Officer s = new Security_Officer(); s.ShowDialog(); break; } default: { CommonUser c = new CommonUser(); c.GetUserName = this.userCombox.Text.ToLower(); c.ShowDialog(); break; } } this.Visible = true; }