protected void BtnButton_Click(object sender, EventArgs e) { DataTable dt = (DataTable)ViewState["QuestionAnsDT"]; int rightAnswer = 0; int wrongAnswer = 0; int QuestionBankID = 0; int i = Convert.ToInt32(ViewState["CurQuestion"]); QuestionBankID = Convert.ToInt32(dt.Rows[i]["QuestionBankID"].ToString()); if (dt.Rows.Count - 2 == i) { dt.Rows[i]["GivenAnswer"] = rdb.SelectedItem.Text; dt.Rows[i]["GivenAnswerID"] = rdb.SelectedValue; if (rdb.SelectedValue.ToString() == dt.Rows[i]["AnswerID"].ToString()) { rightAnswer = 1; } else { wrongAnswer = 1; } dt.AcceptChanges(); BtnButton.Text = "Finish"; i = i + 1; ViewState["CurQuestion"] = i; BindNextQuestion(dt); } else if (dt.Rows.Count - 1 != i) { dt.Rows[i]["GivenAnswer"] = rdb.SelectedItem.Text; dt.Rows[i]["GivenAnswerID"] = rdb.SelectedValue; if (rdb.SelectedValue.ToString() == dt.Rows[i]["AnswerID"].ToString()) { rightAnswer = 1; } else { wrongAnswer = 1; } dt.AcceptChanges(); i = i + 1; ViewState["CurQuestion"] = i; BindNextQuestion(dt); } else { dt.Rows[i]["GivenAnswerID"] = rdb.SelectedValue; dt.Rows[i]["GivenAnswer"] = rdb.SelectedItem.Text; if (rdb.SelectedValue.ToString() == dt.Rows[i]["AnswerID"].ToString()) { rightAnswer = 1; } else { wrongAnswer = 1; } dt.AcceptChanges(); int trueAns = 0, falseAns = 0; for (int AnsLoo = 0; AnsLoo < dt.Rows.Count; AnsLoo++) { if (dt.Rows[AnsLoo]["AnswerID"].ToString() == dt.Rows[AnsLoo]["GivenAnswerID"].ToString()) { trueAns = trueAns + 1; dt.Rows[AnsLoo]["ResultTF"] = "True"; dt.AcceptChanges(); } else { falseAns = falseAns + 1; dt.Rows[AnsLoo]["ResultTF"] = "False"; dt.AcceptChanges(); } } lblTotalQues.Text = Convert.ToString(trueAns + falseAns); lblTrueAns.Text = Convert.ToString(trueAns); lblFalseAns.Text = Convert.ToString(falseAns); ExamResult.Visible = true; Examtbl.Visible = false; lbluserScoreValue.Text = lblTrueAns.Text + "/" + lblTotalQues.Text; ViewState["QuestionAnsDT"] = dt; Session["ExamStarted"] = "Finished"; if (AppSessions.StudentID != null && AppSessions.StudentID != 0) { dt.TableName = "StudentResult"; dt.AcceptChanges(); QuestionMaster objQuestionMaster = new QuestionMaster(); objQuestionMaster.BAL_StudentExamResult(Convert.ToInt32(dt.Rows[0]["BMSSCTID"].ToString()), AppSessions.StudentID, dt, ViewState["TestTypeToTable"].ToString()); } gvAnalysis.DataSource = dt; gvAnalysis.DataBind(); //WebMsg.Show("Your Exam Finished"); i = i + 1; } //For Save to Application to view Teacher DataTable dtExaAuto = null; Hashtable Question = (Hashtable)Application["Exam_TeacherSheResult"]; if (Question == null) { Question = new Hashtable(); } else { dtExaAuto = (DataTable)Question[Session["TrackLogID"].ToString()]; } if (dtExaAuto != null) { Application.Lock(); //lock to prevent duplicate objects //foreach (DataRow dr in dtExaAuto.Rows) //{ DataRow dr = dtExaAuto.Select("QuestionBankID=" + QuestionBankID.ToString()).FirstOrDefault(); if (dr["QuestionBankID"].ToString() == QuestionBankID.ToString()) { if (dr["RightAnswer"].ToString() != string.Empty) { dr["RightAnswer"] = Convert.ToInt32(dr["RightAnswer"].ToString()) + rightAnswer; } else { dr["RightAnswer"] = rightAnswer; } if (dr["WrongAnswer"].ToString() != string.Empty) { dr["WrongAnswer"] = Convert.ToInt32(dr["WrongAnswer"].ToString()) + wrongAnswer; } else { dr["WrongAnswer"] = wrongAnswer; } if (dr["Attendent"].ToString() != string.Empty) { dr["Attendent"] = Convert.ToInt32(dr["Attendent"].ToString()) + 1; } else { dr["Attendent"] = 1; } } //} dtExaAuto.AcceptChanges(); Question[Session["TrackLogID"].ToString()] = dtExaAuto; Application["Exam_TeacherSheResult"] = Question; Application.UnLock(); } //For End Save to Application }
protected void BtnButton_Click(object sender, EventArgs e) { DataTable dt = (DataTable)ViewState["QuestionAnsDT"]; int i = Convert.ToInt32(ViewState["CurQuestion"]); if (dt.Rows.Count - 2 == i) { dt.Rows[i]["GivenAnswer"] = rdb.SelectedItem.Text; dt.Rows[i]["GivenAnswerID"] = rdb.SelectedValue; dt.AcceptChanges(); BtnButton.Text = "Finish"; i = i + 1; ViewState["CurQuestion"] = i; BindNextQuestion(dt); } else if (dt.Rows.Count - 1 != i) { dt.Rows[i]["GivenAnswer"] = rdb.SelectedItem.Text; dt.Rows[i]["GivenAnswerID"] = rdb.SelectedValue; dt.AcceptChanges(); i = i + 1; ViewState["CurQuestion"] = i; BindNextQuestion(dt); } else { dt.Rows[i]["GivenAnswerID"] = rdb.SelectedValue; dt.Rows[i]["GivenAnswer"] = rdb.SelectedItem.Text; dt.AcceptChanges(); int trueAns = 0, falseAns = 0; for (int AnsLoo = 0; AnsLoo < dt.Rows.Count; AnsLoo++) { if (dt.Rows[AnsLoo]["AnswerID"].ToString() == dt.Rows[AnsLoo]["GivenAnswerID"].ToString()) { trueAns = trueAns + 1; dt.Rows[AnsLoo]["ResultTF"] = "True"; dt.AcceptChanges(); } else { falseAns = falseAns + 1; dt.Rows[AnsLoo]["ResultTF"] = "False"; dt.AcceptChanges(); } } lblTotalQues.Text = Convert.ToString(trueAns + falseAns); lblTrueAns.Text = Convert.ToString(trueAns); lblFalseAns.Text = Convert.ToString(falseAns); ExamResult.Visible = true; Examtbl.Visible = false; lbluserScoreValue.Text = lblTrueAns.Text + "/" + lblTotalQues.Text; ViewState["QuestionAnsDT"] = dt; if (AppSessions.StudentID != null && AppSessions.StudentID != 0) { dt.TableName = "StudentResult"; dt.AcceptChanges(); QuestionMaster objQuestionMaster = new QuestionMaster(); objQuestionMaster.BAL_StudentExamResult(Convert.ToInt32(dt.Rows[0]["BMSSCTID"].ToString()), AppSessions.StudentID, dt, ViewState["TestTypeToTable"].ToString()); } gvAnalysis.DataSource = dt; gvAnalysis.DataBind(); //WebMsg.Show("Your Exam Finished"); } }