This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
forked from pigsquare/StuAct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.aspx.cs
68 lines (65 loc) · 2.26 KB
/
Index.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Configuration;
using System.Data.SqlClient;
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Session["login"]!=null)
{
string a = Session["login"].ToString();
jieguo.InnerText = a;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string username = Text1.Value;
string password = Password1.Value;
string conf = ConfigurationManager.ConnectionStrings["ActManageConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(conf);
if (Radio1.Checked)
{
string sql = "SELECT * FROM [Stu] WHERE stu_id='"+username+"' AND password='"+password+"'";
jieguo.InnerText = sql;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
jieguo.InnerHtml = dr.GetString(1);
Session["role"] = "stu";
Session["name"] = dr.GetString(1);
Session["id"] = dr.GetString(0);
Response.Redirect("StuHome.aspx");
}
else
{
jieguo.InnerHtml = "学生登录失败!";
}
dr.Close();
conn.Close();
}
if (Radio2.Checked)
{
string sql = "SELECT * FROM [Teacher] WHERE teacher_id='" + username + "' AND password='" + password + "'";
jieguo.InnerText = sql;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
jieguo.InnerHtml = dr.GetString(1);
Session["role"] = "teacher";
Session["name"] = dr.GetString(1);
Session["id"] = dr.GetString(0);
Response.Redirect("TeacherHome.aspx");
}
else
{
jieguo.InnerHtml = "教师/管理员登录失败!";
}
dr.Close();
conn.Close();
}
}
}