protected void Page_Load(object sender, EventArgs e) { sqlHelp sqlhelper = new sqlHelp(); Label1.Text = "东北大学"; Label2.Text = sqlhelper.executeNonQueryCount("select * from departmentInfo").ToString() + "个"; Label3.Text = sqlhelper.executeNonQueryCount("select * from collegeInfo").ToString() + "个"; Label4.Text = sqlhelper.executeNonQueryCount("select * from classInfo").ToString() + "个"; Label5.Text = sqlhelper.executeNonQueryCount("select * from teacherInfo").ToString() + "个"; Label6.Text = sqlhelper.executeNonQueryCount("select * from studentInfo").ToString() + "个"; }
protected void LinkButton1_Click(object sender, EventArgs e) { string departmentName = TextBox1.Text; sqlHelp sqlhelper = new sqlHelp(); string selectsql = "select * from departmentInfo where departmentName='" + departmentName + "'"; int count = sqlhelper.executeNonQueryCount(selectsql); if (count <= 0) { string insertsql = "insert into departmentInfo(departmentName) values('" + departmentName + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Write("<script> alert('部门添加成功,请刷新查看!');</script>"); } else { Response.Write("<script> alert('部门已存在!');</script>"); } }
protected void LinkButton1_Click(object sender, EventArgs e) { string collegename = DropDownList1.Text.ToString(); string classname = TextBox1.Text.ToString(); string selectsql = "select * from classInfo where className='" + classname + "'and collegeName='" + collegename + "'"; sqlHelp sqlhelper = new sqlHelp(); int count = sqlhelper.executeNonQueryCount(selectsql); if (count > 0) { Response.Write("<script>alert('该专业已存在!');</script>"); } else { string insertsql = "insert into classInfo(className,collegeName) values('" + classname + "','" + collegename + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Write("<script>alert('专业添加成功,请刷新查看!');</script>"); } }
protected void LinkButton1_Click(object sender, EventArgs e) { string username = TextBox1.Text.ToString(); string userpass = TextBox2.Text.ToString(); sqlHelp sqlhelper = new sqlHelp(); string selectsql = "select * from adminInfo where adminName='" + username + "'"; int count = sqlhelper.executeNonQueryCount(selectsql); if (count <= 0) { string addsql = "insert into adminInfo(adminName,adminPass) values('" + username + "','" + userpass + "')"; sqlhelper.SqlServerExcute(addsql); Response.Write("<script>alert('添加成功');</script>"); } else { Response.Write("<script>alert('添加失败,该管理已经存在');</script>"); } }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { sqlHelp sqlhelper = new sqlHelp(); string username, password, verifycode1, verifycode2, loginstate; username = TextBox1.Text.ToString(); password = TextBox2.Text.ToString(); verifycode1 = TextBox3.Text.ToString(); verifycode2 = Request.Cookies["verifycode"].Value.ToString(); if (verifycode1 == verifycode2) { string selectsql = "select * from adminInfo where adminName='" + username + "'and adminPass='******'"; int count = sqlhelper.executeNonQueryCount(selectsql); if (count > 0) { loginstate = "登陆成功"; Session["adminName"] = username; Session["adminPass"] = password; string datetime = DateTime.Now.ToString(); string ip = Request.ServerVariables["REMOTE_ADDR"].ToString(); //取得本机IP搜索 string strHostName = Dns.GetHostName(); //得到本机的主机名 string insertsql = "insert into loginInfo(loginname,loginState,loginTime,loginIP,loginHostname) values('" + username + "','" + loginstate + "','" + datetime + "','" + ip + "','" + strHostName + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Redirect("Default.aspx"); } else { loginstate = "登陆失败"; string datetime = DateTime.Now.ToString(); string ip = Request.ServerVariables["REMOTE_ADDR"].ToString(); //取得本机IP搜索 string strHostName = Dns.GetHostName(); //得到本机的主机名 string insertsql = "insert into loginInfo(loginname,loginState,loginTime,loginIP,loginHostname) values('" + username + "','" + loginstate + "','" + datetime + "','" + ip + "','" + strHostName + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Write("<Script>alert('用户名或密码错误');</Script>"); } } else { Response.Write("<Script>alert('验证码错误');</Script>"); } }
protected void LinkButton1_Click(object sender, EventArgs e) { string username = TextBox1.Text.ToString(); string userpass = TextBox2.Text.ToString(); string newpass = TextBox3.Text.ToString(); sqlHelp sqlhelper = new sqlHelp(); string selectsql = "select * from adminInfo where adminName='" + username + "'and adminPass='******'"; int count = sqlhelper.executeNonQueryCount(selectsql); if (count > 0) { sqlHelp sqlhelper1 = new sqlHelp(); string updatesql = "update adminInfo set adminPass='******'where adminName='" + username + "'"; sqlhelper1.SqlServerExcute(updatesql); Response.Write("<script>alert('密码修改成功!');</script>"); } else { Response.Write("<script>alert('密码修改失败!');</script>"); } }
protected void LinkButton1_Click(object sender, EventArgs e) { string num = TextBox1.Text.ToString(); string name = TextBox2.Text.ToString(); string sex = TextBox3.Text.ToString(); string ID = TextBox4.Text.ToString(); string national = TextBox5.Text.ToString(); string tel = TextBox6.Text.ToString(); string department = DropDownList1.Text.ToString(); string stuPic = string.Empty; sqlHelp sqlhelper = new sqlHelp(); string selectsql = "select * from teacherInfo where teaNum='" + num + "'"; int count = sqlhelper.executeNonQueryCount(selectsql); if (count > 0) { Response.Write("<Script>alert('该工号已存在,请核实后再添加!');</script>"); } else { if (FileUpload1.HasFile) { Random r = new Random(); string ex = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); if (ex != ".gif" && ex != ".jpg" && ex != ".jpeg" && ex != ".bmp" && ex != ".png") { Response.Write("<script>alert('文件格式不正确!')</script>"); Response.End(); } string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + r.Next(100, 999).ToString() + ex; DateTime now = DateTime.Now; //获取系统时间 string classid = DateTime.Now.ToString("yyyy-MM"); //根据年份判断在该路径下是否存在以当年年份文件夹 否则将建立以该年份的文件夹 if (!Directory.Exists(HttpContext.Current.Server.MapPath("../picture/") + "//" + classid)) //HttpContext.Current.Server.MapPath(相对路径):把相对路径转为服务器上的绝对路径。File.Exists(绝对路径):检查是否存在绝对路径指向的文件或目录。 { System.IO.Directory.CreateDirectory(@HttpContext.Current.Server.MapPath("../picture/") + "//" + classid); //System.IO.Directory.CreateDirectory(文件夹绝对路径):建立绝对路径文件夹。 } FileUpload1.SaveAs(Server.MapPath("../picture//" + classid + "//" + newFileName)); string tpic = "picture/" + classid + "/" + newFileName; string insertsql = "insert into teacherInfo(teaNum,teaName,teaSex,teaID,teaNational,teaTel,teaDepartment,teaPic) values('" + num + "','" + name + "','" + sex + "','" + ID + "','" + national + "','" + tel + "','" + department + "','" + tpic + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Write("<Script>alert('该教师已添加,请刷新查看!');</script>"); }//end of if (FileUpload1.HasFile) else { if (sex == "男") { stuPic = "picture/man.jpg"; string insertsql = "insert into teacherInfo(teaNum,teaName,teaSex,teaID,teaNational,teaTel,teaDepartment,teaPic) values('" + num + "','" + name + "','" + sex + "','" + ID + "','" + national + "','" + tel + "','" + department + "','" + stuPic + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Write("<script>alert('信息添加成功');</script>"); } else { stuPic = "picture/women.jpg"; string insertsql = "insert into teacherInfo(teaNum,teaName,teaSex,teaID,teaNational,teaTel,teaDepartment,teaPic) values('" + num + "','" + name + "','" + sex + "','" + ID + "','" + national + "','" + tel + "','" + department + "','" + stuPic + "')"; sqlhelper.SqlServerExcute(insertsql); Response.Write("<script>alert('信息添加成功');</script>"); } } } }
protected void LinkButton1_Click(object sender, EventArgs e) { string stuid = Session["stuidedit"].ToString(); sqlHelp sqlhelp = new sqlHelp(); string stuNum = TextBox1.Text; string stuName = TextBox2.Text; string stuSex = TextBox3.Text; string stuID = TextBox4.Text; string stuNational = TextBox5.Text; string stuTel = TextBox6.Text; string stuCollege = DropDownList1.Text; string stuClass = DropDownList2.Text; string stuChangerequest = TextBox7.Text; string stuPic = string.Empty; string selectcount = "select * from studentInfo where stuNum='" + stuNum + "'"; int count = sqlhelp.executeNonQueryCount(selectcount); if (count <= 1) { if (FileUpload1.HasFile) { Random r = new Random(); string ex = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); if (ex != ".gif" && ex != ".jpg" && ex != ".jpeg" && ex != ".bmp" && ex != ".png") { Response.Write("<script>alert('文件格式不正确!')</script>"); Response.End(); } string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + r.Next(100, 999).ToString() + ex; DateTime now = DateTime.Now; //获取系统时间 string classid = DateTime.Now.ToString("yyyy-MM"); //根据年份判断在该路径下是否存在以当年年份文件夹 否则将建立以该年份的文件夹 if (!Directory.Exists(HttpContext.Current.Server.MapPath("../picture/") + "//" + classid)) //HttpContext.Current.Server.MapPath(相对路径):把相对路径转为服务器上的绝对路径。File.Exists(绝对路径):检查是否存在绝对路径指向的文件或目录。 { System.IO.Directory.CreateDirectory(@HttpContext.Current.Server.MapPath("../picture/") + "//" + classid); //System.IO.Directory.CreateDirectory(文件夹绝对路径):建立绝对路径文件夹。 } FileUpload1.SaveAs(Server.MapPath("../picture//" + classid + "//" + newFileName)); string tpic = "picture/" + classid + "/" + newFileName; // string sql = "insert into studentInfo(stuNum,stuName,stuSex,stuID,stuNational,stuTel,stuCollege,stuClass,stuChangerequest,stuPic) values('" + stuNum + "','" + stuName + "','" + stuSex + "','" + stuID + "','" + stuNational + "','" + stuTel + "','" + stuCollege + "','" + stuClass + "'," + stuChangerequest + "'," + tpic + ")"; string sql = "update studentInfo set stuNum='" + stuNum + "',stuName='" + stuName + "',stuSex='" + stuSex + "',stuID='" + stuID + "',stuNational='" + stuNational + "',stuTel='" + stuTel + "',stuCollege='" + stuCollege + "',stuClass='" + stuClass + "',stuChangerequest='" + stuChangerequest + "',stuPic='" + tpic + "'where id='" + stuid + "'"; sqlhelp.SqlServerExcute(sql); Response.Write("<script>alert('信息修改成功');</script>"); }//end of if (FileUpload1.HasFile) else { if (stuSex == "男") { stuPic = "picture/man.jpg"; string sql = "update studentInfo set stuNum='" + stuNum + "',stuName='" + stuName + "',stuSex='" + stuSex + "',stuID='" + stuID + "',stuNational='" + stuNational + "',stuTel='" + stuTel + "',stuCollege='" + stuCollege + "',stuClass='" + stuClass + "',stuChangerequest='" + stuChangerequest + "',stuPic='" + stuPic + "'where id='" + stuid + "'"; sqlhelp.SqlServerExcute(sql); Response.Write("<script>alert('信息修改成功');</script>"); } else { stuPic = "picture/women.jpg"; string sql = "update studentInfo set stuNum='" + stuNum + "',stuName='" + stuName + "',stuSex='" + stuSex + "',stuID='" + stuID + "',stuNational='" + stuNational + "',stuTel='" + stuTel + "',stuCollege='" + stuCollege + "',stuClass='" + stuClass + "',stuChangerequest='" + stuChangerequest + "',stuPic='" + stuPic + "'where id='" + stuid + "'"; sqlhelp.SqlServerExcute(sql); Response.Write("<script>alert('信息修改成功');</script>"); } } //end of else! (FileUpload1.HasFile) } //end of if count<=0 else { Response.Write("<script>alert('信息修改失败');</script>"); } }