123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Reports;
- using InABox.Core.Reports;
- using InABox.Scripting;
- using InABox.Wpf.Reports;
- using InABox.WPF;
- using InABox.Wpf;
- using PRSDesktop.Configuration;
- using Fluent;
- using Button = Fluent.Button;
- using ContextMenu = System.Windows.Controls.ContextMenu;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using MenuItem = Fluent.MenuItem;
- namespace PRSDesktop;
- /// <summary>
- /// Interaction logic for SecondaryWindow.xaml
- /// </summary>
- public partial class SecondaryWindow : RibbonWindow, IPanelHostControl
- {
- private readonly Guid _id = Guid.Empty;
- private readonly string _modulesection = "";
- private readonly string _type = "";
- private bool bLoaded;
- private List<Control> CurrentModules = new List<Control>();
- public IBasePanel Panel { get; private set; }
- private PanelHost PanelHost;
- public SecondaryWindow(Guid id, string type, string modulesection, double left, double top, double width, double height)
- {
- PanelHost = new PanelHost(this);
- _id = id;
- _modulesection = modulesection;
- InitializeComponent();
- Left = left;
- Top = top;
- Width = width;
- Height = height;
- Title = string.Format("{0} - PRS Desktop (Release {1})", modulesection, CoreUtils.GetVersion());
- SecondaryTab.Header = modulesection;
-
- Panel = PanelHost.LoadPanel(Type.GetType(type), modulesection);
- ContentBorder.Child = Panel as UIElement;
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- PanelHost.Refresh();
- bLoaded = true;
- }
- private void RefreshMenu_Click(object sender, RoutedEventArgs e)
- {
- PanelHost.Refresh();
- }
- private void Wiki_Click(object sender, RoutedEventArgs e)
- {
- Process.Start("https://prsdigital.com.au/wiki/index.php/" + _type.Replace(" ", "_").Replace("/", ""));
- }
- #region Save / Load Window Location
- private void SaveSettings()
- {
- if (App.IsClosing)
- return;
- var tuple = new Tuple<string, string, double, double, double, double>(
- Panel.GetType().EntityName(),
- _modulesection,
- Left,
- Top,
- Width,
- Height
- );
- App.DatabaseSettings.SecondaryWindows[_id] = tuple;
- new LocalConfiguration<DatabaseSettings>(App.Profile).Save(App.DatabaseSettings);
- }
- private void Window_Closing(object sender, CancelEventArgs e)
- {
- PanelHost.UnloadPanel(e);
- if (e.Cancel) return;
- if (App.IsClosing)
- return;
- App.DatabaseSettings.SecondaryWindows.Remove(_id);
- new LocalConfiguration<DatabaseSettings>(App.Profile).Save(App.DatabaseSettings);
- }
- private void Window_LocationChanged(object sender, EventArgs e)
- {
- if (bLoaded)
- SaveSettings();
- }
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- if (bLoaded)
- SaveSettings();
- }
- #endregion
-
-
- public void CreatePanelAction(PanelAction action)
- {
-
- if (action.OnPopulate != null)
- {
- Fluent.DropDownButton button = null;
- if (action.OnExecute != null)
- {
- button = new Fluent.SplitButton();
- ((Fluent.SplitButton)button).Click += (o, e) => action.Execute();
- }
- else
- button = new Fluent.DropDownButton();
-
- button.MinWidth = 60;
- button.DataContext = action;
- button.DropDownOpened += (sender, args) => { button.ItemsSource = CreateMenuItems(action); };
- button.Bind<PanelAction, String>(Fluent.DropDownButton.HeaderProperty, x => x.Caption, null);
- button.Bind<PanelAction, Bitmap?>(Fluent.DropDownButton.LargeIconProperty, x => x.Image,
- new BitmapToBitmapImageConverter());
- button.Bind<PanelAction, ContextMenu?>(ContextMenuProperty, x => x.Menu);
- button.Bind<PanelAction, bool>(IsEnabledProperty, x => x.IsEnabled);
- button.Bind<PanelAction, Visibility>(VisibilityProperty, x => x.Visibility);
- Actions.Items.Add(button);
- CurrentModules.Add(button);
- }
-
- else
- {
- var button = new Fluent.Button()
- {
- MinWidth = 60,
- DataContext = action
- };
- button.Bind<PanelAction, String>(Fluent.Button.HeaderProperty, x => x.Caption, null);
- button.Bind<PanelAction, Bitmap?>(Fluent.Button.LargeIconProperty, x => x.Image,
- new BitmapToBitmapImageConverter());
- button.Bind<PanelAction, ContextMenu?>(Fluent.Button.ContextMenuProperty, x => x.Menu);
- button.Bind<PanelAction, bool>(Fluent.Button.IsEnabledProperty, x => x.IsEnabled);
- button.Bind<PanelAction, Visibility>(Fluent.Button.VisibilityProperty, x => x.Visibility);
- button.Click += (o, e) => action.Execute();
- Actions.Items.Add(button);
- CurrentModules.Add(button);
- }
-
- ActionsSeparator.Visibility = Visibility.Visible;
- }
-
- private static ObservableCollection<MenuItem> CreateMenuItems(PanelAction action)
- {
- var items = new ObservableCollection<MenuItem>();
- var entries = action.Populate();
- if (entries != null)
- {
- foreach (var entry in entries)
- {
- var item = new Fluent.MenuItem()
- {
- Header = entry.Caption,
- DataContext = entry.Data,
- Icon = entry.Image?.AsBitmapImage()
- };
- item.Click += (o, eventArgs) => entry.Execute();
- items.Add(item);
- }
- }
- return items;
- }
- public void CreateReport(PanelAction action)
- {
- Print.Visibility = Visibility.Visible;
- var button = new Button
- {
- Header = action.Caption,
- LargeIcon = action.Image.AsBitmapImage()
- };
- if (action.Menu is not null)
- {
- button.ContextMenu = action.Menu;
- }
- button.Click += (o, e) => action.Execute();
- Print.Items.Add(button);
- }
- private void Setup_Click(object sender, RoutedEventArgs e)
- {
- var menu = new ContextMenu();
- PanelHost.InitialiseSetupMenu(menu);
- menu.IsOpen = true;
- }
- public void ClearActions()
- {
- foreach (var module in CurrentModules)
- {
- if (module.Parent is Fluent.RibbonGroupBox bar)
- bar.Items.Remove(module);
- }
- CurrentModules.Clear();
- ActionsSeparator.Visibility = Visibility.Collapsed;
- }
- public void ClearReports()
- {
- Print.Items.Clear();
- Print.Visibility = Visibility.Visible;
- }
- public void Heartbeat()
- {
- PanelHost.Heartbeat();
- }
- }
|