123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using DB.Classes;
- namespace DB.Pages
- {
- /// <summary>
- /// Логика взаимодействия для ListViewPage.xaml
- /// </summary>
- public partial class ListViewPage : Page
- {
- public ListViewPage()
- {
- InitializeComponent();
- LVService.ItemsSource = DataBaseClass.entity.Service.ToList();
- CBFIlter.Items.Add(0);
- foreach(Service service in LVService.ItemsSource)
- {
- CBFIlter.Items.Add(service.Discount);
- }
- CBFIlter.SelectedIndex = 0;
- CBSort.Items.Add("Сброс");
- CBSort.Items.Add("По заголовку по возрастанию");
- CBSort.Items.Add("По заголовку по уьыванию");
- CBSort.SelectedIndex = 0;
- }
- void Filter()
- {
- List<Service> services = new List<Service>();
- double type = Convert.ToDouble(CBFIlter.SelectedValue);
- int id = CBFIlter.SelectedIndex;
- if(id != 0)
- {
- services = DataBaseClass.entity.Service.Where(x => x.Discount == type).ToList();
- }
- else
- {
- services = DataBaseClass.entity.Service.ToList();
- }
- int ids = CBSort.SelectedIndex;
- if(ids == 1)
- {
- services.Sort((x,y) => x.Title.CompareTo(y.Title));
- }
- else if(ids == 2)
- {
- services.Sort((x, y) => x.Title.CompareTo(y.Title));
- services.Reverse();
- }
- if(!string.IsNullOrWhiteSpace(TBSearch.Text))
- {
- services = services.Where(x => x.Title.ToLower().Contains(TBSearch.Text.ToLower())).ToList();
- }
- LVService.ItemsSource = services;
- }
- private void TBDate_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- List<ClientService> CS = DataBaseClass.entity.ClientService.Where(x => x.ServiceID == index).ToList();
- foreach (ClientService cs in CS)
- {
- tb.Text = "Дата: " + cs.StartTime.ToString();
- }
- }
- private void CBFIlter_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Filter();
- }
- private void CBSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Filter();
- }
- private void TBSearch_TextChanged(object sender, TextChangedEventArgs e)
- {
- Filter();
- }
- private void BTNDelete_Click(object sender, RoutedEventArgs e)
- {
- Button button = (Button)sender;
- int index = Convert.ToInt32(button.Uid);
- Service DeleteObject = DataBaseClass.entity.Service.FirstOrDefault(x => x.ID == index);
- switch (MessageBox.Show("Вы точно хотите удалить эту запись?", "DeleteObject", MessageBoxButton.YesNo, MessageBoxImage.Question))
- {
- case MessageBoxResult.Yes:
- DataBaseClass.entity.Service.Remove(DeleteObject);
- DataBaseClass.entity.SaveChanges();
- FrameClass.MainFrame.Navigate(new ListViewPage());
- break;
- case MessageBoxResult.No:
- MessageBox.Show("Хорошо");
- break;
- }
- }
- private void BTNChange_Click(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int index = Convert.ToInt32(btn.Uid);
- FrameClass.MainFrame.Navigate(new AddChangePage(index));
- }
- private void BTNAdd_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new AddChangePage());
- }
- }
- }
|