getPassword.aspx.cs
资源名称:MEIMS.rar [点击查看]
上传用户:ah_jiwei
上传日期:2022-07-24
资源大小:54044k
文件大小:2k
源码类别:
数据库编程
开发平台:
Visual C++
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class getPassword : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- //注册按钮
- protected void Button1_Click(object sender, EventArgs e)
- {
- }
- //登陆按钮
- protected void Button2_Click(object sender, EventArgs e)
- {
- string userId = TextBox1.Text.ToString().Trim();
- string password = TextBox2.Text.ToString().Trim();
- SqlConnection con = DB.connect_la();
- try
- {
- con.Open();
- string commandString = "select * from id_password_role where id = '" + userId + "' and password= '" + password + "'";
- SqlCommand cmd = new SqlCommand(commandString, con);
- SqlDataReader sdr = cmd.ExecuteReader();
- if (sdr.Read())
- {
- string role_log = sdr.GetString(2);
- Session["userId"] = userId;
- if (role_log.StartsWith("t"))
- Response.Redirect("teacher/index.aspx?");
- else if (role_log.StartsWith("s"))
- Response.Redirect("student/index.aspx?");
- else if (role_log.StartsWith("a"))
- Response.Redirect("administration/index.aspx?");
- }
- else
- {
- Response.Write("<script>alert('用户名或密码错误!');window.location='login.aspx'</script>");
- }
- sdr.Close();
- con.Close();
- }
- catch (Exception exception)
- {
- Response.Write("<script>alert('数据库读取异常!');window.location='login.aspx'</script>");
- }
- finally
- {
- if (con.State == ConnectionState.Open)
- {
- con.Close();
- }
- }
- }
- }