SupplierBillEditLayout.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using Comal.Classes;
  2. using InABox.DynamicGrid;
  3. using InABox.Wpf;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  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.Navigation;
  19. using System.Windows.Shapes;
  20. namespace PRSDesktop;
  21. /// <summary>
  22. /// Interaction logic for SupplierBillEditLayout.xaml
  23. /// </summary>
  24. public partial class SupplierBillEditLayout : DynamicEditorGridLayout, INotifyPropertyChanged
  25. {
  26. public event Action? Approve;
  27. public override bool TabStripVisible
  28. {
  29. get { return Editors.TabStripVisible; }
  30. set { Editors.TabStripVisible = value; }
  31. }
  32. private double _totalWidth;
  33. public override double TotalWidth => _totalWidth;
  34. private double _datesHeight;
  35. private double _editorHeight;
  36. private double _pageHeight;
  37. public override double TotalHeight => Math.Max(_datesHeight, _editorHeight) + _pageHeight;
  38. private double _poAmount;
  39. public double POAmount
  40. {
  41. get => _poAmount;
  42. set
  43. {
  44. _poAmount = value;
  45. OnPropertyChanged();
  46. OnPropertyChanged(nameof(BillLessThanPO));
  47. }
  48. }
  49. private double _billAmount;
  50. public double BillAmount
  51. {
  52. get => _billAmount;
  53. set
  54. {
  55. _billAmount = value;
  56. OnPropertyChanged();
  57. OnPropertyChanged(nameof(BillLessThanPO));
  58. }
  59. }
  60. private bool _canApprove = false;
  61. public bool CanApprove
  62. {
  63. get => _canApprove;
  64. set
  65. {
  66. _canApprove = value;
  67. OnPropertyChanged();
  68. }
  69. }
  70. private bool _isApproved = false;
  71. public bool IsApproved
  72. {
  73. get => _isApproved;
  74. set
  75. {
  76. _isApproved = value;
  77. ApproveButton.Content = value ? "Unapprove" : "Approve";
  78. OnPropertyChanged();
  79. }
  80. }
  81. public bool BillLessThanPO => BillAmount <= POAmount;
  82. public SupplierBillEditLayout()
  83. {
  84. InitializeComponent();
  85. }
  86. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  87. {
  88. Editors.Items.Clear();
  89. OtherPages.Items.Clear();
  90. Dates.Items.Clear();
  91. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order).ThenBy(x => x.Caption()))
  92. {
  93. var tab = new DynamicTabItem();
  94. tab.Header = page.Caption();
  95. if (page is FrameworkElement element)
  96. element.Margin = new Thickness(0, 2, 0, 0);
  97. tab.Content = page;
  98. var minSize = page.MinimumSize();
  99. if(page is DynamicEditorGrid.DynamicEditPage)
  100. {
  101. if (page.Caption() == "Dates")
  102. {
  103. Dates.Items.Add(tab);
  104. _datesHeight = Math.Max(_editorHeight, minSize.Height);
  105. }
  106. else
  107. {
  108. Editors.Items.Add(tab);
  109. _editorHeight = Math.Max(_editorHeight, minSize.Height);
  110. _totalWidth = Math.Max(_totalWidth, minSize.Width);
  111. }
  112. }
  113. else
  114. {
  115. OtherPages.Items.Add(tab);
  116. _pageHeight = Math.Max(_pageHeight, minSize.Height);
  117. }
  118. }
  119. Dates.Visibility = Dates.Items.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
  120. Dates.SelectedIndex = 0;
  121. Editors.SelectedIndex = 0;
  122. OtherPages.SelectedIndex = 0;
  123. }
  124. private bool bChanging;
  125. public event PropertyChangedEventHandler? PropertyChanged;
  126. protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
  127. {
  128. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  129. }
  130. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  131. {
  132. if (bChanging) return;
  133. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  134. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  135. bChanging = true;
  136. try
  137. {
  138. if (tab is not null && tab.Content is IDynamicEditorPage page)
  139. {
  140. SelectPage(page);
  141. }
  142. }
  143. finally
  144. {
  145. bChanging = false;
  146. }
  147. }
  148. private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
  149. {
  150. EditorRow.MaxHeight = e.NewSize.Height - 50;
  151. }
  152. private void ApproveButton_Click(object sender, RoutedEventArgs e)
  153. {
  154. Approve?.Invoke();
  155. }
  156. }