Beispiel #1
0
 public static void SaveMark(MarkInfo info)
 {
     using (IDbConnection cnn = new SqlConnection(connection()))
     {
         cnn.Execute("insert into Marks (Test,ActualAnswer,TheirAnswer,Question,StudentId) values (@Test,@ActualAnswer,@TheirAnswer,@Question,@StudentId)", info);
     }
 }
        private void BtSubmit_Click(object sender, RoutedEventArgs e)
        {
            //filling list
            test = Methods.fillTest();
            //assigning variable
            string questionselected = LBQuestions.SelectedItem.ToString();

            //checking what they answered
            if ((bool)RBAnswerA.IsChecked == true)
            {
                answer = 'A';
            }
            if ((bool)RBAnswerB.IsChecked == true)
            {
                answer = 'B';
            }
            if ((bool)RBAnswerC.IsChecked == true)
            {
                answer = 'C';
            }
            if ((bool)RBAnswerD.IsChecked == true)
            {
                answer = 'D';
            }
            //looping through list
            foreach (TestInfo b in test)
            {
                //checking if the questions are the same
                if (questionselected == ("Questions" + b.id.ToString()))
                {
                    //chekcing is the answer they answered was right or wrong
                    if (answer == b.ActualAnswer.ToCharArray()[0])
                    {
                        //adding data to variables
                        Test         = b.Test.ToString();
                        ActualAnswer = b.ActualAnswer.ToString();
                        TheirAnswer  = answer.ToString();
                        id           = b.id.ToString();
                        //printing that they where right
                        DLL.correctanswer();
                    }
                    else
                    {
                        //adding data to variables
                        Test         = b.Test.ToString();
                        ActualAnswer = b.ActualAnswer.ToString();
                        TheirAnswer  = answer.ToString();
                        id           = b.id.ToString();
                        //printing that they where wrong
                        DLL.Wronganswer();
                    }
                }
            }
            //adding answers and other info to objects
            MarkInfo m = new MarkInfo();

            m.Test         = Test;
            m.ActualAnswer = ActualAnswer;
            m.TheirAnswer  = TheirAnswer;
            m.Question     = "Question" + id;
            m.StudentId    = MainWindow.PersonID;
            //filling list
            marks = Methods.fillMarks();
            //looping through list
            foreach (var h in marks)
            {
                //checking is the person has answered this question before
                if (h.StudentId == MainWindow.PersonID)
                { //checking iff match
                    if (h.Question == "Question" + id)
                    {
                        isthere = true;
                    }
                }
            }
            if (isthere == true)
            {
                //saying that they have answered that question before
                DLL.alreadyanswered();
            }
            else
            {
                //saves info to DB
                Methods.SaveMark(m);
            }
        }