OUP.xaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using OUP.ForOUP;
  2. using OUP.Services;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace OUP
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для OUP.xaml
  21. /// </summary>
  22. public partial class OUP : Window
  23. {
  24. private readonly string PATH = $"{Environment.CurrentDirectory}\\todoDataList";
  25. private BindingList<Descriptions> _todoDataList;
  26. private FileService _fileService;
  27. public OUP()
  28. {
  29. InitializeComponent();
  30. }
  31. private void Window_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. _fileService = new FileService(PATH);
  34. try
  35. {
  36. _todoDataList = _fileService.LoadData();
  37. }
  38. catch (Exception ex)
  39. {
  40. MessageBox.Show(ex.Message);
  41. Close();
  42. }
  43. Supply.ItemsSource = _todoDataList;
  44. _todoDataList.ListChanged += _todoDataList_ListChanged;
  45. }
  46. private void _todoDataList_ListChanged(object sender, ListChangedEventArgs e)
  47. {
  48. if (e.ListChangedType == ListChangedType.ItemAdded || e.ListChangedType == ListChangedType.ItemDeleted || e.ListChangedType == ListChangedType.ItemChanged)
  49. {
  50. try
  51. {
  52. _fileService.SaveData(sender);
  53. }
  54. catch (Exception ex)
  55. {
  56. MessageBox.Show(ex.Message);
  57. Close();
  58. }
  59. }
  60. }
  61. }
  62. }