public DataTable FindQuestion(QuestionBO oQuestionBO) { try { query = @"SELECT *, ISNULL(Stuff((SELECT ',' + answer FROM DefaultAnswer DA LEFT JOIN Question Q ON DA.questionID = Q.questionID WHERE Question.questionID = DA.questionID FOR XML PATH('')),1,1,''), '') defaultAnswers FROM Question INNER JOIN QuestionRepitation ON Question.QRID = QuestionRepitation.QRID WHERE question LIKE '%' + @question +'%' ORDER BY questionID DESC"; dad = new SqlDataAdapter(query, con); if (con.State == ConnectionState.Closed) { con.Open(); } dad.SelectCommand.Parameters.AddWithValue("@question", oQuestionBO.question); dt = new DataTable(); dad.Fill(dt); return dt; } catch { throw; } finally { con.Close(); } }
public frmQuestion() { this.questionBO = this.questionBO ?? new QuestionBO(); this.departmentBO = this.departmentBO ?? new DepartmentBO(); InitializeComponent(); QuestionBO q = new QuestionBO(); gridControl1.DataSource = q.GetDepartmentnameFromDepartmentID(1); }
public ActionResult Edit(Question question) { try { if (ModelState.IsValid) { db.Entry(question).State = EntityState.Modified; //取消更新前的字段验证 db.Configuration.ValidateOnSaveEnabled = false; var entry = db.Entry(question); //以下字段不更新 entry.Property(e => e.CreationDate).IsModified = false; entry.Property(e => e.CreatedBy).IsModified = false; entry.Property(e => e.Attribute1).IsModified = false; entry.Property(e => e.Attribute2).IsModified = false; entry.Property(e => e.Attribute3).IsModified = false; entry.Property(e => e.Attribute4).IsModified = false; entry.Property(e => e.Attribute5).IsModified = false; entry.Property(e => e.Attribute6).IsModified = false; entry.Property(e => e.Attribute7).IsModified = false; entry.Property(e => e.Attribute8).IsModified = false; entry.Property(e => e.Attribute9).IsModified = false; entry.Property(e => e.Attribute10).IsModified = false; entry.Property(e => e.QuestionTitle).IsModified = false; entry.Property(e => e.QuestionType).IsModified = false; entry.Property(e => e.CourseId).IsModified = false; entry.Property(e => e.Status).IsModified = false; question.LastUpdateDate = DateTime.Now; question.LastUpdatedBy = Convert.ToInt32(UserLogin.userid); //从系统获取 //Validate Question before commit to Database QuestionBO questioneBO = new QuestionBO(); string errorMsg = ""; errorMsg = questioneBO.ValidateQuestionEdit(question); if (!String.IsNullOrEmpty(errorMsg)) { ViewBag.ErrorMsg = errorMsg; return(View(question)); } db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; return(RedirectToAction("Index")); } } catch (Exception ex) { ViewBag.ErrorMsg = ex.Message; return(View(question)); } return(View(question)); }
public DataTable FindQuestion(QuestionBO oQuestionBO) { try { return oQuestionDAL.FindQuestion(oQuestionBO); } catch { throw; } finally { } }
public string InsertQuestion(QuestionBO oQuestionBO, DefaultAnswerBO oDefaultAnswerBO) { try { return oQuestionDAL.InsertQuestion(oQuestionBO, oDefaultAnswerBO); } catch { throw; } finally { } }
public void DeleteQuestion(QuestionBO oQuestionBO) { try { oQuestionDAL.DeleteQuestion(oQuestionBO); } catch { throw; } finally { } }
private void cboDepartment_TextChanged(object sender, EventArgs e) { DepartmentBO department = new DepartmentBO(); QuestionBO q = new QuestionBO(); var a = department.getDepartmentName(cboDepartment.Text); string b = "0"; foreach (var temp in a) { b = temp.DepartmentID.ToString(); } if (b != "0") { gridControl1.DataSource = q.GetDepartmentnameFromDepartmentID(Int32.Parse(b)); } if (b == "0") { gridControl1.DataSource = q.GetDepartmentALL(); } }
public void DeleteQuestion(QuestionBO oQuestionBO) { try { query = "DELETE FROM Question WHERE questionID=@questionID"; cmd = new SqlCommand(query, con); if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Parameters.AddWithValue("@questionID", oQuestionBO.questionID); cmd.ExecuteNonQuery(); } catch { throw; } finally { con.Close(); } }
protected void btn_Save_Click(object sender, EventArgs e) { Result oResult = new Result(); Question oQuestion = new Question(); QuestionBO oQuestionBO = new QuestionBO(); Objective oObjective = new Objective(); List<Category> oListCategory = new List<Category>(); List<Choice> oListOfChoices = new List<Choice>(); String sHiddenFieldValue = String.Empty; String sChoiceWithCheck = String.Empty; String sTxtValue = String.Empty; String sChkValue = String.Empty; bool bflag = false; int iNextStartIndex=0; int Index = 0; try { if (IsValidSaveCategory(dr_SaveCategory.SelectedValue) && IsValidQuestionText(txt_SaveQuestion.Text) && IsValidPossibleAnswerTime(txt_PossibleAnswerTime.Text) && IsValidSystemUserID() && IsValidDefaultQuestionMark(txt_SaveDefaultMark.Text) && IsValidTypeName(SelectQuestionSave.Value) && IsValidQuestionLevel(drDn_QuestionLevel.SelectedValue)) { oQuestion.QuestionText = txt_SaveQuestion.Text.Replace("'",String.Empty); oQuestion.QuestionCreator.SystemUserID = gSystemUserID; oQuestion.QuestionDefaultMark = float.Parse(txt_SaveDefaultMark.Text); oQuestion.QuestionIsUsed = false; oQuestion.QuestionPossibleAnswerTime = float.Parse(txt_PossibleAnswerTime.Text); oQuestion.QuestionLevel.LevelID = new Guid(drDn_QuestionLevel.SelectedValue); oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory); oQuestion.QuestionCategory.CategoryID = oListCategory[dr_SaveCategory.SelectedIndex - 1].CategoryID; if (SelectQuestionSave.Value.Equals("Objective")) { //oQuestion.QuestionObjectiveType.TypeName = SelectQuestionSave.Value; //populate the choices //get the choices from, runtime created textboxes oQuestion.QuestionQuestionType.QuestionTypeID = 0; sHiddenFieldValue = HiddenStoreTxtBoxCheckBoxValue.Value.Replace("'", String.Empty); if (IsValidChoices(sHiddenFieldValue)) { while (iNextStartIndex < sHiddenFieldValue.Length && sHiddenFieldValue.IndexOf('@', iNextStartIndex) >= 0) { Index = sHiddenFieldValue.IndexOf('@', iNextStartIndex); sChoiceWithCheck = sHiddenFieldValue.Substring(iNextStartIndex, Index - iNextStartIndex); sTxtValue = sChoiceWithCheck.Substring(0, sChoiceWithCheck.IndexOf(':', 0)); sChkValue = sChoiceWithCheck.Substring(sChoiceWithCheck.IndexOf(':', 0) + 1); Choice oChoice = new Choice(); oChoice.ChoiceName = sTxtValue; oChoice.ChoiceIsValid = Convert.ToBoolean(sChkValue); if (!oChoice.ChoiceName.Equals(String.Empty) && oChoice.ChoiceName.Length<=1000) { oListOfChoices.Add(oChoice); if (oChoice.ChoiceIsValid) { bflag = true; } } iNextStartIndex = Index + 1; } oObjective.ListOfChoices = oListOfChoices; oQuestion.QuestionObjectiveType = oObjective; } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Enter Choices in corrected format."; } } else if (SelectQuestionSave.Value.Equals("Descriptive")) { oQuestion.QuestionQuestionType.QuestionTypeID = 1; bflag = true; } if (bflag) { oResult = oQuestionBO.QuestionEntry(oQuestion); if (oResult.ResultIsSuccess) { lbl_error.ForeColor = Color.Green; lbl_error.Text = oResult.ResultMessage; clearControlValue(); } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Check All entered value."; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Enter all value in corrected format."; } } catch (Exception oEx) { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Exception occured during Question Entry."; } }
public string InsertQuestion(QuestionBO oQuestionBO, DefaultAnswerBO oDefaultAnswerBO) { try { cmd = new SqlCommand("InsertQuestion", con); cmd.CommandType = CommandType.StoredProcedure; if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Parameters.AddWithValue("@question", oQuestionBO.question); cmd.Parameters.AddWithValue("@QTypeID", oQuestionBO.QTypeID); cmd.Parameters.AddWithValue("@answer", oDefaultAnswerBO.answer); cmd.Parameters.AddWithValue("@QRID", oQuestionBO.QRID); cmd.Parameters.AddWithValue("@status", oQuestionBO.status); SqlParameter message = cmd.Parameters.Add("@message", SqlDbType.VarChar, 500); message.Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); return message.Value.ToString(); } catch { throw; } finally { con.Close(); } }
public void UpdateQuestion(QuestionBO oQuestionBO) { try { query = "UPDATE Question set QRID=@QRID, status=@status WHERE questionID=@questionID"; cmd = new SqlCommand(query, con); if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Parameters.AddWithValue("@questionID", oQuestionBO.questionID); cmd.Parameters.AddWithValue("@QRID", oQuestionBO.QRID); cmd.Parameters.AddWithValue("@status", oQuestionBO.status); cmd.ExecuteNonQuery(); } catch { throw; } finally { con.Close(); } }
protected void btn_Setup_Click(object sender, EventArgs e) { String sHiddenFiledValue = HiddenFieldForStoreChkBoxIndex.Value; String sHiddenFiledMark = HiddenFieldForStoreTxtBoxMark.Value; String sCheckedRowIndex = String.Empty; String sNewRowMark = String.Empty; Exam oExam = new Exam(); Result oResult = new Result(); QuestionBO oQuestionBO = new QuestionBO(); List<QuestionSetup> oListQuestionSetupForShow = new List<QuestionSetup>(); List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>(); float fTotalMarks = 0f; float fTotalTime = 0f; bool IsRandomSelection = false; //bool IsSetupSuccessByLevelOrFromList = false; bool IsBylevelSelection = false; try { if (oObject!= null) { oExam = (Exam)oObject; //oExam.ExamConstraint="some value from the UI"; //update EX_Exam in the DAO by the oExam.ExamConstraint. //oExam.ExamConstraint is defaultly =0; if(IsBeforeExamStarted(oExam)) { if (dr_ListOrRandom.SelectedValue.Equals("By Question Level")) { IsBylevelSelection = true; } if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]") && !lbl_Questions.Text.Equals(String.Empty) && (dr_ListOrRandom.SelectedValue.Equals("From List") || (dr_ListOrRandom.SelectedValue.Equals("By Question Level") && !drdnSelectQuestionLevel.SelectedValue.Equals("[Select One]")))) { int iNextStartIndex = 0; int Index = 0; int i = 0; int j = 0; float f = 0f; Boolean flag = false; //oListQuestionSetupForShow = (List<QuestionSetup>)Utils.GetSession(SessionManager.csStoreGridView); oListQuestionSetupForShow = (List<QuestionSetup>)this.ViewState[SessionManager.csStoreGridView]; int[] iarrChecked = new int[oListQuestionSetupForShow.Count]; float[] iarrNewMark = new float[oListQuestionSetupForShow.Count]; for (j = 0; j < iarrChecked.Length; j++) { iarrChecked[j] = 0; iarrNewMark[j] = oListQuestionSetupForShow[j].QuestionSetupMark; } while (iNextStartIndex < sHiddenFiledValue.Length && sHiddenFiledValue.IndexOf(':', iNextStartIndex) >= 0) { Index = sHiddenFiledValue.IndexOf(':', iNextStartIndex); sCheckedRowIndex = sHiddenFiledValue.Substring(iNextStartIndex, Index - iNextStartIndex); if (int.TryParse(sCheckedRowIndex, out i)) { iarrChecked[Grid_Questions.PageIndex * Grid_Questions.PageSize + int.Parse(sCheckedRowIndex)] = 1; //marked flag = true; } iNextStartIndex = Index + 1; } if (flag) { iNextStartIndex = 0; Index = 0; //get the marks from the text boxes in the GridView i = 0; while (iNextStartIndex < sHiddenFiledMark.Length && sHiddenFiledMark.IndexOf(':', iNextStartIndex) >= 0) { Index = sHiddenFiledMark.IndexOf(':', iNextStartIndex); sNewRowMark = sHiddenFiledMark.Substring(iNextStartIndex, Index - iNextStartIndex); if (float.TryParse(sNewRowMark, out f)) { iarrNewMark[Grid_Questions.PageIndex * Grid_Questions.PageSize + i] = float.Parse(sNewRowMark); //marked } //else //{ // iarrNewMark[Grid_Questions.PageIndex * Grid_Questions.PageSize + i] = oListQuestionSetupForShow[Grid_Questions.PageIndex * Grid_Questions.PageSize + i].QuestionSetupMark; //} i++; iNextStartIndex = Index + 1; } oResult = oQuestionBO.GetTotalLastSetupQuestionMark(oExam); if (oResult.ResultIsSuccess) { fTotalMarks = (float)oResult.ResultObject; //populate the List of QuestionSetupObject i = 0; foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow) { QuestionSetup oQuestionSetup = new QuestionSetup(); oQuestionSetup.QuestionSetupExam = oExam; oQuestionSetup.QuestionSetupGenerationTime = DateTime.Now; oQuestionSetup.QuestionSetupSystemUser = oSystemUser; oQuestionSetup.QuestionSetupMark = iarrNewMark[i]; if (!oQuestionSetupInList.QuestionSetupQuestion.QuestionIsUsed && iarrChecked[i]==1) { fTotalMarks = fTotalMarks + iarrNewMark[i]; } oQuestionSetup.QuestionSetupQuestion = oQuestionSetupInList.QuestionSetupQuestion; oListQuestionSetup.Add(oQuestionSetup); i++; } if (fTotalMarks <= (float)oExam.ExamTotalMarks) { oResult = oQuestionBO.GetTotalLastSetupQuestionTime(oExam); if (oResult.ResultIsSuccess) { //sum the fTotalTime by the Grid's possible time for each question fTotalTime = (float)oResult.ResultObject; i=0; foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow) { if (!oQuestionSetupInList.QuestionSetupQuestion.QuestionIsUsed && iarrChecked[i] == 1) { fTotalTime = fTotalTime + oQuestionSetupInList.QuestionSetupQuestion.QuestionPossibleAnswerTime; } i++; } if (fTotalTime <= (float)(oExam.ExamDurationinHour * 60f)) { //now call the BO to insert question oResult = oQuestionBO.QuestionSetup(oListQuestionSetup, iarrChecked); if (oResult.ResultIsSuccess) { lbl_error.ForeColor = Color.Green; lbl_error.Text = oResult.ResultMessage; i = 0; foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetup) { oListQuestionSetupForShow[i].QuestionSetupMark = oQuestionSetupInList.QuestionSetupMark; i++; } //Utils.SetSession(SessionManager.csStoreGridView, oListQuestionSetupForShow); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionSetupForShow); //LoadCategoryfromSession(); //LoadQuestionType(); //LoadSelectionDropdownList(); //IsSetupSuccessByLevelOrFromList = true; } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Total Time OverFlow."; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Total Marks OverFlow."; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Select a Question please."; } } else if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]") && lbl_Questions.Text.Equals(String.Empty) && dr_ListOrRandom.SelectedValue.Equals("Random")) { IsRandomSelection = true; oListQuestionSetupForShow = (List<QuestionSetup>)this.ViewState[SessionManager.csStoreGridView]; int j = 0; int iTotalRandomQuestions = 0; int iFullfillTotalRandomnumber = 0; int iNextRandomIndex = -1000; int[] iarrChecked = new int[oListQuestionSetupForShow.Count]; int[] iarrRandomIndexChecked = new int[oListQuestionSetupForShow.Count]; for (j = 0; j < iarrChecked.Length; j++) { iarrChecked[j] = 0; iarrRandomIndexChecked[j] = 0; } if (IsValidPositiveInteger(txt_RandomQuestions.Text)) { if (int.Parse(txt_RandomQuestions.Text) <= oListQuestionSetupForShow.Count) { iTotalRandomQuestions = int.Parse(txt_RandomQuestions.Text); while (iFullfillTotalRandomnumber < iTotalRandomQuestions) { iNextRandomIndex = new Random().Next(0, oListQuestionSetupForShow.Count); if (iarrRandomIndexChecked[iNextRandomIndex] == 0) { iFullfillTotalRandomnumber = iFullfillTotalRandomnumber + 1; iarrRandomIndexChecked[iNextRandomIndex] = 1; iarrChecked[iNextRandomIndex] = 1; } } if (iFullfillTotalRandomnumber == iTotalRandomQuestions) { foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow) { oQuestionSetupInList.QuestionSetupExam = oExam; oQuestionSetupInList.QuestionSetupGenerationTime = DateTime.Now; oQuestionSetupInList.QuestionSetupSystemUser = oSystemUser; } oResult = oQuestionBO.QuestionSetup(oListQuestionSetupForShow, iarrChecked); if (oResult.ResultIsSuccess) { lbl_error.ForeColor = Color.Green; lbl_error.Text = oResult.ResultMessage; //Utils.SetSession(SessionManager.csStoreGridView, oListQuestionSetupForShow); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionSetupForShow); //LoadCategoryfromSession(); //LoadQuestionType(); //LoadSelectionDropdownList(); } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } lbl_RandomQuestions.Visible = true; txt_RandomQuestions.Visible = true; lblRandomOutOf.Visible = true; txtRandomOutOf.Visible = true; btn_View.Visible = false; } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Random question number must less than Total question Number"; lbl_RandomQuestions.Visible = true; txt_RandomQuestions.Visible = true; lblRandomOutOf.Visible = true; txtRandomOutOf.Visible = true; btn_View.Visible = false; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Random question number must greater than zero "; lbl_RandomQuestions.Visible = true; txt_RandomQuestions.Visible = true; lblRandomOutOf.Visible = true; txtRandomOutOf.Visible = true; btn_View.Visible = false; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Please Select Category,Type & SelectionType."; if (dr_ListOrRandom.SelectedValue.Equals("By Question Level") && drdnSelectQuestionLevel.SelectedValue.Equals("[Select One]")) { lbl_error.Text = "Please Select Category,Type,SelectionType & Question Level."; } } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Can not setup Question After Exam Started."; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Select an Exam please."; } //rdo_QuestionSelection.Items[0].Selected = false; //rdo_QuestionSelection.Items[1].Selected = false; if (!IsRandomSelection) { if (IsBylevelSelection) { lblQuestionLevel.Visible = true; drdnSelectQuestionLevel.Visible = true; } if (oListQuestionSetupForShow.Count > 0) { lbl_Questions.Text = "Questions"; Grid_Questions.Visible = true; //List<Question> oListQuestionForGridViewBind = new List<Question>(); //foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow) //{ // oListQuestionForGridViewBind.Add(oQuestionSetupInList.QuestionSetupQuestion); //} Grid_Questions.DataSource = oListQuestionSetupForShow; //Grid_Questions.DataSource = oListQuestionForGridViewBind; Grid_Questions.DataBind(); pnl_questions.Visible = true; pnl_questions.ScrollBars = ScrollBars.Auto; //pnl_questions.Controls.Add(Grid_Questions); } else { lbl_Questions.Text = String.Empty; } } //LoadSelectionDropdownList(); //lbl_Questions.Text = String.Empty; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} } catch (Exception oEx) { } }
protected void dr_Type_SelectedIndexChanged(object sender, EventArgs e) { HiddenForStoreSelectedRowIndex.Value = String.Empty; try { if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]")) { List<Category> oListCategory = new List<Category>(); oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory); Question oQuestion = new Question(); Objective oObjective = new Objective(); QuestionBO oQuestionBO = new QuestionBO(); Result oResult = new Result(); List<Question> oListQuestion = new List<Question>(); oQuestion.QuestionCategory.CategoryID = oListCategory[dr_Category.SelectedIndex - 1].CategoryID; oQuestion.QuestionCreator.SystemUserID = gSystemUserID; oQuestion.QuestionCreator.SystemUserName = sSystemUserName; if (dr_Type.SelectedValue.Equals("Objective")) { //For Show List of choice OR Answer is not necessary. oQuestion.QuestionQuestionType.QuestionTypeID=0; } else if (dr_Type.SelectedValue.Equals("Descriptive")) { oQuestion.QuestionQuestionType.QuestionTypeID = 1; } oResult = oQuestionBO.QuestionListShow(oQuestion); if (oResult.ResultIsSuccess) { oListQuestion =(List<Question>)oResult.ResultObject; //if objective then the list of choices and answers will be populated for each question //Utils.SetSession(SessionManager.csStoreGridView, oListQuestion); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestion); if (oListQuestion.Count > 0) { lbl_Questions.Text = "Questions"; Grid_Questions.DataSource = oListQuestion; Grid_Questions.DataBind(); pnl_questions.Visible = true; pnl_questions.ScrollBars = ScrollBars.Auto; pnl_questions.Controls.Add(Grid_Questions); } else { Label oLblError = new Label(); oLblError.Text = "No Question Found."; oLblError.ForeColor = Color.Red; pnl_questions.Visible = true; pnl_questions.Controls.Add(oLblError); lbl_Questions.Text = String.Empty; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; lbl_Questions.Text = String.Empty; txt_SaveQuestion.Text = String.Empty; txt_SaveDefaultMark.Text = String.Empty; txt_CurrentDefaultMark.Text = String.Empty; if (pnl_questions.Controls.Contains(Grid_Questions)) { pnl_questions.Controls.Remove(Grid_Questions); } } } else { if (dr_Type.SelectedValue.Equals("[Select One]")) { clearControlValue(); } } } catch (Exception oEx) { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Exception occured during Question List Show."; } }
public void UpdateQuestion(QuestionBO oQuestionBO) { try { oQuestionDAL.UpdateQuestion(oQuestionBO); } catch { throw; } finally { } }
protected void btn_Delete_Click(object sender, EventArgs e) { Result oResult = new Result(); QuestionBO oQuestionBO = new QuestionBO(); List<Question> oListQuestion = new List<Question>(); String sHiddenFiledValue = HiddenFieldForStoreChkBoxIndex.Value; String sCheckedRowIndex = String.Empty; //HiddenForStoreSelectedRowIndex.Value = String.Empty; try { if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]") && !lbl_Questions.Text.Equals(String.Empty)) { int iNextStartIndex = 0; int Index = 0; int i = 0; int j = 0; bool bAnySelectedQuestion = false; //oListQuestion = (List<Question>)Utils.GetSession(SessionManager.csStoreGridView); oListQuestion = (List<Question>)this.ViewState[SessionManager.csStoreGridView]; int[] iarrChecked = new int[oListQuestion.Count]; for (j = 0; j < iarrChecked.Length; j++) { iarrChecked[j] = 0; } while (iNextStartIndex < sHiddenFiledValue.Length && sHiddenFiledValue.IndexOf(':', iNextStartIndex) >= 0) { Index = sHiddenFiledValue.IndexOf(':', iNextStartIndex); sCheckedRowIndex = sHiddenFiledValue.Substring(iNextStartIndex, Index - iNextStartIndex); if (int.TryParse(sCheckedRowIndex, out i)) { iarrChecked[Grid_Questions.PageIndex * Grid_Questions.PageSize + int.Parse(sCheckedRowIndex)] = 1; //marked bAnySelectedQuestion = true; } iNextStartIndex = Index + 1; } if (bAnySelectedQuestion) { oResult = oQuestionBO.DeleteQuestionList(oListQuestion, iarrChecked); if (oResult.ResultIsSuccess) { oListQuestion = (List<Question>)oResult.ResultObject; txt_SaveQuestion.Text = String.Empty; txt_SaveDefaultMark.Text = String.Empty; txt_CurrentDefaultMark.Text = String.Empty; txt_CurrentpossibleTime.Text = String.Empty; txt_LastPossibleTime.Text = String.Empty; if (oListQuestion.Count > 0) { lbl_Questions.Text = "Questions"; Grid_Questions.DataSource = oListQuestion; Grid_Questions.DataBind(); pnl_questions.Visible = true; pnl_questions.ScrollBars = ScrollBars.Auto; pnl_questions.Controls.Add(Grid_Questions); if (oListQuestion.Count < iarrChecked.Length) { lbl_error.ForeColor = Color.Green; } else if (oListQuestion.Count == iarrChecked.Length) { lbl_error.ForeColor = Color.Red; } lbl_error.Text = oResult.ResultMessage; } else { lbl_error.ForeColor = Color.Green; lbl_error.Text = oResult.ResultMessage; lbl_Questions.Text = String.Empty; if (pnl_questions.Controls.Contains(Grid_Questions)) { pnl_questions.Controls.Remove(Grid_Questions); } } //Utils.SetSession(SessionManager.csStoreGridView, oListQuestion); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestion); } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Please select question."; } if (oListQuestion.Count > 0) { lbl_Questions.Text = "Questions"; Grid_Questions.DataSource = oListQuestion; Grid_Questions.DataBind(); pnl_questions.Visible = true; pnl_questions.ScrollBars = ScrollBars.Auto; pnl_questions.Controls.Add(Grid_Questions); } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Select category & type first, then delete question."; } } catch (Exception oEx) { oResult.ResultMessage = "Exception occured during Question Delete."; } }
protected void btn_Update_Click(object sender, EventArgs e) { Result oResult = new Result(); Question oQuestion = new Question(); QuestionBO oQuestionBO = new QuestionBO(); Objective oObjective = new Objective(); List<Category> oListCategory = new List<Category>(); List<Question> oListQuestion = new List<Question>(); List<Choice> oListOfChoices = new List<Choice>(); String sHiddenFieldValue = String.Empty; String sChoiceWithCheck = String.Empty; String sTxtValue = String.Empty; String sChkValue = String.Empty; bool bflag = false; int iNextStartIndex = 0; int Index = 0; int iSelectedRowIndex = -1000; int iOut=0; float fQuestionDefaultMark = 0f; float fQuestionPossibleTime = 0f; try { //oListQuestion = (List<Question>)Utils.GetSession(SessionManager.csStoreGridView); oListQuestion = (List<Question>)this.ViewState[SessionManager.csStoreGridView]; if (IsValidSaveCategory(dr_Category.SelectedValue) && IsValidSystemUserID() && IsValidTypeName(dr_Type.SelectedValue) && !lbl_Questions.Text.Equals(String.Empty)) { //oQuestion.QuestionCreator.SystemUserID = gSystemUserID; if (IsValidDefaultQuestionMark(txt_CurrentDefaultMark.Text)) { fQuestionDefaultMark = float.Parse(txt_CurrentDefaultMark.Text); } else if (IsValidDefaultQuestionMark(txt_SaveDefaultMark.Text)) { fQuestionDefaultMark = float.Parse(txt_SaveDefaultMark.Text); } if (IsValidPossibleAnswerTime(txt_CurrentpossibleTime.Text)) { fQuestionPossibleTime = float.Parse(txt_CurrentpossibleTime.Text); } else if (IsValidPossibleAnswerTime(txt_LastPossibleTime.Text)) { fQuestionPossibleTime = float.Parse(txt_LastPossibleTime.Text); } //oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory); //oQuestion.QuestionCategory.CategoryID = oListCategory[dr_Category.SelectedIndex - 1].CategoryID; if (int.TryParse(HiddenForStoreSelectedRowIndex.Value, out iOut)) { iSelectedRowIndex = int.Parse(HiddenForStoreSelectedRowIndex.Value); } if (iSelectedRowIndex >= 0 && fQuestionDefaultMark > 0f && fQuestionPossibleTime>0f) { oQuestion = oListQuestion[Grid_Questions.PageIndex * Grid_Questions.PageSize + iSelectedRowIndex]; oQuestion.QuestionDefaultMark = fQuestionDefaultMark; oQuestion.QuestionPossibleAnswerTime = fQuestionPossibleTime; if (dr_Type.SelectedValue.Equals("Objective")) { oQuestion.QuestionQuestionType.QuestionTypeID=0; //oQuestion.QuestionObjectiveType.TypeName = SelectQuestionSave.Value; //populate the choices //get the choices from, runtime created textboxes sHiddenFieldValue = HiddenStoreTxtBoxCheckBoxValue.Value.Replace("'",String.Empty); if (IsValidChoices(sHiddenFieldValue)) { while (iNextStartIndex < sHiddenFieldValue.Length && sHiddenFieldValue.IndexOf('@', iNextStartIndex) >= 0) { Index = sHiddenFieldValue.IndexOf('@', iNextStartIndex); sChoiceWithCheck = sHiddenFieldValue.Substring(iNextStartIndex, Index - iNextStartIndex); sTxtValue = sChoiceWithCheck.Substring(0, sChoiceWithCheck.IndexOf(':', 0)); sChkValue = sChoiceWithCheck.Substring(sChoiceWithCheck.IndexOf(':', 0) + 1); Choice oChoice = new Choice(); oChoice.ChoiceName = sTxtValue; oChoice.ChoiceIsValid = Convert.ToBoolean(sChkValue); if (!oChoice.ChoiceName.Equals(String.Empty) && oChoice.ChoiceName.Length<=1000) { oListOfChoices.Add(oChoice); if (oChoice.ChoiceIsValid) { bflag = true; } } iNextStartIndex = Index + 1; } oObjective.ListOfChoices = oListOfChoices; oQuestion.QuestionObjectiveType = oObjective; //bflag = true; } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Enter Choices in corrected format."; } } else if (dr_Type.SelectedValue.Equals("Descriptive")) { //oQuestion.QuestionDescriptiveType.TypeName = SelectQuestionSave.Value; oQuestion.QuestionQuestionType.QuestionTypeID = 1; bflag = true; } if (bflag) { oResult = oQuestionBO.UpdateQuestion(oQuestion); if (oResult.ResultIsSuccess) { oListQuestion.RemoveAt(Grid_Questions.PageIndex * Grid_Questions.PageSize + iSelectedRowIndex); oListQuestion.Insert(Grid_Questions.PageIndex * Grid_Questions.PageSize + iSelectedRowIndex, (Question)oResult.ResultObject); //Utils.SetSession(SessionManager.csStoreGridView, oListQuestion); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestion); lbl_error.ForeColor = Color.Green; lbl_error.Text = oResult.ResultMessage; txt_SaveQuestion.Text = String.Empty; txt_SaveDefaultMark.Text = String.Empty; txt_CurrentDefaultMark.Text = String.Empty; txt_LastPossibleTime.Text = String.Empty; txt_CurrentpossibleTime.Text = String.Empty; } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Must View a Question. Or Check Any one"; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Select a question and click view button."; } if (oListQuestion != null && oListQuestion.Count > 0) { lbl_Questions.Text = "Questions"; Grid_Questions.DataSource = oListQuestion; Grid_Questions.DataBind(); pnl_questions.Visible = true; pnl_questions.ScrollBars = ScrollBars.Auto; pnl_questions.Controls.Add(Grid_Questions); } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Select category & type first. Then select a question and click view button."; } HiddenForStoreSelectedRowIndex.Value = String.Empty; } catch (Exception oEx) { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Exception occured during Question Update."; } }
private void LoadAllQuestionsOfAnExamToGrid() { try { QuestionBO oQuestionBO = new QuestionBO(); Result oResult = new Result(); oResult = oQuestionBO.LoadAllQuestionsOfAnExam(oSelectedExam); if (oResult.ResultIsSuccess) { oListQuestionForGrid = (List<QuestionSetup>)oResult.ResultObject; this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionForGrid); if (oListQuestionForGrid.Count > 0) { Grid_AllQuestionsOfExam.DataSource = oListQuestionForGrid; Grid_AllQuestionsOfExam.DataBind(); lblTotalQuestions.Text = oListQuestionForGrid.Count.ToString(); } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = "No Question found."; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; } } catch (Exception oEx) { } }
public ActionResult Create(QuestionsMassVM questions) { //初始化项目名称列表 List <SelectListItem> projectList = new List <SelectListItem>(); //根据用户身份做判断 List <Project> pList = new List <Project>(); if (UserLogin.userroles.Contains("M")) { int userid = Convert.ToInt32(UserLogin.userid); var user = db.Users.Where(x => x.id == userid).FirstOrDefault(); var pros = from Projects in db.Projects where Projects.ManagerId == user.PersonId select Projects; pList = pros.ToList(); } else { pList = db.Projects.ToList(); } foreach (var item in pList) { SelectListItem listItem = new SelectListItem(); listItem.Text = item.ProjectName; listItem.Value = item.id.ToString(); projectList.Add(listItem); } ViewData["ProjectList"] = projectList; List <Question> quests = new List <Question>(); for (int i = 0; i < questions.QuestionDesc.Count; i++) { Question q = new Question() { CourseId = questions.CourseId, Status = "C", //默认都为保存未发布状态 QuestionType = questions.QuestionType, QuestionDesc = questions.QuestionDesc[i], QuestionNum = questions.QuestionNum[i], Comments = questions.Comments[i], CreatedBy = Convert.ToInt32(UserLogin.userid), //Need to change: to get userid from session!!! CreationDate = DateTime.Now, LastUpdateDate = DateTime.Now, LastUpdatedBy = Convert.ToInt32(UserLogin.userid) //Need to change: to get userid from session!!! }; quests.Add(q); } QuestionBO questionBO = new QuestionBO(); try { //Validation logic is needed before save to database 验证序号是否已经存在 string msg = questionBO.ValidateProject(quests); db.Questions.AddRange(quests); if (!String.IsNullOrEmpty(msg)) { ViewBag.ErrorMsg = msg; //return View(questions); return(Content("<script >alert('" + msg + "'); window.history.back();</script >", "text/html")); //return Content( msg ); } db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.ErrorMsg = ex.Message; return(View(questions)); } }
protected void dr_ListOrRandom_SelectedIndexChanged(object sender, EventArgs e) { try { if (dr_ListOrRandom.SelectedValue.Equals("[Select One]")) { lbl_Questions.Text = String.Empty; Grid_Questions.Visible = false; pnl_questions.Visible = false; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} } else if (dr_ListOrRandom.SelectedValue.Equals("Random")) { if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]")) { List<Category> oListCategory = new List<Category>(); oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory); Question oQuestion = new Question(); QuestionBO oQuestionBO = new QuestionBO(); Result oResult = new Result(); List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>(); oQuestion.QuestionCategory.CategoryID = oListCategory[dr_Category.SelectedIndex - 1].CategoryID; oQuestion.QuestionCreator.SystemUserID = gSystemUserID; oQuestion.QuestionCreator.SystemUserName = sSystemUserName; if (dr_Type.SelectedValue.Equals("Objective")) { oQuestion.QuestionQuestionType.QuestionTypeID = 0; } else if (dr_Type.SelectedValue.Equals("Descriptive")) { oQuestion.QuestionQuestionType.QuestionTypeID = 1; } if (oObject != null) { oResult = oQuestionBO.QuestionListShowForSetup(oQuestion, (Exam)oObject); if (oResult.ResultIsSuccess) { oListQuestionSetup = (List<QuestionSetup>)oResult.ResultObject; //if objective then the list of choices and answers will be populated for each question //Utils.SetSession(SessionManager.csStoreGridView, oListQuestionSetup); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionSetup); if (oListQuestionSetup.Count > 0) { lbl_Questions.Text = String.Empty; Grid_Questions.Visible = false; pnl_questions.Visible = false; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} //Grid_Questions.DataSource = oListQuestionSetup; //Grid_Questions.DataBind(); //pnl_questions.Visible = true; //pnl_questions.ScrollBars = ScrollBars.Auto; //pnl_questions.Controls.Add(Grid_Questions); lbl_RandomQuestions.Visible = true; txt_RandomQuestions.Visible = true; lblRandomOutOf.Visible = true; txtRandomOutOf.Visible = true; txtRandomOutOf.Text = oListQuestionSetup.Count.ToString(); btn_View.Visible = false; } else { Label oLblError = new Label(); oLblError.Text = "No Question Found."; oLblError.ForeColor = Color.Red; ////pnl_questions.Visible = true; pnl_questions.Visible = true; pnl_questions.Controls.Add(oLblError); lbl_Questions.Text = String.Empty; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; lbl_Questions.Text = String.Empty; //pnl_questions.Visible = true; Grid_Questions.Visible = false; pnl_questions.Visible = false; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} } } } else { lbl_Questions.Text = String.Empty; //pnl_questions.Visible = true; Grid_Questions.Visible = false; pnl_questions.Visible = false; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} } } else if (dr_ListOrRandom.SelectedValue.Equals("From List")) { try { if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]")) { List<Category> oListCategory = new List<Category>(); oListCategory = (List<Category>)Utils.GetSession(SessionManager.csStoredCategory); Question oQuestion = new Question(); QuestionBO oQuestionBO = new QuestionBO(); Result oResult = new Result(); List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>(); oQuestion.QuestionCategory.CategoryID = oListCategory[dr_Category.SelectedIndex - 1].CategoryID; oQuestion.QuestionCreator.SystemUserID = gSystemUserID; oQuestion.QuestionCreator.SystemUserName = sSystemUserName; if (dr_Type.SelectedValue.Equals("Objective")) { oQuestion.QuestionQuestionType.QuestionTypeID = 0; } else if (dr_Type.SelectedValue.Equals("Descriptive")) { oQuestion.QuestionQuestionType.QuestionTypeID = 1; } if (oObject != null) { oResult = oQuestionBO.QuestionListShowForSetup(oQuestion,(Exam)oObject); if (oResult.ResultIsSuccess) { oListQuestionSetup = (List<QuestionSetup>)oResult.ResultObject; //if objective then the list of choices and answers will be populated for each question //Utils.SetSession(SessionManager.csStoreGridView, oListQuestionSetup); this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionSetup); if (oListQuestionSetup.Count > 0) { lbl_Questions.Text = "Questions"; Grid_Questions.Visible = true; //List<Question> oListQuestionForGridViewBind = new List<Question>(); //foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetup) //{ // oListQuestionForGridViewBind.Add(oQuestionSetupInList.QuestionSetupQuestion); //} Grid_Questions.DataSource = oListQuestionSetup; //Grid_Questions.DataSource = oListQuestionForGridViewBind; Grid_Questions.DataBind(); pnl_questions.Visible = true; pnl_questions.ScrollBars = ScrollBars.Auto; //pnl_questions.Controls.Add(Grid_Questions); } else { Label oLblError = new Label(); oLblError.Text = "No Question Found."; oLblError.ForeColor = Color.Red; ////pnl_questions.Visible = true; pnl_questions.Visible = true; pnl_questions.Controls.Add(oLblError); lbl_Questions.Text = String.Empty; } } else { lbl_error.ForeColor = Color.Red; lbl_error.Text = oResult.ResultMessage; lbl_Questions.Text = String.Empty; Grid_Questions.Visible = false; pnl_questions.Visible = false; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} } } } else { lbl_Questions.Text = String.Empty; Grid_Questions.Visible = false; pnl_questions.Visible = false; //pnl_questions.Visible = true; //if (pnl_questions.Controls.Contains(Grid_Questions)) //{ // pnl_questions.Controls.Remove(Grid_Questions); //} } //rdo_QuestionSelection.Items[1].Selected = false; //LoadSelectionDropdownList(); } catch (Exception oEx1) { lbl_error.ForeColor = Color.Red; lbl_error.Text = "Exception occured during Question List Show."; } } else if (dr_ListOrRandom.SelectedValue.Equals("By Question Level")) { if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]")) { lblQuestionLevel.Visible = true; drdnSelectQuestionLevel.Visible = true; lbl_Questions.Text = String.Empty; LoadLevelsFromDatabase(); } else { lbl_Questions.Text = String.Empty; pnl_questions.Visible = false; Grid_Questions.Visible = false; } } } catch (Exception oEx2) { } }