TestPage.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace PsychoTest.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для TestPage.xaml
  19. /// </summary>
  20. public partial class TestPage : Page
  21. {
  22. public PsychoBase DB = new PsychoBase();
  23. List<Questions> questions;
  24. public int n = 0;
  25. public double TotalScore = 0;
  26. int test_id, user_id;
  27. public TestPage(int id_test, int id_user)
  28. {
  29. InitializeComponent();
  30. questions = DB.Questions.Where(x=>x.Id_test==id_test).ToList();
  31. QuestionContent.Text = questions[n].Content;
  32. NameOfTest.Text = DB.Tests.Where(x => x.Test_id == id_test).Select(x=>x.Test_name).FirstOrDefault();
  33. test_id = id_test;
  34. user_id = id_user;
  35. }
  36. private void TotalAgree(object sender, RoutedEventArgs e)
  37. {
  38. CountScoring(5);
  39. }
  40. private void PartAgree(object sender, RoutedEventArgs e)
  41. {
  42. CountScoring(4);
  43. }
  44. private void NotSure(object sender, RoutedEventArgs e)
  45. {
  46. CountScoring(3);
  47. }
  48. private void PartDisagree(object sender, RoutedEventArgs e)
  49. {
  50. CountScoring(2);
  51. }
  52. private void TotalDisagree(object sender, RoutedEventArgs e)
  53. {
  54. CountScoring(1);
  55. }
  56. private void ExitOfTest(object sender, RoutedEventArgs e)
  57. {
  58. MainFrame.frame.Navigate(new UserTests(user_id));
  59. }
  60. public void CountScoring(int answer)
  61. {
  62. switch(answer)
  63. {
  64. case 1:
  65. if (questions[n].Id_answer == 1)
  66. {
  67. TotalScore++;
  68. }
  69. break;
  70. case 2:
  71. if (questions[n].Id_answer == 1)
  72. {
  73. TotalScore+=0.75;
  74. }
  75. else
  76. {
  77. TotalScore += 0.25;
  78. }
  79. break;
  80. case 3:
  81. TotalScore += 0.5;
  82. break;
  83. case 4:
  84. if (questions[n].Id_answer == 1)
  85. {
  86. TotalScore += 0.25;
  87. }
  88. else
  89. {
  90. TotalScore += 0.75;
  91. }
  92. break;
  93. case 5:
  94. if (questions[n].Id_answer == 5)
  95. {
  96. TotalScore++;
  97. }
  98. break;
  99. default:
  100. MessageBox.Show("Что-то не так");
  101. break;
  102. }
  103. n++;
  104. try
  105. {
  106. QuestionContent.Text = questions[n].Content;
  107. }
  108. catch
  109. {
  110. MainFrame.frame.Navigate(new ResultPage(test_id,user_id, TotalScore));
  111. }
  112. }
  113. }
  114. }