Ejemplo n.º 1
0
        private void buttonPassTest_Click(object sender, EventArgs e)
        {
            Button   testButton = sender as Button;
            TestExam t          = tests.Where(x => string.Compare(x.BodyTest.Name, testButton.Text) == 0).FirstOrDefault();
            PassTest passTest   = new PassTest(t);

            passTest.ShowDialog();
            int Grade = passTest.ResultTest;

            MessageBox.Show(Grade.ToString());
            TestResult testResult = new TestResult()
            {
                IdTest = t.Id, Grade = Grade, Date = DateTime.Now
            };

            //відправити на сервер
            SendTestResult(new TestExam
            {
                Id     = t.Id,
                Result = Grade
            });

            //оновити вигляд тестів
            var passedTest = tests.Where(x => x.Id == t.Id).FirstOrDefault();

            passedTest.IsAvailable = false;
            passedTest.Result      = Grade;
            passedTest.Date        = testResult.Date;
            ShowTests();
        }
Ejemplo n.º 2
0
 public PassTest(TestExam test)
 {
     InitializeComponent();
     answers   = new List <CurrentAnswer>();
     this.test = test;
     ShowQuestion();
     PositionChanged();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// відправляє результати пройденого тесту на сервер
        /// </summary>
        /// <param name="result"> результат пройденого тесту для відправки </param>
        private void SendTestResult(TestExam result)
        {
            var client  = new RestClient("http://localhost:32225");
            var request = new RestRequest("test/exam", Method.POST);

            request.AddHeader("Authentication", $"Bearer {token}");
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = DataFormat.Json;
            request.AddBody(result);
            client.Execute <TestResult>(request);
        }
Ejemplo n.º 4
0
 public void PassExam(TestExam test)
 {
     _sqlConnection.Execute(@"
         UPDATE Test 
         SET TestResult = @TestResult, 
         Date = @Now 
         WHERE Id = @Id", new
     {
         Id         = test.Id,
         TestResult = test.Result,
         Now        = DateTime.Now
     });
 }
Ejemplo n.º 5
0
        public IEnumerable <TestExam> GetExams()
        {
            var tests = _sqlConnection.Query <(int Id, string Content, int Result)>("SELECT Id, Content, TestResult as Result FROM Test");

            foreach (var test in tests)
            {
                var result = new TestExam
                {
                    Id          = test.Id,
                    BodyTest    = JsonConvert.DeserializeObject <Test>(test.Content),
                    Result      = test.Result,
                    IsAvailable = test.Result == 0
                };
                yield return(result);
            }
        }
Ejemplo n.º 6
0
        private void SetTests()
        {
            List <Answer> answers = new List <Answer>();

            answers.Add(new Answer()
            {
                Text = "x+2"
            });
            answers.Add(new Answer()
            {
                Text = "x2"
            });
            answers.Add(new Answer()
            {
                Text = "b ^ 2 - 4ac", Correct = true
            });

            TestExam test1 = new TestExam();

            test1.BodyTest.Questions.Add(new Question(answers, "D="));
            test1.BodyTest.Questions.Add(new Question(answers, "x1="));
            test1.IsAvailable      = true;
            test1.BodyTest.Name    = "Test1";
            test1.BodyTest.Subject = "Math";
            tests.Add(test1);

            TestExam test2 = new TestExam();

            test2.BodyTest.Questions.Add(new Question(answers, "И"));
            test2.BodyTest.Questions.Add(new Question(answers, "аапвап"));
            test2.IsAvailable      = true;
            test2.BodyTest.Name    = "Test2";
            test2.BodyTest.Subject = "Math";
            tests.Add(test2);
            answers.Add(new Answer()
            {
                Text = "ghgh"
            });
            TestExam test3 = new TestExam();

            test2.BodyTest.Questions.Add(new Question(answers, "fgfg"));
            test2.BodyTest.Questions.Add(new Question(answers, "dfdп"));
            test3.IsAvailable      = false;
            test3.BodyTest.Name    = "Test3";
            test3.BodyTest.Subject = "Math";
            tests.Add(test3);
        }
Ejemplo n.º 7
0
        /*
         * Lấy tất cả ca thi của môn trong một kì thi từ sql server
         */
        public List <TestExam> GetTestExam(string subjects, int examid, out string out_mess)
        {
            out_mess = "";
            List <TestExam> data = new List <TestExam>();

            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SHOW_ALL_TEST_EXAM_OF_SUBJECT", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@INT_SUBJECT_ID", SqlDbType.Int);
                cmd.Parameters["@INT_SUBJECT_ID"].Value = int.Parse(subjects);
                cmd.Parameters.Add("@INT_EXAM_ID", SqlDbType.Int);
                cmd.Parameters["@INT_EXAM_ID"].Value = examid;
                cmd.Parameters.Add("@OUT_MESSAGE", SqlDbType.NVarChar, 50).Direction = ParameterDirection.Output;
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var order = Convert.ToInt32(reader[10]);
                    var hour  = "7h-9h";
                    if (order == 1)
                    {
                        hour = "7h-9h";
                    }
                    if (order == 2)
                    {
                        hour = "9h-11h";
                    }
                    if (order == 1)
                    {
                        hour = "11h-13h";
                    }
                    if (order == 1)
                    {
                        hour = "13h-15h";
                    }
                    if (order == 1)
                    {
                        hour = "15h-17h";
                    }
                    if (order == 1)
                    {
                        hour = "17h-19h";
                    }
                    string x = reader[1].ToString();
                    x = x.ToString();
                    var erb = new TestExam(
                        Convert.ToInt32(reader[0]),
                        Convert.ToInt32(reader[1]),
                        Convert.ToDateTime(reader[2]).ToString("dd-MM-yyyy"),
                        Convert.ToBoolean(reader[3]),
                        Convert.ToInt32(reader[4]),
                        Convert.ToInt32(reader[5]),
                        reader[6].ToString(),
                        Convert.ToInt32(reader[7]),
                        reader[8].ToString(),
                        Convert.ToInt32(reader[9]),
                        hour
                        );
                    data.Add(erb);
                }
            }
            catch (Exception ex)
            {
                out_mess = ex.Message;
                return(null);
            }
            return(data);
        }
Ejemplo n.º 8
0
 public void PassExam([FromBody] TestExam testExam)
 {
     _testsRepository.PassExam(testExam);
 }