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. public partial class TestsCatalog : Page
  18. {
  19. public TestsCatalog()
  20. {
  21. InitializeComponent();
  22. TestsListBox.Items.Clear();
  23. if (Session.User.Post == "Преподаватель")
  24. AddTestButton.Visibility = Visibility.Visible;
  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.StartsWith(TestNameBox.Text)).ToList();
  35. if (AuthorTestBox.Text != "Автор")
  36. list = list.Where(item => item.Users.Login.StartsWith(AuthorTestBox.Text)).ToList();
  37. TestsListBox.ItemsSource = list;
  38. }
  39. private void FindTests_Click(object sender, RoutedEventArgs e)
  40. {
  41. LoadingTests();
  42. }
  43. private void TestsListBox_Selected(object sender, RoutedEventArgs e)
  44. {
  45. try
  46. {
  47. if (((Tests)TestsListBox.SelectedItem) != null)
  48. {
  49. Session.OpenedTest = cnt.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
  50. Session.Points = 0;
  51. Session.CurQuestion = 0;
  52. Session.Quest.Content = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
  53. Session.Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
  54. NavigationService.Navigate(new Pages.CurTestPage());
  55. }
  56. }
  57. catch
  58. {
  59. new ErrorWindow("Ошибка открытия теста.").ShowDialog();
  60. }
  61. }
  62. }
  63. }
  64. //拯救我们被关在地下室