TestsCatalog.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. List<Tests> list = cnt.db.Tests.Where(item => item.IsVisible == true && item.Questions.Count > 0).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 TestNameBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  44. {
  45. TestNameBox.Text = string.Empty;
  46. }
  47. private void TestNameBox_LostFocus(object sender, RoutedEventArgs e)
  48. {
  49. if (TestNameBox.Text.Trim() == "")
  50. TestNameBox.Text = "Название теста";
  51. }
  52. private void AuthorTestBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  53. {
  54. AuthorTestBox.Text = string.Empty;
  55. }
  56. private void AuthorTestBox_LostFocus(object sender, RoutedEventArgs e)
  57. {
  58. if (AuthorTestBox.Text.Trim() == "")
  59. AuthorTestBox.Text = "Преподаватель";
  60. }
  61. private void TestsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  62. {
  63. try
  64. {
  65. if (((Tests)TestsListBox.SelectedItem) != null)
  66. {
  67. Session.OpenedTest = cnt.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
  68. Session.Points = 0;
  69. Session.CurQuestion = 0;
  70. Session.Quest.Content = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
  71. Session.Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
  72. NavigationService.Navigate(new Pages.CurTestPage());
  73. }
  74. }
  75. catch
  76. {
  77. new ErrorWindow("Ошибка открытия теста.").ShowDialog();
  78. }
  79. }
  80. }
  81. }
  82. //拯救我们被关在地下室