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
{
///
/// Логика взаимодействия для ListViewPage.xaml
///
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 services = new List();
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 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());
}
}
}