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 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"); }
/// <summary> /// 批量导入信息 /// </summary> public int Add(Page page, FileUpload fu) { 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/studentInput/"); 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) { MessageBox.Show(page, "Excel表为空表,无数据!");//当Excel表为空时,对用户进行提示 return 0; } else { for (i = 0; i < dr.Length; i++) { student Student = new student(); string stuId = dr[i]["学生学号"].ToString(); if (stuId.Length < 1) { MessageBox.Show(page, "第" + (i + 1).ToString() + "学生学号不能为空,请检查数据"); return i; } else Student.stuId = stuId; string name = dr[i]["学生姓名"].ToString(); if (name.Length < 1) { MessageBox.Show(page, "第" + (i + 1).ToString() + "学生姓名不能为空,请检查数据"); return i; } else Student.name = name; Student.nation = Tools.safeUserInput(dr[i]["学生民族"].ToString()); Student.birthday = Tools.safeUserInput(dr[i]["出生日期"].ToString()); Student.certificateType = Tools.safeUserInput(dr[i]["证件类型"].ToString()); Student.certificateId = Tools.safeUserInput(dr[i]["证件号码"].ToString()); Student.majorId = Tools.safeUserInput(dr[i]["专业代码"].ToString()); Student.majorName = Tools.safeUserInput(dr[i]["专业名称"].ToString()); Student.colleage = Tools.safeUserInput(dr[i]["所在学院"].ToString()); Student.classType = Tools.safeUserInput(dr[i]["集中办学"].ToString()); Student.degree = Tools.safeUserInput(dr[i]["毕业学位"].ToString()); Student.placeOfWork =Tools.safeUserInput( dr[i]["工作单位"].ToString()); Student.type = Tools.safeUserInput(dr[i]["单位类型"].ToString()); Student.workPhone = Tools.safeUserInput(dr[i]["办公电话"].ToString()); Student.phone = Tools.safeUserInput(dr[i]["移动电话"].ToString()); Student.email = Tools.safeUserInput(dr[i]["电子邮箱"].ToString()); Student.address = Tools.safeUserInput(dr[i]["工作地址"].ToString()); Student.zipCode = Tools.safeUserInput(dr[i]["邮政编码"].ToString()); Student.passWord = Tools.encrypt(Student.certificateId); Student.sex = Tools.safeUserInput(dr[i]["学生性别"].ToString()); Student.admissionDate = Tools.safeUserInput(dr[i]["入学年份"].ToString()); Add(Student); string oldStuId = Tools.safeUserInput(dr[i]["进修学号"].ToString().Trim()); if (oldStuId.Length > 1) { examrecordBLL ExamRecordBLL = new examrecordBLL(); studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL(); ExamRecordBLL.repalaceStuId(oldStuId, Student.stuId); StudentLoginLogBLL.repalaceStuId(oldStuId, Student.stuId); Delete(GetModel(oldStuId).id); } } return i+1; } } catch { return 0; } finally { } }
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"); }