ViewDeletionWindow.xaml.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 DeletionData DeletionData { get; set; }
  29. private HashSet<DynamicTabItem> _loaded = new();
  30. public ViewDeletionWindow(Deletion deletion)
  31. {
  32. InitializeComponent();
  33. Deletion = deletion;
  34. DeletionData = Serialization.Deserialize<DeletionData>(deletion.Data) ?? new();
  35. Pages.SelectionChanged += PagesSelectionChanged;
  36. LoadPages();
  37. }
  38. private void PagesSelectionChanged(object sender, SelectionChangedEventArgs e)
  39. {
  40. var tab = Pages.SelectedItem as DynamicTabItem;
  41. if (!_loaded.Contains(tab))
  42. {
  43. var grid = tab.Content as IDynamicGrid;
  44. grid.Refresh(true, true);
  45. _loaded.Add(tab);
  46. }
  47. }
  48. private void LoadPages()
  49. {
  50. foreach(var (entityName, cascade) in DeletionData.Cascades)
  51. {
  52. if (!CoreUtils.TryGetEntity(entityName, out var entityType)) continue;
  53. var title = new Inflector.Inflector(new CultureInfo("en")).Pluralize(CoreUtils.GetCaption(entityType));
  54. var tab = new DynamicTabItem() { Header = title };
  55. var grid = Activator.CreateInstance(typeof(DeletedEntityGrid<>).MakeGenericType(entityType), cascade) as IDynamicGrid;
  56. grid.Refresh(true, true);
  57. tab.Content = grid;
  58. Pages.Items.Add(tab);
  59. }
  60. }
  61. }
  62. }