TestsCatalog.xaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. NavigationService.Navigate(new Pages.TestPage(((Tests)TestsListBox.SelectedItem).IdTest));
  51. Session.openedTest = ((Tests)TestsListBox.SelectedItem).IdTest;
  52. }
  53. }
  54. catch
  55. {
  56. new ErrorWindow("Ошибка открытия теста.").ShowDialog();
  57. }
  58. }
  59. }
  60. }