protected void b_send_Click(object sender, EventArgs e) { if (tb_cno.Text.Length == 0) { WebMessage.Show("请输入课程号!"); } else { ConnSql con = new ConnSql(); System.Data.DataTable table = new System.Data.DataTable(); string tno = con.RunSqlReturnTable("select tno from teacher where tname='" + ddl_lt.Text.Trim() + "'").Rows[0][0].ToString(); int result = con.RunSql("insert into course(cno,cname,tno,xs,skdd) values ('" + tb_cno.Text.Trim() + "','" + tb_cname.Text.Trim() + "','" + tno + "','" + tb_cth.Text.Trim() + "','" + tb_classAdd.Text.Trim() + "')"); if (result == 1) { WebMessage.Show("添加成功"); } else { WebMessage.Show("添加失败"); } } }
protected void Button1_Click(object sender, EventArgs e) { string sqltext = ""; ConnSql con = new ConnSql(); if (TextBox1.Text == "") { WebMessage.Show("输入初始密码!"); } else if (TextBox2.Text == "") { WebMessage.Show("请输入密码!"); } else if (TextBox2.Text != TextBox3.Text) { WebMessage.Show("输入的两次密码不相同!"); } else if (TextBox2.Text.Length < 6) { WebMessage.Show("密码长度小于6"); } else if (TextBox1.Text != Session["password"].ToString()) { WebMessage.Show("你输入原始密码不正确!"); } else { sqltext = "update student set pwd='" + TextBox2.Text + "'where sno='" + Session["username"].ToString() + "'"; con.RunSql(sqltext); Session["password"] = TextBox2.Text;//保存新密码到Session WebMessage.Show("修改密码正确!", "selectCourse.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { if (Session["username"] == null) { WebMessage.Show("请登录", "Login.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { if (Session["username"] == null) { WebMessage.Show("请登录", "Default.aspx"); } else { Label1.Text = "欢迎你" + Session["sname"].ToString().Trim() + "同学!"; } } }
protected void Button1_Click(object sender, EventArgs e) { ConnSql con = new ConnSql(); string sqltext = ""; sqltext = "delete student where sno='" + TextBox1.Text.Trim() + "'"; if (con.RunSql(sqltext) == 1) { WebMessage.Show("删除成功"); } else { WebMessage.Show("删除失败"); } }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string user_ip = Request.UserHostAddress;//获取用户IP地址信息 sqltext = "select * from users where username='******'"; table = con.RunSqlReturnTable(sqltext); if (TextBox3.Text.Trim().ToUpper() != Button1.Text.Trim().ToUpper()) { WebMessage.Show("验证码错误!"); } else if (table.Rows.Count <= 0) { WebMessage.Show("用户名错误!"); } else if (table.Rows[0][1].ToString() != TextBox2.Text.Trim()) { WebMessage.Show("密码错误!"); } else if (Session["username"] == null || Session["username"].ToString().Trim() == "") { UserLogin(TextBox1.Text.Trim(), user_ip); table = con.RunSqlReturnTable(sqltext); Session["username"] = TextBox1.Text.Trim(); Session["password"] = TextBox2.Text.Trim(); Session["nc"] = table.Rows[0]["nc"].ToString().Trim(); Session["jf"] = table.Rows[0]["jf"].ToString().Trim().ToString(); Session["realname"] = table.Rows[0]["realname"].ToString().Trim(); Session["lb"] = table.Rows[0]["lb"].ToString().Trim(); Session["pic"] = table.Rows[0]["pic"].ToString().Trim(); Session["sex"] = table.Rows[0]["sex"].ToString().Trim(); if (table.Rows[0]["last_time"].ToString().Length > 5) { Session["last_time"] = table.Rows[0]["last_time"].ToString().Trim().Substring(0, 10); } if (Session["url"] == null || Session["url"].ToString().Trim() == "") { Response.Redirect("Default.aspx"); } else { Response.Redirect(Session["url"].ToString()); } } else { WebMessage.Shows("请退出当前登录的用户!"); } }
protected void Button_Confirm(object sender, EventArgs e) { if (Username.Text == "") { WebMessage.Show("请输入用户名"); } else if (name.Text == "") { WebMessage.Show("请输入姓名"); } else if (xueyuan.Text == "") { WebMessage.Show("请输入学院"); } else if (banji.Text == "") { WebMessage.Show("请输入班级"); } else if (Password.Text == "") { WebMessage.Show("请输入密码"); } else if (Check.Text == "") { WebMessage.Show("请再次输入密码"); } else if (Password.Text != Check.Text) { WebMessage.Show("密码不一致!"); } else { string sql = "INSERT INTO bookuser (id,pwd,name,class,xueyuan,status,sex,admin,times1) VALUES ('" + Username.Text.Trim() + "','" + Password.Text.Trim() + "','" + name.Text.Trim() + "','" + banji.Text.Trim() + "','" + xueyuan.Text.Trim() + "','1','" + RadioButtonList1.SelectedValue + "','0','0')"; ConnSql conn = new ConnSql(); int s = conn.RunSql(sql); if (s > 0) { WebMessage.Show("添加成功", "Index.aspx"); } else { WebMessage.Show("添加失败"); } } }
protected void bSend_Click(object sender, EventArgs e) { //!Error 学生姓名过长会 截断字符串 ConnSql con = new ConnSql(); int sex_tmp = rb_girl.Checked ? 1 : 0; // 暂存性别信息 女true 男false sex_tmp = con.RunSql("update student set sname = '" + tb_sname.Text.Trim() + "', sex=" + sex_tmp + ", birthday = '" + tb_birth.Text.Trim() + "' where sno = '" + tb_sno.Text.Trim() + "'"); if (sex_tmp.Equals(1)) { WebMessage.Show("执行成功"); } else { WebMessage.Show("执行失败"); } }
protected void btn_edit_Click(object sender, EventArgs e) { ConnSql con = new ConnSql(); string sql = "update course set " + "cname = '" + tb_cname.Text + "'," + "xs = " + int.Parse(tb_lt.Text.Trim()) + "," + "skdd = '" + tb_addr.Text + "'," + "tno = '" + ddl_tch.SelectedValue + "'" + " where cno = '" + tb_cno.Text + "'"; try { con.RunSql(sql); } catch (Exception ex) { WebMessage.Show(ex.ToString()); throw; } }
protected void Button2_Click(object sender, EventArgs e) { if (TextBox1.Text.Trim() == "") { WebMessage.Show("请输入用户名"); } else if (TextBox2.Text.Trim() == "") { WebMessage.Show("请输入密码"); } else if (TextBox3.Text.Trim() == "") { WebMessage.Show("请输入验证码"); } else { string sqltext = "select * from student where sno='" + TextBox1.Text.Trim() + "'"; DataTable table = new DataTable(); ConnSql cn = new ConnSql(); table = cn.RunSqlReturnTable(sqltext); if (table.Rows.Count <= 0) { WebMessage.Show("用户名错误!"); } else if (table.Rows[0]["pwd"].ToString().Trim() != TextBox2.Text) { WebMessage.Show("密码错误!"); } else if (TextBox3.Text.Trim().ToUpper() != Button1.Text.Trim().ToUpper()) { WebMessage.Show("验证码错误!"); } else { Session["username"] = TextBox1.Text.Trim(); Session["password"] = TextBox2.Text.Trim(); Session["sname"] = table.Rows[0]["sname"].ToString().Trim(); WebMessage.Show("全部正确", "StudentMain.aspx"); } } }
protected void bCheck_Click(object sender, EventArgs e) { if (tb_sno.Text.Length == 0) { WebMessage.Show("请输入学号!"); } else { ConnSql con = new ConnSql(); DataTable table = new DataTable(); table = con.RunSqlReturnTable("select * from student where sno = " + "'" + tb_sno.Text.Trim() + "'"); if (table.Rows.Count.Equals(0)) { WebMessage.Show("学号不存在"); return; } else { tb_sname.Text = table.Rows[0][1].ToString(); //获取出生年月日 string s = table.Rows[0]["birthday"].ToString(); tb_birth.Text = s.Substring(0, s.LastIndexOf(' ')); //获取性别 if (table.Rows[0]["sex"].Equals(true)) { rb_girl.Checked = true; } else { rb_man.Checked = true; } tb_sno.BackColor = System.Drawing.Color.DarkGray; tb_sno.ReadOnly = true; } } }
protected void btn_login_Click(object sender, EventArgs e) { string sqltext = "select * from admini where username = '******' and pwd = '" + tb_password.Text + "'"; ConnSql conn = new ConnSql(); System.Data.DataTable table = conn.RunSqlReturnTable(sqltext); if (tb_checkcode.Text == btn_img.Text) { if (table.Rows.Count != 1) { WebMessage.Show("用户名或密码错误。"); } else { Session["username"] = table.Rows[0]["username"]; Response.Redirect("Index_Admin.aspx"); } //return; } else { WebMessage.Show("验证码错误。"); } }
protected void Button_Login(object sender, EventArgs e) { if (Username.Text == "") { WebMessage.Show("请输入用户名"); } else if (Password.Text == "") { WebMessage.Show("请输入密码"); } else if (yzm.Text == "") { WebMessage.Show("请输入验证码"); } else { string sqltext = "select * from bookuser where id='" + Username.Text + "'"; DataTable table = new DataTable(); ConnSql cn = new ConnSql(); table = cn.RunSqlReturnTable(sqltext); if (table.Rows.Count <= 0) { WebMessage.Show("用户名错误!"); } else if (table.Rows[0][1].ToString().Trim() != Password.Text) { WebMessage.Show("密码错误!"); } else if (table.Rows[0][4].ToString().Trim() == "0") { WebMessage.Show("账户处于挂失状态,无法登陆!"); } else if (yzm.Text != btn_yzm.Text) { WebMessage.Show("验证码输入错误"); } else { ConnSql con = new ConnSql(); string sql = "update bookuser SET last_login_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff") + "' WHERE id='" + table.Rows[0][0].ToString() + "'"; con.RunSql(sql); //保存登录的用户的用户名和密码到Session对象 Session["Admin"] = table.Rows[0][5].ToString(); if (Session["Admin"].ToString() == "1") { Session["Username"] = table.Rows[0][0].ToString(); Session["Password"] = table.Rows[0][1].ToString(); Session["Name"] = table.Rows[0][2].ToString(); Session["Time"] = table.Rows[0][6].ToString(); Session["id"] = Username.Text; WebMessage.Show("登录成功,管理员:" + Session["Name"].ToString().Trim() + "欢迎您!", "/Admin/Index/Index.aspx"); } else if (Session["Admin"].ToString() == "0") { Session["Username"] = table.Rows[0][0].ToString(); Session["Password"] = table.Rows[0][1].ToString(); Session["Name"] = table.Rows[0][2].ToString(); Session["Time"] = table.Rows[0][6].ToString(); Session["id"] = Username.Text; WebMessage.Show("登录成功," + Session["Name"].ToString().Trim() + "同学,欢迎您!", "/Home/Index/Index.aspx"); } } } }