123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Media;
- namespace WpfApp3
- {
- public partial class MainWindow : Window
- {
- public ObservableCollection<Student> StudentList { get; set; }
- private Dictionary<string, object> filters = new Dictionary<string, object>();
- private string currentStyle = "StackStyle";
- public MainWindow()
- {
- InitializeComponent();
- DataContext = this;
- Globals.dataProvider = new LocalDataProvider();
- StudentList = new ObservableCollection<Student>(Globals.dataProvider.GetStudents());
- List<string> styles = new List<string> { "light", "dark" };
- styleBox.SelectionChanged += ThemeChange;
- styleBox.ItemsSource = styles;
- styleBox.SelectedItem = "dark";
- Style buttonStyle = new Style();
- buttonStyle.Setters.Add(
- new Setter
- {
- Property = Control.FontFamilyProperty,
- Value = new FontFamily("Verdana")
- });
- buttonStyle.Setters.Add(
- new Setter
- {
- Property = Control.MarginProperty,
- Value = new Thickness(10)
- });
- buttonStyle.Setters.Add(
- new Setter
- {
- Property = Control.BackgroundProperty,
- Value = new SolidColorBrush(Colors.PowderBlue)
- });
- buttonStyle.Setters.Add(
- new Setter
- {
- Property = Control.ForegroundProperty,
- Value = new SolidColorBrush(Colors.Black)
- });
-
- }
- private void ExitButton_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- private void NameFilter_TextChanged(object sender, TextChangedEventArgs e)
- {
- filters["Name"] = ((TextBox)sender).Text;
- ApplyFilter();
- }
- private void NationFilter_TextChanged(object sender, TextChangedEventArgs e)
- {
- filters["Nation"] = ((TextBox)sender).Text;
- ApplyFilter();
- }
- private void ApplyFilter()
- {
- var filteredStudents = Globals.dataProvider.GetStudents();
- foreach (var filter in filters)
- {
- filteredStudents = filteredStudents.Where(s => s.GetType().GetProperty(filter.Key).GetValue(s, null).ToString().Contains(filter.Value.ToString()));
- }
- filteredStudents = filteredStudents.Where(s => s.Age >= 20 && s.Course > 2);
- StudentList = new ObservableCollection<Student>(filteredStudents);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- MessageBoxResult result = MessageBox.Show("Семен Хомяк закончит универ ?", "Вопрос", MessageBoxButton.YesNo);
- if (result == MessageBoxResult.Yes)
- {
- }
- else
- {
- }
- }
- private void Button2_Click(object sender, RoutedEventArgs e)
- {
- MessageBoxResult result = MessageBox.Show("Сколько живет пингвин ?", "Вопрос", MessageBoxButton.YesNo);
- if (result == MessageBoxResult.Yes)
- {
- }
- else
- {
- }
- }
- private void ThemeChange(object sender, SelectionChangedEventArgs e)
- {
- string style = styleBox.SelectedItem as string;
- var uri = new Uri(style + ".xaml", UriKind.Relative);
- ResourceDictionary resourceDict =
- Application.LoadComponent(uri) as ResourceDictionary;
- Application.Current.Resources.Clear();
- Application.Current.Resources.MergedDictionaries.Add(resourceDict);
- }
- private void ToggleViewButton_Click(object sender, RoutedEventArgs e) {
- currentStyle = currentStyle == "StackStyle" ? "WrapStyle" : "StackStyle";
- var newStyle = (Style)TryFindResource(currentStyle);
- if (newStyle != null)
- StudentListBox.Style = newStyle;
- }
- }
- internal interface IDataProvider
- {
- IEnumerable<Student> GetStudents();
- }
- public class LocalDataProvider : IDataProvider
- {
- public IEnumerable<Student> GetStudents()
- {
- return new List<Student>
- {
- new Student { Id = 1, Name = "Хэй Вэнь", Age = 24, Country = "Китай", GPA = 5.0, Speciality = "Программирование", Grant = 25000.0, Course = 4, EnrollmentDate = new DateTime(2020, 9, 1), IsFullTime = true },
- new Student { Id = 2, Name = "Семен Хомяк", Age = 22, Country = "Россия", GPA = 3.7, Speciality = "Инженерия", Grant = 10000.0, Course = 2, EnrollmentDate = new DateTime(2022, 1, 15), IsFullTime = false },
- new Student { Id = 3, Name = "Джейкоб Ли", Age = 19, Country = "Америка", GPA = 4.4, Speciality = "Лингвистика", Grant = 20000.0, Course = 1, EnrollmentDate = new DateTime(2023, 8, 20), IsFullTime = true },
- new Student { Id = 4, Name = "Арамсунторнсук Пирапонг", Age = 18, Country = "Таиланд", GPA = 4.1, Speciality = "Логистика", Grant = 15000.0, Course = 1, EnrollmentDate = new DateTime(2023, 4, 6), IsFullTime = false },
- new Student { Id = 5, Name = "Рипка Дарина", Age = 18, Country = "Украина", GPA = 4.8, Speciality = "Дизайн", Grant = 23000.0, Course = 1, EnrollmentDate = new DateTime(2023, 5, 15), IsFullTime = true },
- };
- }
- }
- public class Student
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public string Speciality { get; set; }
- public string Country { get; set; }
- public double GPA { get; set; }
- public double Grant { get; set; }
- public DateTime EnrollmentDate { get; set; }
- public bool IsFullTime { get; set; }
- public int Age { get; internal set; }
- public int Course { get; internal set; }
- }
- }
|