public QuestionsSelection(string Subject) { subjects = Subject.GetSubject(null, new List <string> { " name = '" + Subject + "'" }); outcomesList = Outcome.GetOutcome(null, new List <string> { "SubjectID = " + subjects[0].SubjectId }); outcomeDetailsList = OutcomeDetails.GetOutcomeDetails(null, null); foreach (Outcome item in outcomesList) { foreach (OutcomeDetails item2 in outcomeDetailsList) { if (item.OutcomeId == item2.OutcomeId) { outcomeDetailsListRelavent.Add(item2); } } } questionTypesList = QuestionType.GetQuestionType(null, null); questionsList = question.GetQuestion(null, null); foreach (Question item in questionsList) { foreach (OutcomeDetails item2 in outcomeDetailsListRelavent) { if (item.OutcomeDetailsId == item2.OutcomeDetailsId) { questionListRelavent.Add(item); } } } }
/// <summary> /// This Method is for Match the Columns of the exam paper /// </summary> /// <param name="NumberOfQuestions">This is the number of questions under the multiple choice section</param> /// <param name="QuestionNumber">the number of the question in the exam</param> public void MatchColumnsQuestions(int NumberOfQuestions, int QuestionNumber, OutcomesCollection outcomesWhere, int ArrayPosition) { Random random = new Random(); Question question = new Question(); Question ChoosenQuestion = new Question(); OutcomeDetails outcomeDetails = new OutcomeDetails(); Answer ChosenAnswer = new Answer(); List <Question> questionsList = new List <Question>(); List <Answer> answersList = new List <Answer>(); List <string> answerWhere = new List <string>(); List <Question> QuestionsChoosenForDi = new List <Question>(); //Dont forget to include a where clause for the questions and choices for outcomes chosen and types for the questions // questionsList = question.Select(outcomesWhere.OutcomesList); //fix This later..... foreach (Question item in questionsList) { answerWhere.Add(item.QuestionId.ToString()); } //answersList = Answer.Select(answerWhere); Answer[] ChoosenAnswersArray = new Answer[NumberOfQuestions]; int[] AnswersUsed = new int[NumberOfQuestions]; int[] QuestionsUsed = new int[NumberOfQuestions]; Question[] questionArray = new Question[NumberOfQuestions]; int Total = NumberOfQuestions * 2; using (WordprocessingDocument doc = WordprocessingDocument.Open(outputLocation, true)) { Body docBody = doc.MainDocumentPart.Document.Body; Table table = new Table(); TableRow row1 = new TableRow(); TableRow row2 = new TableRow(); TableCell cell = new TableCell(); cell.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); TableCell cell2 = new TableCell(); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "5000" })); TableCell cell3 = new TableCell(); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "500" })); Paragraph paragraph = new Paragraph(new Run(new Text(string.Format("Question {0}", QuestionNumber)))); Paragraph paragraph1 = new Paragraph(new Run(new Text(string.Format("[{0}]", Total)))); cell.Append(paragraph); cell3.Append(paragraph1); row1.Append(cell); row1.Append(cell2); row1.Append(cell3); //row1.Append(cell2); int LetterCounter = 0; Letters letters = (Letters)LetterCounter; for (int i = 0; i < NumberOfQuestions; i++) { questionArray[i] = questionsList[random.Next(questionsList.Count)]; ChoosenQuestion = questionArray[i]; questionsList.Remove(ChoosenQuestion); //QuestionsChosen[ArrayPosition].Add(ChoosenQuestion); QuestionsChoosenForDi.Add(ChoosenQuestion); foreach (Answer item in answersList) { if (ChoosenQuestion.QuestionId == item.QuestionId) { ChoosenAnswersArray[i] = item; } } } for (int i = 0; i < NumberOfQuestions; i++) { TableRow QuestionRow = new TableRow(); cell = new TableCell(); cell2 = new TableCell(); cell.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); cell3 = new TableCell(); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); // this doesnt make sense and needs thought //someone please check this logic for (int j = 0; j < NumberOfQuestions; j++) { int questionRandom = random.Next(questionArray.Length); if (QuestionsUsed[j] != questionRandom) { ChoosenQuestion = questionArray[questionRandom]; QuestionsUsed[i] = questionRandom; } } for (int j = 0; j < NumberOfQuestions; j++) { int answerRandom = random.Next(questionArray.Length); if (AnswersUsed[j] != answerRandom) { ChosenAnswer = ChoosenAnswersArray[answerRandom]; AnswersUsed[i] = answerRandom; } } int LetterCounter2 = LetterCounter + 1; Paragraph Question = new Paragraph(new Run(new Text(LetterCounter2 + "." + ChoosenQuestion.Questions))); Paragraph Answer = new Paragraph(new Run(new Text(letters + "." + ChosenAnswer.Answers))); Paragraph QuestionWeight = new Paragraph(new Run(new Text(ChoosenQuestion.Weight.ToString()))); cell.Append(Question); cell2.Append(Answer); cell3.Append(QuestionWeight); QuestionRow.Append(cell); QuestionRow.Append(cell2); QuestionRow.Append(cell3); table.Append(QuestionRow); letters++; letters = (Letters)LetterCounter; } docBody.Append(table); QuestionsChosen.Add(ArrayPosition, QuestionsChoosenForDi); } }