ListViewPage.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. using DB.Classes;
  16. namespace DB.Pages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для ListViewPage.xaml
  20. /// </summary>
  21. public partial class ListViewPage : Page
  22. {
  23. public ListViewPage()
  24. {
  25. InitializeComponent();
  26. LVService.ItemsSource = DataBaseClass.entity.Service.ToList();
  27. CBFIlter.Items.Add(0);
  28. foreach(Service service in LVService.ItemsSource)
  29. {
  30. CBFIlter.Items.Add(service.Discount);
  31. }
  32. CBFIlter.SelectedIndex = 0;
  33. CBSort.Items.Add("Сброс");
  34. CBSort.Items.Add("По заголовку по возрастанию");
  35. CBSort.Items.Add("По заголовку по уьыванию");
  36. CBSort.SelectedIndex = 0;
  37. }
  38. void Filter()
  39. {
  40. List<Service> services = new List<Service>();
  41. double type = Convert.ToDouble(CBFIlter.SelectedValue);
  42. int id = CBFIlter.SelectedIndex;
  43. if(id != 0)
  44. {
  45. services = DataBaseClass.entity.Service.Where(x => x.Discount == type).ToList();
  46. }
  47. else
  48. {
  49. services = DataBaseClass.entity.Service.ToList();
  50. }
  51. int ids = CBSort.SelectedIndex;
  52. if(ids == 1)
  53. {
  54. services.Sort((x,y) => x.Title.CompareTo(y.Title));
  55. }
  56. else if(ids == 2)
  57. {
  58. services.Sort((x, y) => x.Title.CompareTo(y.Title));
  59. services.Reverse();
  60. }
  61. if(!string.IsNullOrWhiteSpace(TBSearch.Text))
  62. {
  63. services = services.Where(x => x.Title.ToLower().Contains(TBSearch.Text.ToLower())).ToList();
  64. }
  65. LVService.ItemsSource = services;
  66. }
  67. private void TBDate_Loaded(object sender, RoutedEventArgs e)
  68. {
  69. TextBlock tb = (TextBlock)sender;
  70. int index = Convert.ToInt32(tb.Uid);
  71. List<ClientService> CS = DataBaseClass.entity.ClientService.Where(x => x.ServiceID == index).ToList();
  72. foreach (ClientService cs in CS)
  73. {
  74. tb.Text = "Дата: " + cs.StartTime.ToString();
  75. }
  76. }
  77. private void CBFIlter_SelectionChanged(object sender, SelectionChangedEventArgs e)
  78. {
  79. Filter();
  80. }
  81. private void CBSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  82. {
  83. Filter();
  84. }
  85. private void TBSearch_TextChanged(object sender, TextChangedEventArgs e)
  86. {
  87. Filter();
  88. }
  89. private void BTNDelete_Click(object sender, RoutedEventArgs e)
  90. {
  91. Button button = (Button)sender;
  92. int index = Convert.ToInt32(button.Uid);
  93. Service DeleteObject = DataBaseClass.entity.Service.FirstOrDefault(x => x.ID == index);
  94. switch (MessageBox.Show("Вы точно хотите удалить эту запись?", "DeleteObject", MessageBoxButton.YesNo, MessageBoxImage.Question))
  95. {
  96. case MessageBoxResult.Yes:
  97. DataBaseClass.entity.Service.Remove(DeleteObject);
  98. DataBaseClass.entity.SaveChanges();
  99. FrameClass.MainFrame.Navigate(new ListViewPage());
  100. break;
  101. case MessageBoxResult.No:
  102. MessageBox.Show("Хорошо");
  103. break;
  104. }
  105. }
  106. private void BTNChange_Click(object sender, RoutedEventArgs e)
  107. {
  108. Button btn = (Button)sender;
  109. int index = Convert.ToInt32(btn.Uid);
  110. FrameClass.MainFrame.Navigate(new AddChangePage(index));
  111. }
  112. private void BTNAdd_Click(object sender, RoutedEventArgs e)
  113. {
  114. FrameClass.MainFrame.Navigate(new AddChangePage());
  115. }
  116. }
  117. }