private void StudentGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs location) { int rowId = (int)((long)StudentGridView.Rows[this.mouseLocation.RowIndex].Cells["ID"].Value); SelectedTest = this.elementBase.SelectOneTest(rowId); List <GlobalClass.QuestionAnswersMapper> setQuestion = new List <GlobalClass.QuestionAnswersMapper>(); IEnumerable <IGrouping <string, GlobalClass.AnswerWithQuestionMapper> > query = SelectedTest.GroupBy(Question => Question.Question, Question => Question); foreach (IGrouping <string, GlobalClass.AnswerWithQuestionMapper> QuestionGRoup in query) { List <GlobalClass.AnswerMapper> tempAnswers = new List <GlobalClass.AnswerMapper>(); // Print the key value of the IGrouping. // Iterate over each value in the // IGrouping and print the value. int id_Q = -1; foreach (GlobalClass.AnswerWithQuestionMapper Answer in QuestionGRoup) { GlobalClass.AnswerMapper tempAnswer = new GlobalClass.AnswerMapper(Answer.ID_Answer, Answer.Answer, Answer.isTrue); id_Q = Answer.ID_Question; tempAnswers.Add(tempAnswer); } GlobalClass.QuestionAnswersMapper tempQuestion = new GlobalClass.QuestionAnswersMapper(id_Q, -1, QuestionGRoup.Key, tempAnswers.Count, tempAnswers); setQuestion.Add(tempQuestion); } TestingForm NewTest = new TestingForm(setQuestion, rowId, selectedUser.ID); NewTest.ShowDialog(); }
private void SaveBtn_Click(object sender, EventArgs e) { List <GlobalClass.AnswerMapper> Answers = new List <GlobalClass.AnswerMapper>(); foreach (rowAddAnswer oneAnswer in RowListanswer) { GlobalClass.AnswerMapper tempAnswer = new GlobalClass.AnswerMapper(0, oneAnswer.AnswerT.Text, oneAnswer.checkBx.Checked); Answers.Add(tempAnswer); } GlobalClass.QuestionAnswersMapper tempQ = new GlobalClass.QuestionAnswersMapper(0, (int)this.SubjectList.SelectedValue, this.QuestionT.Text, this.RowListanswer.Count, Answers); elementBase.InsertQuestionWithAnswers(tempQ); this.Close(); }
public GlobalClass.QuestionAnswersMapper SelectQuestionWithAnswers(int id) { string questionQuery = @"select a.ID, a.ID_subject, a.Question from questions as a where a.ID = " + id; string answersQuery = @"select b.ID, b.answer, b.true_variant from qs_ar as a join answer as b ON b.ID = a.ID_A where a.ID_Q = " + id; List <GlobalClass.AnswerMapper> Answers = new List <GlobalClass.AnswerMapper>(); GlobalClass.QuestionAnswersMapper tempQ = new GlobalClass.QuestionAnswersMapper(); if (this.openConnection() == true) { MySqlCommand cmd = new MySqlCommand(answersQuery, dbConnect); MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int I = (int)((long)dataReader["ID"]); string A = (string)dataReader["answer"]; int F = (int)((sbyte)dataReader["true_variant"]); Boolean Fl; if (F == 1) { Fl = true; } else { Fl = false; } GlobalClass.AnswerMapper tempAnswer = new GlobalClass.AnswerMapper(I, A, Fl); Answers.Add(tempAnswer); } //close Data Reader dataReader.Close(); cmd = new MySqlCommand(questionQuery, dbConnect); dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int I = (int)((long)dataReader["ID"]); int IS = (int)((long)dataReader["ID_subject"]); string A = (string)dataReader["Question"]; tempQ = new GlobalClass.QuestionAnswersMapper(I, IS, A, Answers.Count, Answers); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return(tempQ); } else { return(tempQ); } }