SupplierBillEditLayout.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Comal.Classes;
  2. using InABox.DynamicGrid;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace PRSDesktop;
  20. /// <summary>
  21. /// Interaction logic for SupplierBillEditLayout.xaml
  22. /// </summary>
  23. public partial class SupplierBillEditLayout : DynamicEditorGridLayout, INotifyPropertyChanged
  24. {
  25. public override bool TabStripVisible
  26. {
  27. get { return Editors.TabStripVisible; }
  28. set { Editors.TabStripVisible = value; }
  29. }
  30. public SupplierBillEditLayout()
  31. {
  32. InitializeComponent();
  33. }
  34. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  35. {
  36. Editors.Items.Clear();
  37. OtherPages.Items.Clear();
  38. DocumentControl.Content = null;
  39. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  40. {
  41. if(page is DynamicDocumentGrid<BillDocument, Bill, BillLink> docs)
  42. {
  43. docs.SimpleTemplate = true;
  44. DocumentControl.Content = docs;
  45. }
  46. else
  47. {
  48. var tab = new DynamicTabItem();
  49. tab.Header = page.Caption();
  50. if (page is FrameworkElement element)
  51. element.Margin = new Thickness(0, 2, 0, 0);
  52. tab.Content = page;
  53. if (page is DynamicEditorGrid.DynamicEditPage)
  54. {
  55. Editors.Items.Add(tab);
  56. }
  57. else
  58. {
  59. OtherPages.Items.Add(tab);
  60. }
  61. }
  62. }
  63. Editors.SelectedIndex = 0;
  64. OtherPages.SelectedIndex = 0;
  65. }
  66. private bool bChanging;
  67. public event PropertyChangedEventHandler? PropertyChanged;
  68. protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
  69. {
  70. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  71. }
  72. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  73. {
  74. if (bChanging) return;
  75. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  76. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  77. bChanging = true;
  78. try
  79. {
  80. if (tab is not null && tab.Content is IDynamicEditorPage page)
  81. {
  82. SelectPage(page);
  83. }
  84. }
  85. finally
  86. {
  87. bChanging = false;
  88. }
  89. }
  90. }