123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Markup;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Детский_сад
- {
- /// <summary>
- /// Логика взаимодействия для ViewChildren.xaml
- /// </summary>
- public partial class ViewChildren : Page
- {
- Pagination Pagin = new Pagination();
- List<Children> ChildList = new List<Children>();
- bool StartForFilter = true;
- bool StartForSort = true;
- public ViewChildren()
- {
- InitializeComponent();
- ChildList = Base.KE.Children.ToList();
- lv.ItemsSource = ChildList;
- Pagin.CountPage = Base.KE.Children.ToList().Count;
- DataContext = Pagin;
- CbFilter.SelectedIndex = 0;
- CbSort.SelectedIndex = 0;
- }
- private void btnBack_Click(object sender, RoutedEventArgs e)
- {
- Base.mainFrame.Navigate(new Account());
- }
- private void tbMather_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int id = Convert.ToInt32(tb.Uid);
- Kinships kinships = Base.KE.Kinships.FirstOrDefault(x => x.Id_child == id && x.Parents.Id_gender == 2);
- if (kinships != null)
- {
- tb.Text = "Мать: ";
- tb.Text += kinships.Parents.FullName;
- }
- else
- {
- tb.Visibility = Visibility.Collapsed;
- }
- }
- private void tbVather_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int id = Convert.ToInt32(tb.Uid);
- Kinships kinships = Base.KE.Kinships.FirstOrDefault(x => x.Id_child == id && x.Parents.Id_gender == 1);
- if (kinships != null)
- {
- tb.Text = "Отец: ";
- tb.Text += kinships.Parents.FullName;
- }
- else
- {
- tb.Visibility = Visibility.Collapsed;
- }
- }
- private void btnAdd_Click(object sender, RoutedEventArgs e)
- {
- Base.mainFrame.Navigate(new AddChild());
- }
- private void btnDelete_Click(object sender, RoutedEventArgs e)
- {
- Button button = (Button)sender;
- int id = Convert.ToInt32(button.Uid);
- Children child = Base.KE.Children.FirstOrDefault(x => x.Id_child == id);
- List<Kinships> kinships = Base.KE.Kinships.Where(x => x.Id_child == id).ToList();
- Base.KE.Children.Remove(child);
- Base.KE.SaveChanges();
- foreach (Kinships item in kinships)
- {
- if (Base.KE.Kinships.Where(x => x.Id_parent == item.Id_parent).ToList().Count == 0)
- {
- Parents parent = Base.KE.Parents.FirstOrDefault(x => x.Id_parent == item.Id_parent);
- Base.KE.Parents.Remove(parent);
- }
- }
- Base.KE.SaveChanges();
- MessageBox.Show("Ребёнок успешно удалён", "Дети", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- private void lv_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- Children child = (Children)lv.SelectedItem;
- Base.mainFrame.Navigate(new AddChild(Base.KE.Children.FirstOrDefault(x => x.Id_child == child.Id_child)));
- }
- private void CbFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Filter();
- }
- private void TBoxFind_TextChanged(object sender, TextChangedEventArgs e)
- {
- Filter();
- }
- private void ChBPhoto_Click(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void Filter()
- {
- ChildList.Clear();
- switch (CbFilter.SelectedIndex)
- {
- case 1:
- ChildList = Base.KE.Children.Where(x => x.Surname.StartsWith(TBoxFind.Text)).ToList();
- break;
- case 2:
- ChildList = Base.KE.Children.Where(x => x.Names.StartsWith(TBoxFind.Text)).ToList();
- break;
- case 3:
- ChildList = Base.KE.Children.Where(x => x.Patronymic.StartsWith(TBoxFind.Text)).ToList();
- break;
- case 4:
- foreach (Children item in Base.KE.Children)
- {
- if (item.Groups.Name_group.StartsWith(TBoxFind.Text))
- {
- ChildList.Add(item);
- }
- }
- break;
- default:
- ChildList = Base.KE.Children.ToList();
- break;
- }
- if ((bool)ChBPhoto.IsChecked)
- {
- ChildList = ChildList.Where(x => x.Photo != "\\Resources\\Заглушка.png").ToList();
- }
- switch (CbSort.SelectedIndex)
- {
- case 1:
- ChildList.Sort((x, y) => x.Surname.CompareTo(y.Surname));
- break;
- case 2:
- ChildList.Sort((x, y) => x.Names.CompareTo(y.Names));
- break;
- case 3:
- ChildList.Sort((x, y) => x.Patronymic.CompareTo(y.Patronymic));
- break;
- case 4:
- ChildList.Sort((x, y) => x.Surname.CompareTo(y.Surname));
- ChildList.Reverse();
- break;
- case 5:
- ChildList.Sort((x, y) => x.Names.CompareTo(y.Names));
- ChildList.Reverse();
- break;
- case 6:
- ChildList.Sort((x, y) => x.Patronymic.CompareTo(y.Patronymic));
- ChildList.Reverse();
- break;
- }
- lv.ItemsSource = ChildList;
- if (ChildList.Count != 0)
- {
- SetPagination();
- }
- }
- private void GoPage_MouseDown(object sender, MouseButtonEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- switch (tb.Uid)
- {
- case "first":
- Pagin.CurrentPage = 1;
- break;
- case "last":
- Pagin.CurrentPage = ChildList.Count;
- break;
- case "back":
- Pagin.CurrentPage--;
- break;
- case "next":
- Pagin.CurrentPage++;
- break;
- default:
- Pagin.CurrentPage = Convert.ToInt32(tb.Text);
- break;
- }
- lv.ItemsSource = ChildList.Skip(Pagin.CurrentPage * Pagin.CountPage - Pagin.CountPage).Take(Pagin.CountPage).ToList();
- }
- private void tboxPageCount_TextChanged(object sender, TextChangedEventArgs e)
- {
- SetPagination();
- }
- private void SetPagination()
- {
- try
- {
- Pagin.CountPage = Convert.ToInt32(tboxPageCount.Text);
- }
- catch
- {
- Pagin.CountPage = ChildList.Count;
- }
- Pagin.CountList = ChildList.Count;
- lv.ItemsSource = ChildList.Skip(0).Take(Pagin.CountPage).ToList();
- if (!StartForFilter && !StartForSort)
- {
- Pagin.CurrentPage = 1;
- }
- if (!StartForFilter)
- {
- StartForSort = false;
- }
- StartForFilter = false;
- }
- }
- }
|