SecondaryWindow.xaml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 Fluent.Button
  105. {
  106. Header = action.Caption,
  107. LargeIcon = action.Image?.AsBitmapImage(),
  108. MinWidth = 60
  109. };
  110. button.Bind<PanelAction, String>(Fluent.Button.HeaderProperty, x=>x.Caption, null);
  111. button.Bind<PanelAction, Bitmap>(Fluent.Button.LargeIconProperty, x => x.Image, new BitmapToBitmapImageConverter());
  112. button.Bind<PanelAction, ContextMenu?>(Fluent.Button.ContextMenuProperty, x=>x.Menu);
  113. button.Bind<PanelAction, bool>(Fluent.Button.IsEnabledProperty, x => x.IsEnabled);
  114. button.Bind<PanelAction, Visibility>(Fluent.Button.VisibilityProperty, x => x.Visibility);
  115. button.DataContext = action;
  116. button.Click += (o, e) => action.Execute();
  117. Actions.Items.Add(button);
  118. CurrentModules.Add(button);
  119. ActionsSeparator.Visibility = Visibility.Visible;
  120. }
  121. public void CreateReport(PanelAction action)
  122. {
  123. Print.Visibility = Visibility.Visible;
  124. var button = new Button
  125. {
  126. Header = action.Caption,
  127. LargeIcon = action.Image.AsBitmapImage()
  128. };
  129. if (action.Menu is not null)
  130. {
  131. button.ContextMenu = action.Menu;
  132. }
  133. button.Click += (o, e) => action.Execute();
  134. Print.Items.Add(button);
  135. }
  136. private void Setup_Click(object sender, RoutedEventArgs e)
  137. {
  138. var menu = new ContextMenu();
  139. PanelHost.InitialiseSetupMenu(menu);
  140. menu.IsOpen = true;
  141. }
  142. public void ClearActions()
  143. {
  144. foreach (var module in CurrentModules)
  145. {
  146. if (module.Parent is Fluent.RibbonGroupBox bar)
  147. bar.Items.Remove(module);
  148. }
  149. CurrentModules.Clear();
  150. ActionsSeparator.Visibility = Visibility.Collapsed;
  151. }
  152. public void ClearReports()
  153. {
  154. Print.Items.Clear();
  155. Print.Visibility = Visibility.Visible;
  156. }
  157. public void Heartbeat()
  158. {
  159. PanelHost.Heartbeat();
  160. }
  161. }