protected void ibtCommit_Click(object sender, ImageClickEventArgs e) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///创建Question类的实例 //Question q = new Question(); Subject s = new Subject(); //q.Score = Int32.Parse(tbScore.Text); //q.SubjectID = subjectID; //q.Title = tbTitle.Text; s.Name = tbTitle.Text; //q.Answer = ddlAnswer.SelectedValue; ///插入到数据库中 db.Subject.InsertOnSubmit(s); db.SubmitChanges(); ///查询最近被插入的问题,并获取其ID值 var query = from qe in db.Subject orderby qe.ID descending select qe; if (query.Count() > 0) { ///获取问题的ID值,并添加它的答案 int questionID = query.First().ID; //AddAnswer(db,questionID,"A",tbAnswerA.Text); //AddAnswer(db,questionID,"B",tbAnswerB.Text); //AddAnswer(db,questionID,"C",tbAnswerC.Text); //AddAnswer(db,questionID,"D",tbAnswerD.Text); } ///将修改保存到数据库 db.SubmitChanges(); ///跳转到考题管理页面 Response.Redirect("~/Admin/SubjectManage.aspx"); }
protected void gvQuestion_RowCommand(object sender, GridViewCommandEventArgs e) { //if(e.CommandName == "edit") //{ ///跳转到修改考题页面 // Response.Redirect("~/Admin/UpdateQuestion.aspx?QuestionID=" + e.CommandArgument.ToString()); //} if (e.CommandName == "del") { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///产生答案 //var queryA = from a in db.Answer // where a.QuestionID.Value.ToString() == e.CommandArgument.ToString() // select a; //db.Answer.DeleteAllOnSubmit(queryA); ///删除考题 var queryQ = from q in db.Subject where q.ID.ToString() == e.CommandArgument.ToString() select q; db.Subject.DeleteAllOnSubmit(queryQ); ///提交到数据库 db.SubmitChanges(); ///重新显示考题 BindPageData(Int32.Parse(ddlSubject.SelectedValue)); } }
private void BindPageData() { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///获取所有考生成绩 gvScore.DataSource = db.Pr_GetScores(); gvScore.DataBind(); }
private void AddAnswer(ExamineDBDataContext db, int questionID, string tag, string body) { ///创建Answer类的实例,并插入到数据库中 Answer a = new Answer(); a.Tag = tag; a.Body = body; a.QuestionID = questionID; db.Answer.InsertOnSubmit(a); }
protected void ibtCommit_Click(object sender, ImageClickEventArgs e) { int totalScore = 0; ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///获取当前考生的在线考试的ID值 //if(Session["OnlineExamineID"] == null) return; //int onlineExamineID = Int32.Parse(Session["OnlineExamineID"].ToString()); foreach (GridViewRow row in gvQuestion.Rows) { RadioButtonList rbl = (RadioButtonList)row.FindControl("rblAnswer"); if (rbl != null) { ///获取考题ID值,考生的答案等信息 int questionID = Int32.Parse(gvQuestion.DataKeys[row.RowIndex]["ID"].ToString()); string answer = string.Empty; if (rbl.SelectedIndex > -1) { answer = ((char)(((int)'A') + rbl.SelectedIndex)).ToString(); } ///将考生的答案添加到数据库中 //ExamineeAnswer ea = new ExamineeAnswer(); //ea.OnlineExamineID = onlineExamineID; //ea.QuestionID = questionID; //ea.Answer = answer; //db.ExamineeAnswer.InsertOnSubmit(ea); ///获取当前考题的正确答案,并得出考生的得分 var query = from q in db.Question where q.ID == questionID select q; if (query.Count() > 0) { ///比较考生的答案和该题的正确答案,如果正确,则计算分值 Question cq = query.First(); if (cq.Answer.ToUpper().Trim() == answer.ToUpper().Trim()) { totalScore += cq.Score.Value; } } } } ///将考试成绩保存到数据库 //var queryoex = from oe in db.OnlineExamine // where oe.ID == onlineExamineID // select oe; //foreach(OnlineExamine oex in queryoex) //{ // oex.Score = totalScore; //} ///讲考生答题保存到数据库 //db.SubmitChanges(); ///显示考试成绩 lbTotalScore.Text = "提交完成,本次测试成绩为:" + totalScore.ToString() + "分"; }
private void BindPageData(int questionID) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///查询被显示的考题 var query = from q in db.Question where q.ID == questionID select q; if (query.Count() > 0) { ///获取考题,并显示 Question curq = query.First(); tbTitle.Text = curq.Title; tbScore.Text = curq.Score.Value.ToString(); ///显示正确的答案 for (int i = 0; i < ddlAnswer1.Items.Count; i++) { if (ddlAnswer1.Items[i].Value == curq.Answer.Trim()) { ddlAnswer1.SelectedIndex = i; break; } } ///查询考题的答案 var queryA = from a in db.Answer where a.QuestionID == questionID select a; ///判断考题答案的数量是否为4个 if (queryA.Count() != 4) { return; } ///显示每一个答案 foreach (Answer aw in queryA) { if (aw.Tag.Trim() == "A") { tbAnswerA.Text = aw.Body; continue; } if (aw.Tag.Trim() == "B") { tbAnswerB.Text = aw.Body; continue; } if (aw.Tag.Trim() == "C") { tbAnswerC.Text = aw.Body; continue; } if (aw.Tag.Trim() == "D") { tbAnswerD.Text = aw.Body; continue; } } } }
private void BindPageData(int subjectID) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///查询考题 var query = from q in db.Subject //where q.SubjectID == subjectID select q; ///绑定控件数据,并显示考题 gvQuestion.DataSource = query; gvQuestion.DataBind(); }
private void BindPageData() { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///获取考题的考题信息 var query = from q in db.Question where q.SubjectID == subjectID select q; ///显示考题 gvQuestion.DataSource = query; gvQuestion.DataBind(); }
protected void ibtCommit_Click(object sender, ImageClickEventArgs e) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///创建Question类的实例 Question q = new Question(); q.Score = Int32.Parse(tbScore.Text); q.SubjectID = subjectID; q.Title = tbTitle.Text; //q.Answer = ddlAnswer1.SelectedValue; string answer, a1, a2, a3, a4 = string.Empty; a1 = ddlAnswer1.SelectedValue; a2 = ddlAnswer2.SelectedValue; a3 = ddlAnswer3.SelectedValue; a4 = ddlAnswer4.SelectedValue; answer = a1; if (a2 != "无" && a2 != a1) { answer += "/" + a2; } if (a3 != "无" && a3 != a1 && a3 != a2) { answer += "/" + a3; } if (a4 != "无" && a4 != a1 && a4 != a2 && a4 != a3) { answer += "/" + a4; } q.Answer = answer; //Response.Write(answer); ///插入到数据库中 db.Question.InsertOnSubmit(q); db.SubmitChanges(); ///查询最近被插入的问题,并获取其ID值 var query = from qe in db.Question orderby qe.ID descending select qe; if (query.Count() > 0) { ///获取问题的ID值,并添加它的答案 int questionID = query.First().ID; AddAnswer(db, questionID, "A", tbAnswerA.Text); AddAnswer(db, questionID, "B", tbAnswerB.Text); AddAnswer(db, questionID, "C", tbAnswerC.Text); AddAnswer(db, questionID, "D", tbAnswerD.Text); } ///将修改保存到数据库 db.SubmitChanges(); ///跳转到考题管理页面 Response.Redirect("~/Admin/QuestionManage.aspx"); }
private void BindPageData() { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///查询考试科目 var query = from s in db.Subject select s; ///绑定控件数据,并显示考试科目 ddlSubject.DataSource = query; ddlSubject.DataTextField = "Name"; ddlSubject.DataValueField = "ID"; ddlSubject.DataBind(); }
private void BindAnswerData(RadioButtonList rbl, int questionID) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///获取考题的答案信息 var query = from a in db.Answer where a.QuestionID == questionID select a; ///绑定到指定的列表控件 rbl.DataSource = query; rbl.DataTextField = "Body"; rbl.DataValueField = "ID"; rbl.DataBind(); }
protected void ibtCommit_Click(object sender, ImageClickEventArgs e) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///查询被修改的考题 var query = from q in db.Question where q.ID == questionID select q; ///修改考题的信息 foreach (Question qe in query) { qe.Answer = ddlAnswer.SelectedValue; qe.Score = Int32.Parse(tbScore.Text); qe.Title = tbTitle.Text; } ///查询被修改的答案 var queryA = from a in db.Answer where a.QuestionID == questionID select a; ///修改答案的信息 foreach (Answer aw in queryA) { if (aw.Tag.Trim() == "A") { aw.Body = tbAnswerA.Text; } if (aw.Tag.Trim() == "B") { aw.Body = tbAnswerB.Text; } if (aw.Tag.Trim() == "C") { aw.Body = tbAnswerC.Text; } if (aw.Tag.Trim() == "D") { aw.Body = tbAnswerD.Text; } } ///将修改保存到数据库 db.SubmitChanges(); ///跳转到考题管理页面 Response.Redirect("~/Admin/QuestionManage.aspx"); }
protected void ibtLogin_Click(object sender, ImageClickEventArgs e) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///查询Examinee表 var query = from ex in db.AdminUser where ex.Username == tbUsername.Text.Trim() && ex.Password == tbPassword.Text.Trim() select ex; ///获取用户信息,并判断用户登录是否成功 if (query.Count() > 0) { ///保存用户登录信息 Session["UserID"] = query.First().ID.ToString(); Session["Username"] = query.First().Username; ///跳转到Select.aspx页面 Response.Redirect("~/Admin/Main.aspx"); } }
protected void ibtCommit_Click(object sender, ImageClickEventArgs e) { ///创建ExamineDB数据库的数据上下文 ExamineDBDataContext db = new ExamineDBDataContext(OnlineExamineSystem.ExamineDBConnectionString); ///查询被修改的考题 var query = from q in db.Question where q.ID == questionID select q; ///修改考题的信息 foreach (Question qe in query) { //qe.Answer = ddlAnswer1.SelectedValue; string answer, a1, a2, a3, a4 = string.Empty; a1 = ddlAnswer1.SelectedValue; a2 = ddlAnswer2.SelectedValue; a3 = ddlAnswer3.SelectedValue; a4 = ddlAnswer4.SelectedValue; answer = a1; if (a2 != "无" && a2 != a1) { answer += "/" + a2; } if (a3 != "无" && a3 != a1 && a3 != a2) { answer += "/" + a3; } if (a4 != "无" && a4 != a1 && a4 != a2 && a4 != a3) { answer += "/" + a4; } qe.Answer = answer; qe.Score = Int32.Parse(tbScore.Text); qe.Title = tbTitle.Text; } ///查询被修改的答案 var queryA = from a in db.Answer where a.QuestionID == questionID select a; ///修改答案的信息 foreach (Answer aw in queryA) { if (aw.Tag.Trim() == "A") { aw.Body = tbAnswerA.Text; } if (aw.Tag.Trim() == "B") { aw.Body = tbAnswerB.Text; } if (aw.Tag.Trim() == "C") { aw.Body = tbAnswerC.Text; } if (aw.Tag.Trim() == "D") { aw.Body = tbAnswerD.Text; } } ///将修改保存到数据库 db.SubmitChanges(); ///跳转到考题管理页面 Response.Redirect("~/Admin/QuestionManage.aspx"); }