| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 | 
							- 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 PRSDesktop.Configuration;
 
- using Syncfusion.Windows.Tools;
 
- using Syncfusion.Windows.Tools.Controls;
 
- namespace PRSDesktop
 
- {
 
-     /// <summary>
 
-     ///     Interaction logic for SecondaryWindow.xaml
 
-     /// </summary>
 
-     public partial class SecondaryWindow : RibbonWindow, IPanelHost
 
-     {
 
-         private readonly Guid _id = Guid.Empty;
 
-         private readonly string _modulesection = "";
 
-         private readonly IBasePanel _panel;
 
-         private readonly string _type = "";
 
-         private bool bLoaded;
 
-         public SecondaryWindow(Guid id, string type, string modulesection, double left, double top, double width, double height)
 
-         {
 
-             _id = id;
 
-             _modulesection = modulesection;
 
-             _type = type;
 
-             InitializeComponent();
 
-             _ribbon.BackStageButton.Visibility = Visibility.Collapsed;
 
-             Left = left;
 
-             Top = top;
 
-             Width = width;
 
-             Height = height;
 
-             _panel = Activator.CreateInstance(Type.GetType(type)) as IBasePanel;
 
-             ContentBorder.Child = _panel as UIElement;
 
-             Title = string.Format("{0} - PRS Desktop (Release {1})", modulesection, CoreUtils.GetVersion());
 
-             (_ribbon.Items[0] as RibbonTab).Caption = modulesection;
 
-         }
 
-         private void Window_Loaded(object sender, RoutedEventArgs e)
 
-         {
 
-             _panel.Setup();
 
-             _panel.Refresh();
 
-             var model = _panel.DataModel(Selection.None);
 
-             var section = _panel.SectionName;
 
-             ReloadModules(section, model);
 
-             ReloadReports(section, model);
 
-             bLoaded = true;
 
-         }
 
-         private void RefreshMenu_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             _panel.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)
 
-         {
 
-             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
 
-         #region Report Buttons
 
-         private void ReloadReports(string section, DataModel model)
 
-         {
 
-             Print.Visibility = Security.IsAllowed<CanDesignReports>() ? Visibility.Visible : Visibility.Collapsed;
 
-             Print.LauncherButton.Tag = model;
 
-             Print.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-             Print.Items.Clear();
 
-             var worker = new BackgroundWorker();
 
-             IProgress<Tuple<string, Guid>> progress = new Progress<Tuple<string, Guid>>(report => CreateReportButton(report));
 
-             worker.DoWork += (o, e) =>
 
-             {
 
-                 var client = new Client<ReportTemplate>();
 
-                 var templates = client.Query(
 
-                     new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
 
-                         .And(x => x.Section).IsEqualTo(section)
 
-                         .And(x => x.Visible).IsEqualTo(true),
 
-                     new Columns<ReportTemplate>(x => x.ID, x => x.Name),
 
-                     new SortOrder<ReportTemplate>(x => x.Name)
 
-                 );
 
-                 foreach (var row in templates.Rows)
 
-                     progress.Report(
 
-                         new Tuple<string, Guid>(
 
-                             row.Get<ReportTemplate, string>(x => x.Name),
 
-                             row.Get<ReportTemplate, Guid>(x => x.ID)
 
-                         )
 
-                     );
 
-             };
 
-             worker.RunWorkerAsync();
 
-         }
 
-         public void CreateReportButton(Tuple<string, Guid> report)
 
-         {
 
-             Print.Visibility = Visibility.Visible;
 
-             var button = new RibbonButton
 
-             {
 
-                 Label = report.Item1,
 
-                 LargeIcon = PRSDesktop.Resources.printer.AsBitmapImage(),
 
-                 Tag = report.Item2,
 
-                 SizeForm = SizeForm.Large,
 
-                 MinWidth = 60
 
-             };
 
-             button.Click += ReportMenu_Checked;
 
-             Print.Items.Add(button);
 
-         }
 
-         private void ReportMenu_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             var item = (RibbonButton)sender;
 
-             var id = (Guid)item.Tag;
 
-             var template = new Client<ReportTemplate>().Load(new Filter<ReportTemplate>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
 
-             var selection = Selection.None;
 
-             if (template.SelectedRecords && template.AllRecords)
 
-                 selection = RecordSelectionDialog.Execute();
 
-             else if (template.SelectedRecords)
 
-                 selection = Selection.Selected;
 
-             else if (template.AllRecords)
 
-                 selection = Selection.All;
 
-             else
 
-                 MessageBox.Show("Report must have either [Selected Records] or [All Records] checked to display!");
 
-             if (selection != Selection.None)
 
-                 ReportUtils.PreviewReport(template, _panel.DataModel(selection), false, Security.IsAllowed<CanDesignReports>());
 
-         }
 
-         private void ManageReportsClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var model = _panel.DataModel(Selection.None);
 
-             var section = _panel.SectionName;
 
-             var form = new ReportManager { 
 
-                 DataModel = model,
 
-                 Section = section
 
-             };
 
-             form.ShowDialog();
 
-             ReloadReports(section, model);
 
-         }
 
-         #endregion
 
-         #region Modules
 
-         public void CreatePanelAction(PanelAction action)
 
-         {
 
-             var button = new RibbonButton
 
-             {
 
-                 Label = action.Caption,
 
-                 LargeIcon = action.Image.AsBitmapImage(),
 
-                 SizeForm = SizeForm.Large,
 
-                 MinWidth = 60,
 
-                 Tag = action
 
-             };
 
-             button.Click += PaneActionClick;
 
-             Actions.Items.Add(button);
 
-         }
 
-         public void CreateSetupAction(PanelAction action) => CreatePanelAction(action);
 
-         private void PaneActionClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var button = (Control)sender;
 
-             var action = (PanelAction)button.Tag;
 
-             action.Execute();
 
-         }
 
-         private void ReloadModules(string section, DataModel model)
 
-         {
 
-             if (!ClientFactory.IsSupported<CustomModule>())
 
-                 return;
 
-             Actions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-             while (Actions.Items.Count > 2)
 
-                 Actions.Items.RemoveAt(Actions.Items.Count - 1);
 
-             _panel.CreateToolbarButtons(this);
 
-             new Client<CustomModule>().Query(
 
-                 new Filter<CustomModule>(x => x.Section).IsEqualTo(section)
 
-                     .And(x => x.DataModel).IsEqualTo(model.Name)
 
-                     .And(x => x.Visible).IsEqualTo(true),
 
-                 new Columns<CustomModule>(x => x.ID)
 
-                     .Add(x => x.Name)
 
-                     .Add(x => x.Script)
 
-                     .Add(x => x.Thumbnail.ID),
 
-                 new SortOrder<CustomModule>(x => x.Name),
 
-                 (modules, e1) =>
 
-                 {
 
-                     if (modules != null)
 
-                     {
 
-                         var ids = modules.ExtractValues<CustomModule, Guid>(x => x.Thumbnail.ID).ToArray();
 
-                         new Client<Document>().Query(
 
-                             new Filter<Document>(x => x.ID).InList(ids),
 
-                             new Columns<Document>(x => x.ID)
 
-                                 .Add(x => x.Data),
 
-                             null,
 
-                             (documents, e2) =>
 
-                             {
 
-                                 Dispatcher.Invoke(() =>
 
-                                 {
 
-                                     CreateModules(modules, documents);
 
-                                     CheckModuleSeparator();
 
-                                 });
 
-                             }
 
-                         );
 
-                     }
 
-                     else
 
-                     {
 
-                         Dispatcher.Invoke(() => { CheckModuleSeparator(); });
 
-                     }
 
-                 }
 
-             );
 
-         }
 
-         private void CheckModuleSeparator()
 
-         {
 
-             Separator.Visibility = Actions.Items.Count > 2
 
-                 ? Visibility.Visible
 
-                 : Visibility.Collapsed;
 
-         }
 
-         private void CreateModules(CoreTable modules, CoreTable documents)
 
-         {
 
-             foreach (var module in modules.Rows)
 
-             {
 
-                 var bmp = PRSDesktop.Resources.edit;
 
-                 var document = documents.Rows.FirstOrDefault(r =>
 
-                     r.Get<Document, Guid>(c => c.ID) == module.Get<CustomModule, Guid>(c => c.Thumbnail.ID));
 
-                 if (document != null)
 
-                     bmp = new ImageConverter().ConvertFrom(document.Get<Document, byte[]>(c => c.Data)) as Bitmap;
 
-                 var button = new RibbonButton
 
-                 {
 
-                     Label = module.Get<CustomModule, string>(c => c.Name),
 
-                     LargeIcon = bmp.AsBitmapImage(),
 
-                     SizeForm = SizeForm.Large,
 
-                     MinWidth = 60,
 
-                     Tag = module.Get<CustomModule, string>(c => c.Script)
 
-                 };
 
-                 button.Click += Module_Click;
 
-                 Actions.Items.Add(button);
 
-             }
 
-         }
 
-         private void Module_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var item = (RibbonButton)sender;
 
-             var code = (string)item.Tag;
 
-             if (!string.IsNullOrWhiteSpace(code))
 
-                 try
 
-                 {
 
-                     var script = new ScriptDocument(code);
 
-                     if (script.Compile())
 
-                     {
 
-                         script.SetValue("Data", _panel.Selected());
 
-                         var result = script.Execute();
 
-                         if (result)
 
-                             _panel.Refresh();
 
-                     }
 
-                     else
 
-                     {
 
-                         MessageBox.Show("Unable to Compile Script!");
 
-                     }
 
-                 }
 
-                 catch (Exception err)
 
-                 {
 
-                     MessageBox.Show(CoreUtils.FormatException(err));
 
-                 }
 
-             else
 
-                 MessageBox.Show("Unable to load " + item.Label);
 
-         }
 
-         private void ManageModulesClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var model = _panel.DataModel(Selection.None);
 
-             var section = _panel.SectionName;
 
-             var manager = new CustomModuleManager
 
-             {
 
-                 DataModel = model,
 
-                 Section = section
 
-             };
 
-             manager.ShowDialog();
 
-             ReloadModules(section, model);
 
-         }
 
-         #endregion
 
-     }
 
- }
 
 
  |