protected void saveBtn_Click(object sender, EventArgs e) { if (!Session["check"].ToString().Trim().Equals("1")) { Session["check"] = "0"; Panel1.Visible = true; Panel2.Visible = false; return; } string passwordStr1 = Tools.safeUserInput(passWordTB1.Text.ToString().Trim()); string passwordStr2 = Tools.safeUserInput(passWordTB2.Text.ToString().Trim()); if (passwordStr1.Equals(passwordStr2)) { studentBLL StudentBLL = new studentBLL(); student Student = StudentBLL.GetModel(ViewState["stuId"].ToString()); Student.passWord = Tools.encrypt(passwordStr1); try { StudentBLL.Update(Student); } catch { MessageBox.Show(this, "密码修改失败!"); return; } MessageBox.ShowAndRedirect(this, "密码修改成功!", "Default.aspx"); } else { MessageBox.Show(this, "密码不一致!"); return; } }
protected void changeBtn_Click(object sender, EventArgs e) { string passWordStr1 = Tools.safeUserInput(passWordTB1.Text.ToString().Trim()); string passWordStr2 = Tools.safeUserInput(passWordTB2.Text.ToString().Trim()); if (passWordStr1.Length > 0 && passWordStr2.Length > 0 && passWordStr1.Equals(passWordStr2)) { studentBLL StudentBLL = new studentBLL(); student Student = StudentBLL.GetModel(Session["UserId"].ToString().Trim()); Student.passWord = Tools.encrypt(passWordStr1); try { if (StudentBLL.Update(Student)) { MessageBox.Show(this, "修改成功!"); initial(Session["UserId"].ToString().Trim()); } else MessageBox.Show(this, "修改失败!"); } catch { MessageBox.Show(this, "修改失败!"); } } else { MessageBox.Show(this, "密码为空或者密码不同!"); } }
protected void checkBtn_Click(object sender, EventArgs e) { string stuIdStr = Tools.safeUserInput(stuIdTB.Text.ToString().Trim()); string idStr = Tools.safeUserInput(idTB.Text.ToString().Trim()); if (stuIdStr.Length < 1) { MessageBox.Show(this, "学号不能为空!"); return; } if (idStr.Length < 1) { MessageBox.Show(this, "身份证号不能为空!"); return; } studentBLL StudentBLL = new studentBLL(); student Student = StudentBLL.GetModel(stuIdStr); if (Student == null) { MessageBox.Show(this, "你输入的学号不存在!"); return; } if (Student.certificateId.Equals(idStr)) { Session["check"] = "1"; ViewState["stuId"] = stuIdStr; Panel1.Visible = false; Panel2.Visible = true; } else { Session["check"] = "0"; MessageBox.Show(this, "您输入的学号与身份证号不匹配!"); return; } }
protected void uploadBtn_Click(object sender, EventArgs e) { studentBLL StudentBLL = new studentBLL(); int result=StudentBLL.Add(this, excelFU); if (result == 0) MessageBox.Show(this, "上传失败!"); else MessageBox.ShowAndRedirect(this, "成功导入" + result + "个学生信息","student.aspx"); }
protected void loginBtn_Click(object sender, EventArgs e) { string userName = Tools.safeUserInput(stuIdTB.Text.Trim()); string passWord = Tools.safeUserInput(passwordTB.Text.Trim()); string yzmStr = yzmTB.Text.Trim(); if (userName.Length < 1) { MessageBox.Show(this, "用户名不能为空"); return; } if (passWord.Length < 1) { MessageBox.Show(this, "密码不能为空"); return; } if (yzmStr.Length < 1) { MessageBox.Show(this, "验证码不能为空"); return; } if (yzmStr.Equals(Request.Cookies["CheckCode"].Value.ToString())) { studentBLL StudentBLL = new studentBLL(); string loginMessage = StudentBLL.Login(userName, passWord); if (loginMessage.Equals("1")) { string stuIdStr = StudentBLL.GetModel(userName).stuId.ToString(); Session["status"] = "true"; Session["UserId"] = stuIdStr; Session["type"] = "2"; studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL(); StudentLoginLogBLL.login(Request.ServerVariables["REMOTE_ADDR"].ToString(), stuIdStr); MessageBox.ShowAndRedirect(this, "登录成功!", "student.aspx"); } else { Session["status"] = "false"; Session["UserId"] = "0"; Session["type"] = "0"; MessageBox.ShowAndRedirect(this, loginMessage, "logout.aspx"); } } else { MessageBox.ShowAndRedirect(this, "验证码错误!", "logout.aspx"); return; } }
protected void addStudentBtn_Click(object sender, EventArgs e) { student Student = new student(); if (isTextBoxEmpty(stuIdTB, "学生学号")) Student.stuId = getText(stuIdTB); else return; if (isTextBoxEmpty(nameTB, "学生姓名")) Student.name = getText(nameTB); else return; Student.sex = sexDDL.SelectedItem.Value; if (isTextBoxEmpty(nationTB, "民族")) Student.nation = getText(nationTB); else return; if (isTextBoxEmpty(birthdayTB, "出生日期")) { string birthday = getText(birthdayTB); if (birthday.Length != 8) { MessageBox.Show(this, "出生日期格式不正确!"); return; } Student.birthday = birthday; } else return; if (isTextBoxEmpty(certificateTypeTB, "证件类型")) Student.certificateType = getText(certificateTypeTB); else return; if (isTextBoxEmpty(certificateIdTB, "证件号码")) Student.certificateId = getText(certificateIdTB); else return; if (isTextBoxEmpty(majorIdTB, "专业代码")) Student.majorId = getText(majorIdTB); else return; if (isTextBoxEmpty(majorNameTB, "专业名称")) Student.majorName = getText(majorNameTB); else return; if (isTextBoxEmpty(colleageTB, "所在学院")) Student.colleage = getText(colleageTB); else return; Student.classType = getText(classTypeTB); if (isTextBoxEmpty(degreeTB, "毕业学位")) Student.degree = getText(degreeTB); else return; Student.type = getText(typeTB); Student.placeOfWork = getText(placeOfWorkTB); Student.workPhone = getText(workPhoneTB); if (isTextBoxEmpty(phoneTB, "移动电话")) Student.phone = getText(phoneTB); else return; Student.email = getText(emailTB); Student.address = getText(addressTB); Student.zipCode = getText(zipCodeTB); string passWord = Tools.safeUserInput(passWordTB.Text.Trim().ToString()); if (passWord.Length < 1) Student.passWord = Tools.encrypt(Student.certificateId); else Student.passWord = Tools.encrypt(passWord); try { studentBLL StudentBLL = new studentBLL(); StudentBLL.Add(Student); } catch { MessageBox.Show(this, "添加失败!"); } MessageBox.Show(this, "添加成功!"); }
protected void initial(string stuId) { studentBLL StudentBLL = new studentBLL(); student Student = StudentBLL.GetModel(stuId); stuIdStr = Student.stuId; nameStr = Student.name; majorNameStr = Student.majorName; idStr = Student.certificateId; emailTB.Text = Student.email; cellPhoneTB.Text = Student.phone; }
protected void InitializePage() { studentBLL StudentBAll = new studentBLL(); student Student = StudentBAll.GetModel(stuId); stuIdStr = Student.stuId; nameStr = Student.name; sexStr = Student.sex; colleageStr = Student.colleage; majorStr = Student.majorName; if (Student.admissionDate != null && Student.admissionDate.ToString().Length == 6) schoolTimeStr = Student.admissionDate.Insert(4, "年").Insert(7, "年"); examrecordBLL ExamRecordBLL = new examrecordBLL(); zongXueFenStr = ExamRecordBLL.SumCredit(stuId); xueWeiKeZongXueFenStr = ExamRecordBLL.SumGXWCredit(stuId); xueWeikeJiaQuanPingJunStr = ExamRecordBLL.SumGXWAverageCredit(stuId); }
protected void Button2_Click(object sender, EventArgs e) { studentBLL StudentBLL = new studentBLL(); examrecordBLL ExamRecordBLL = new examrecordBLL(); studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL(); try { ExamRecordBLL.Delete(Session["StuId"].ToString().Trim()); StudentLoginLogBLL.Delete(Session["StuId"].ToString().Trim()); StudentBLL.Delete(id); } catch { MessageBox.Show(this, "删除失败!"); } MessageBox.ShowAndRedirect(this, "删除成功!", "student.aspx"); }
protected void saveBtn_Click(object sender, EventArgs e) { string emailStr = Tools.safeUserInput(emailTB.Text.ToString().Trim()); string cellPhoneStr = Tools.safeUserInput(cellPhoneTB.Text.ToString().Trim()); studentBLL StudentBLL = new studentBLL(); student Student = StudentBLL.GetModel(Session["UserId"].ToString().Trim()); Student.phone = cellPhoneStr; Student.email = emailStr; try { if (StudentBLL.Update(Student)) { MessageBox.Show(this, "修改成功!"); initial(Session["UserId"].ToString().Trim()); } else MessageBox.Show(this, "修改失败!"); } catch { MessageBox.Show(this, "修改失败!"); } }
protected void Button1_Click(object sender, EventArgs e) { studentBLL StudentBLL = new studentBLL(); student Student = new student(); DataSet Students = new DataSet(); int select = Convert.ToInt32(DropDownList1.SelectedValue); try { switch (select) { case 0: Students = StudentBLL.GetList("[stuId] LIKE '%" + Tools.safeUserInput(TextBox1.Text.Trim()) + "%'"); GridView3.DataSource = Students; GridView3.DataBind(); Panel1.Visible = false; Panel2.Visible = false; Panel3.Visible = true; break; break; case 1: Students = StudentBLL.GetList("[name] LIKE '%" + Tools.safeUserInput(TextBox1.Text.Trim()) + "%'"); GridView3.DataSource = Students; GridView3.DataBind(); Panel1.Visible = false; Panel2.Visible = false; Panel3.Visible = true; break; case 2: Student = StudentBLL.GetModelList("[certificateId] ='" +Tools.safeUserInput( TextBox1.Text.Trim() )+ "'")[0]; Response.Redirect("studentView.aspx?id=" + Student.id); break; case 3: Student = StudentBLL.GetModelList("[phone] ='" + Tools.safeUserInput(TextBox1.Text.Trim()) + "'")[0]; Response.Redirect("studentView.aspx?id=" + Student.id); break; } } catch { MessageBox.Show(this, "查询失败!"); } }
/// <summary> /// 添加EXCEL信息 /// </summary> public int Add(Page page, FileUpload fu, int classId) { examrecordDAL ExamRecordDAL = new examrecordDAL(); try { int i = 0; if (fu.HasFile == false) { MessageBox.Show(page, "请选择您要上传的Excel文件!"); return 0;//当无文件时,返回 } string IsXls = System.IO.Path.GetExtension(fu.FileName).ToString().ToLower(); if (IsXls != ".xls") { MessageBox.Show(page, "只可以上传Excel文件!"); return 0;//当选择的不是Excel文件时,返回 } string path = page.Server.MapPath("storage/scoreInput/"); string strpath = fu.PostedFile.FileName.ToString(); //获取Execle文件路径 string filename = "批量成绩信息" + System.DateTime.Now.ToString("yyyyMMddHHmmss").Trim() + ".xls"; //从时间获取文件路径 fu.PostedFile.SaveAs(path + filename); DataSet ds = Tools.ExecleDs(path + filename, filename); DataRow[] dr = ds.Tables[0].Select(); //定义一个DataRow数组 int rowsnum = ds.Tables[0].Rows.Count; if (rowsnum == 0) { //Response.Write("<script>alert('Excel表为空表,无数据!')</script>"); MessageBox.Show(page, "Excel表为空表,无数据!");//当Excel表为空时,对用户进行提示 return 0; } else { for (i = 0; i < dr.Length; i++) { if (isInClass(dr[i]["任课教师"].ToString(), dr[i]["课程名称"].ToString(), classId)) { examrecord ExamRecord = new examrecord(); string stuId = dr[i]["学生学号"].ToString(); if (stuId.Length < 1) { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生学号不能为空,请检查数据"); return i; } else { studentBLL StudentBLL = new studentBLL(); student Student = null; try { Student = StudentBLL.GetModelList("stuId='" + stuId + "'")[0]; } catch { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生学号不存在,请检查数据"); return i; } if (Student != null) { if (Student.name.Trim().Equals(dr[i]["学生姓名"].ToString().Trim())) { ExamRecord.student = stuId; } else { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生学号不存在,请检查数据"); return i; } } } int score = 0; try { score = Convert.ToInt32(dr[i]["成绩"].ToString()); } catch { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生成绩仅可以为数字且不能为空,请检查数据"); return i; } if (score != 0) { ExamRecord.score = score.ToString(); } else { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生成绩仅可以为数字且不能为空,请检查数据"); return i; } ExamRecord.classId = classId.ToString(); ExamRecordDAL.Add(ExamRecord); } else { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生课程名称不存在,请检查数据"); return i; } } return i; } } catch { return 0; } finally { } }
protected string getStuName(string stuId) { studentBLL StudentBLL = new studentBLL(); return StudentBLL.GetStuName(stuId); }
protected void initial(int Id) { studentBLL StudentBLL = new studentBLL(); student Student = StudentBLL.GetModel(Id); try { stuIdTB.Text = Student.stuId; nameTB.Text = Student.name; sexDDL.SelectedValue = Student.sex; nationTB.Text = Student.nation; birthdayTB.Text = Student.birthday; certificateTypeTB.Text = Student.certificateType; certificateIdTB.Text = Student.certificateId; majorIdTB.Text = Student.majorId; majorNameTB.Text = Student.majorName; colleageTB.Text = Student.colleage; degreeTB.Text = Student.degree; classTypeTB.Text = Student.classType; typeTB.Text = Student.type; placeOfWorkTB.Text = Student.placeOfWork; workPhoneTB.Text = Student.workPhone; phoneTB.Text = Student.phone; emailTB.Text = Student.email; addressTB.Text = Student.address; zipCodeTB.Text = Student.zipCode; schoolYearTB.Text = Student.admissionDate; } catch { MessageBox.Show(this, "该学生不存在!"); Response.Write("<script language=javascript>history.go(-2);</script>"); } finally { }; examrecordBLL ExamRecordBLL = new examrecordBLL(); sumCreditStr = ExamRecordBLL.SumCredit(Session["StuId"].ToString().Trim()); stuGXWCreditStr = ExamRecordBLL.SumGXWCredit(Session["StuId"].ToString().Trim()); stuGXWAverageCreditStr = ExamRecordBLL.SumGXWAverageCredit(Session["StuId"].ToString().Trim()); }
protected void updateStudentBtn_Click(object sender, EventArgs e) { student Student = new student(); if (isTextBoxEmpty(stuIdTB, "学生学号")) Student.stuId = getText(stuIdTB); else return; if (isTextBoxEmpty(nameTB, "学生姓名")) Student.name = getText(nameTB); else return; Student.sex = sexDDL.SelectedItem.Value; if (isTextBoxEmpty(nationTB, "民族")) Student.nation = getText(nationTB); else return; if (isTextBoxEmpty(birthdayTB, "出生日期")) { string birthday = getText(birthdayTB); if (birthday.Length != 8) { MessageBox.Show(this, "出生日期格式不正确!"); return; } Student.birthday = birthday; } else return; if (isTextBoxEmpty(certificateTypeTB, "证件类型")) Student.certificateType = getText(certificateTypeTB); else return; if (isTextBoxEmpty(certificateIdTB, "证件号码")) Student.certificateId = getText(certificateIdTB); else return; if (isTextBoxEmpty(schoolYearTB, "入学时间")) Student.admissionDate = getText(schoolYearTB); else return; if (isTextBoxEmpty(majorIdTB, "专业代码")) Student.majorId = getText(majorIdTB); else return; if (isTextBoxEmpty(majorNameTB, "专业名称")) Student.majorName = getText(majorNameTB); else return; if (isTextBoxEmpty(colleageTB, "所在学院")) Student.colleage = getText(colleageTB); else return; Student.classType = getText(classTypeTB); Student.degree = getText(degreeTB); Student.type = getText(typeTB); Student.placeOfWork = getText(placeOfWorkTB); Student.workPhone = getText(workPhoneTB); if (isTextBoxEmpty(phoneTB, "移动电话")) Student.phone = getText(phoneTB); else return; Student.email = getText(emailTB); Student.address = getText(addressTB); Student.zipCode = getText(zipCodeTB); string passWord = Tools.safeUserInput(passWordTB.Text.Trim().ToString()); studentBLL StudentBLL = new studentBLL(); if (passWord.Length < 1) Student.passWord = StudentBLL.GetModel(id).passWord; else Student.passWord = Tools.encrypt(passWord); if (StudentBLL.GetModel(id).stuId != Student.stuId) { examrecordBLL ExamRecordBLL = new examrecordBLL(); studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL(); try { StudentBLL.Add(Student); ExamRecordBLL.repalaceStuId(StudentBLL.GetModel(id).stuId, Student.stuId); StudentLoginLogBLL.repalaceStuId(StudentBLL.GetModel(id).stuId, Student.stuId); StudentBLL.Delete(id); } catch { MessageBox.Show(this, "更新失败!"); } } if (Session["StuId"].ToString().Trim().Equals(getText(stuIdTB))) { Student.id = id; try { StudentBLL.Update(Student); } catch { MessageBox.Show(this, "更新失败!"); } } MessageBox.ShowAndRedirect(this, "更新成功!", "student.aspx"); }
protected void Page_Load(object sender, EventArgs e) { Tools.authentication(this, "1", "2"); if (Session["type"].ToString().Equals("2")) Panel1.Visible = false; markUnder60(); try { id = Convert.ToInt32(Request.QueryString["id"].ToString().Trim()); ViewState["id"] = id; studentBLL StudentBLL = new studentBLL(); Session["StuId"] = StudentBLL.GetModel(id).stuId; } catch { MessageBox.Show(this, "你查询的页面不存在!"); Response.Write("<script language=javascript>history.go(-2);</script>"); } finally { } if (!Page.IsPostBack) { id = Convert.ToInt32(ViewState["id"]); initial(id); } }