SupplierBillEditLayout.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. private double _documentWidth = 400;
  31. public double DocumentWidth
  32. {
  33. get => _documentWidth;
  34. set
  35. {
  36. _documentWidth = value;
  37. OnPropertyChanged();
  38. }
  39. }
  40. public SupplierBillEditLayout()
  41. {
  42. InitializeComponent();
  43. }
  44. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  45. {
  46. Editors.Items.Clear();
  47. OtherPages.Items.Clear();
  48. DocumentControl.Content = null;
  49. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  50. {
  51. if(page is DynamicDocumentGrid<BillDocument, Bill, BillLink>)
  52. {
  53. DocumentControl.Content = page;
  54. }
  55. else
  56. {
  57. var tab = new DynamicTabItem();
  58. tab.Header = page.Caption();
  59. if (page is FrameworkElement element)
  60. element.Margin = new Thickness(0, 2, 0, 0);
  61. tab.Content = page;
  62. if (page is DynamicEditorGrid.DynamicEditPage)
  63. {
  64. Editors.Items.Add(tab);
  65. }
  66. else
  67. {
  68. OtherPages.Items.Add(tab);
  69. }
  70. }
  71. }
  72. Editors.SelectedIndex = 0;
  73. OtherPages.SelectedIndex = 0;
  74. }
  75. private bool bChanging;
  76. public event PropertyChangedEventHandler? PropertyChanged;
  77. protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
  78. {
  79. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  80. }
  81. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  82. {
  83. if (bChanging) return;
  84. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  85. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  86. bChanging = true;
  87. try
  88. {
  89. if (tab is not null && tab.Content is IDynamicEditorPage page)
  90. {
  91. SelectPage(page);
  92. }
  93. }
  94. finally
  95. {
  96. bChanging = false;
  97. }
  98. }
  99. }