SupplierBillEditDocumentLayout.xaml.cs 3.2 KB

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