ViewDeletionWindow.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using InABox.Core;
  2. using InABox.Database;
  3. using InABox.DynamicGrid;
  4. using InABox.Wpf;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Shapes;
  19. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
  20. namespace PRSServer.Forms
  21. {
  22. /// <summary>
  23. /// Interaction logic for ViewDeletionWindow.xaml
  24. /// </summary>
  25. public partial class ViewDeletionWindow : ThemableWindow
  26. {
  27. private Deletion Deletion { get; set; }
  28. private HashSet<DynamicTabItem> _loaded = new();
  29. public ViewDeletionWindow(Deletion deletion)
  30. {
  31. InitializeComponent();
  32. Deletion = deletion;
  33. Pages.SelectionChanged += PagesSelectionChanged;
  34. LoadPages();
  35. }
  36. private void PagesSelectionChanged(object sender, SelectionChangedEventArgs e)
  37. {
  38. var tab = Pages.SelectedItem as DynamicTabItem;
  39. if (!_loaded.Contains(tab))
  40. {
  41. var grid = tab.Content as IDynamicGrid;
  42. grid.Refresh(true, true);
  43. _loaded.Add(tab);
  44. }
  45. }
  46. private void LoadPages()
  47. {
  48. var entityTypes = DbFactory.Provider.GetDeletionTypes(Deletion);
  49. foreach(var type in entityTypes)
  50. {
  51. var title = new Inflector.Inflector(new CultureInfo("en")).Pluralize(CoreUtils.GetCaption(type));
  52. var tab = new DynamicTabItem() { Header = title };
  53. var grid = Activator.CreateInstance(typeof(DeletedEntityGrid<>).MakeGenericType(type), Deletion) as IDynamicGrid;
  54. grid.Refresh(true, true);
  55. tab.Content = grid;
  56. Pages.Items.Add(tab);
  57. }
  58. }
  59. }
  60. }