SecondaryWindow.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using Comal.Classes;
  10. using InABox.Clients;
  11. using InABox.Configuration;
  12. using InABox.Core;
  13. using InABox.DynamicGrid;
  14. using InABox.Reports;
  15. using InABox.Core.Reports;
  16. using InABox.Scripting;
  17. using InABox.Wpf.Reports;
  18. using InABox.WPF;
  19. using InABox.Wpf;
  20. using PRSDesktop.Configuration;
  21. using Fluent;
  22. using Button = Fluent.Button;
  23. using ContextMenu = System.Windows.Controls.ContextMenu;
  24. using System.Collections.Generic;
  25. namespace PRSDesktop;
  26. /// <summary>
  27. /// Interaction logic for SecondaryWindow.xaml
  28. /// </summary>
  29. public partial class SecondaryWindow : RibbonWindow, IPanelHostControl
  30. {
  31. private readonly Guid _id = Guid.Empty;
  32. private readonly string _modulesection = "";
  33. private readonly string _type = "";
  34. private bool bLoaded;
  35. private List<Control> CurrentModules = new List<Control>();
  36. public IBasePanel Panel { get; private set; }
  37. private PanelHost PanelHost;
  38. public SecondaryWindow(Guid id, string type, string modulesection, double left, double top, double width, double height)
  39. {
  40. PanelHost = new PanelHost(this);
  41. _id = id;
  42. _modulesection = modulesection;
  43. InitializeComponent();
  44. Left = left;
  45. Top = top;
  46. Width = width;
  47. Height = height;
  48. Title = string.Format("{0} - PRS Desktop (Release {1})", modulesection, CoreUtils.GetVersion());
  49. SecondaryTab.Header = modulesection;
  50. Panel = PanelHost.LoadPanel(Type.GetType(type), modulesection);
  51. ContentBorder.Child = Panel as UIElement;
  52. }
  53. private void Window_Loaded(object sender, RoutedEventArgs e)
  54. {
  55. PanelHost.Refresh();
  56. bLoaded = true;
  57. }
  58. private void RefreshMenu_Click(object sender, RoutedEventArgs e)
  59. {
  60. PanelHost.Refresh();
  61. }
  62. private void Wiki_Click(object sender, RoutedEventArgs e)
  63. {
  64. Process.Start("https://prsdigital.com.au/wiki/index.php/" + _type.Replace(" ", "_").Replace("/", ""));
  65. }
  66. #region Save / Load Window Location
  67. private void SaveSettings()
  68. {
  69. if (App.IsClosing)
  70. return;
  71. var tuple = new Tuple<string, string, double, double, double, double>(
  72. Panel.GetType().EntityName(),
  73. _modulesection,
  74. Left,
  75. Top,
  76. Width,
  77. Height
  78. );
  79. App.DatabaseSettings.SecondaryWindows[_id] = tuple;
  80. new LocalConfiguration<DatabaseSettings>(App.Profile).Save(App.DatabaseSettings);
  81. }
  82. private void Window_Closing(object sender, CancelEventArgs e)
  83. {
  84. PanelHost.UnloadPanel(e);
  85. if (e.Cancel) return;
  86. if (App.IsClosing)
  87. return;
  88. App.DatabaseSettings.SecondaryWindows.Remove(_id);
  89. new LocalConfiguration<DatabaseSettings>(App.Profile).Save(App.DatabaseSettings);
  90. }
  91. private void Window_LocationChanged(object sender, EventArgs e)
  92. {
  93. if (bLoaded)
  94. SaveSettings();
  95. }
  96. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  97. {
  98. if (bLoaded)
  99. SaveSettings();
  100. }
  101. #endregion
  102. public void CreatePanelAction(PanelAction action)
  103. {
  104. var button = new Button
  105. {
  106. Header = action.Caption,
  107. LargeIcon = action.Image.AsBitmapImage()
  108. };
  109. button.Click += (o, e) => action.Execute();
  110. if (action.Menu is not null)
  111. {
  112. button.ContextMenu = action.Menu;
  113. }
  114. Actions.Items.Add(button);
  115. CurrentModules.Add(button);
  116. ActionsSeparator.Visibility = Visibility.Visible;
  117. }
  118. public void CreateReport(PanelAction action)
  119. {
  120. Print.Visibility = Visibility.Visible;
  121. var button = new Button
  122. {
  123. Header = action.Caption,
  124. LargeIcon = action.Image.AsBitmapImage()
  125. };
  126. if (action.Menu is not null)
  127. {
  128. button.ContextMenu = action.Menu;
  129. }
  130. button.Click += (o, e) => action.Execute();
  131. Print.Items.Add(button);
  132. }
  133. private void Setup_Click(object sender, RoutedEventArgs e)
  134. {
  135. var menu = new ContextMenu();
  136. PanelHost.InitialiseSetupMenu(menu);
  137. menu.IsOpen = true;
  138. }
  139. public void ClearActions()
  140. {
  141. foreach (var module in CurrentModules)
  142. {
  143. if (module.Parent is Fluent.RibbonGroupBox bar)
  144. bar.Items.Remove(module);
  145. }
  146. CurrentModules.Clear();
  147. ActionsSeparator.Visibility = Visibility.Collapsed;
  148. }
  149. public void ClearReports()
  150. {
  151. Print.Items.Clear();
  152. Print.Visibility = Visibility.Visible;
  153. }
  154. public void Heartbeat()
  155. {
  156. PanelHost.Heartbeat();
  157. }
  158. }