/// <summary>
 /// Сохраняет изменения в таблице
 /// </summary>
 /// <param name="question">вопрос</param>
 public void SaveOrUpdate(SQLiteConnection conn, QuestionResult question)
 {
     if (question.ID == 0)
     {
         int ID = indexService.NextID(TABLE_NAME);
         using (SQLiteCommand insertSQL = new SQLiteCommand("insert into QUESTION_RESULT (ID, QuestionTitle, TEST_RESULT_ID) values (@ID, @QuestionTitle, @TEST_RESULT_ID)", conn))
         {
             insertSQL.Parameters.AddWithValue("@QuestionTitle", question.QuestionTitle);
             insertSQL.Parameters.AddWithValue("@TEST_RESULT_ID", question.testResult.ID);
             insertSQL.Parameters.AddWithValue("@ID", ID);
             insertSQL.ExecuteNonQuery();
             question.ID = ID;
         }
         
     }
     else
     {
         using (SQLiteCommand insertSQL = new SQLiteCommand("UPDATE QUESTION_RESULT SET QuestionTitle = @QuestionTitle, TEST_RESULT_ID = @TEST_RESULT_ID WHERE ID = @ID", conn))
         {
             insertSQL.Parameters.AddWithValue("@QuestionTitle", question.QuestionTitle);
             insertSQL.Parameters.AddWithValue("@TEST_RESULT_ID", question.testResult.ID);
             insertSQL.Parameters.AddWithValue("@ID", question.ID);
             insertSQL.ExecuteNonQuery();
         }
     }
 }
Пример #2
0
 public void AddQuestion(QuestionResult question)
 {
     if (Questions == null)
     {
         Questions = new List<QuestionResult>();
     }
     question.testResult = this;
     Questions.Add(question);
 }
 /// <summary>
 /// Преобразует ответ в "вопрос"
 /// </summary>
 /// <param name="reader">Ответ из БД</param>
 /// <returns>вопрос</returns>
 private QuestionResult ToQuestion(SQLiteDataReader reader)
 {
     QuestionResult question = new QuestionResult(Convert.ToString(reader["QuestionTitle"]));
     question.ID = Convert.ToInt32(reader["ID"]);
     question.testResult = new TestResult(Convert.ToInt32(reader["TEST_RESULT_ID"]));
     return question;
 }
 /// <summary>
 /// Проверка на правильный ответ
 /// </summary>
 /// <param name="answers">список ответветов</param>
 public void Test(params bool[] answers)
 {
     if (answers.Length != current.Answers.Count)
     {
         throw new Exception("Количество ответов не соответствует с тестовыми");
     }
     QuestionResult questionResult = new QuestionResult(current.Value);
     for (int i = 0; i < current.Answers.Count; i++)
     {
         UserAnswer answer = new UserAnswer(current.Answers[i].Value, answers[i], current.Answers[i].Right);
         questionResult.AddAnswer(answer);
     }
     userResult.AddQuestion(questionResult);
     IDX++;
 }