-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
70 lines (64 loc) · 2.1 KB
/
Default.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
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using MyClasses;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnLogin_Click(object sender, EventArgs e)
{
SuperConn scnn = new SuperConn("User.accdb");
scnn.Open();
string _sql = "SELECT * FROM T_user WHERE (U_name = '" + TbName.Text + "' AND U_password = '" + TbPassword.Text + "' AND U_valid = True)";
//Response.Write(_sql);
OleDbDataReader dr = scnn.GetDataReader(_sql);
if (dr.Read())
{
//Response.Write(_sql);
Session["user"] = TbName.Text;
Boolean i =Boolean.Parse(dr["U_admin"].ToString());
if (i)
{
Session["admin"] = i;
}
LabelState.Text = "登陆成功!";
}
else
{
LabelState.Text = "登录失败!";
}
scnn.Close();
LabelState.Visible = true;
TbName.Text = TbPassword.Text = "";
}
protected void BtnRegister_Click(object sender, EventArgs e)
{
Response.Redirect("/Library/Register.aspx");
}
protected void BtnInsertMsg_Click(object sender, EventArgs e)
{
SuperConn scnn = new SuperConn("Message.accdb");
scnn.Open();
string _sql = "INSERT INTO T_message (M_name, M_time, M_message, M_visible) VALUES ('" + LabelNameMsg.Text + "', '" + DateTime.Now.ToString() + "', '" + TBTextMsg.Text + "', " + CBvisible.Checked.ToString() + ")";
//Response.Write(_sql);
OleDbCommand cmd = new OleDbCommand(_sql, scnn.cnn);
cmd.ExecuteNonQuery();
scnn.Close();
LVmsg.DataBind();
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (Session["user"] != null)
{
divinsertmsg.Visible = true;
LabelNameMsg.Text = Session["user"].ToString();
}
}
}