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;
namespace Khaustov_ProbniyDE
{
///
/// Логика взаимодействия для Услуги.xaml
///
public partial class Услуги : Page
{
public Услуги()
{
InitializeComponent();
DGridУслуги.ItemsSource = Хаустов_ПробныйДЭEntities.GetContext().Service.ToList();
}
private void BtnEdit_Click(object sender, RoutedEventArgs e)
{
Switcher.MainFrame.Navigate(new AddEditPage((sender as Button).DataContext as Service));
}
private void BtnAdd_Click(object sender, RoutedEventArgs e)
{
Switcher.MainFrame.Navigate(new AddEditPage(null));
}
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
var ServiceForRemoving = DGridУслуги.SelectedItems.Cast().ToList();
if (MessageBox.Show($"Вы точно хотите удалить следующие {ServiceForRemoving.Count()} элементов?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
try
{
Хаустов_ПробныйДЭEntities.GetContext().Service.RemoveRange(ServiceForRemoving);
Хаустов_ПробныйДЭEntities.GetContext().SaveChanges();
MessageBox.Show("Данные удалены");
DGridУслуги.ItemsSource = Хаустов_ПробныйДЭEntities.GetContext().Service.ToList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
}