TestsCatalog.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 MyTests.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для TestsCatalog.xaml
  19. /// </summary>
  20. public partial class TestsCatalog : Page
  21. {
  22. public TestsCatalog()
  23. {
  24. InitializeComponent();
  25. LoadingTests();
  26. }
  27. private void AddTest_Click(object sender, RoutedEventArgs e)
  28. {
  29. }
  30. void LoadingTests()
  31. {
  32. var list = cnt.db.Tests.ToList();
  33. if (TestNameBox.Text != "Название теста")
  34. list = list.Where(item => item.Name == TestNameBox.Text).ToList();
  35. if (AuthorTestBox.Text != "Автор")
  36. list = list.Where(item => item.Users.Login == AuthorTestBox.Text).ToList();
  37. TestsListBox.Items.Clear();
  38. TestsListBox.ItemsSource = list;
  39. }
  40. private void FindTests_Click(object sender, RoutedEventArgs e)
  41. {
  42. LoadingTests();
  43. }
  44. private void TestsListBox_Selected(object sender, RoutedEventArgs e)
  45. {
  46. try
  47. {
  48. if (((Tests)TestsListBox.SelectedItem) != null)
  49. {
  50. Session.OpenedTest = cnt.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
  51. NavigationService.Navigate(new Pages.TestPage(Session.OpenedTest.IdTest));
  52. Session.Points = 0;
  53. Session.CurQuestion = 0;
  54. Session.Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
  55. Session.Quest.Content = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
  56. }
  57. }
  58. catch
  59. {
  60. new ErrorWindow("Ошибка открытия теста.").ShowDialog();
  61. }
  62. }
  63. }
  64. }
  65. //拯救我们被关在地下室