SecondaryWindow.xaml.cs 4.8 KB

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