using OUP.ForOUP;
using OUP.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Shapes;
namespace OUP
{
///
/// Логика взаимодействия для OUP.xaml
///
public partial class OUP : Window
{
private readonly string PATH = $"{Environment.CurrentDirectory}\\todoDataList";
private BindingList _todoDataList;
private FileService _fileService;
public OUP()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_fileService = new FileService(PATH);
try
{
_todoDataList = _fileService.LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Close();
}
Supply.ItemsSource = _todoDataList;
_todoDataList.ListChanged += _todoDataList_ListChanged;
}
private void _todoDataList_ListChanged(object sender, ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded || e.ListChangedType == ListChangedType.ItemDeleted || e.ListChangedType == ListChangedType.ItemChanged)
{
try
{
_fileService.SaveData(sender);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Close();
}
}
}
}
}