protected void Page_Load(object sender, EventArgs e) { if (Session["DepartmentID"] == null) Response.Redirect("~/login.aspx"); if (!IsPostBack) { if (Request.QueryString["StudentID"] != null) { try { int sID = int.Parse(Request.QueryString["StudentID"]); s = Student.GetStudentByID(sID); } catch { } } else { s = Student.GetStudentByID(UserID); } ShowProfile(); } }
/// <summary> /// 插入一个学生实体 /// </summary> /// <param name="Student">学生实体</param> /// <returns></returns> public static bool InsertStudent(StudentInfo s) { ExamDbDataContext dc = DataAccess.CreateDBContext(); if (dc.StudentInfo.Any(p => p.LoginName == s.LoginName)) return false; dc.StudentInfo.InsertOnSubmit(s); dc.SubmitChanges(); PurgeCacheItems("AllStudents"); return true; }
protected void Page_Load(object sender, EventArgs e) { if(s==null)s = Student.GetStudentByID(UserID,out dc); if (Session["DepartmentID"] == null) Response.Redirect("~/login.aspx"); if (!IsPostBack) { SetProfile(); panelModify.Visible = true; } }
private void ShowProfile(StudentInfo s) { if (s == null) { Response.Write("对不起,暂未分配学生给您!"); return; } //lblRealName.Text = ReturnValidString(s.StuName); //lblMajor.Text = BaseData.GetMajorByID(s.MajorID).MajorName; //lblHomePhone.Text = ReturnValidString(s.HomePhoneNum); //lblAddress.Text = ReturnValidString(s.HomeAddress); //lblCellPhone.Text = ReturnValidString(s.CellPhone); //lblClass.Text = ReturnValidString(s.Class); //lblDepartment.Text =BaseData.GetDepartmentByID(s.DepartmentID).DepartmentName; //lblEmail.Text = ReturnValidString(s.Email); //lblQQ.Text = ReturnValidString(s.QQNum); //lblGrade.Text = ReturnValidString(s.Grade); //lblPersonalDesc.Text = ReturnValidString(s.PersonalDesc); //lblStuNum.Text = ReturnValidString(s.StuNum); //imgPhoto.ImageUrl = s.ImagePath; //panelCurrentProile.Visible = true; }
private void StartExam() { //if (Utility.CheckIfFinished(UserID)) //{ // NotAllowToExam(); // return; //} if (Utility.CheckIfFinished(StuNum,BasicExamID)) { NotAllowToExam(); return; } string showEndtime=""; XElement xroot = null; // WebConfigurationManager.AppSettings["ActiveBasicExamID"]; //这里不需要设置courseID,,//只要设置basicExamID即可,可以从网址中获取!! //if (basicExamID == null) return; int examID = BasicExamID; lblPaperName.Text = BasicExam.GetBasicExamByID(examID).BasicExamTitle; if (File.Exists(Utility.GetStuExamFilePath(StuNum,examID)) == false) //如果考生xml文件不存在,则创建。 { StudentInfo stu=null; int randomExamID = 0; if(Session["Role"].ToString()=="visitor") { stu=new StudentInfo(); lblWelcome.Text = "游客,欢迎您!!"; stu.StuNum=StuNum; stu.StudentID=0; stu.ClassID = 0; } else { stu=Student.GetStudentByID(UserID); lblWelcome.Text = stu.StuName + "同学,欢迎您!!"; } lblWelcome.Visible = true; randomExamID = RandomExam.CreatRandomExamXMLFile(stu, examID); if (randomExamID == 0) return; ExamDbDataContext dc = DataAccess.CreateDBContext(); RandomExamInfo r = RandomExam.GetRandomExamByID(randomExamID, out dc); r.StartTime = DateTime.Now; r.EndTime = DateTime.Now.AddMinutes((double)r.TimeUse); showEndtime = r.EndTime.ToString(); dc.SubmitChanges(); xroot = GetRootElement(); xroot.SetAttributeValue("endTime", showEndtime); xroot.SetAttributeValue("loginNum", 1); this.index = (int)r.TimeUse; } else //如果考生xml文件已经存在,则直接读取。 { ViewState["againLogin"] = true; xroot = GetRootElement(); showEndtime = xroot.Attribute("endTime").Value;//从xml文件中获取结束时间 string loginNum = xroot.Attribute("loginNum").Value; int l = int.Parse(loginNum); l++; xroot.SetAttributeValue("loginNum", l); TimeSpan tLeft = DateTime.Parse(showEndtime) - DateTime.Now; //如果考试时间已过,不允许考试!! //如果已经交卷了呢?? this.index = tLeft.Minutes+tLeft.Hours*60; if (index <= 0) { // NotAllowToExam(); //这里应该对RandomExam重新设置,还需要帮学生交卷计分 RandomExam.SetTotalMark(xroot, 0, 0, 0, true); // EndExam("由于考试时间已到,系统自动交卷,考试结束!!"); // RandomExam.SetRandomExamFinished(int.Parse(xroot.Attribute("randomExamID").Value)); return; } } xroot.Save(Utility.GetStuExamFilePath(StuNum,BasicExamID)); panelWholePaper.Visible = true; lblTotalTimeHint.Text = "考试总时间为:" + this.index.ToString() + "分钟,结束时间为:"; if (ViewState["againLogin"] != null && (bool)ViewState["againLogin"]) lblTotalTimeHint.Text = "考试总时间为:" + this.index.ToString() + "分钟(因为您已登录过),结束时间为:"; lblTotalTimeHint.Text += showEndtime+",到时会自动交卷。请注意时间。"; lblTime.Text = this.index+ "分钟"; Timer1.Enabled = true; btnSubmit.Enabled = true; lblMessage.Visible = false;//或者给其他提示信息 BindRep(); // //ClientTimer_Test.TimerEnabled = true; //ClientTimer_Test.TimeOutLength = index; }
/// <summary> /// 将excel文件中的数据转换成学生实体集合 /// </summary> /// <param name="filePath">excel文件的物理路径</param> /// <returns></returns> private static IList<StudentInfo> ChangeExcelToStudents(string filePath) { IList<StudentInfo> students = new List<StudentInfo>(); string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; if (filePath.EndsWith("xlsx")) strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\""; string deptName = ""; string majorName = ""; OleDbConnection myConn = new OleDbConnection(strConn); string strCom = " SELECT * FROM [Sheet1$]"; OleDbCommand cmd = new OleDbCommand(strCom, myConn); string defaultPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "SHA1"); OleDbDataReader dr = null; try { myConn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { //if(dr["姓名"]==null||dr["学号"]==null||dr["班级"]==null||dr["专业"]==null|| dr["家庭地址"]==null) // continue; StudentInfo s = new StudentInfo(); s.StuName = dr["姓名"].ToString(); s.LoginName = dr["学号"].ToString(); s.Password = defaultPwd; s.StuNum = dr["学号"].ToString(); s.Class = dr["班级"].ToString(); deptName = dr["系别"].ToString(); s.DepartmentID = ReturnID(deptDic, deptName); // else s.DepartmentID = deptDic["外语系"]; majorName = dr["专业"].ToString(); s.MajorID = ReturnID(majorDic, majorName); if (s.MajorID == 0 || s.DepartmentID == 0) { throw new Exception("系别或专业名称中有错,请按照提示填写! "+deptName+" "+ majorName); } //else s.MajorID = 10001; if (dr["性别"] != null && dr["性别"].ToString().Equals("男")) s.Sex = false; else s.Sex = true; // if(dr["家庭地址"]!=null) s.HomeAddress = dr["家庭地址"].ToString(); if (dr["年级"] != null) s.Grade = dr["年级"].ToString(); // else s.Grade = "2010"; if (dr["学生类别"] != null) s.StuType = dr["学生类别"].ToString(); //s.IdentityCardNo=decimal.Parse(dr["身份证号"].ToString()); s.MajorDirection = dr["专业方向"].ToString(); if (dr["民族"] != null) s.Race = dr["民族"].ToString(); // s.LengthOfSchool = (char)dr["学制"]; // s.Birthday = DateTime.Parse(dr["出生日期"].ToString()); // if(dr["相片地址"]!=null)s.ImagePath="~/Files/Student/Photos/"+ dr["相片地址"].ToString(); s.ImagePath = "~/Files/PublicFiles/Student/Photos/" + deptName + "/" + s.StuNum + ".jpg"; s.IsFullProfile = false; s.State = -1; s.TeacherID = null; students.Add(s); // HttpContext.Current.Response.Write("一条记录<br>"); } } catch (Exception e) { HttpContext.Current.Response.Write("错误信息:" + e.Message); students = null; } finally { if (dr != null) dr.Close(); myConn.Close(); } return students; }
public static void UpdateStudent(StudentInfo s, ExamDbDataContext dc) { AttachInfo<StudentInfo>(dc.StudentInfo, s); dc.SubmitChanges(); PurgeCacheItems("AllStudents"); PurgeCacheItems("StudentsToSelect_" + s.DepartmentID); }
/// <summary> /// 更新学生实体信息 /// </summary> /// <param name="s">需要更新的学生实体</param> public static void UpdateStudent(StudentInfo s) { ExamDbDataContext dc = DataAccess.CreateDBContext(); StudentInfo ss = new StudentInfo(); ss.CellPhone = s.CellPhone; ss.Class = s.Class; ss.Email = s.Email; ss.DepartmentID = s.DepartmentID; ss.DepartmentInfo = s.DepartmentInfo; ss.Grade = s.Grade; // ss.HasSelectedExam = s.HasSelectedExam; ss.HomeAddress = s.HomeAddress; ss.HomePhoneNum = s.HomePhoneNum; ss.ImagePath = s.ImagePath; ss.IsFullProfile = s.IsFullProfile; ss.LoginName = s.LoginName; ss.MajorID = s.MajorID; ss.Password = s.Password; ss.PersonalDesc = s.PersonalDesc; ss.QQNum = s.QQNum; ss.State = s.State; ss.StudentID = s.StudentID; ss.StuName = s.StuName; ss.StuNum = s.StuNum; ss.TeacherID = s.TeacherID; AttachInfo<StudentInfo>(dc.StudentInfo, ss); dc.SubmitChanges(); PurgeCacheItems("AllStudents"); }
private bool GetInfoByControls(StudentInfo oldstu) { oldstu.StuName = txtRealName.Text; oldstu.StuNum = txtStuNum.Text; oldstu.LoginName = txtLoginName.Text; if (IsSuperAdmin() && btnSubmit.Text == "确定添加") { //lblDeptAndMajor.Text = ddlSelectDepts.SelectedItem.Text + " " + ddlSelectMajor.SelectedItem.Text; // lblDept.Visible = true; //int dID = int.Parse(ddlSelectDepts.SelectedValue); //int mID = int.Parse(ddlSelectMajor.SelectedValue); //if (dID == 0 || mID == 0) //没有选择系别专业 //{ // lblError.Text = "请选择系别合专业!"; // lblError.Visible = true; // return false; //} //else //{ oldstu.DepartmentID = DeptMajorClassDropdownList1.DepartmentID;// dID; oldstu.MajorID = DeptMajorClassDropdownList1.MajorID; oldstu.ClassID = DeptMajorClassDropdownList1.ClassID; oldstu.Class = DeptMajorClassDropdownList1.ClassName; if (oldstu.DepartmentID == 0 || oldstu.MajorID == 0 || oldstu.ClassID == 0) { lblError.Text = "请依次选择系别专业班级!"; lblError.Visible = true; return false; } //} } else { oldstu.DepartmentID = DeptID; //oldstu.MajorID = int.Parse(ddlMajors.SelectedValue); } oldstu.Grade = txtGrade.Text; oldstu.HomeAddress = txtHomeAddress.Text; oldstu.Sex = bool.Parse(ddlSex.SelectedValue); oldstu.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1"); return true; }
protected void btnSubmit_Click(object sender, EventArgs e) { if (btnSubmit.Text == "确定添加") { StudentInfo s = new StudentInfo(); if (GetInfoByControls(s) == false) return; //s.ClassID = 0; ///先假设新增的班级id都为0 Student.InsertStudent(s); this.ClientScript.RegisterStartupScript(this.GetType(), "Hint", "<script>alert('成功添加学生信息')</script>"); } else { if (Session["dc"] != null && Session["stuInfo"] != null) { ExamDbDataContext dc = Session["dc"] as ExamDbDataContext; StudentInfo oldstu = Session["stuInfo"] as StudentInfo; if (GetInfoByControls(oldstu) == false) return; Student.UpdateStudent(oldstu, dc); Session["dc"] = null; Session["stuInfo"] = null; this.ClientScript.RegisterStartupScript(this.GetType(), "Hint", "<script>alert('成功修改学生信息')</script>"); } else { Response.Write("Session is null,can't modify"); return; } } BindGrid(); GridView1.Visible = true; panelModify.Visible = false; }
protected void Button1_Click(object sender, EventArgs e) { if (s == null) { lblMessage.Text="不能获取学生信息~"; lblMessage.Visible = true; s = Student.GetStudentByID(UserID); if (s == null) Response.Redirect("~/Login.aspx"); } string pwd123 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "SHA1"); if (txtPassword.Text == "123456") { lblMessage.Text="初始密码必须修改为其他!"; lblMessage.Visible = true; return; } else if (txtPassword.Text == "" && s.Password == pwd123) { lblMessage.Text = "必须修改初始密码为其他!"; lblMessage.Visible = true; return; } bool hasAttachment = false; string attachmentPath = ""; if (ViewState["hasAttachment"] != null) hasAttachment = (bool)ViewState["hasAttachment"]; if (ViewState["attachmentPath"] != null) attachmentPath = ViewState["attachmentPath"].ToString(); s.LoginName = txtLoginName.Text; s.StuName = txtRealName.Text; if (txtPassword.Text != "") { string pwdEncode = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1"); s.Password = pwdEncode; } //s.MajorID= txtMajor.Text ; s.HomePhoneNum = txtHomePhone.Text; s.HomeAddress = txtAddress.Text; s.CellPhone = txtCellPhone.Text; s.Class = txtClass.Text; // s.DepartmentID=; s.Email = txtEmail.Text; s.QQNum = txtQQ.Text; s.PersonalDesc = txtPersonalDesc.Text; s.StuNum = txtStuNum.Text; if (hasAttachment == true) s.ImagePath = attachmentPath; //else s.ImagePath = "no pic"; s.IsFullProfile = true; s.Grade = txtGrade.Text; Student.UpdateStudent(s,dc); Session["FullProfile"] = true; ViewState["hasAttachment"] = null; ViewState["attachmentPath"] = null; this. ClientScript.RegisterStartupScript(this.GetType(), "Hint", "<script>alert('成功修改个人资料')</script>"); Response.Redirect("ProfileManagement.aspx"); }
///生成学生随机试卷的xml文件,返回随机试卷的ID public static int CreatRandomExamXMLFile(StudentInfo stu, int basicExamID) { ExamDbDataContext dc = DataAccess.CreateDBContext(); BasicExamInfo exam = dc.BasicExamInfo.Single(p => p.BasicExamID == basicExamID); if (exam == null) return 0; IList<int> singleChoices = GetSingleChoicesIDs(dc, exam); IList<int> mutilChoices = GetMutilChoicesIDs(dc, exam); IList<int> judges = GetJudgesIDs(dc, exam); //将随机生成的选择题id和判断题id分别插入随机试卷实体中 RandomExamInfo re = new RandomExamInfo(); re.SingleChoiceIDs = getIDs(singleChoices); if (mutilChoices == null) re.MutilChoiceIDs = "0"; else re.MutilChoiceIDs = getIDs(mutilChoices); re.JudgeIDs = getIDs(judges); re.BasicExamID = basicExamID; re.ExamInfoFilePath =Utility.GetRelativeExamFilePath(stu.StuNum,basicExamID);//需要相对路径,待修改!! re.StudentID = stu.StudentID; re.ClassID = (int)stu.ClassID; re.InExaming = true; re.LoginTimes = 1; re.HasFinished = false; re.StartTime = DateTime.Now; re.TimeUse = exam.TimeUse; re.IsVisitor = (stu.StudentID == 0); re.StuNum = stu.StuNum; int randomExamID = RandomExam.InsertRandomExam(re); //XDocument xdoc=new XDocument( XElement xroot = new XElement("StudentExam"); xroot.SetAttributeValue("stuNum", stu.StuNum); xroot.SetAttributeValue("basicExamID", basicExamID); xroot.SetAttributeValue("randomExamID", randomExamID); xroot.SetAttributeValue("getMark",0); //xroot.SetAttributeValue("timeLeft", re); xroot.SetAttributeValue("endTime", ""); xroot.SetAttributeValue("loginNum", "1"); //随机获取指定数量的单项选择题,假设要5条单项题 //if (singleChoices == null || mutilChoices == null || judges == null) return 0; //if (singleChoices.Count == 0 || mutilChoices.Count == 0 || judges.Count == 0) return 0; XElement singlesElement= GetChoices(dc, exam, singleChoices,"SingleChoice"); xroot.Add(singlesElement); XElement mutilsElement = GetChoices(dc, exam, mutilChoices, "MutilChoice"); if (mutilChoices != null) xroot.Add(mutilsElement); XElement judgesElement = GetJudgesELement(dc, exam, judges); xroot.Add(judgesElement); xroot.Save(Utility.GetStuExamFilePath(stu.StuNum,basicExamID)); return randomExamID; }
private void detach_StudentInfo1(StudentInfo entity) { this.SendPropertyChanging(); entity.TeacherInfo1 = null; }
private void attach_StudentInfo(StudentInfo entity) { this.SendPropertyChanging(); entity.TeacherInfo = this; }
private void detach_StudentInfo(StudentInfo entity) { this.SendPropertyChanging(); entity.MajorInfo = null; }