| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.ComponentModel;
 
- using System.Diagnostics;
 
- using System.Drawing;
 
- using System.Drawing.Drawing2D;
 
- using System.Drawing.Imaging;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Net.Http;
 
- using System.Net.Mail;
 
- using System.Reflection;
 
- using System.Runtime.InteropServices;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using System.Windows;
 
- using System.Windows.Controls;
 
- using System.Windows.Controls.Primitives;
 
- using System.Windows.Forms;
 
- using System.Windows.Input;
 
- using System.Windows.Interop;
 
- using System.Windows.Media;
 
- using System.Windows.Threading;
 
- using AvalonDock.Layout;
 
- using Comal.Classes;
 
- using Comal.Stores;
 
- using Comal.TaskScheduler.Shared;
 
- using H.Pipes;
 
- using InABox.Client.IPC;
 
- using InABox.Clients;
 
- using InABox.Configuration;
 
- using InABox.Core;
 
- using InABox.Database;
 
- using InABox.Database.SQLite;
 
- using InABox.DeviceIdentifier;
 
- using InABox.DynamicGrid;
 
- using InABox.Mail;
 
- using InABox.Reports;
 
- using InABox.Core.Reports;
 
- using InABox.Scripting;
 
- using InABox.WPF;
 
- using NAudio.Wave;
 
- using PRS.Shared;
 
- using InABox.WPF.Themes;
 
- using NPOI.SS.Formula.Functions;
 
- using PRSDesktop.Configuration;
 
- using PRSDesktop.Forms;
 
- using PRSServer;
 
- using SharpAvi.Codecs;
 
- using SharpAvi.Output;
 
- using Syncfusion.UI.Xaml.Maps;
 
- using Syncfusion.Windows.Shared;
 
- using Syncfusion.Windows.Tools;
 
- using Syncfusion.Windows.Tools.Controls;
 
- using Activity = Comal.Classes.Activity;
 
- using Application = System.Windows.Application;
 
- using ButtonBase = System.Windows.Controls.Primitives.ButtonBase;
 
- using Color = System.Windows.Media.Color;
 
- using ColorConverter = System.Windows.Media.ColorConverter;
 
- using Control = System.Windows.Controls.Control;
 
- using Image = System.Drawing.Image;
 
- using KeyEventArgs = System.Windows.Input.KeyEventArgs;
 
- using MessageBox = System.Windows.MessageBox;
 
- using Pen = System.Drawing.Pen;
 
- using PixelFormat = System.Drawing.Imaging.PixelFormat;
 
- using Role = Comal.Classes.Role;
 
- using SortDirection = InABox.Core.SortDirection;
 
- using ValidationResult = InABox.Clients.ValidationResult;
 
- using System.Diagnostics.CodeAnalysis;
 
- using System.Runtime.InteropServices;
 
- using FastReport.Export.Email;
 
- using InABox.Wpf;
 
- using javax.xml.crypto;
 
- using PRSDesktop.Components.Spreadsheet;
 
- using InABox.Wpf.Reports;
 
- namespace PRSDesktop
 
- {
 
-     /// <summary>
 
-     ///     Interaction logic for Main.xaml
 
-     /// </summary>
 
-     public partial class MainWindow : IPanelHost
 
-     {
 
-         //private const int WM_LBUTTONDOWN = 0x201;
 
-         private static PipeServer<string>? _client;
 
-         private WaveIn? _audio;
 
-         private bool _audioMuted;
 
-         private MemoryStream? _audioStream;
 
-         private readonly Dictionary<DateTime, Stream> _bitmaps = new();
 
-         private Console? _console;
 
-         private Dictionary<DateTime, Tuple<Rectangle, string>> _notes = new();
 
-         //Dictionary<Type, IBasePanel> Panels = new Dictionary<Type, IBasePanel>();
 
-         private DispatcherTimer? _recorder;
 
-         private Process? _recordingnotes;
 
-         private int _screenheight = 720;
 
-         private int _screenleft;
 
-         private int _screentop;
 
-         private int _screenwidth = 1280;
 
-         private readonly Dictionary<Guid, SecondaryWindow> _secondarywindows = new();
 
-         private CoreTable? _timesheets;
 
-         private DailyActivityHistory? ActivityHistory;
 
-         private readonly List<Control> CurrentModules = new();
 
-         private IBasePanel? CurrentPanel;
 
-         private int CurrentPanel_Clicks;
 
-         private int CurrentPanel_Keys;
 
-         private string CurrentPanel_Label = "";
 
-         private DateTime CurrentPanel_Ticks = DateTime.MinValue;
 
-         private Fluent.RibbonTabItem? CurrentTab;
 
-         private Fluent.Button? CurrentButton;
 
-         private readonly int FRAMES_PER_SECOND = 10;
 
-         private DatabaseType DatabaseType;
 
-         private readonly Dictionary<int, int> messages = new();
 
-         private readonly DispatcherTimer NotificationsWatchDog;
 
-         private DateTime pausestarted = DateTime.MinValue;
 
-         private readonly Scheduler scheduler = new() { Interval = new TimeSpan(0, 5, 0) };
 
-         // We use a Guid for the StationID rather than an IP or Mac address
 
-         // because we want true single-instance restriction.  Using either of
 
-         // the above allows for two instances on the once machine, and thus
 
-         // double-counting in the Heartbeat() function
 
-         private Login station = new() { StationID = Guid.NewGuid().ToString() };
 
-         private TimeSpan totalpauses = new(0);
 
-         private readonly int VIDEO_HEIGHT = 1080;
 
-         private readonly int VIDEO_WIDTH = 1920;
 
-         public MainWindow()
 
-         {
 
-             NotificationsWatchDog = new DispatcherTimer { IsEnabled = false };
 
-             NotificationsWatchDog.Tick += Notifications_Tick;
 
-             NotificationsWatchDog.Interval = new TimeSpan(0, 2, 0);
 
-             ClientFactory.Notifications.AddHandler<Notification>(ReceiveNotification);
 
-             ClientFactory.RegisterMailer(EmailType.IMAP, typeof(IMAPMailer));
 
-             ClientFactory.RegisterMailer(EmailType.Exchange, typeof(ExchangeMailer));
 
-             ClientFactory.OnLog += (_, message) => { Logger.Send(LogType.Information, ClientFactory.UserID, message); };
 
-             ClientFactory.OnRequestError += ClientFactory_OnRequestError;
 
-             HotKeyManager.Initialize();
 
-             HotKeyManager.RegisterHotKey(Key.F1, ShowHelp);
 
-             HotKeyManager.RegisterHotKey(Key.F5, ToggleRecording);
 
-             HotKeyManager.RegisterHotKey(Key.F6, ShowRecordingNotes);
 
-             HotKeyManager.RegisterHotKey(Key.F4, ToggleRecordingAudio);
 
-             DatabaseType = App.DatabaseSettings.DatabaseType;
 
-             switch (DatabaseType)
 
-             {
 
-                 case DatabaseType.Standalone:
 
-                     ClientFactory.SetClientType(typeof(LocalClient<>), "Wpf", CoreUtils.GetVersion());
 
-                     DbFactory.ColorScheme = App.DatabaseSettings.ColorScheme;
 
-                     DbFactory.Logo = App.DatabaseSettings.Logo;
 
-                     break;
 
-                 
 
-                 case DatabaseType.Networked:
 
-                     var url = JsonClient<User>.Ping(App.DatabaseSettings.URLs, out DatabaseInfo info);
 
-                     ClientFactory.SetClientType(typeof(JsonClient<>), "Wpf", CoreUtils.GetVersion(), 
 
-                         url, true);
 
-                     break;
 
-                 
 
-                 case DatabaseType.Local:
 
-                     ClientFactory.SetClientType(typeof(PipeIPCClient<>), "Wpf", CoreUtils.GetVersion(), 
 
-                         DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName));
 
-                     break;
 
-             }
 
-             ThemeManager.BaseColor = Colors.CornflowerBlue;
 
-             Progress.DisplayImage = PRSDesktop.Resources.splash_small.AsBitmapImage();
 
-             try
 
-             {
 
-                 var dbInfo = new Client<User>().Info();
 
-                 ThemeManager.BaseColor = (Color)ColorConverter.ConvertFromString(dbInfo.ColorScheme);
 
-                 if (dbInfo.Logo?.Any() == true)
 
-                     using (var ms = new MemoryStream(dbInfo.Logo))
 
-                     {
 
-                         Progress.DisplayImage = new Bitmap(ms).AsBitmapImage();
 
-                     }
 
-             }
 
-             catch
 
-             {
 
-             }
 
-             InitializeComponent();
 
-             VideoRecordingStatus.Source = PRSDesktop.Resources.videorecording.AsGrayScale().AsBitmapImage();
 
-             AudioRecordingStatus.Source = PRSDesktop.Resources.audiorecording.AsGrayScale().AsBitmapImage();
 
-             SecondaryWindowStatus.Source = PRSDesktop.Resources.target.AsGrayScale().AsBitmapImage();
 
-             ConsoleStatus.Source = PRSDesktop.Resources.view.AsGrayScale().AsBitmapImage();
 
-             SelectTask.Source = PRSDesktop.Resources.uparrow.Invert().AsBitmapImage();
 
-             Title = $"{(String.Equals(App.Profile?.ToUpper(), "DEFAULT") ? "PRS Desktop" : App.Profile)} (Release {CoreUtils.GetVersion()})";
 
-             CheckForUpdates();
 
-             Exception? startupException = null;
 
-             Exception? loginException = null;
 
-             ValidationResult? loginStatus = null;
 
-             Progress.ShowModal("Loading PRS", progress =>
 
-             {
 
-                 DynamicGridUtils.PreviewReport = (t, m) => { ReportUtils.PreviewReport(t, m, false, Security.IsAllowed<CanDesignReports>()); };
 
-                 DynamicGridUtils.PrintMenu = (e, s, m, p) => { ReportUtils.PrintMenu(e, s, m, Security.IsAllowed<CanDesignReports>(), p); };
 
-                 ImportFactory.Register(typeof(ExcelImporter<>), "Excel File", "Excel Files (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm");
 
-                 FormUtils.Register();
 
-                 Logger.Send(LogType.Information, "", "Registering Classes");
 
-                 progress.Report("Registering Classes");
 
-                 var tasks = new List<Task>
 
-                 {
 
-                     Task.Run(() => CoreUtils.RegisterClasses(typeof(KanbanGrid).Assembly)),
 
-                     Task.Run(() => CoreUtils.RegisterClasses()),
 
-                     Task.Run(() => ComalUtils.RegisterClasses()),
 
-                     Task.Run(() => ReportUtils.RegisterClasses()),
 
-                     Task.Run(() => ConfigurationUtils.RegisterClasses()),
 
-                     Task.Run(() => DynamicGridUtils.RegisterClasses()),
 
-                     Task.Run(() =>
 
-                     {
 
-                         ScriptDocument.DefaultAssemblies.AddRange(
 
-                             Assembly.Load("RoslynPad.Roslyn.Windows"),
 
-                             Assembly.Load("RoslynPad.Editor.Windows"),
 
-                             typeof(Control).Assembly,
 
-                             typeof(MessageBox).Assembly,
 
-                             typeof(SolidColorBrush).Assembly
 
-                         );
 
-                         ScriptDocument.Initialize();
 
-                     }),
 
-                     Task.Run(() => DatabaseUpdateScripts.RegisterScripts())
 
-                 };
 
-                 Task.WaitAll(tasks.ToArray());
 
-                 progress.Report("Configuring Application");
 
-                 RegisterModules(progress);
 
-                 if (DatabaseType == DatabaseType.Standalone)
 
-                 {
 
-                     progress.Report("Starting local database...");
 
-                     try
 
-                     {
 
-                         StartLocalDatabase(progress);
 
-                     }
 
-                     catch (Exception err)
 
-                     {
 
-                         startupException = new Exception(
 
-                             string.Format(
 
-                                 "Unable to open database ({0})\n\n{1}\n\n{2}",
 
-                                 App.DatabaseSettings.FileName,
 
-                                 err.Message,
 
-                                 err.StackTrace
 
-                             )
 
-                         );
 
-                     }
 
-                 }
 
-                 /*if (startupException == null && App.DatabaseSettings.Autologin)
 
-                 {
 
-                     progress.Report("Logging in...");
 
-                     if (App.DatabaseSettings.LoginType == LoginType.UserID)
 
-                     {
 
-                         ValidationResult? result;
 
-                         try
 
-                         {
 
-                             result = ClientFactory.Validate(App.DatabaseSettings.UserID, App.DatabaseSettings.Password);
 
-                         }
 
-                         catch(Exception e)
 
-                         {
 
-                             Logger.Send(LogType.Error, ClientFactory.UserID, $"Error connecting to server: {CoreUtils.FormatException(e)}");
 
-                             loginException = new Exception("Error connecting to server.\nPlease check the server URL and port number.");
 
-                             result = null;
 
-                         }
 
-                         loginStatus = result;
 
-                         if (result == ValidationResult.INVALID)
 
-                         {
 
-                             loginException = new Exception("Unable to Login with User ID: " + App.DatabaseSettings.UserID);
 
-                         }
 
-                     }
 
-                     if(loginStatus == ValidationResult.VALID)
 
-                     {
 
-                         LoadCurrentEmployee();
 
-                         if(!CheckTimesheetBypass(false))
 
-                         {
 
-                             loginException = new Exception("You must clock on before logging in to PRS!");
 
-                             loginStatus = null;
 
-                         }
 
-                     }
 
-                 }*/
 
-             });
 
-             if (startupException != null)
 
-                 MessageBox.Show(startupException.Message);
 
-             else if (loginException != null)
 
-                 MessageBox.Show(loginException.Message);
 
-             if (DoLogin(App.DatabaseSettings.Autologin) == ValidationResult.VALID)
 
-             {
 
-                 AfterLogin();
 
-             }
 
-             ProfileName.Content = App.Profile;
 
-             URL.Content = DatabaseType switch
 
-             {
 
-                 DatabaseType.Networked => ClientFactory.Parameters?.FirstOrDefault(),
 
-                 DatabaseType.Standalone => App.DatabaseSettings.FileName,
 
-                 DatabaseType.Local => App.DatabaseSettings.LocalServerName,
 
-                 _ => ""
 
-             };
 
-             Progress.ShowModal("Starting Up", progress =>
 
-             {
 
-                 if (loginStatus == ValidationResult.VALID && DatabaseType == DatabaseType.Standalone)
 
-                 {
 
-                     progress.Report("Starting Scheduler");
 
-                     scheduler.Start();
 
-                 }
 
-             });
 
-         }
 
-         private bool _loggingOut = false;
 
-         private void ClientFactory_OnRequestError(RequestException e)
 
-         {
 
-             if (e.Status == StatusCode.Unauthenticated)
 
-             {
 
-                 switch (e.Method)
 
-                 {
 
-                     case RequestMethod.Query:
 
-                     case RequestMethod.Save:
 
-                     case RequestMethod.Delete:
 
-                     case RequestMethod.MultiQuery:
 
-                     case RequestMethod.MultiSave:
 
-                     case RequestMethod.MultiDelete:
 
-                         if (!_loggingOut)
 
-                         {
 
-                             Dispatcher.InvokeAsync(() =>
 
-                             {
 
-                                 _loggingOut = true;
 
-                                 try
 
-                                 {
 
-                                     Logout(null, true);
 
-                                 }
 
-                                 finally
 
-                                 {
 
-                                     _loggingOut = false;
 
-                                 }
 
-                             });
 
-                         }
 
-                         break;
 
-                     default:
 
-                         break;
 
-                 }
 
-             }
 
-         }
 
-         private void ApplyColorScheme()
 
-         {
 
-             Color baseColor;
 
-             try
 
-             {
 
-                 baseColor = (Color)ColorConverter.ConvertFromString(App.DatabaseSettings.ColorScheme);
 
-             }
 
-             catch
 
-             {
 
-                 baseColor = Colors.CornflowerBlue;
 
-             }
 
-             ThemeManager.BaseColor = baseColor;
 
-             BaseDynamicGrid.SelectionBackground = ThemeManager.SelectionBackgroundBrush;
 
-             BaseDynamicGrid.SelectionForeground = ThemeManager.SelectionForegroundBrush;
 
-             BaseDynamicGrid.FilterBackground = ThemeManager.FilterBackgroundBrush;
 
-             //_ribbon.Background =  new SolidColorBrush(Colors.White);
 
-             //_ribbon.BackStageColor = ThemeConverter.GetBrush(ElementType.Ribbon, BrushType.Background);
 
-             ////_ribbon.BackStage.Background = ThemeConverter.GetBrush(ElementType.Ribbon, BrushType.Background);
 
-             ////_ribbon.BackStage.Foreground = ThemeConverter.GetBrush(ElementType.Ribbon, BrushType.Foreground);
 
-             UpdateRibbonColors();
 
-             CurrentPanel?.Refresh();
 
-         }
 
-         #region Configuration
 
-         /*
 
-         protected override void OnSourceInitialized(EventArgs e)
 
-         {
 
-             base.OnSourceInitialized(e);
 
-             var source = PresentationSource.FromVisual(this) as HwndSource;
 
-             source?.AddHook(WndProc);
 
-         }
 
-         private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 
-         {
 
-             var message = (App.Message)msg;
 
-             switch (message)
 
-             {
 
-                 case App.Message.Maximise:
 
-                     WindowState = WindowState.Maximized;
 
-                     break;
 
-             }
 
-             return IntPtr.Zero;
 
-         }*/
 
-         private interface ISetupActionItem
 
-         {
 
-         }
 
-         private class SetupActionItem : ISetupActionItem
 
-         {
 
-             public string Name { get; set; }
 
-             public Action Action { get; set; }
 
-             public Bitmap? Image { get; set; }
 
-             public Type? SecurityToken { get; set; }
 
-             public Func<bool>? CanView { get; set; }
 
-             public SetupActionItem(string name, Action action, Bitmap? image)
 
-             {
 
-                 Name = name;
 
-                 Action = action;
 
-                 Image = image;
 
-             }
 
-             public bool IsVisible() => (SecurityToken == null || Security.IsAllowed(SecurityToken)) && (CanView == null || CanView());
 
-             public SetupActionItem SetSecurityToken<T>() where T : ISecurityDescriptor, new()
 
-             {
 
-                 SecurityToken = typeof(T);
 
-                 return this;
 
-             }
 
-             public SetupActionItem SetCanView<T>() where T : Entity
 
-             {
 
-                 return SetSecurityToken<AutoSecurityDescriptor<T, CanView<T>>>();
 
-             }
 
-         }
 
-         private class SetupSeparator : ISetupActionItem { }
 
-         private Dictionary<Fluent.RibbonTabItem, List<ISetupActionItem>> SetupActions = new();
 
-         private List<ISetupActionItem> GetSetupActionList(Fluent.RibbonTabItem tab)
 
-         {
 
-             if (!SetupActions.TryGetValue(tab, out var list))
 
-             {
 
-                 list = new();
 
-                 SetupActions[tab] = list;
 
-             }
 
-             return list;
 
-         }
 
-         private SetupActionItem AddSetupAction(List<ISetupActionItem> list, string header, Action action, Bitmap? image)
 
-         {
 
-             var item = new SetupActionItem(header, action, image);
 
-             list.Add(item);
 
-             return item;
 
-         }
 
-         private SetupActionItem AddSetupAction(Fluent.RibbonTabItem tab, string header, Action action, Bitmap? image)
 
-             => AddSetupAction(GetSetupActionList(tab), header, action, image);
 
-         private SetupActionItem? AddSetupAction(Fluent.RibbonTabItem tab, string header, Action action, Bitmap? image, bool canView)
 
-         {
 
-             if (!canView)
 
-                 return null;
 
-             return AddSetupAction(tab, header, action, image);
 
-         }
 
-         private SetupSeparator AddSetupSeparator(List<ISetupActionItem> list)
 
-         {
 
-             var separator = new SetupSeparator();
 
-             list.Add(separator);
 
-             return separator;
 
-         }
 
-         private SetupSeparator AddSetupSeparator(Fluent.RibbonTabItem tab)
 
-             => AddSetupSeparator(GetSetupActionList(tab));
 
-         private void AddSetupModulesAndReports(Fluent.RibbonTabItem tab)
 
-         {
 
-             AddSetupSeparator(tab);
 
-             AddSetupAction(tab, "Custom Modules", ManageModules, PRSDesktop.Resources.script).SetSecurityToken<CanCustomiseModules>();
 
-             AddSetupAction(tab, "Reports", ManageReports, PRSDesktop.Resources.printer).SetSecurityToken<CanDesignReports>();
 
-             AddSetupAction(tab, "Email Templates", ManageEmailTemplates, PRSDesktop.Resources.email).SetSecurityToken<CanDesignReports>();
 
-         }
 
-         private void ConfigureMainScreen()
 
-         {
 
-             var button = _ribbon.FindVisualChildren<Fluent.DropDownButton>().FirstOrDefault();
 
-             if (button != null)
 
-                 button.Visibility = Visibility.Collapsed;
 
-             if (ClientFactory.UserGuid == Guid.Empty)
 
-                 _ribbonRow.Height = new GridLength(30, GridUnitType.Pixel);
 
-             else
 
-                 _ribbonRow.Height = new GridLength(1, GridUnitType.Auto);
 
-             var bMaps = Security.CanView<Equipment>()
 
-                         || Security.CanView<Job>()
 
-                         || Security.CanView<TimeSheet>()
 
-                         || Security.CanView<GPSTracker>();
 
-             Progress.ShowModal(
 
-                 new ProgressSection(
 
-                     "Configuring Main Screen",
 
-                     () =>
 
-                     {
 
-                         ReportUtils.ExportDefinitions.Clear();
 
-                         ReportUtils.ExportDefinitions.AddRange(AddTemplateDefinitions());
 
-                         //DockManager.SidePanelSize = OutstandingDailyReports(false) ? 0.00F : 30.00F;
 
-                         // Notifications Area
 
-                         SetVisibility(SendNotification, Security.CanView<Notification>());
 
-                         SetVisibility(Notifications, Security.CanView<Notification>());
 
-                         SetVisibility(TaskTracking, Security.IsAllowed<CanTrackTasksInDailyReport>());
 
-                         UserID.Content = ClientFactory.UserID;
 
-                         if (ClientFactory.PasswordExpiration != DateTime.MinValue)
 
-                         {
 
-                             var timeUntilExpiration = ClientFactory.PasswordExpiration - DateTime.Now;
 
-                             if (timeUntilExpiration.Days < 14)
 
-                             {
 
-                                 PasswordExpiryNotice.Content = $"Password will expire in {timeUntilExpiration.Days} days!";
 
-                                 PasswordExpiryNotice.Visibility = Visibility.Visible;
 
-                             }
 
-                             else
 
-                             {
 
-                                 PasswordExpiryNotice.Visibility = Visibility.Collapsed;
 
-                             }
 
-                         }
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Quotes",
 
-                     () =>
 
-                     {
 
-                         //// Quotes Menu Bar
 
-                         SetVisibility(QuotesDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(QuotesMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(QuotesTaskButton, Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(QuotesAttendanceButton, Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(QuotesMapButton, bMaps);
 
-                         SetVisibility(QuotesDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(QuotesButton, Security.CanView<Quote>());
 
-                         SetVisibility(KitsMasterList, Security.CanView<Kit>());
 
-                         SetVisibility(CostSheetsMasterList, Security.CanView<CostSheet>());
 
-                         SetVisibleIfEither(QuotesTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 QuotesDashboardButton, QuotesMessagesButton, QuotesTaskButton, QuotesAttendanceButton, QuotesMapButton,
 
-                                 QuotesDailyReportButton
 
-                             }, new FrameworkElement[] { QuotesButton });
 
-                         
 
-                         SetVisibleIfEither(QuotesActionSeparator, new FrameworkElement[] { QuotesButton },
 
-                             new FrameworkElement[] { KitsMasterList, CostSheetsMasterList });
 
-                         SetVisibleIfAny(QuotesActions, QuotesButton, KitsMasterList, CostSheetsMasterList);
 
-                         AddSetupAction(QuotesTab, "Status Codes", QuoteStatusButton_Click, PRSDesktop.Resources.quotestatus,
 
-                             ClientFactory.IsSupported<Quote>() && Security.IsAllowed<CanModifyQuoteStatuses>());
 
-                         AddSetupAction(QuotesTab, "Design Sections", QuoteDesignSectionButton_Click, PRSDesktop.Resources.design,
 
-                             Security.CanView<QuoteDesignSection>());
 
-                         AddSetupSeparator(QuotesTab);
 
-                         AddSetupAction(QuotesTab, "Kit Conditions", KitConditionList_Click, PRSDesktop.Resources.kitcondition,
 
-                             Security.CanView<KitCondition>());
 
-                         AddSetupAction(QuotesTab, "Kit Formulae", KitFormulaeList_Click, PRSDesktop.Resources.kitformula,
 
-                             Security.CanView<KitFormula>());
 
-                         AddSetupAction(QuotesTab, "Cost Sheet Types", CostSheetTypeList_Click, PRSDesktop.Resources.costsheettype,
 
-                             Security.CanView<CostSheetType>());
 
-                         AddSetupAction(QuotesTab, "Cost Sheet Brands", CostSheetBrandList_Click, PRSDesktop.Resources.costsheetbrand,
 
-                             Security.CanView<CostSheetBrand>());
 
-                         AddSetupAction(QuotesTab, "Cost Sheet Sections", CostSheetSectionList_Click, PRSDesktop.Resources.costsheetsection,
 
-                             Security.CanView<CostSheetSection>());
 
-                         AddSetupSeparator(QuotesTab);
 
-                         AddSetupAction(QuotesTab, "Symbols", QuoteDiagramSymbols_Checked, PRSDesktop.Resources.pencil,
 
-                             Security.CanView<QuoteDiagramSymbol>());
 
-                         AddSetupAction(QuotesTab, "Symbol Types", QuoteDiagramSymbolTypes_Checked, PRSDesktop.Resources.attachment,
 
-                             Security.CanView<QuoteDiagramSymbol>());
 
-                         AddSetupAction(QuotesTab, "Dimension Types", QuoteTakeOffUnits_Click, PRSDesktop.Resources.box,
 
-                             Security.CanView<QuoteTakeOffUnit>());
 
-                         
 
-                         AddSetupSeparator(QuotesTab);
 
-                         AddSetupAction(QuotesTab, "Spreadsheet Templates", () => ViewSpreadsheetTemplates<Quote>(), PRSDesktop.Resources.box,
 
-                             Security.CanView<QuoteSpreadsheet>());                        
 
-                         AddSetupModulesAndReports(QuotesTab);
 
-                         SetTabVisibleIfAny(QuotesTab, QuotesActions);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Projects",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(ProjectsDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(ProjectMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(ProjectTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(ProjectAttendanceButton, ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(ProjectsMapButton, bMaps);
 
-                         SetVisibility(ProjectDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(ProjectsButton, Security.CanView<Job>());
 
-                         SetVisibility(ServiceButton, false);
 
-                         SetVisibility(ProjectPlannerButton, Security.CanView<Job>());
 
-                         SetVisibleIfEither(ProjectTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 ProjectsDashboardButton, ProjectMessagesButton, ProjectTaskButton, ProjectAttendanceButton, ProjectsMapButton,
 
-                                 ProjectDailyReportButton
 
-                             }, new FrameworkElement[] { QuotesButton, ProjectsButton, ServiceButton, ProjectPlannerButton });
 
-                         AddSetupAction(ProjectsTab, "Job Statuses", JobStatusButton_Click, PRSDesktop.Resources.view,
 
-                             Security.CanView<JobStatus>());
 
-                         AddSetupAction(ProjectsTab, "Document MileStones", JobDocumentMileStoneButton_OnClick, PRSDesktop.Resources.revision,
 
-                             true);
 
-                         //AddSetupAction(ProjectsTab, "Document Tags", JobDocumentTagButton_OnClick, PRSDesktop.Resources.checklist,
 
-                         //    true);
 
-                         AddSetupAction(ProjectsTab, "Financial Statuses", FinancialStatusButton_Click, PRSDesktop.Resources.view,
 
-                             Security.CanView<JobFinancial>());
 
-                         AddSetupAction(ProjectsTab, "Drawing Templates", DrawingTemplatesButton_Click, PRSDesktop.Resources.doc_misc,
 
-                             true);
 
-                             
 
-                         AddSetupSeparator(ProjectsTab);
 
-                         AddSetupAction(ProjectsTab, "Spreadsheet Templates", () => ViewSpreadsheetTemplates<Job>(), PRSDesktop.Resources.box,
 
-                             Security.CanView<JobSpreadsheet>());   
 
-                         AddSetupModulesAndReports(ProjectsTab);
 
-                         //ProjectsActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //ProjectReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         SetTabVisibleIfAny(ProjectsTab, ProjectsButton, ServiceButton, ProjectPlannerButton);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Manufacturing",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(ManufacturingDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(ManufacturingMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(ManufacturingTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(ManufacturingAttendanceButton,
 
-                             ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(ManufacturingMapButton, bMaps);
 
-                         SetVisibility(ManufacturingDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(FactoryStatusButton,
 
-                             ClientFactory.IsSupported<ManufacturingFactory, ManufacturingPacket>() && Security.IsAllowed<CanViewFactoryStatus>());
 
-                         SetVisibility(FactoryAllocationButton,
 
-                             ClientFactory.IsSupported<ManufacturingFactory, ManufacturingPacket, ManufacturingPacketStage>() &&
 
-                             Security.IsAllowed<CanViewFactoryAllocation>());
 
-                         //SetVisibility(FactoryScheduleButton, ClientFactory.IsSupported<Booking>() && ClientFactory.IsEnabled<>());
 
-                         SetVisibility(FactoryFloorButton,
 
-                             ClientFactory.IsSupported<ManufacturingPacket>() && Security.IsAllowed<CanViewFactoryFloor>());
 
-                         //SetVisibility(FactoryReadyButton, ClientFactory.IsSupported<ManufacturingPacket>() && Security.IsAllowed<CanViewFactoryReadyToGo>());
 
-                         SetVisibleIfEither(ManufacturingTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 ManufacturingDashboardButton, ManufacturingMessagesButton, ManufacturingTaskButton, ManufacturingAttendanceButton,
 
-                                 ManufacturingMapButton, ManufacturingDailyReportButton
 
-                             }, new FrameworkElement[] { FactoryStatusButton, FactoryAllocationButton, FactoryFloorButton /* , FactoryReadyButton */ });
 
-                         SetVisibleIfAny(ManufacturingActions, ManufacturingDashboardButton, ManufacturingMessagesButton, ManufacturingTaskButton,
 
-                             ManufacturingAttendanceButton, ManufacturingDailyReportButton, FactoryStatusButton, FactoryAllocationButton,
 
-                             FactoryFloorButton);
 
-                         AddSetupAction(ManufacturingTab, "Factory Settings", FactorySetup_Click, PRSDesktop.Resources.factorysetup,
 
-                             ClientFactory.IsSupported<ManufacturingFactory>() && Security.IsAllowed<CanViewFactorySettings>());
 
-                         AddSetupAction(ManufacturingTab, "Manufacturing Templates", TemplateSetup_Click, PRSDesktop.Resources.template,
 
-                             Security.CanView<ManufacturingTemplate>());
 
-                         AddSetupAction(ManufacturingTab, "Manufacturing Trolleys", TrolleySetup_Click, PRSDesktop.Resources.trolley,
 
-                             Security.CanView<ManufacturingTrolley>());
 
-                         AddSetupAction(ManufacturingTab, "Lost Time Types", LostTimeSetup_Click, PRSDesktop.Resources.smiley,
 
-                             Security.CanView<ManufacturingLostTime>());
 
-                         //ManufacturingActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //ManufacturingReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         AddSetupModulesAndReports(ManufacturingTab);
 
-                         SetTabVisibleIfAny(ManufacturingTab, FactoryStatusButton, FactoryAllocationButton, FactoryFloorButton);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Logistics",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(LogisticsDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(LogisticsMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(LogisticsTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(LogisticsAttendanceButton, ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(LogisticsMapButton, bMaps);
 
-                         SetVisibility(LogisticsDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(ReadyToGoItemsButton,
 
-                             ClientFactory.IsSupported<DeliveryItem>() && Security.IsAllowed<CanViewLogisticsReadyToGo>());
 
-                         SetVisibility(DispatchButton, Security.CanView<Shipment>() && Security.CanView<DeliveryItem>());
 
-                         SetVisibility(RequisitionsButton, Security.CanView<Requisition>());
 
-                         SetVisibility(DeliveriesButton, Security.IsAllowed<CanViewDeliveriesModule>());
 
-                         SetVisibility(DeliveredItemsButton,
 
-                             ClientFactory.IsSupported<DeliveryItem>() && Security.IsAllowed<CanViewDeliveredOnSite>());
 
-                         SetVisibility(ConsignmentButton, Security.CanView<Consignment>());
 
-                         SetVisibleIfEither(LogisticsTaskSeparator1,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 LogisticsDashboardButton, LogisticsMessagesButton, LogisticsTaskButton, LogisticsAttendanceButton, LogisticsMapButton,
 
-                                 LogisticsDailyReportButton
 
-                             },
 
-                             new FrameworkElement[]
 
-                                 { ReadyToGoItemsButton, DispatchButton, RequisitionsButton, DeliveriesButton, DeliveredItemsButton });
 
-                         SetVisibleIfEither(LogisticsTaskSeparator2,
 
-                             new FrameworkElement[]
 
-                                 { ReadyToGoItemsButton, DispatchButton, RequisitionsButton, DeliveriesButton, DeliveredItemsButton },
 
-                             new FrameworkElement[] { ConsignmentButton });
 
-                         AddSetupAction(LogisticsTab, "Delivery Types", DeliveryTypesButton_Click, PRSDesktop.Resources.truck,
 
-                             Security.CanView<ConsignmentType>());
 
-                         AddSetupAction(LogisticsTab, "Consignment Types", ConsignmentTypesButton_Click, PRSDesktop.Resources.service,
 
-                             Security.CanView<DeliveryType>());
 
-                         //LogisticsActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //LogisticsReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         AddSetupModulesAndReports(LogisticsTab);
 
-                         SetTabVisibleIfAny(LogisticsTab, DispatchButton, RequisitionsButton, DeliveriesButton, ReadyToGoItemsButton,
 
-                             DeliveredItemsButton,
 
-                             ConsignmentButton);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Products",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(ProductsDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(ProductsMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(ProductsTaskButton, Security.CanView<Kanban>());
 
-                         SetVisibility(ProductsAttendanceButton, Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(ProductsMapButton, bMaps);
 
-                         SetVisibility(ProductsDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(ProductsMasterList, Security.CanView<Product>());
 
-                         SetVisibility(StockLocationList, Security.CanView<StockLocation>());
 
-                         SetVisibility(StockMovementList, Security.CanView<StockMovement>());
 
-                         SetVisibility(StockSummaryButton, Security.CanView<Product>() && Security.CanView<JobMaterial>());
 
-                         SetVisibleIfEither(ProductsTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 ProductsDashboardButton, ProductsMessagesButton, ProductsTaskButton, ProductsAttendanceButton, ProductsMapButton,
 
-                                 ProductsDailyReportButton
 
-                             }, new FrameworkElement[] { ProductsMasterList, StockLocationList, StockMovementList, StockSummaryButton });
 
-                         SetVisibleIfAny(ProductActions, ProductsMasterList, StockLocationList, StockMovementList, StockSummaryButton);
 
-                         AddSetupAction(ProductTab, "Product Dimensions", ProductDimensionUnitsList_Click, PRSDesktop.Resources.unitofmeasure,
 
-                             Security.CanView<ProductDimensionUnit>());
 
-                         AddSetupAction(ProductTab, "Product Groups", ProductGroupsList_Click, PRSDesktop.Resources.productgroup,
 
-                             Security.CanView<ProductGroup>());
 
-                         AddSetupAction(ProductTab, "Product Styles", ProductStylesList_Click, PRSDesktop.Resources.palette,
 
-                             Security.CanView<ProductStyle>());
 
-                         AddSetupAction(ProductTab, "Stock Areas", StockAreasList_Click, PRSDesktop.Resources.rack,
 
-                             Security.CanView<StockArea>());
 
-                         AddSetupAction(ProductTab, "Stock Warehouses", StockWarehouseList_Click, PRSDesktop.Resources.factorysetup,
 
-                             Security.CanView<StockWarehouse>());
 
-                             
 
-                         AddSetupSeparator(ProductTab);
 
-                         AddSetupAction(ProductTab, "Spreadsheet Templates", () => ViewSpreadsheetTemplates<Product>(), PRSDesktop.Resources.box,
 
-                             Security.CanView<ProductSpreadsheet>());  
 
-                         AddSetupModulesAndReports(ProductTab);
 
-                         SetTabVisibleIfAny(ProductTab, ProductActions);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Human Resources",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(HumanResourcesDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(HumanResourcesMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(HumanResourcesTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(HumanResourcesAttendanceButton,
 
-                             ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(HumanResourcesMapButton, bMaps);
 
-                         SetVisibility(HumanResourcesDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(AssignmentsButton, Security.CanView<Assignment>());
 
-                         SetVisibility(EmployeePlannerButton, Security.CanView<Assignment>());
 
-                         SetVisibility(TimesheetsButton, Security.CanView<TimeSheet>());
 
-                         SetVisibility(LeaveRequestsButton, Security.CanView<LeaveRequest>());
 
-                         SetVisibility(OrgChartButton,
 
-                             ClientFactory.IsSupported<Employee>()
 
-                             && (
 
-                                 Security.IsAllowed<CanViewOrgChartByEmployee>()
 
-                                 || Security.IsAllowed<CanViewOrgChartByPosition>()
 
-                                 || Security.IsAllowed<CanViewOrgChartByRole>()
 
-                             )
 
-                         );
 
-                         SetVisibleIfEither(HumanResourcesTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 HumanResourcesDashboardButton, HumanResourcesMessagesButton, HumanResourcesTaskButton, HumanResourcesAttendanceButton,
 
-                                 HumanResourcesMapButton, HumanResourcesDailyReportButton
 
-                             }, new FrameworkElement[] { AssignmentsButton, EmployeePlannerButton, TimesheetsButton, LeaveRequestsButton, OrgChartButton });
 
-                         SetVisibleIfAny(HumanResourcesActions, HumanResourcesDashboardButton, HumanResourcesTaskButton,
 
-                             HumanResourcesAttendanceButton,
 
-                             HumanResourcesDailyReportButton, AssignmentsButton, EmployeePlannerButton, TimesheetsButton, LeaveRequestsButton, OrgChartButton);
 
-                         SetVisibility(UsersButton, Security.CanView<User>());
 
-                         SetVisibility(EmployeesButton, Security.CanView<Employee>());
 
-                         AddSetupAction(HumanResourcesTab, "Security Groups", SecurityGroupsButton_Click, PRSDesktop.Resources.securitygroup,
 
-                             Security.CanView<SecurityGroup>());
 
-                         AddSetupSeparator(HumanResourcesTab);
 
-                         AddSetupAction(HumanResourcesTab, "Employee Groups", GroupsSetup_Click, PRSDesktop.Resources.employees,
 
-                             Security.CanView<EmployeeGroup>());
 
-                         AddSetupAction(HumanResourcesTab, "Positions", PositionsSetup_Click, PRSDesktop.Resources.position,
 
-                             Security.CanView<EmployeePosition>());
 
-                         AddSetupAction(HumanResourcesTab, "Roles", RolesSetup_Click, PRSDesktop.Resources.employeerole,
 
-                             Security.CanView<EmployeeRole>());
 
-                         AddSetupAction(HumanResourcesTab, "Teams", EmployeeTeamsButton_Click, PRSDesktop.Resources.team,
 
-                             Security.CanView<EmployeeTeam>());
 
-                         AddSetupAction(HumanResourcesTab, "Activities", ActivityMenu_Click, PRSDesktop.Resources.quality,
 
-                             Security.CanView<Activity>());
 
-                         AddSetupAction(HumanResourcesTab, "Qualifications", QualificationMenu_Click, PRSDesktop.Resources.certificate,
 
-                             Security.CanView<Qualification>());
 
-                         AddSetupAction(HumanResourcesTab, "Rosters", RosterMenu_Click, PRSDesktop.Resources.assignments,
 
-                             Security.CanView<EmployeeRoster>());
 
-                         AddSetupSeparator(HumanResourcesTab);
 
-                         // AddSetupAction(HumanResourcesTab, "Rosters", RostersButton_Click, PRSDesktop.Resources.attendance,
 
-                         //     Security.CanView<Roster>());
 
-                         AddSetupAction(HumanResourcesTab, "Overtime Rules", OvertimeRulesButton_Click, PRSDesktop.Resources.overtime,
 
-                             Security.CanView<OvertimeRule>());
 
-                         AddSetupAction(HumanResourcesTab, "Standard Leave", StandardLeaveButton_Click, PRSDesktop.Resources.fireworks,
 
-                             Security.CanView<StandardLeave>());
 
-                         SetVisibleIfEither(HumanResourcesSetupSeparator1,
 
-                             new FrameworkElement[] { AssignmentsButton, TimesheetsButton, LeaveRequestsButton, OrgChartButton },
 
-                             new FrameworkElement[] { UsersButton, EmployeesButton });
 
-                         //HumanResourcesActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //HumanResourcesReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         
 
-                         AddSetupSeparator(HumanResourcesTab);
 
-                         AddSetupAction(HumanResourcesTab, "Spreadsheet Templates", () => ViewSpreadsheetTemplates<Employee>(), PRSDesktop.Resources.box,
 
-                             Security.CanView<EmployeeSpreadsheet>());  
 
-                         AddSetupModulesAndReports(HumanResourcesTab);
 
-                         SetTabVisibleIfAny(HumanResourcesTab, AssignmentsButton, TimesheetsButton, LeaveRequestsButton, OrgChartButton, UsersButton, EmployeesButton);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Accounts",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(AccountsDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(AccountsMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(AccountsTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(AccountsDataButton, Security.IsAllowed<CanViewDataEntryPanel>());
 
-                         SetVisibility(AccountsAttendanceButton, ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(AccountsMapButton, bMaps);
 
-                         SetVisibility(AccountsDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(CustomerList, ClientFactory.IsSupported<Customer>() && Security.CanView<Customer>());
 
-                         SetVisibility(InvoiceList, ClientFactory.IsSupported<Invoice>() && Security.CanView<Invoice>());
 
-                         SetVisibility(ReceiptList, ClientFactory.IsSupported<Receipt>() && Security.CanView<Receipt>());
 
-                         SetVisibility(SupplierList, ClientFactory.IsSupported<Supplier>() && Security.CanView<Supplier>());
 
-                         SetVisibility(PurchasesList, ClientFactory.IsSupported<PurchaseOrder>() && Security.CanView<PurchaseOrder>());
 
-                         SetVisibility(BillsList, ClientFactory.IsSupported<Bill>() && Security.CanView<Bill>());
 
-                         SetVisibility(PaymentsList, ClientFactory.IsSupported<Payment>() && Security.CanView<Payment>());
 
-                         SetVisibleIfEither(AccountsTaskSeparator1,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 AccountsDashboardButton, AccountsMessagesButton, AccountsTaskButton, AccountsAttendanceButton, AccountsMapButton,
 
-                                 AccountsDailyReportButton
 
-                             }, new FrameworkElement[] { CustomerList, InvoiceList, ReceiptList });
 
-                         SetVisibleIfEither(AccountsTaskSeparator2, new FrameworkElement[] { CustomerList, InvoiceList, ReceiptList },
 
-                             new FrameworkElement[] { SupplierList, PurchasesList, BillsList, PaymentsList });
 
-                         SetVisibleIfAny(AccountsActions, AccountsDashboardButton, AccountsMessagesButton, AccountsTaskButton,
 
-                             AccountsAttendanceButton,
 
-                             AccountsDailyReportButton, CustomerList, InvoiceList, ReceiptList, SupplierList, PurchasesList, BillsList, PaymentsList);
 
-                         AddSetupAction(AccountsTab, "Contact Types", ContactTypeList_Click, PRSDesktop.Resources.contacttype,
 
-                             ClientFactory.IsSupported<Contact>() && Security.CanView<ContactType>());
 
-                         AddSetupAction(AccountsTab, "Tax Codes", TaxCodeList_Click, PRSDesktop.Resources.taxcode,
 
-                             ClientFactory.IsSupported<GLCode>() && Security.CanView<TaxCode>());
 
-                         AddSetupAction(AccountsTab, "Receipt Types", ReceiptTypeList_Click, PRSDesktop.Resources.receipt,
 
-                             ClientFactory.IsSupported<GLCode>() && Security.CanView<ReceiptType>());
 
-                         AddSetupAction(AccountsTab, "Payment Types", PaymentTypeList_Click, PRSDesktop.Resources.payment,
 
-                             ClientFactory.IsSupported<GLCode>() && Security.CanView<PaymentType>());
 
-                         AddSetupAction(AccountsTab, "Cost Centres", CostCentresList_Click, PRSDesktop.Resources.costcentre,
 
-                             ClientFactory.IsSupported<CostCentre>() && Security.CanView<CostCentre>());
 
-                         AddSetupAction(AccountsTab, "GL Codes", GLCodesList_Click, PRSDesktop.Resources.glcode,
 
-                             ClientFactory.IsSupported<GLCode>() && Security.CanView<GLCode>());
 
-                         AddSetupAction(AccountsTab, "Purchase Order Categories", PurchaseOrderCategoriesButton_Click, PRSDesktop.Resources.service,
 
-                             ClientFactory.IsSupported<PurchaseOrderCategory>() && Security.CanView<PurchaseOrderCategory>());
 
-                         //AccountsActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //AccountsReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         
 
-                         AddSetupSeparator(AccountsTab);
 
-                         AddSetupAction(AccountsTab, "Customer Spreadsheet Templates", () => ViewSpreadsheetTemplates<Customer>(), PRSDesktop.Resources.box,
 
-                             Security.CanView<CustomerSpreadsheet>()); 
 
-                         AddSetupAction(AccountsTab, "Supplier Spreadsheet Templates", () => ViewSpreadsheetTemplates<Supplier>(), PRSDesktop.Resources.box,
 
-                             Security.CanView<SupplierSpreadsheet>()); 
 
-                         AddSetupModulesAndReports(AccountsTab);
 
-                         SetTabVisibleIfAny(AccountsTab, CustomerList, InvoiceList, ReceiptList, SupplierList, PurchasesList, BillsList, PaymentsList);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Equipment",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(EquipmentDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(EquipmentMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(EquipmentTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(EquipmentAttendanceButton, ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(EquipmentMapButton, bMaps);
 
-                         SetVisibility(EquipmentDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(EquipmentButton, ClientFactory.IsSupported<Equipment>() && Security.CanView<Equipment>());
 
-                         SetVisibleIfEither(EquipmentTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 EquipmentDashboardButton, EquipmentMessagesButton, EquipmentTaskButton, EquipmentAttendanceButton, EquipmentMapButton,
 
-                                 EquipmentDailyReportButton
 
-                             }, new FrameworkElement[] { EquipmentButton });
 
-                         SetVisibleIfAny(EquipmentActions, EquipmentDashboardButton, EquipmentMessagesButton, EquipmentTaskButton,
 
-                             EquipmentAttendanceButton, EquipmentDailyReportButton, EquipmentButton);
 
-                         SetVisibility(TrackersMasterList, Security.CanView<GPSTracker>());
 
-                         AddSetupAction(EquipmentTab, "Tracker Types", TrackerTypes_Click, PRSDesktop.Resources.milestone,
 
-                             Security.CanView<GPSTrackerType>());
 
-                         AddSetupAction(EquipmentTab, "Stickers", Stickers_Click, PRSDesktop.Resources.barcode,
 
-                             Security.CanView<WebSticker>());
 
-                         AddSetupAction(EquipmentTab, "Digital Keys", DigitalKeys_Click, PRSDesktop.Resources.key,
 
-                             Security.CanView<DigitalKey>());
 
-                         AddSetupAction(EquipmentTab, "Equipment Groups", EquipmentGroupList_Click, PRSDesktop.Resources.specifications,
 
-                             Security.CanView<EquipmentGroup>());
 
-                         //EquipmentActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //EquipmentReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         AddSetupModulesAndReports(EquipmentTab);
 
-                         SetTabVisibleIfAny(EquipmentTab, EquipmentButton, TrackersMasterList);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring Dashboards",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(DashboardsDashboardButton, Security.IsAllowed<CanViewUserDefinedDashboards>());
 
-                         SetVisibility(DashboardMessagesButton, Security.CanView<Notification>());
 
-                         SetVisibility(DashboardsTaskButton, ClientFactory.IsSupported<Kanban>() && Security.IsAllowed<CanViewTasks>());
 
-                         SetVisibility(DashboardsAttendanceButton, ClientFactory.IsSupported<TimeSheet>() && Security.IsAllowed<CanViewInOutBoard>());
 
-                         SetVisibility(DashboardsMapButton, bMaps);
 
-                         SetVisibility(DashboardsDailyReportButton,
 
-                             ClientFactory.IsSupported<TimeSheet, Assignment>() && Security.IsAllowed<CanViewDailyReports>());
 
-                         SetVisibility(FactoryProductivityButton,
 
-                             ClientFactory.IsSupported<ManufacturingHistory>() && Security.IsAllowed<CanViewFactoryKPIs>());
 
-                         SetVisibility(TemplateAnalysisButton,
 
-                             ClientFactory.IsSupported<ManufacturingTemplate, ManufacturingHistory>() &&
 
-                             Security.IsAllowed<CanViewTemplateAnalysis>());
 
-                         SetVisibility(FactoryAnalysisButton,
 
-                             ClientFactory.IsSupported<ManufacturingTemplate, ManufacturingHistory>() && Security.IsAllowed<CanViewFactoryAnalysis>());
 
-                         SetVisibility(DatabaseActivityButton,
 
-                             ClientFactory.IsSupported<UserTracking>() && Security.IsAllowed<CanViewDatabaseActivity>());
 
-                         SetVisibility(UserActivityButton, ClientFactory.IsSupported<ModuleTracking>() && Security.IsAllowed<CanViewUserActivity>());
 
-                         SetVisibility(QAAnalysisButton, Security.IsAllowed<CanViewDigitalFormsDashbaord>());
 
-                         SetVisibility(QuickStatusButton, Security.IsAllowed<CanViewQuickStatus>());
 
-                         SetVisibleIfEither(DashboardsTaskSeparator,
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 DashboardsDashboardButton, DashboardMessagesButton, DashboardsTaskButton, DashboardsAttendanceButton,
 
-                                 DashboardsMapButton,
 
-                                 DashboardsDailyReportButton
 
-                             },
 
-                             new FrameworkElement[]
 
-                             {
 
-                                 FactoryProductivityButton, TemplateAnalysisButton, FactoryAnalysisButton, DatabaseActivityButton, UserActivityButton,
 
-                                 QAAnalysisButton, QuickStatusButton
 
-                             });
 
-                         SetVisibleIfAny(DashboardsActions, DashboardsDashboardButton, DashboardMessagesButton, DashboardsTaskButton,
 
-                             DashboardsAttendanceButton, DashboardsDailyReportButton, FactoryProductivityButton, TemplateAnalysisButton,
 
-                             FactoryAnalysisButton, DatabaseActivityButton, UserActivityButton, QAAnalysisButton, QuickStatusButton);
 
-                         //DashboardsActions.IsLauncherButtonVisible = Security.IsAllowed<CanCustomiseModules>();
 
-                         //DashboardsReports.IsLauncherButtonVisible = Security.IsAllowed<CanDesignReports>();
 
-                         AddSetupModulesAndReports(DashboardsTab);
 
-                         SetVisibleIfAny(DashboardsTab, FactoryProductivityButton, TemplateAnalysisButton, FactoryAnalysisButton,
 
-                             DatabaseActivityButton,
 
-                             UserActivityButton, QAAnalysisButton, QuickStatusButton);
 
-                     }
 
-                 ),
 
-                 new ProgressSection(
 
-                     "Configuring System Modules",
 
-                     () =>
 
-                     {
 
-                         SetVisibility(CompanyInformation, Security.CanView<CompanyInformation>());
 
-                         SetVisibleIfAny(BackstageSeparator0, CompanyInformation);
 
-                         SetVisibility(SecurityDefaultsButton,
 
-                             ClientFactory.IsSupported<GlobalSecurityToken>() && Security.IsAllowed<CanCustomiseSecurityDefaults>());
 
-                         SetVisibleIfAny(BackstageSeparator1, SecurityDefaultsButton);
 
-                         BackstageSeparator1a.Visibility = Visibility.Visible;
 
-                         SystemLogsButton.Visibility = Visibility.Visible;
 
-                         SetVisibility(DocumentTypeList, ClientFactory.IsSupported<DocumentType>() && Security.IsAllowed<CanViewDocumentTypes>());
 
-                         SetVisibility(DocumentList, ClientFactory.IsSupported<Document>() && Security.IsAllowed<CanViewDocumentList>());
 
-                         SetVisibility(QAFormSetupButton,
 
-                             ClientFactory.IsSupported<DigitalForm>() && Security.IsAllowed<CanAdministerDigitalFormsLibrary>());
 
-                         SetVisibleIfAny(BackstageSeparator2, DocumentTypeList, DocumentList, QAFormSetupButton);
 
-                         SetVisibility(VideoRecordingButton, Security.IsAllowed<CanRecordScreen>());
 
-                         LogoutButton.Visibility = ClientFactory.UserGuid == Guid.Empty ? Visibility.Collapsed : Visibility.Visible;
 
-                         LoginButton.Visibility = ClientFactory.UserGuid != Guid.Empty ? Visibility.Collapsed : Visibility.Visible;
 
-                         EditDetailsButton.Visibility = ClientFactory.UserGuid == Guid.Empty ? Visibility.Collapsed : Visibility.Visible;
 
-                         SetupDock<CanViewContactsDock>(ContactDock, Contacts);
 
-                         SetupDock<CanViewJobDock>(JobDock, Jobs);
 
-                         SetupDock<CanViewConsignmentDock>(ConsignmentDock, Consignments);
 
-                         SetupDock<CanViewDeliveryDock>(DeliveryDock, Deliveries);
 
-                         SetupDock<CanViewProductDock>(ProductLookupDock, ProductLookup);
 
-                         SetupDock<CanViewDigitalFormsDock>(DigitalFormsDock, DigitalForms);
 
-                         SetupDock<CanViewDataEntryPanel>(ScansDock, Scans);
 
-                         _ribbon.InvalidateArrange();
 
-                     }
 
-                 )
 
-             );
 
-         }
 
-         private void ViewSpreadsheetTemplates<TEntity>() where TEntity : Entity
 
-         {
 
-             SpreadsheetTemplateGrid grid = new SpreadsheetTemplateGrid();
 
-             grid.AppliesTo = typeof(TEntity);
 
-             grid.Refresh(true, true);
 
-             DynamicContentDialog dlg = new DynamicContentDialog(grid,false);
 
-             dlg.Title = $"{typeof(TEntity).EntityName().Split(".").Last()} Spreadsheet Templates";
 
-             dlg.ShowDialog();
 
-         }
 
-         private IEnumerable<ReportExportDefinition> AddTemplateDefinitions()
 
-         {
 
-             if (CurrentPanel == null)
 
-                 return new List<ReportExportDefinition>() { new ReportExportDefinition("Email Report", PRSDesktop.Resources.email, ReportExportType.PDF,
 
-                             EmailUtils.DoEmailReport)};
 
-             else
 
-                 return EmailUtils.CreateTemplateDefinitions(CurrentPanel.DataModel(Selection.None));
 
-         }
 
-         private void SetupDock<TSecurityDescriptor>(LayoutAnchorable layout, IDockPanel dock)
 
-             where TSecurityDescriptor : ISecurityDescriptor, new()
 
-         {
 
-             if (Security.IsAllowed<TSecurityDescriptor>())
 
-             {
 
-                 if (!DockGroup.Children.Any(x => x == layout))
 
-                 {
 
-                     DockGroup.Children.Add(layout);
 
-                 }
 
-                 if (layout.IsVisible && (ClientFactory.UserGuid != Guid.Empty))
 
-                     dock.Setup();
 
-             }
 
-             else
 
-             {
 
-                 DockGroup.RemoveChild(layout);
 
-             }
 
-         }
 
-         private void LoadApplicationState()
 
-         {
 
-             if (ClientFactory.UserGuid != Guid.Empty)
 
-             {
 
-                 _ribbon.IsCollapsed = false;
 
-                 if (OutstandingDailyReports(false))
 
-                 {
 
-                     MessageBox.Show("There are outstanding Daily Reports that must be filled out before continuing!" +
 
-                                     "\n\nAccess to PRS is restricted until this is corrected.",
 
-                         "Outstanding Reports"
 
-                     );
 
-                     var dailyReportPanel = LoadWindow<DailyReport>(ProjectDailyReportButton);
 
-                     dailyReportPanel.OnTimeSheetConfirmed += e =>
 
-                     {
 
-                         if (!OutstandingDailyReports(true))
 
-                         {
 
-                             ConfigureMainScreen();
 
-                             LoadApplicationState();
 
-                         }
 
-                     };
 
-                     return;
 
-                 }
 
-                 using (new WaitCursor())
 
-                 {
 
-                     _ribbon.IsCollapsed = false;
 
-                     LoadInitialWindow();
 
-                 }
 
-             }
 
-         }
 
-         private void LoadInitialWindow()
 
-         {
 
-             var app = new LocalConfiguration<AppSettings>().Load();
 
-             if (app.Settings.ContainsKey("CurrentPanel"))
 
-             {
 
-                 try
 
-                 {
 
-                     var bFound = false;
 
-                     var module = app.Settings["CurrentPanel"].Split(new[] { " / " }, StringSplitOptions.None);
 
-                     if (module.Length == 2)
 
-                         foreach (Fluent.RibbonTabItem tab in _ribbon.Tabs)
 
-                         {
 
-                             if (String.Equals(tab.Header, module.First()))
 
-                             {
 
-                                 _ribbon.SelectedTabItem = tab;
 
-                                 foreach (Fluent.RibbonGroupBox bar in tab.Groups)
 
-                                 {
 
-                                     foreach (var item in bar.Items)
 
-                                     {
 
-                                         var button = item as Fluent.Button;
 
-                                         if (button != null && String.Equals(button.Header, module.Last()))
 
-                                         {
 
-                                             bFound = true;
 
-                                             button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
 
-                                             break;
 
-                                         }
 
-                                     }
 
-                                     if (bFound)
 
-                                         break;
 
-                                 }
 
-                             }
 
-                             if (bFound)
 
-                                 break;
 
-                         }
 
-                 }
 
-                 catch (Exception e)
 
-                 {
 
-                     MessageBox.Show(string.Format("Unable to Load {0}!\n\n{1}\n{2}", app.Settings["CurrentPanel"], e.Message, e.StackTrace));
 
-                 }
 
-             }
 
-         }
 
-         private void _ribbon_OnLoaded(object sender, RoutedEventArgs e)
 
-         {
 
-             _ribbon.SelectedTabItem = CurrentTab;
 
-         }
 
-         private void LoadSecondaryWindows()
 
-         {
 
-             if (ClientFactory.UserGuid != Guid.Empty)
 
-             {
 
-                 var windows = App.DatabaseSettings.SecondaryWindows;
 
-                 foreach (var key in windows.Keys.ToArray())
 
-                 {
 
-                     _secondarywindows[key] = new SecondaryWindow(
 
-                         key,
 
-                         windows[key].Item1,
 
-                         windows[key].Item2,
 
-                         windows[key].Item3,
 
-                         windows[key].Item4,
 
-                         windows[key].Item5,
 
-                         windows[key].Item6
 
-                     );
 
-                     _secondarywindows[key].Closed += (o, e) => { _secondarywindows.Remove(key); };
 
-                     _secondarywindows[key].Show();
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 foreach (var key in _secondarywindows.Keys.ToArray())
 
-                 {
 
-                     App.IsClosing = true;
 
-                     _secondarywindows[key].Close();
 
-                     App.IsClosing = false;
 
-                 }
 
-             }
 
-         }
 
-         private Fluent.RibbonTabItem GetTabItem(FrameworkElement? sender)
 
-         {
 
-             if (sender == null)
 
-                 throw new Exception("No Tab Found!");
 
-             if (sender is Fluent.RibbonTabItem)
 
-                 return (Fluent.RibbonTabItem)sender;
 
-             return GetTabItem(sender.Parent as FrameworkElement);
 
-         }
 
-         private T LoadWindow<T>(Fluent.Button sender) where T : IBasePanel, new()
 
-         {
 
-             using (new WaitCursor())
 
-             {
 
-                 UnloadWindow();
 
-                 CurrentTab = GetTabItem(sender);
 
-                 CurrentButton = sender;
 
-                 //CurrentButton.IsSelected = true;
 
-                 UpdateRibbonColors();
 
-                 var panel = new T();
 
-                 CurrentPanel = panel;
 
-                 ReportUtils.ExportDefinitions.Clear();
 
-                 ReportUtils.ExportDefinitions.AddRange(AddTemplateDefinitions());
 
-                 InitializePanelProperties(panel);
 
-                 CurrentPanel.IsReady = false;
 
-                 CurrentPanel.Setup();
 
-                 CurrentPanel.IsReady = true;
 
-                 CurrentPanel.OnUpdateDataModel += (s, m) =>
 
-                 {
 
-                     ReloadModules(s, m);
 
-                     ReloadReports(s, m);
 
-                 };
 
-                 CurrentPanel_Label = sender.Header?.ToString() ?? "";
 
-                 CurrentPanel_Ticks = DateTime.Now;
 
-                 ContentControl.Content = CurrentPanel;
 
-                 Title =
 
-                     $"{CurrentPanel_Label} - {(String.Equals(App.Profile?.ToUpper(), "DEFAULT") ? "PRS Desktop" : App.Profile)} (Release {CoreUtils.GetVersion()})";
 
-                 if (sender != null)
 
-                 {
 
-                     var model = CurrentPanel.DataModel(Selection.None);
 
-                     var section = CurrentPanel.SectionName;
 
-                     ReloadModules(section, model);
 
-                     ReloadReports(section, model);
 
-                 }
 
-                 CurrentPanel.Refresh();
 
-                 if (CurrentPanel is NotificationPanel)
 
-                 {
 
-                     Logger.Send(LogType.Information, ClientFactory.UserID, "Disabling Heartbeat");
 
-                     NotificationsWatchDog.IsEnabled = false;
 
-                     Notifications.Visibility = Visibility.Collapsed;
 
-                     DockingGrid.ColumnDefinitions[1].Width = new GridLength(0, GridUnitType.Pixel);
 
-                     DockingGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Pixel);
 
-                 }
 
-                 else
 
-                 {
 
-                     ReloadNotifications();
 
-                 }
 
-                 if (sender != null)
 
-                 {
 
-                     var settings = new LocalConfiguration<AppSettings>().Load();
 
-                     var module = string.Format("{0} / {1}", CurrentTab?.Header, sender.Header);
 
-                     if (!settings.Settings.ContainsKey("CurrentPanel") || module != settings.Settings["CurrentPanel"])
 
-                     {
 
-                         settings.Settings["CurrentPanel"] = module;
 
-                         try
 
-                         {
 
-                             new LocalConfiguration<AppSettings>().Save(settings);
 
-                         }
 
-                         catch (Exception e)
 
-                         {
 
-                             Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
 
-                         }
 
-                     }
 
-                 }
 
-                 //stopwatch.Stop();
 
-                 //Logger.Send(LogType.Information, ClientFactory.UserID, String.Format("Loading {0} to took {1} ms", sender != null ? sender.Label : module, stopwatch.ElapsedMilliseconds));
 
-                 return panel;
 
-             }
 
-         }
 
-         private void UpdateRibbonColors()
 
-         {
 
-             foreach (var tab in _ribbon.Tabs)
 
-             {
 
-                 bool bFound = false;
 
-                 foreach (var grp in tab.Groups)
 
-                 {
 
-                     foreach (var btn in grp.Items)
 
-                     {
 
-                         if (btn is Fluent.Button fluentbutton)
 
-                         {
 
-                             bFound = bFound || (btn == CurrentButton);
 
-                             fluentbutton.Background = (btn == CurrentButton) ? ThemeManager.SelectedTabItemBackgroundBrush : new SolidColorBrush(Colors.White);
 
-                             fluentbutton.Foreground = (btn == CurrentButton) ? ThemeManager.SelectedTabItemForegroundBrush : new SolidColorBrush(Colors.Black);
 
-                         }
 
-                     }
 
-                     tab.Background = bFound ? ThemeManager.SelectedTabItemBackgroundBrush : new SolidColorBrush(Colors.White);
 
-                     tab.Foreground = bFound ? ThemeManager.SelectedTabItemForegroundBrush : new SolidColorBrush(Colors.Black);
 
-                 }
 
-             }
 
-         }
 
-         private static void StartLocalDatabase(IProgress<string> progress)
 
-         {
 
-             var dirName = Path.GetDirectoryName(App.DatabaseSettings.FileName);
 
-             if (!Directory.Exists(dirName) && dirName != null)
 
-                 Directory.CreateDirectory(dirName);
 
-             var FileName = App.DatabaseSettings.FileName;
 
-             var Exists = File.Exists(FileName);
 
-             progress.Report("Configuring Stores");
 
-             DbFactory.Stores = CoreUtils.TypeList(
 
-                 new[]
 
-                 {
 
-                     typeof(DocumentStore).Assembly,
 
-                     typeof(EquipmentStore).Assembly
 
-                 },
 
-                 myType =>
 
-                     myType.IsClass
 
-                     && !myType.IsAbstract
 
-                     && !myType.IsGenericType
 
-                     && myType.GetInterfaces().Contains(typeof(IStore))
 
-             ).ToArray();
 
-             DbFactory.Provider = new SQLiteProvider(App.DatabaseSettings.FileName);
 
-             DbFactory.ColorScheme = App.DatabaseSettings.ColorScheme;
 
-             DbFactory.Logo = App.DatabaseSettings.Logo;
 
-             progress.Report("Starting Local Database");
 
-             DbFactory.Start();
 
-             progress.Report("Checking Database");
 
-             var users = DbFactory.Provider.Load<User>();
 
-             if (!users.Any())
 
-             {
 
-                 var user = new User { UserID = "ADMIN", Password = "admin" };
 
-                 DbFactory.Provider.Save(user);
 
-                 var employee = DbFactory.Provider.Load(new Filter<Employee>(x => x.Code).IsEqualTo("ADMIN")).FirstOrDefault();
 
-                 employee ??= new Employee { Code = "ADMIN", Name = "Administrator Account" };
 
-                 employee.UserLink.ID = user.ID;
 
-                 DbFactory.Provider.Save(employee);
 
-             }
 
-             StoreUtils.GoogleAPIKey = App.DatabaseSettings.GoogleAPIKey;
 
-             JobStore.AutoIncrementPrefix = App.DatabaseSettings.JobPrefix;
 
-             PurchaseOrderStore.AutoIncrementPrefix = App.DatabaseSettings.PurchaseOrderPrefix;
 
-         }
 
-         #endregion
 
-         #region Login Management
 
-         private ValidationResult? DoLogin(bool autoLogin)
 
-         {
 
-             ValidationResult? result = null;
 
-             if (autoLogin)
 
-             {
 
-                 if (App.DatabaseSettings.LoginType == LoginType.UserID)
 
-                 {
 
-                     try
 
-                     {
 
-                         result = ClientFactory.Validate(App.DatabaseSettings.UserID, App.DatabaseSettings.Password);
 
-                     }
 
-                     catch (Exception e)
 
-                     {
 
-                         Logger.Send(LogType.Error, ClientFactory.UserID, $"Error connecting to server: {CoreUtils.FormatException(e)}");
 
-                         MessageBox.Show("Error connecting to server.\nPlease check the server URL and port number.");
 
-                         result = null;
 
-                     }
 
-                     if (result == ValidationResult.INVALID)
 
-                     {
 
-                         MessageBox.Show("Unable to Login with User ID: " + App.DatabaseSettings.UserID);
 
-                     }
 
-                 }
 
-             }
 
-             if (result != ValidationResult.VALID)
 
-             {
 
-                 var login = new PinLogin(CoreUtils.GetVersion(), result ?? ValidationResult.INVALID);
 
-                 if (login.ShowDialog() == true)
 
-                 {
 
-                     result = ValidationResult.VALID;
 
-                 }
 
-             }
 
-             return result ?? ValidationResult.INVALID;
 
-         }
 
-         /// <summary>
 
-         /// To be called after <see cref="DoLogin(bool)"/> and if a valid login session exists. Configures the main screen and loads the windows.
 
-         /// </summary>
 
-         private void AfterLogin()
 
-         {
 
-             LoadCurrentEmployee();
 
-             if (CheckTimesheetBypass(true))
 
-             {
 
-                 UpdateCurrentLogin();
 
-             }
 
-             else
 
-             {
 
-                 MessageBox.Show("You must clock on before logging in to PRS!");
 
-                 ClientFactory.InvalidateUser();
 
-                 App.EmployeeID = Guid.Empty;
 
-                 App.EmployeeName = "";
 
-                 App.EmployeeEmail = "";
 
-             }
 
-             ApplyColorScheme();
 
-             ConfigureMainScreen();
 
-             LoadApplicationState();
 
-             LoadSecondaryWindows();
 
-             //if (_ribbon.Menu.IsVisible)
 
-             //{
 
-             //    _ribbon.;
 
-             //}
 
-         }
 
-         /// <summary>
 
-         /// Creates a new <see cref="Login"/> if one does not already exist. Otherwise, updates the <see cref="Login"/> entry in the database with new Station ID.
 
-         /// </summary>
 
-         private void UpdateCurrentLogin()
 
-         {
 
-             if (CoreUtils.GetVersion().Equals("???"))
 
-                 return;
 
-             // Register this station with the Server
 
-             // Later on, the heartbeat will check to make sure 
 
-             // that the StationID hasn't changed.  If it has,
 
-             // then we've logged in somewhere else and we'll
 
-             // drop out of this station
 
-             var curr = new Client<Login>().Query(
 
-                 new Filter<Login>(x => x.User.ID).IsEqualTo(ClientFactory.UserGuid),
 
-                 null
 
-             ).Rows.FirstOrDefault();
 
-             if (curr != null)
 
-             {
 
-                 var c = curr.ToObject<Login>();
 
-                 c.StationID = station.StationID;
 
-                 station = c;
 
-             }
 
-             else
 
-             {
 
-                 station.User.ID = ClientFactory.UserGuid;
 
-                 station.TimeStamp = DateTime.Now;
 
-             }
 
-             new Client<Login>().Save(station, "", (o, e) => { });
 
-         }
 
-         private void LoadCurrentEmployee()
 
-         {
 
-             var me = new Client<Employee>().Query(
 
-                 new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid),
 
-                 new Columns<Employee>(x => x.ID).Add(x => x.Email).Add(x=>x.Name)
 
-             );
 
-             App.EmployeeID = me.Rows.FirstOrDefault()?.Get<Employee, Guid>(x => x.ID) ?? Guid.Empty;
 
-             App.EmployeeName = me.Rows.FirstOrDefault()?.Get<Employee, String>(x => x.Name) ?? "";
 
-             App.EmployeeEmail = me.Rows.FirstOrDefault()?.Get<Employee, String>(x => x.Email) ?? "";
 
-         }
 
-         private void ExecuteLogout()
 
-         {
 
-             new Client<Login>().Delete(station, "");
 
-             station.ID = Guid.Empty;
 
-             App.EmployeeID = Guid.Empty;
 
-             App.EmployeeName = "";
 
-             App.EmployeeEmail = "";
 
-         }
 
-         /// <summary>
 
-         /// Logs the user out and unloads windows
 
-         /// </summary>
 
-         /// <param name="message">A message to display as the reason for logging out, or <c>null</c> for no message.</param>
 
-         private bool Logout(string? message = null, bool force = false)
 
-         {
 
-             // I really don't like all these try-catch blocks; unfortunately, if we are trying to log out and invalidate due to an unauthenticated user,
 
-             // all the queries that get called here will throw exceptions and thus break our system, failing to log out.
 
-             try
 
-             {
 
-                 FinalizeAutoTimesheet();
 
-             }
 
-             catch
 
-             {
 
-                 if (!force) throw;
 
-             }
 
-             // Try to unload the window;
 
-             try
 
-             {
 
-                 UnloadWindow();
 
-                 if (DatabaseType == DatabaseType.Standalone && !CoreUtils.GetVersion().Equals("???"))
 
-                     scheduler.Stop();
 
-             }
 
-             catch
 
-             {
 
-                 if (!force) throw;
 
-             }
 
-             // Next, try to set things to being empty
 
-             try
 
-             {
 
-                 if (!CoreUtils.GetVersion().Equals("???"))
 
-                     if (station.ID != Guid.Empty)
 
-                     {
 
-                         ExecuteLogout();
 
-                     }
 
-                 ClearTrackingKanban();
 
-             }
 
-             catch
 
-             {
 
-                 if (!force) throw;
 
-             }
 
-             ClientFactory.InvalidateUser();
 
-             ConfigureMainScreen();
 
-             LoadSecondaryWindows();
 
-             if (message != null)
 
-             {
 
-                 MessageBox.Show(message);
 
-             }
 
-             if (DoLogin(false) == ValidationResult.VALID)
 
-             {
 
-                 AfterLogin();
 
-             }
 
-             return true;
 
-         }
 
-         #endregion
 
-         #region Timesheets
 
-         private void RefreshTimeSheets()
 
-         {
 
-             if (App.EmployeeID == Guid.Empty)
 
-                 return;
 
-             var filter = new Filter<TimeSheet>(x => x.EmployeeLink.ID).IsEqualTo(App.EmployeeID);
 
-             filter = filter.And(new Filter<TimeSheet>(x => x.Confirmed).IsEqualTo(DateTime.MinValue).Or(x => x.Date).IsEqualTo(DateTime.Today));
 
-             _timesheets = new Client<TimeSheet>().Query(
 
-                 filter,
 
-                 new Columns<TimeSheet>(
 
-                     x => x.ID,
 
-                     x => x.Date,
 
-                     x => x.Finish
 
-                 )
 
-             );
 
-         }
 
-         private CoreTable GetTimesheet()
 
-         {
 
-             return new Client<TimeSheet>().Query(
 
-                 new Filter<TimeSheet>(x => x.Date).IsEqualTo(DateTime.Today)
 
-                     .And(x => x.EmployeeLink.ID).IsEqualTo(App.EmployeeID)
 
-                     .And(x => x.Finish).IsEqualTo(TimeSpan.Zero)
 
-             );
 
-         }
 
-         private bool CheckTimesheetBypass(bool message)
 
-         {
 
-             if (!ClientFactory.IsSupported<TimeSheet>())
 
-                 return true;
 
-             var isClockedOn = IsClockedOn();
 
-             if (!Security.IsAllowed<CanBypassTimeBench>())
 
-             {
 
-                 if (!isClockedOn)
 
-                 {
 
-                     if (message)
 
-                         MessageBox.Show("You must clock on before opening this screen");
 
-                     return false;
 
-                 }
 
-                 return true;
 
-             }
 
-             if (Security.IsAllowed<AutoGenerateTimesheet>())
 
-                 if (!isClockedOn)
 
-                 {
 
-                     var ts = new TimeSheet();
 
-                     ts.Date = DateTime.Today;
 
-                     ts.Start = DateTime.Now.TimeOfDay;
 
-                     ts.EmployeeLink.ID = App.EmployeeID;
 
-                     ts.Notes = "Automatic Login from PRS Desktop";
 
-                     new Client<TimeSheet>().Save(ts, "AutoLogon because Timebench Bypass is enabled", (o, e) => { });
 
-                 }
 
-             return true;
 
-         }
 
-         private bool IsClockedOn()
 
-         {
 
-             RefreshTimeSheets();
 
-             if (_timesheets == null)
 
-                 return false;
 
-             return _timesheets.Rows.Any(r =>
 
-                 r.Get<TimeSheet, DateTime>(c => c.Date).Date == DateTime.Today && r.Get<TimeSheet, TimeSpan>(c => c.Finish) == new TimeSpan());
 
-         }
 
-         #endregion
 
-         private string CurrentPanelSlug()
 
-         {
 
-             var app = new LocalConfiguration<AppSettings>().Load();
 
-             var module = app.Settings["CurrentPanel"].Split(new[] { " / " }, StringSplitOptions.None);
 
-             return module.LastOrDefault()?.Replace(" ", "_").Replace("/", "") ?? "";
 
-         }
 
-         private bool ShowHelp()
 
-         {
 
-             Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + CurrentPanelSlug()) { UseShellExecute = true });
 
-             return true;
 
-         }
 
-         private void Wiki_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ShowHelp();
 
-         }
 
-         private void Window_Loaded(object sender, RoutedEventArgs e)
 
-         {
 
-         }
 
-         private void UnloadWindow()
 
-         {
 
-             if (CurrentPanel != null)
 
-             {
 
-                 Heartbeat(DateTime.Now - CurrentPanel_Ticks, true);
 
-                 try
 
-                 {
 
-                     CurrentPanel.Shutdown();
 
-                 }
 
-                 catch (Exception e)
 
-                 {
 
-                     Logger.Send(LogType.Error, ClientFactory.UserID, string.Format("Error in UnloadWindow(): {0}\n{1}", e.Message, e.StackTrace));
 
-                 }
 
-                 CurrentPanel_Ticks = DateTime.MinValue;
 
-                 CurrentPanel_Label = "";
 
-                 CurrentPanel_Clicks = 0;
 
-                 CurrentPanel_Keys = 0;
 
-                 Title =
 
-                     $"{CurrentPanel_Label} - {(String.Equals(App.Profile?.ToUpper(), "DEFAULT") ? "PRS Desktop" : App.Profile)} (Release {CoreUtils.GetVersion()})";
 
-                 if (CurrentTab != null)
 
-                 {
 
-                     var border = VisualUtils.EnumChildrenOfType(CurrentTab, typeof(Border)).LastOrDefault();
 
-                     if (border != null)
 
-                     {
 
-                         ((Border)border).Background = new SolidColorBrush(Colors.Transparent);
 
-                         ((Border)border).BorderBrush = new SolidColorBrush(Colors.Transparent);
 
-                     }
 
-                     var ReportsBar = FindRibbonBar(CurrentTab, x => x.Header.Equals("Print"));
 
-                     if (ReportsBar is not null)
 
-                     {
 
-                         ReportsBar.Items.Clear();
 
-                         ReportsBar.Visibility = Visibility.Collapsed;
 
-                         ReportsBar.IsLauncherVisible = false;
 
-                     }
 
-                     var ActionBar = FindRibbonBar(CurrentTab, x => x.Header.Equals("Actions"));
 
-                     if (ActionBar is not null)
 
-                     {
 
-                         ActionBar.IsLauncherVisible = false;
 
-                         foreach (var module in CurrentModules)
 
-                             ActionBar.Items.Remove(module);
 
-                     }
 
-                 }
 
-             }
 
-             CurrentTab = null;
 
-             CurrentButton = null;
 
-             CurrentPanel = null;
 
-             ContentControl.Content = null;
 
-         }
 
-         private void SecondaryWindow_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             if (CurrentPanel == null)
 
-                 return;
 
-             var id = Guid.NewGuid();
 
-             var window = new Tuple<string, string, double, double, double, double>(
 
-                 CurrentPanel.GetType().EntityName(),
 
-                 CurrentPanel_Label,
 
-                 Left + 100,
 
-                 Top + 100,
 
-                 Width - 200,
 
-                 Height - 200
 
-             );
 
-             App.DatabaseSettings.SecondaryWindows[id] = window;
 
-             new LocalConfiguration<DatabaseSettings>(App.Profile).Save(App.DatabaseSettings);
 
-             _secondarywindows[id] = new SecondaryWindow(
 
-                 id,
 
-                 window.Item1,
 
-                 window.Item2,
 
-                 window.Item3,
 
-                 window.Item4,
 
-                 window.Item5,
 
-                 window.Item6
 
-             );
 
-             _secondarywindows[id].Show();
 
-         }
 
-         private void RibbonWindow_Activated(object sender, EventArgs e)
 
-         {
 
-         }
 
-         private void RegisterModules(IProgress<string> progress)
 
-         {
 
-             foreach (Fluent.RibbonTabItem tab in _ribbon.Tabs)
 
-                 foreach (Fluent.RibbonGroupBox bar in tab.Groups)
 
-                     foreach (var item in bar.Items)
 
-                         Dispatcher.Invoke(() =>
 
-                         {
 
-                             var button = item as RibbonButton;
 
-                             if (button != null && button.Label != "Refresh")
 
-                                 if (bar.Header.Equals("Actions"))
 
-                                     Modules.Register(button.Label);
 
-                         });
 
-             //foreach (var item in _ribbon.BackStage.Items)
 
-             //{
 
-             //    BackStageCommandButton button = item as BackStageCommandButton;
 
-             //    if ((button != null) && (button.Header != "Log Out") && (button.Header != "Exit"))
 
-             //        SecurityFactory.Register("System", button.Header, String.Format("System: Configure {0}", button.Header));
 
-             //}
 
-         }
 
-         private void SetVisibility(FrameworkElement button, bool visible)
 
-         {
 
-             var vResult = true;
 
-             var eResult = ClientFactory.UserGuid != Guid.Empty && visible;
 
-             button.Visibility = vResult && eResult ? Visibility.Visible : Visibility.Collapsed;
 
-             if (button is RibbonButton rb)
 
-             {
 
-                 CustomModules.Register(rb.Label);
 
-                 rb.IsEnabled = !OutstandingDailyReports(false);
 
-             }
 
-         }
 
-         private void SetVisibleIfEither(FrameworkElement separator, FrameworkElement[] left, FrameworkElement[] right)
 
-         {
 
-             var bLeft = false;
 
-             foreach (var button in left)
 
-                 bLeft = bLeft || button.Visibility == Visibility.Visible;
 
-             var bRight = false;
 
-             foreach (var button in right)
 
-                 bRight = bRight || button.Visibility == Visibility.Visible;
 
-             separator.Visibility = bLeft && bRight ? Visibility.Visible : Visibility.Collapsed;
 
-         }
 
-         private void SetVisibleIfAny(FrameworkElement separator, params FrameworkElement[] buttons)
 
-         {
 
-             var bVisible = false;
 
-             foreach (var button in buttons)
 
-                 bVisible = bVisible || button.Visibility == Visibility.Visible;
 
-             separator.Visibility = bVisible ? Visibility.Visible : Visibility.Collapsed;
 
-         }
 
-         private void SetTabVisibleIfAny(Fluent.RibbonTabItem tab, params FrameworkElement[] buttons)
 
-         {
 
-             var bVisible = false;
 
-             foreach (var button in buttons)
 
-                 bVisible = bVisible || button.Visibility == Visibility.Visible;
 
-             bVisible = bVisible || (SetupActions.GetValueOrDefault(tab)?.Count(x => x is SetupActionItem) ?? 0) > 3;
 
-             tab.Visibility = bVisible ? Visibility.Visible : Visibility.Collapsed;
 
-         }
 
-         private Fluent.RibbonGroupBox? FindRibbonBar(Fluent.RibbonTabItem tab, Func<Fluent.RibbonGroupBox, bool> predicate)
 
-         {
 
-             foreach (var group in tab.Groups)
 
-             {
 
-                 if (group != null)
 
-                     if (predicate.Invoke(group))
 
-                         return group;
 
-             }
 
-             return null;
 
-         }
 
-         //private Style tabselected = null;
 
-         //private Style tabunselected = null;
 
-         //private Style Getstyle(bool selected)
 
-         //{
 
-         //    if (tabunselected == null)
 
-         //    {
 
-         //        tabunselected = new Style(typeof(TabButton));
 
-         //        Setter st1 = new Setter(TabButton.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
 
-         //        tabunselected.Setters.Add(st1);
 
-         //    }
 
-         //    if (tabselected == null)
 
-         //    {
 
-         //        tabselected = new Style(typeof(TabButton));
 
-         //        Setter st1 = new Setter(TabButton.BackgroundProperty, new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x9E, 0xDA, 0x11)));
 
-         //        tabselected.Setters.Add(st1);
 
-         //    }
 
-         //    return selected ? tabselected : tabunselected;
 
-         //}
 
-         #region Button Event Handlers
 
-         private void DataEntry_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<DataEntryPanel>((Fluent.Button)sender);
 
-         }
 
-         private void Console_Click(object sender, RoutedEventArgs a)
 
-         {
 
-             if (_console is null)
 
-             {
 
-                 _console = new Console();
 
-                 _console.Closing += (o, args) => _console = null;
 
-             }
 
-             _console.Show();
 
-         }
 
-         private void Quotes_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<QuotePanel>((Fluent.Button)sender);
 
-         }
 
-         private void Jobs_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<JobPanel>((Fluent.Button)sender);
 
-         }
 
-         private void ProjectPlanner_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<JobResourcePlannerPanel>((Fluent.Button)sender);
 
-         }
 
-         private void Service_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             MessageBox.Show("Not Implemented");
 
-             //LoadWindow<JobPanel>((RibbonButton)sender);
 
-         }
 
-         private void Tasks_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             //LoadWindow<KanbanPanel>((RibbonButton)sender);
 
-             LoadWindow<TaskPanel>((Fluent.Button)sender);
 
-         }
 
-         private void ManufacturingMenu_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<ManufacturingPanel>((Fluent.Button)sender);
 
-         }
 
-         // private void Schedule_Checked(object sender, RoutedEventArgs e)
 
-         // {
 
-         //     LoadWindow<SchedulePanel>((RibbonButton)sender);
 
-         // }
 
-         private void FactoryFloorButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<FactoryPanel>((Fluent.Button)sender);
 
-         }
 
-         private void DispatchMenu_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<DispatchPanel>((Fluent.Button)sender);
 
-         }
 
-         private void ReadyToGoMenu_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<ReadyToGoPanel>((Fluent.Button)sender);
 
-         }
 
-         private void Equipment_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<EquipmentPanel>((Fluent.Button)sender);
 
-         }
 
-         private void Requisitions_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<RequisitionPanel>((Fluent.Button)sender);
 
-         }
 
-         //private void Purchases_Checked(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    LoadWindow(PurchasesMenu, new PurchasesPanel());
 
-         //}
 
-         private void Timesheets_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<TimesheetPanel>((Fluent.Button)sender);
 
-         }
 
-         private void Attendance_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<AttendancePanel>((Fluent.Button)sender);
 
-         }
 
-         private void Maps_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<MapsPanel>((Fluent.Button)sender);
 
-         }
 
-         private void FactorySetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(ManufacturingFactory));
 
-             list.ShowDialog();
 
-         }
 
-         private void TemplateSetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(ManufacturingTemplate), "Factory.Name", null, true);
 
-             list.ShowDialog();
 
-         }
 
-         private void RefreshMenu_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             if (CurrentPanel != null)
 
-                 CurrentPanel.Refresh();
 
-         }
 
-         private void MenuItem_Click(object sender, RoutedEventArgs e)
 
-         {
 
-         }
 
-         private void QuoteStatusButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(QuoteStatus));
 
-             list.ShowDialog();
 
-         }
 
-         private void QuoteDesignSectionButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(QuoteDesignSection));
 
-             list.ShowDialog();
 
-         }
 
-         private void JobStatusButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(JobStatus));
 
-             list.ShowDialog();
 
-         }
 
-         private void FinancialStatusButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(JobFinancialStatus));
 
-             list.ShowDialog();
 
-         }
 
-         private void DrawingTemplatesButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(DrawingTemplate));
 
-             list.ShowDialog();
 
-         }
 
-         private void RolesSetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(Role));
 
-             list.ShowDialog();
 
-         }
 
-         private void GroupsSetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(EmployeeGroup));
 
-             list.ShowDialog();
 
-         }
 
-         private void PositionsSetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(EmployeePosition));
 
-             list.ShowDialog();
 
-         }
 
-         private void UserSetup_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<UserPanel>((Fluent.Button)sender);
 
-             //MasterList list = new MasterList(typeof(User));
 
-             //list.ShowDialog();
 
-         }
 
-         private void Employees_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<EmployeePanel>((Fluent.Button)sender);
 
-             //MasterList list = new MasterList(typeof(Employee));
 
-             //list.ShowDialog();
 
-         }
 
-         private void Customers_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(Customer));
 
-             list.ShowDialog();
 
-         }
 
-         private void Stickers_Click()
 
-         {
 
-             var list = new MasterList(typeof(WebSticker));
 
-             list.ShowDialog();
 
-         }
 
-         private void Trackers_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<GPSTrackers>((Fluent.Button)sender);
 
-             //MasterList list = new MasterList(typeof(GPSTracker));
 
-             //list.ShowDialog();
 
-         }
 
-         private void TrackerTypes_Click()
 
-         {
 
-             var list = new MasterList(typeof(GPSTrackerType));
 
-             list.ShowDialog();
 
-         }
 
-         private void DigitalKeys_Click()
 
-         {
 
-             var list = new MasterList(typeof(DigitalKey));
 
-             list.ShowDialog();
 
-         }
 
-         private void SupplierMenu_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(Supplier));
 
-             list.ShowDialog();
 
-         }
 
-         private void DeliveredOnSiteMenu_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<DeliveredOnSitePanel>((Fluent.Button)sender);
 
-         }
 
-         private void DatabaseScripts_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(Script), "Section", null, true);
 
-             list.ShowDialog();
 
-         }
 
-         private void WebTemplates_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             MasterList list = new MasterList(typeof(WebTemplate), null, null, true);
 
-             list.ShowDialog();
 
-         }
 
-         private void ActivityMenu_Click()
 
-         {
 
-             var list = new MasterList(typeof(Activity));
 
-             list.ShowDialog();
 
-         }
 
-         private void QualificationMenu_Click()
 
-         {
 
-             var list = new MasterList(typeof(Qualification));
 
-             list.ShowDialog();
 
-         }
 
-         private void RosterMenu_Click()
 
-         {
 
-             var list = new MasterList(typeof(EmployeeRoster));
 
-             list.ShowDialog();
 
-         }
 
-         private void Reports_LauncherClick(object sender, RoutedEventArgs e)
 
-         {
 
-         }
 
-         private void Products_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<ProductsPanel>((Fluent.Button)sender);
 
-         }
 
-         private void StockLocations_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<StockLocationPanel>((Fluent.Button)sender);
 
-         }
 
-         private void StockMovements_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<StockMovementPanel>((Fluent.Button)sender);
 
-         }
 
-         private void StockSummaryButton_Clicked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<StockSummaryPanel>((Fluent.Button)sender);
 
-         }
 
-         private void KitsMasterList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<KitPanel>((Fluent.Button)sender);
 
-         }
 
-         private void CostSheetsMasterList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<CostSheetPanel>((Fluent.Button)sender);
 
-         }
 
-         private void LeaveRequestsButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<LeaveRequestPanel>((Fluent.Button)sender);
 
-         }
 
-         
 
-         private void MeetingsButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<MeetingPanel>((Fluent.Button)sender);
 
-         }
 
-         private void OrgChartButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<OrgChartPanel>((Fluent.Button)sender);
 
-         }
 
-         private void EquipmentGroupList_Click()
 
-         {
 
-             var list = new MasterList(typeof(EquipmentGroup));
 
-             list.ShowDialog();
 
-         }
 
-         private void KitConditionList_Click()
 
-         {
 
-             var list = new MasterList(typeof(KitCondition));
 
-             list.ShowDialog();
 
-         }
 
-         //private void KitGroupList_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    MasterList list = new MasterList(typeof(KitGroup));
 
-         //    list.ShowDialog();
 
-         //}
 
-         private void KitFormulaeList_Click()
 
-         {
 
-             var list = new MasterList(typeof(KitFormula));
 
-             list.ShowDialog();
 
-         }
 
-         private void CustomFields_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(CustomProperty), "Class", null, true);
 
-             list.ShowDialog();
 
-         }
 
-         private void CostSheetTypeList_Click()
 
-         {
 
-             var list = new MasterList(typeof(CostSheetType));
 
-             list.ShowDialog();
 
-         }
 
-         private void CostSheetBrandList_Click()
 
-         {
 
-             var list = new MasterList(typeof(CostSheetBrand));
 
-             list.ShowDialog();
 
-         }
 
-         private void CostSheetSectionList_Click()
 
-         {
 
-             var list = new MasterList(typeof(CostSheetSection));
 
-             list.ShowDialog();
 
-         }
 
-         private void ProductDimensionUnitsList_Click()
 
-         {
 
-             var list = new MasterList(typeof(ProductDimensionUnit));
 
-             list.ShowDialog();
 
-         }
 
-         private void SupplierList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<SupplierPanel>((Fluent.Button)sender);
 
-         }
 
-         private void CustomerList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<CustomerPanel>((Fluent.Button)sender);
 
-         }
 
-         private void ProductGroupsList_Click()
 
-         {
 
-             var list = new MasterList(typeof(ProductGroup));
 
-             list.ShowDialog();
 
-         }
 
-         private void ProductStylesList_Click()
 
-         {
 
-             var list = new MasterList(typeof(ProductStyle));
 
-             list.ShowDialog();
 
-         }
 
-         private void StockAreasList_Click()
 
-         {
 
-             var list = new MasterList(typeof(StockArea));
 
-             list.ShowDialog();
 
-         }
 
-         private void CostCentresList_Click()
 
-         {
 
-             var list = new MasterList(typeof(CostCentre));
 
-             list.ShowDialog();
 
-         }
 
-         private void GLCodesList_Click()
 
-         {
 
-             var list = new MasterList(typeof(GLCode));
 
-             list.ShowDialog();
 
-         }
 
-         private void CalendarButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<CalendarPanel>((Fluent.Button)sender);
 
-         }
 
-         private void EmployeePlannerButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<EmployeeResourcePlannerPanel>((Fluent.Button)sender);
 
-         }
 
-         private void InvoiceList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<InvoicePanel>((Fluent.Button)sender);
 
-         }
 
-         private void ReceiptList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<CustomerReceipts>((Fluent.Button)sender);
 
-         }
 
-         private void PaymentsList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<SupplierPayments>((Fluent.Button)sender);
 
-         }
 
-         private void BillsList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<SupplierBillPanel>((Fluent.Button)sender);
 
-         }
 
-         private void PurchasesList_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<SupplierPurchaseOrderPanel>((Fluent.Button)sender);
 
-         }
 
-         private void ReceiptTypeList_Click()
 
-         {
 
-             var list = new MasterList(typeof(ReceiptType));
 
-             list.ShowDialog();
 
-         }
 
-         private void PaymentTypeList_Click()
 
-         {
 
-             var list = new MasterList(typeof(PaymentType));
 
-             list.ShowDialog();
 
-         }
 
-         private void TaxCodeList_Click()
 
-         {
 
-             var list = new MasterList(typeof(TaxCode));
 
-             list.ShowDialog();
 
-         }
 
-         private void ContactTypeList_Click()
 
-         {
 
-             var list = new MasterList(typeof(ContactType));
 
-             list.ShowDialog();
 
-         }
 
-         private void EmployeeTeamsButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(Team));
 
-             list.ShowDialog();
 
-         }
 
-         // private void RostersButton_Click()
 
-         // {
 
-         //     var list = new MasterList(typeof(Roster));
 
-         //     list.ShowDialog();
 
-         // }
 
-         private void OvertimeRulesButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(OvertimeRule));
 
-             list.ShowDialog();
 
-         }
 
-         private void StandardLeaveButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(StandardLeave));
 
-             list.ShowDialog();
 
-         }
 
-         private void SecurityGroupsButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(SecurityGroup));
 
-             list.ShowDialog();
 
-             Security.Reset();
 
-         }
 
-         private void ImportDatabase_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             Utility.DuplicateDatabase();
 
-         }
 
-         private void DeliveriesButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<DeliveryPanel>((Fluent.Button)sender);
 
-         }
 
-         private void TaskTypesButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(KanbanType));
 
-             list.ShowDialog();
 
-         }
 
-         private void TrolleySetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(ManufacturingTrolley));
 
-             list.ShowDialog();
 
-         }
 
-         private void LostTimeSetup_Click()
 
-         {
 
-             var list = new MasterList(typeof(ManufacturingLostTime));
 
-             list.ShowDialog();
 
-         }
 
-         private void FactoryAllocationButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<ManufacturingAllocationPanel>((Fluent.Button)sender);
 
-         }
 
-         private void Messages_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<NotificationPanel>((Fluent.Button)sender);
 
-         }
 
-         private void DatabaseActivityButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<DatabaseActivityDashboard>((Fluent.Button)sender);
 
-         }
 
-         private void FactoryProductivityButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<FactoryProductivityDashboard>((Fluent.Button)sender);
 
-         }
 
-         private void TemplateAnalysisButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<ManufacturingTemplateAnalysis>((Fluent.Button)sender);
 
-         }
 
-         private void FactoryAnalysisButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<FactoryFloorAnalysis>((Fluent.Button)sender);
 
-         }
 
-         private void UserActivityButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<UserActivity>((Fluent.Button)sender);
 
-         }
 
-         private void QAAnalysisButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<QADashboard>((Fluent.Button)sender);
 
-         }
 
-         private void QuickStatus_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<WidgetDashboard>((Fluent.Button)sender);
 
-         }
 
-         private void ConsignmentButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<ConsignmentsPanel>((Fluent.Button)sender);
 
-         }
 
-         private void ConsignmentTypesButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(ConsignmentType));
 
-             list.ShowDialog();
 
-         }
 
-         private void PurchaseOrderCategoriesButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(PurchaseOrderCategory));
 
-             list.ShowDialog();
 
-         }
 
-         private void DeliveryTypesButton_Click()
 
-         {
 
-             var list = new MasterList(typeof(DeliveryType));
 
-             list.ShowDialog();
 
-         }
 
-         private void ConfigureModules_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var window = new ModuleConfigurationWindow(DbFactory.Provider.URL);
 
-             if (window.ShowDialog() == true)
 
-                 MessageBox.Show("These changes will be applied when the database is restarted!");
 
-         }
 
-         //private void NotificationsList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 
-         //{
 
-         //    if (NotificationsList.SelectedIndex < 0)
 
-         //        return;
 
-         //    var editors = NotificationsList.FindVisualChildren<InABox.DynamicGrid.ExtendedRichTextEditor>().ToArray();
 
-         //    var selected = editors[NotificationsList.SelectedIndex];
 
-         //    selected.Text = (String)selected.Tag; //NotificationsList.SelectedIndex.ToString();
 
-         //}
 
-         //private void ViewNotification_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
 
-         //{
 
-         //    Notification notification = (sender as Label).Tag as Notification;
 
-         //    NotificationDetails details = new NotificationDetails(notification);
 
-         //    details.ShowDialog();
 
-         //    ReloadNotifications();
 
-         //}
 
-         private void DailyReport_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<DailyReport>((Fluent.Button)sender);
 
-         }
 
-         private void Library_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             Process.Start(
 
-                 new ProcessStartInfo
 
-                 {
 
-                     FileName = App.DatabaseSettings.LibraryLocation,
 
-                     UseShellExecute = true,
 
-                     Verb = "open"
 
-                 }
 
-             );
 
-         }
 
-         private void SendNotificationClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var form = new NotificationForm { Description = "" };
 
-             if (form.ShowDialog() == true)
 
-                 ReloadNotifications();
 
-         }
 
-         private void CompanyInformation_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var info = new Client<CompanyInformation>().Load().FirstOrDefault();
 
-             if (info == null)
 
-                 info = new CompanyInformation();
 
-             new DynamicDataGrid<CompanyInformation>().EditItems(new[] { info });
 
-         }
 
-         private void StockWarehouseList_Click()
 
-         {
 
-             var list = new MasterList(typeof(StockWarehouse));
 
-             list.ShowDialog();
 
-         }
 
-         private void Dashboards_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             LoadWindow<UtilityDashboard>((Fluent.Button)sender);
 
-         }
 
-         private void QuoteDiagramSymbols_Checked()
 
-         {
 
-             var list = new MasterList(typeof(QuoteDiagramSymbol), "Section.Name");
 
-             list.ShowDialog();
 
-             QuoteDiagramSymbolCache.Refresh();
 
-         }
 
-         private void QuoteDiagramSymbolTypes_Checked()
 
-         {
 
-             var list = new MasterList(typeof(QuoteDiagramSymbolSection));
 
-             list.ShowDialog();
 
-             QuoteDiagramSymbolCache.Refresh();
 
-         }
 
-         private void QuoteTakeOffUnits_Click()
 
-         {
 
-             var list = new MasterList(typeof(QuoteTakeOffUnit));
 
-             list.ShowDialog();
 
-         }
 
-         private void JobDocumentMileStoneButton_OnClick()
 
-         {
 
-             var list = new MasterList(typeof(JobDocumentSetMileStoneType));
 
-             list.ShowDialog();
 
-         }
 
-         // private void JobDocumentTagButton_OnClick()
 
-         // {
 
-         //     var list = new MasterList(typeof(JobDocumentSetTag));
 
-         //     list.ShowDialog();
 
-         // }
 
-         private void Setup_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var tab = _ribbon.SelectedTabItem;
 
-             if (tab is null)
 
-                 return;
 
-             var items = new List<ISetupActionItem>();
 
-             if (SetupActions.TryGetValue(tab, out var actions))
 
-             {
 
-                 foreach (var action in actions)
 
-                 {
 
-                     items.Add(action);
 
-                 }
 
-             }
 
-             if (PanelSetupActions.Any())
 
-             {
 
-                 AddSetupSeparator(items);
 
-                 foreach (var action in PanelSetupActions)
 
-                 {
 
-                     items.Add(action);
 
-                 }
 
-             }
 
-             items = items.Where(x => x is not SetupActionItem setup || setup.IsVisible()).ToList();
 
-             var menu = new ContextMenu();
 
-             for (var i = 0; i < items.Count; ++i)
 
-             {
 
-                 var item = items[i];
 
-                 if (item is SetupActionItem setupAction)
 
-                 {
 
-                     menu.AddItem(setupAction.Name, setupAction.Image, setupAction.Action);
 
-                 }
 
-                 else if (item is SetupSeparator && i > 0 && i < items.Count - 1)
 
-                 {
 
-                     var last = items[i - 1];
 
-                     if (last is not SetupSeparator)
 
-                         menu.AddSeparator();
 
-                 }
 
-             }
 
-             if (CurrentPanel?.GetType().HasInterface(typeof(IPropertiesPanel<>)) == true && Security.IsAllowed<CanConfigurePanels>())
 
-             {
 
-                 menu.AddItem("Configure Panel", PRSDesktop.Resources.edit, ConfigurePanel_Click);
 
-             }
 
-             if (menu.Items.Count == 0)
 
-             {
 
-                 menu.AddItem("No Items", null, null, false);
 
-             }
 
-             menu.IsOpen = true;
 
-         }
 
-         private void InitializePanelProperties(IBasePanel panel)
 
-         {
 
-             var propertiesInterface = panel.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<>));
 
-             if (propertiesInterface is not null)
 
-             {
 
-                 var propertiesType = propertiesInterface.GenericTypeArguments[0];
 
-                 var method = typeof(MainWindow)
 
-                     .GetMethod(nameof(InitializePanelPropertiesGeneric), BindingFlags.NonPublic | BindingFlags.Instance)
 
-                     ?.MakeGenericMethod(panel.GetType(), propertiesType)
 
-                     .Invoke(this, new object?[] { panel });
 
-             }
 
-         }
 
-         private void InitializePanelPropertiesGeneric<TPanel, TProperties>(TPanel panel)
 
-             where TPanel : IPropertiesPanel<TProperties>
 
-             where TProperties : BaseObject, IGlobalConfigurationSettings, new()
 
-         {
 
-             panel.Properties = LoadPanelProperties<TPanel, TProperties>();
 
-         }
 
-         private TProperties LoadPanelProperties<TPanel, TProperties>()
 
-             where TPanel : IPropertiesPanel<TProperties>
 
-             where TProperties : BaseObject, IGlobalConfigurationSettings, new()
 
-         {
 
-             var config = new GlobalConfiguration<TProperties>();
 
-             return config.Load();
 
-         }
 
-         private void SavePanelProperties<TPanel, TProperties>(TProperties properties)
 
-             where TPanel : IPropertiesPanel<TProperties>
 
-             where TProperties : BaseObject, IGlobalConfigurationSettings, new()
 
-         {
 
-             var config = new GlobalConfiguration<TProperties>();
 
-             config.Save(properties);
 
-         }
 
-         private void EditPanelProperties<TPanel, TProperties>()
 
-             where TPanel : IPropertiesPanel<TProperties>
 
-             where TProperties : BaseObject, IGlobalConfigurationSettings, new()
 
-         {
 
-             var properties = LoadPanelProperties<TPanel, TProperties>();
 
-             var editor = new DynamicEditorForm(typeof(TProperties));
 
-             editor.Items = new BaseObject[] { properties };
 
-             if (editor.ShowDialog() == true)
 
-             {
 
-                 SavePanelProperties<TPanel, TProperties>(properties);
 
-             }
 
-         }
 
-         private void ConfigurePanel_Click()
 
-         {
 
-             if (CurrentPanel is null) return;
 
-             var propertiesInterface = CurrentPanel.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<>))!;
 
-             var propertiesType = propertiesInterface.GenericTypeArguments[0];
 
-             var method = typeof(MainWindow)
 
-                 .GetMethod(nameof(EditPanelProperties), BindingFlags.NonPublic | BindingFlags.Instance)
 
-                 ?.MakeGenericMethod(CurrentPanel.GetType(), propertiesType)
 
-                 .Invoke(this, Array.Empty<object?>());
 
-         }
 
-         private void StartForm<TEntityForm, TEntity, TEntityLink>(DigitalForm form)
 
-             where TEntityForm : EntityForm<TEntity, TEntityLink>, new()
 
-             where TEntity : Entity, new()
 
-             where TEntityLink : EntityLink<TEntity>, new()
 
-         {
 
-             var entityForm = new TEntityForm();
 
-             entityForm.Form.ID = form.ID;
 
-             entityForm.Form.Description = form.Description;
 
-             var entity = DFUtils.NewEntity<TEntityForm, TEntity, TEntityLink>(form);
 
-             if (DynamicFormEditWindow.EditDigitalForm(entityForm, out var dataModel, entity))
 
-             {
 
-                 dataModel.Update(null);
 
-             }
 
-         }
 
-         private void Forms_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var select = new MultiSelectDialog<DigitalForm>(
 
-                 Filter<DigitalForm>.And(
 
-                     LookupFactory.DefineFilter<KanbanForm, DigitalForm>(Array.Empty<KanbanForm>()),
 
-                     new Filter<DigitalForm>(x => x.ID).InQuery(
 
-                         new Filter<EmployeeDigitalForm>(x => x.Employee.ID).IsEqualTo(App.EmployeeID),
 
-                         x => x.Form.ID)),
 
-                 LookupFactory.DefineColumns<DigitalForm>()
 
-                     .Add(x => x.Description),
 
-                 false);
 
-             if (select.ShowDialog() == true)
 
-             {
 
-                 var digitalForm = select.Data().Rows.FirstOrDefault()?.ToObject<DigitalForm>();
 
-                 if (digitalForm is not null)
 
-                 {
 
-                     StartForm<KanbanForm, Kanban, KanbanLink>(digitalForm);
 
-                 }
 
-             };
 
-         }
 
-         #endregion
 
-         private bool OutstandingDailyReports(bool refresh)
 
-         {
 
-             if (!Security.IsAllowed<CanViewDailyReports>() || Security.IsAllowed<BypassOutstandingDailyReports>())
 
-                 return false;
 
-             if (refresh)
 
-                 RefreshTimeSheets();
 
-             if (_timesheets == null)
 
-                 return false;
 
-             return _timesheets.Rows.Any(r => r.Get<TimeSheet, DateTime>(c => c.Date).Date < DateTime.Today);
 
-         }
 
-         private void Window_Unloaded(object sender, RoutedEventArgs e)
 
-         {
 
-         }
 
-         //private bool _closingFromSystemMenu = false;
 
-         private void Window_Closing(object sender, CancelEventArgs e)
 
-         {
 
-             /*if (!_closingFromSystemMenu && !CoreUtils.GetVersion().Equals("???"))
 
-             {
 
-                 WindowState = WindowState.Minimized;
 
-                 e.Cancel = true;
 
-                 return;
 
-             }*/
 
-             App.IsClosing = true;
 
-             FinalizeAutoTimesheet();
 
-             if (!CoreUtils.GetVersion().Equals("???"))
 
-                 scheduler.Stop();
 
-             if (CurrentPanel != null)
 
-                 CurrentPanel.Shutdown();
 
-             CurrentPanel = null;
 
-             CurrentTab = null;
 
-             UpdateRibbonColors();
 
-             if (!CoreUtils.GetVersion().Equals("???"))
 
-                 if (station.ID != Guid.Empty)
 
-                     ExecuteLogout();
 
-         }
 
-         private void FinalizeAutoTimesheet()
 
-         {
 
-             if (Security.IsAllowed<AutoGenerateTimesheet>())
 
-             {
 
-                 var check = new Client<TimeSheet>().Query(
 
-                     new Filter<TimeSheet>(x => x.Date).IsEqualTo(DateTime.Today).And(x => x.EmployeeLink.ID).IsEqualTo(App.EmployeeID).And(x => x.Finish)
 
-                         .IsEqualTo(TimeSpan.Zero)
 
-                 );
 
-                 if (check.Rows.Any())
 
-                 {
 
-                     var ts = check.Rows.First().ToObject<TimeSheet>();
 
-                     if (DateTime.Now.TimeOfDay < ts.Start.Add(new TimeSpan(0, 2, 0)))
 
-                     {
 
-                         new Client<TimeSheet>().Delete(ts, "Deleting Auto TimeSheet because TimeBench Bypass is enabled", (o, ex) => { });
 
-                     }
 
-                     else
 
-                     {
 
-                         ts.Finish = DateTime.Now.TimeOfDay;
 
-                         new Client<TimeSheet>().Save(ts, "Clocking off Auto Timesheet because Timesheet Bypass is enabled", (o, ex) => { });
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void RibbonWindow_Closed(object sender, EventArgs e)
 
-         {
 
-             DisconnectRecorderNotes();
 
-             Application.Current.Shutdown();
 
-         }
 
-         #region Notifications + Heartbeat
 
-         private void ReceiveNotification(Notification notification)
 
-         {
 
-             if (Security.CanView<Notification>())
 
-             {
 
-                 Notifications.AddNotification(notification);
 
-             }
 
-             if (CurrentPanel is NotificationPanel panel)
 
-             {
 
-                 panel.AddNotification(notification);
 
-             }
 
-         }
 
-         private void Notifications_Tick(object? sender, EventArgs e)
 
-         {
 
-             if (ClientFactory.UserGuid != Guid.Empty)
 
-             {
 
-                 try
 
-                 {
 
-                     ReloadNotifications();
 
-                 }
 
-                 catch (Exception err)
 
-                 {
 
-                     Logger.Send(LogType.Error, ClientFactory.UserID,
 
-                         string.Format("Exception in Notifications_Tick:ReloadNotifications() {0}\n{1}", err.Message, err.StackTrace));
 
-                 }
 
-                 Heartbeat(DateTime.Now - CurrentPanel_Ticks, false);
 
-                 try
 
-                 {
 
-                     CheckIsLoggedOn();
 
-                 }
 
-                 catch (Exception err2)
 
-                 {
 
-                     Logger.Send(LogType.Error, ClientFactory.UserID,
 
-                         string.Format("Exception in Notifications_Tick:CheckIsLoggedOn() {0}\n{1}", err2.Message, err2.StackTrace));
 
-                 }
 
-             }
 
-             //else
 
-             //{
 
-             //    Logger.Send(LogType.Information, ClientFactory.UserID, "Notifications_Tick: ClientFactory.UserGuid is empty");
 
-             //}
 
-         }
 
-         private void CheckIsLoggedOn()
 
-         {
 
-             if (CoreUtils.GetVersion().Equals("???"))
 
-                 return;
 
-             var bLogout = false;
 
-             if (!Security.IsAllowed<CanBypassTimeBench>())
 
-                 if (!IsClockedOn())
 
-                 {
 
-                     Logger.Send(LogType.Information, ClientFactory.UserID, "User is no longer clocked in!");
 
-                     bLogout = true;
 
-                     Dispatcher.Invoke(() => { Logout(); });
 
-                 }
 
-             if (!bLogout)
 
-                 new Client<Login>().Query(
 
-                     new Filter<Login>(x => x.User.ID).IsEqualTo(ClientFactory.UserGuid),
 
-                     new Columns<Login>(x => x.StationID),
 
-                     null,
 
-                     (o, e) =>
 
-                     {
 
-                         if (e is RemoteException remote)
 
-                         {
 
-                             if (remote.Status == StatusCode.Unauthenticated)
 
-                             {
 
-                                 Logger.Send(LogType.Information, ClientFactory.UserID, "User has been logged out");
 
-                                 Dispatcher.Invoke(() =>
 
-                                 {
 
-                                     Logout("You have been logged out due to inactivity");
 
-                                 });
 
-                             }
 
-                             else
 
-                             {
 
-                                 Logger.Send(LogType.Information, ClientFactory.UserID, CoreUtils.FormatException(remote));
 
-                             }
 
-                         }
 
-                         else if (e is not null)
 
-                         {
 
-                             Logger.Send(LogType.Information, ClientFactory.UserID, CoreUtils.FormatException(e));
 
-                         }
 
-                         else if (o is not null)
 
-                         {
 
-                             var row = o.Rows.FirstOrDefault();
 
-                             if (row == null)
 
-                             {
 
-                                 station.ID = Guid.Empty;
 
-                                 new Client<Login>().Save(station, "", (o1, e1) => { });
 
-                             }
 
-                             else if (!row.Get<Login, string>(c => c.StationID).Equals(station.StationID))
 
-                             {
 
-                                 Logger.Send(LogType.Information, ClientFactory.UserID, "User logged in somewhere else!");
 
-                                 bLogout = true;
 
-                                 Dispatcher.Invoke(() => { Logout(); });
 
-                             }
 
-                         }
 
-                     }
 
-                 );
 
-         }
 
-         private void Heartbeat(TimeSpan time, bool closing)
 
-         {
 
-             //Task.Run(() =>
 
-             //{
 
-             try
 
-             {
 
-                 bool IsClockedOn = this.IsClockedOn();
 
-                 if (IsClockedOn)
 
-                 {
 
-                     if ((_kanbantrackingassignment != null) && (_kanbantrackingassignment.Actual.Finish < DateTime.Now.TimeOfDay))
 
-                     {
 
-                         _kanbantrackingassignment.Actual.Finish = DateTime.Now.TimeOfDay;
 
-                         new Client<Assignment>().Save(_kanbantrackingassignment, "");
 
-                     }
 
-                     if (Security.IsAllowed<MonitorApplicationWindows>())
 
-                     {
 
-                         if (ActivityHistory == null)
 
-                             ActivityHistory = new LocalConfiguration<DailyActivityHistory>().Load();
 
-                         var appname = OpenWindowGetter.GetActiveWindowProcess();
 
-                         var title = OpenWindowGetter.GetActiveWindowTitle();
 
-                         ActivityHistory.Activities[DateTime.Now] = (!string.IsNullOrWhiteSpace(appname) ? appname.Trim() + " - " : "") + title;
 
-                         new LocalConfiguration<DailyActivityHistory>().Save(ActivityHistory);
 
-                     }
 
-                 }
 
-                 //Logger.Send(LogType.Information, "", string.Format("Heartbeat: {0:hh\\:mm}{1}", time, closing ? " (closing)" : ""));
 
-                 if (!closing && time.TotalMinutes < 5)
 
-                     return;
 
-                 CurrentPanel_Ticks = DateTime.Now;
 
-                 if (CurrentPanel != null)
 
-                 {
 
-                     //Logger.Send(LogType.Information, "", string.Format("Heartbeat: {0}", CurrentPanel_Label));
 
-                     if (ClientFactory.IsSupported<ModuleTracking>())
 
-                     {
 
-                         var keys = CurrentPanel_Keys;
 
-                         CurrentPanel_Keys = 0;
 
-                         var clicks = CurrentPanel_Clicks;
 
-                         CurrentPanel_Clicks = 0;
 
-                         var tracking = new ModuleTracking
 
-                         {
 
-                             Date = DateTime.Today,
 
-                             Module = CurrentPanel_Label,
 
-                             Clicks = clicks,
 
-                             Keys = keys,
 
-                             ActiveTime = clicks + keys > 0 ? time : new TimeSpan(),
 
-                             IdleTime = clicks + keys == 0 ? time : new TimeSpan()
 
-                         };
 
-                         tracking.User.ID = ClientFactory.UserGuid;
 
-                         new Client<ModuleTracking>().Save(tracking, "", (mt, ex) => { });
 
-                     }
 
-                     CurrentPanel.Heartbeat(time);
 
-                 }
 
-             }
 
-             catch (Exception err)
 
-             {
 
-                 Logger.Send(LogType.Error, ClientFactory.UserID, string.Format("Exception in Heartbeat: {0}\n{1}", err.Message, err.StackTrace));
 
-             }
 
-             //});
 
-         }
 
-         private void Notifications_Changed(object sender)
 
-         {
 
-             if (Notifications.IsActive)
 
-             {
 
-                 Notifications.Visibility = Visibility.Visible;
 
-                 DockingGrid.ColumnDefinitions[1].Width = new GridLength(4, GridUnitType.Pixel);
 
-                 DockingGrid.ColumnDefinitions[2].Width = Equals(0.0, DockingGrid.ColumnDefinitions[2].Width.Value)
 
-                     ? new GridLength(300, GridUnitType.Pixel)
 
-                     : DockingGrid.ColumnDefinitions[2].Width;
 
-             }
 
-             else
 
-             {
 
-                 Notifications.Visibility = Visibility.Collapsed;
 
-                 DockingGrid.ColumnDefinitions[1].Width = new GridLength(0, GridUnitType.Pixel);
 
-                 DockingGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Pixel);
 
-             }
 
-         }
 
-         private void ReloadNotifications()
 
-         {
 
-             if (Security.CanView<Notification>())
 
-                 Notifications.Refresh();
 
-             if (!NotificationsWatchDog.IsEnabled)
 
-             {
 
-                 //Logger.Send(LogType.Information, ClientFactory.UserID, "Enabling Heartbeat");
 
-                 NotificationsWatchDog.IsEnabled = true;
 
-             }
 
-         }
 
-         #endregion
 
-         private void RibbonWindow_PreviewMouseUp(object sender, MouseButtonEventArgs e)
 
-         {
 
-             if (CurrentPanel != null)
 
-                 CurrentPanel_Clicks++;
 
-         }
 
-         private void RibbonWindow_PreviewKeyUp(object sender, KeyEventArgs e)
 
-         {
 
-             if (CurrentPanel != null)
 
-                 CurrentPanel_Keys++;
 
-         }
 
-         #region Recording
 
-         //private IntPtr myHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 
-         //{
 
-         //    switch (msg)
 
-         //    {
 
-         //        case 0x100:
 
-         //            if (_subject != null)
 
-         //            {
 
-         //                _recorder.Stop();
 
-         //                pausestarted = DateTime.Now;
 
-         //                _subject.OnNext(new WampEvent() { Arguments = new[] { "EDIT" } });
 
-         //            }
 
-         //            break;
 
-         //        default:
 
-         //            messages.TryGetValue(msg, out int value);
 
-         //            messages[msg] = value + 1;
 
-         //            break;                  
 
-         //    }
 
-         //    return IntPtr.Zero;
 
-         //}
 
-         private void RecordScreenButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ToggleRecording();
 
-         }
 
-         private bool ToggleRecording()
 
-         {
 
-             if (!Security.IsAllowed<CanRecordScreen>())
 
-                 return true;
 
-             if (_recorder is null)
 
-             {
 
-                 var windowInteropHelper = new WindowInteropHelper(this);
 
-                 var screen = Screen.FromHandle(windowInteropHelper.Handle);
 
-                 _screenleft = screen.WorkingArea.Left;
 
-                 _screentop = screen.WorkingArea.Top;
 
-                 _screenwidth = screen.WorkingArea.Width;
 
-                 _screenheight = screen.WorkingArea.Height;
 
-                 //VIDEO_WIDTH = _screenwidth;
 
-                 //VIDEO_HEIGHT = _screenheight;
 
-                 //SetupJPEGEncoder();
 
-                 messages.Clear();
 
-                 _bitmaps.Clear();
 
-                 ConnectToRecordNotes();
 
-                 StartAudio();
 
-                 _recorder = new DispatcherTimer();
 
-                 _recorder.Tick += (timer, args) => { TakeScreenShot(); };
 
-                 _recorder.Interval = TimeSpan.FromMilliseconds(1000 / FRAMES_PER_SECOND);
 
-                 _recorder.Start();
 
-                 VideoRecordingStatus.Source = PRSDesktop.Resources.videorecording.AsBitmapImage();
 
-                 RecordingNotesStatus.Source = PRSDesktop.Resources.speechbubble.AsGrayScale().AsBitmapImage();
 
-                 RecordingNotesButton.Visibility = Visibility.Visible;
 
-                 AudioRecordingStatus.Source = PRSDesktop.Resources.audiorecording.AsGrayScale().AsBitmapImage();
 
-                 AudioRecordingButton.Visibility = Visibility.Visible;
 
-             }
 
-             else
 
-             {
 
-                 using (new WaitCursor())
 
-                 {
 
-                     StopRecording();
 
-                     _recorder.Stop();
 
-                     _recorder = null;
 
-                     DisconnectRecorderNotes();
 
-                     VideoRecordingStatus.Source = PRSDesktop.Resources.videorecording.AsGrayScale().AsBitmapImage();
 
-                     RecordingNotesStatus.Source = PRSDesktop.Resources.speechbubble.AsGrayScale().AsBitmapImage();
 
-                     RecordingNotesButton.Visibility = Visibility.Hidden;
 
-                     AudioRecordingStatus.Source = PRSDesktop.Resources.audiorecording.AsGrayScale().AsBitmapImage();
 
-                     AudioRecordingButton.Visibility = Visibility.Hidden;
 
-                     var filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos),
 
-                         string.Format("PRS Screen Recording {0:yyyy-MM-dd hh-mm-ss-ff}.avi", DateTime.Now));
 
-                     ProcessScreenShots(filename);
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         private void StopRecording()
 
-         {
 
-             try
 
-             {
 
-                 _audio?.StopRecording();
 
-                 AudioRecordingStatus.Source = PRSDesktop.Resources.audiorecording.AsGrayScale().AsBitmapImage();
 
-             }
 
-             catch (Exception e)
 
-             {
 
-                 Logger.Send(LogType.Error, "", string.Format("Unable to stop Audio Recording: {0}\n{1}", e.Message, e.StackTrace));
 
-             }
 
-         }
 
-         private void StartAudio()
 
-         {
 
-             _audioMuted = true;
 
-             _audioStream = new MemoryStream();
 
-             _audio = new WaveIn
 
-             {
 
-                 DeviceNumber = 0,
 
-                 WaveFormat = new WaveFormat(44100, 16, 2)
 
-             };
 
-             _audio.DataAvailable += (o, e) =>
 
-             {
 
-                 var buf = _audioMuted ? new byte[e.BytesRecorded] : e.Buffer;
 
-                 _audioStream.Write(buf, 0, e.BytesRecorded);
 
-             };
 
-             try
 
-             {
 
-                 _audio.StartRecording();
 
-                 AudioRecordingStatus.Source = PRSDesktop.Resources.audiorecording.AsBitmapImage();
 
-             }
 
-             catch (Exception e)
 
-             {
 
-                 Logger.Send(LogType.Error, "", string.Format("Unable to start Audio Recording: {0}\n{1}", e.Message, e.StackTrace));
 
-                 AudioRecordingStatus.Source = PRSDesktop.Resources.audiorecording.AsGrayScale().AsBitmapImage();
 
-             }
 
-         }
 
-         private bool ToggleRecordingAudio()
 
-         {
 
-             if (!Security.IsAllowed<CanRecordScreen>())
 
-                 return true;
 
-             if (_recorder != null)
 
-             {
 
-                 _audioMuted = !_audioMuted;
 
-                 AudioRecordingStatus.Source = _audioMuted
 
-                     ? PRSDesktop.Resources.audiorecording.AsGrayScale().AsBitmapImage()
 
-                     : PRSDesktop.Resources.audiorecording.AsBitmapImage();
 
-             }
 
-             return true;
 
-         }
 
-         private void DisconnectRecorderNotes()
 
-         {
 
-             if (_client != null)
 
-             {
 
-                 _client.WriteAsync("QUIT");
 
-                 _client.StopAsync();
 
-                 _client = null;
 
-             }
 
-         }
 
-         private void ConnectToRecordNotes()
 
-         {
 
-             var filename = Debugger.IsAttached
 
-                 ? "c:\\development\\comal\\prsrecordingnotes\\bin\\debug\\prsrecordingnotes.exe"
 
-                 : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "recordingnotes", "prsrecordingnotes.exe");
 
-             Logger.Send(LogType.Information, "", "Recording Notes: " + filename);
 
-             _recordingnotes = Process.Start(filename);
 
-             //PipeSecurity sec = new System.IO.Pipes.PipeSecurity();
 
-             //sec.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, AccessControlType.Allow));
 
-             _client = new PipeServer<string>("PRSScreenRecorder"); //, sec);
 
-             _client.ClientConnected += (o, args) => args.Connection.WriteAsync("Connected to PRSScreenRecorder");
 
-             _client.MessageReceived += (o, args) =>
 
-             {
 
-                 if (string.Equals(args.Message, "RESUME"))
 
-                     Dispatcher.Invoke(() =>
 
-                     {
 
-                         _audio?.StartRecording();
 
-                         totalpauses += DateTime.Now - pausestarted;
 
-                         _recorder?.Start();
 
-                         Activate();
 
-                         Focus();
 
-                     });
 
-             };
 
-             _client.StartAsync();
 
-         }
 
-         private bool ShowRecordingNotes()
 
-         {
 
-             if (_recorder != null)
 
-             {
 
-                 _audio?.StopRecording();
 
-                 _recorder.Stop();
 
-                 pausestarted = DateTime.Now;
 
-                 _client?.WriteAsync("EDIT");
 
-                 //_subject.OnNext(new WampEvent() { Arguments = new[] { "EDIT" } });
 
-             }
 
-             return true;
 
-         }
 
-         private void TakeScreenShot()
 
-         {
 
-             using (var bmp = new ScreenCapture().CaptureScreen(_screenleft, _screentop, _screenwidth, _screenheight))
 
-             {
 
-                 var cursor = PointToScreen(Mouse.GetPosition(this));
 
-                 using (var g = Graphics.FromImage(bmp))
 
-                 {
 
-                     var brush = new SolidBrush(System.Drawing.Color.FromArgb(128, 255, 255, 0));
 
-                     g.FillEllipse(brush, new RectangleF((float)cursor.X - 25F, (float)cursor.Y - 25F, 50F, 50F));
 
-                     var pen = new Pen(System.Drawing.Color.Black, 0.75F);
 
-                     g.DrawLine(pen, (float)cursor.X - 10F, (float)cursor.Y, (float)cursor.X + 10F, (float)cursor.Y);
 
-                     g.DrawLine(pen, (float)cursor.X, (float)cursor.Y - 10F, (float)cursor.X, (float)cursor.Y + 10F);
 
-                 }
 
-                 var key = DateTime.Now - totalpauses;
 
-                 using (var reduced = ReduceBitmap(bmp, VIDEO_WIDTH, VIDEO_HEIGHT))
 
-                 {
 
-                     var ms = new MemoryStream();
 
-                     reduced.Save(ms, ImageFormat.Png);
 
-                     ms.Position = 0;
 
-                     _bitmaps[key] = ms;
 
-                 }
 
-             }
 
-         }
 
-         public Bitmap ReduceBitmap(Bitmap original, int reducedWidth, int reducedHeight)
 
-         {
 
-             var reduced = new Bitmap(reducedWidth, reducedHeight);
 
-             using (var dc = Graphics.FromImage(reduced))
 
-             {
 
-                 // Figure out the ratio
 
-                 var ratioX = (double)reducedWidth / original.Width;
 
-                 var ratioY = (double)reducedHeight / original.Height;
 
-                 // use whichever multiplier is smaller
 
-                 var ratio = ratioX < ratioY ? ratioX : ratioY;
 
-                 // now we can get the new height and width
 
-                 var newHeight = Convert.ToInt32(original.Height * ratio);
 
-                 var newWidth = Convert.ToInt32(original.Width * ratio);
 
-                 // Now calculate the X,Y position of the upper-left corner 
 
-                 // (one of these will always be zero)
 
-                 var posX = Convert.ToInt32((reducedWidth - original.Width * ratio) / 2);
 
-                 var posY = Convert.ToInt32((reducedHeight - original.Height * ratio) / 2);
 
-                 dc.InterpolationMode = InterpolationMode.HighQualityBicubic;
 
-                 dc.Clear(System.Drawing.Color.Black); // white padding
 
-                 //dc.DrawImage(original, posX, posY, newWidth, newHeight);
 
-                 dc.DrawImage(original, new Rectangle(posX, posY, newWidth, newHeight), new Rectangle(0, 0, original.Width, original.Height),
 
-                     GraphicsUnit.Pixel);
 
-             }
 
-             return reduced;
 
-         }
 
-         public static byte[] BitmapToByteArray(Bitmap bitmap, int width, int height)
 
-         {
 
-             // and buffer of appropriate size for storing its bits
 
-             var buffer = new byte[width * height * 4];
 
-             var pixelFormat = PixelFormat.Format32bppRgb;
 
-             // Now copy bits from bitmap to buffer
 
-             var bits = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, pixelFormat);
 
-             //Marshal.Copy(bits.Scan0, buffer, 0, buffer.Length);
 
-             Marshal.Copy(bits.Scan0, buffer, 0, buffer.Length);
 
-             bitmap.UnlockBits(bits);
 
-             return buffer;
 
-         }
 
-         private void ProcessScreenShots(string filename)
 
-         {
 
-             if (!_bitmaps.Any() || _audioStream is null)
 
-                 return;
 
-             Progress.Show("Saving Video");
 
-             var framRate = 10;
 
-             using (var writer = new AviWriter(filename))
 
-             {
 
-                 writer.FramesPerSecond = framRate;
 
-                 writer.EmitIndex1 = true;
 
-                 _audioStream.Position = 0;
 
-                 var audio = writer.AddAudioStream(2);
 
-                 //audio.WriteBlock(_audioStream.GetBuffer(), 0, (int)_audioStream.Length);
 
-                 //File.WriteAllBytes(Path.ChangeExtension(filename, "wav"), _audioStream.GetBuffer());
 
-                 var audioByteRate = audio.BitsPerSample / 8 * audio.ChannelCount * audio.SamplesPerSecond;
 
-                 var audioBlockSize = (int)(audioByteRate / writer.FramesPerSecond);
 
-                 var audioBuffer = new byte[audioBlockSize];
 
-                 _audioStream.Position = 0;
 
-                 var encoder = new MJpegWpfVideoEncoder(VIDEO_WIDTH, VIDEO_HEIGHT, 50);
 
-                 var stream = writer.AddEncodingVideoStream(encoder, true, VIDEO_WIDTH, VIDEO_HEIGHT);
 
-                 //var encoder = new SharpAvi.Codecs.UncompressedVideoEncoder(VIDEO_WIDTH, VIDEO_HEIGHT);
 
-                 //var stream = writer.AddEncodingVideoStream(encoder,true,VIDEO_WIDTH, VIDEO_HEIGHT);
 
-                 //stream.Codec = CodecIds.Uncompressed;
 
-                 //stream.BitsPerPixel = BitsPerPixel.Bpp16;
 
-                 IEnumerable<DateTime> keys = _bitmaps.Keys.OrderBy(x => x);
 
-                 var start = keys.First();
 
-                 var end = keys.Last();
 
-                 for (var cur = start; cur <= end; cur = cur + TimeSpan.FromMilliseconds(100))
 
-                 {
 
-                     Progress.SetMessage(string.Format("Processing ({0:F2} complete)",
 
-                         (cur - start).TotalSeconds * 100.0F / (end - start).TotalSeconds));
 
-                     var key = keys.LastOrDefault(x => x <= cur);
 
-                     if (_bitmaps.ContainsKey(key))
 
-                     {
 
-                         var frame = (Image.FromStream(_bitmaps[key]) as Bitmap)!;
 
-                         //frame.RotateFlip(RotateFlipType.RotateNoneFlipY);
 
-                         var buf = BitmapToByteArray(frame, stream.Width, stream.Height);
 
-                         stream.WriteFrame(true, buf, 0, buf.Length);
 
-                         if (_audioStream.Position < _audioStream.Length)
 
-                         {
 
-                             var bytes = _audioStream.Read(audioBuffer, 0, audioBlockSize);
 
-                             audio.WriteBlock(audioBuffer, 0, bytes);
 
-                         }
 
-                     }
 
-                 }
 
-                 writer.Close();
 
-                 //foreach (var key in _bitmaps.Keys)
 
-                 //    File.Delete(_bitmaps[key]);
 
-             }
 
-             Progress.SetMessage("Transcoding");
 
-             //var inputFile = new MediaFile { Filename = filename };
 
-             //var outputFile = new MediaFile { Filename = Path.ChangeExtension(filename, "mp4") };
 
-             //using (var engine = new Engine())
 
-             //{
 
-             //    //engine.ConvertProgressEvent += ConvertProgressEvent;
 
-             //    engine.Convert(inputFile, outputFile);
 
-             //}
 
-             Progress.Close();
 
-             var dirName = Path.GetDirectoryName(filename);
 
-             if (dirName is not null)
 
-             {
 
-                 var startInfo = new ProcessStartInfo(dirName);
 
-                 startInfo.Verb = "open";
 
-                 startInfo.UseShellExecute = true;
 
-                 Process.Start(startInfo);
 
-                 //MessageBox.Show("Recording Saved");
 
-             }
 
-         }
 
-         private void VideoRecordingButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ToggleRecording();
 
-         }
 
-         private void AudioRecordingButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ToggleRecordingAudio();
 
-         }
 
-         private void RecordingNotesButton_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ShowRecordingNotes();
 
-         }
 
-         #endregion
 
-         public static void ActivateWindow(Window window)
 
-         {
 
-             var hwnd = new WindowInteropHelper(window).EnsureHandle();
 
-             var threadId1 = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);
 
-             var threadId2 = GetWindowThreadProcessId(hwnd, IntPtr.Zero);
 
-             if (threadId1 != threadId2)
 
-             {
 
-                 AttachThreadInput(threadId1, threadId2, true);
 
-                 SetForegroundWindow(hwnd);
 
-                 AttachThreadInput(threadId1, threadId2, false);
 
-             }
 
-             else
 
-             {
 
-                 SetForegroundWindow(hwnd);
 
-             }
 
-         }
 
-         private static IntPtr GetForegroundWindow()
 
-         {
 
-             var active = GetActiveWindow();
 
-             var window = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => new WindowInteropHelper(x).Handle == active);
 
-             var hwnd = new WindowInteropHelper(window).EnsureHandle();
 
-             return hwnd;
 
-         }
 
-         [DllImport("user32.dll", SetLastError = true)]
 
-         private static extern IntPtr SetForegroundWindow(IntPtr hWnd);
 
-         [DllImport("user32.dll")]
 
-         private static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
 
-         [DllImport("user32.dll")]
 
-         private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
 
-         [DllImport("user32.dll")]
 
-         private static extern IntPtr GetActiveWindow();
 
-         //private void ConvertProgressEvent(object sender, ConvertProgressEventArgs e)
 
-         //{
 
-         //    Dispatcher.Invoke(() =>
 
-         //    {
 
-         //        try
 
-         //        {
 
-         //            if (e.TotalDuration.TotalSeconds != 0.0F)
 
-         //                Progress.SetMessage(String.Format("Transcoding ({0:F2}% complete)", e.ProcessedDuration.TotalSeconds * 100.0F / e.TotalDuration.TotalSeconds));
 
-         //        }
 
-         //        catch (Exception err)
 
-         //        {
 
-         //        }
 
-         //    });
 
-         //}
 
-         #region Check For Updates
 
-         private string GetUpdateLocation()
 
-         {
 
-             if (App.DatabaseSettings.DatabaseType == DatabaseType.Networked)
 
-             {
 
-                 //var domain = App.DatabaseSettings.URL.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).Last();
 
-                 //var port = App.DatabaseSettings.Port;
 
-                 var domain = ClientFactory.Parameters?.FirstOrDefault()?.ToString() ?? "";
 
-                 domain = domain.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).Last();
 
-                 
 
-                 string url;
 
-                 try
 
-                 {
 
-                     var client = new HttpClient { BaseAddress = new Uri($"https://{domain}") };
 
-                     client.GetAsync("operations").Wait();
 
-                     url = $"https://{domain}";
 
-                 }
 
-                 catch (Exception)
 
-                 {
 
-                     url = $"http://{domain}";
 
-                 }
 
-                 return $"{url}";
 
-             }
 
-             else
 
-                 return Path.Combine(CoreUtils.GetCommonAppData("PRSServer"), "update");
 
-         }
 
-         private string GetLatestVersion(string location)
 
-         {
 
-             return App.DatabaseSettings.DatabaseType switch
 
-             {
 
-                 DatabaseType.Networked => Update.GetRemoteFile($"{location}/version").Content,
 
-                 DatabaseType.Standalone or DatabaseType.Local => File.ReadAllText(Path.Combine(location, "version.txt")),
 
-                 _ => "",
 
-             };
 
-         }
 
-         private string GetReleaseNotes(string location)
 
-         {
 
-             return App.DatabaseSettings.DatabaseType switch
 
-             {
 
-                 DatabaseType.Networked => Update.GetRemoteFile($"{location}/releasenotes").Content,
 
-                 DatabaseType.Standalone or DatabaseType.Local => File.ReadAllText(Path.Combine(location, "Release Notes.txt")),
 
-                 _ => "",
 
-             };
 
-         }
 
-         private byte[]? GetInstaller(string location)
 
-         {
 
-             return App.DatabaseSettings.DatabaseType switch
 
-             {
 
-                 DatabaseType.Networked => Update.GetRemoteFile($"{location}/install").RawBytes,
 
-                 DatabaseType.Standalone or DatabaseType.Local => File.ReadAllBytes(Path.Combine(location, "PRSDesktopSetup.exe")),
 
-                 _ => null,
 
-             };
 
-         }
 
-         private void CheckForUpdates()
 
-         {
 
-             Update.CheckForUpdates(
 
-                 GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, null, App.AutoUpdateSettings.Elevated, "PRSDesktopSetup.exe");
 
-         }
 
-         #endregion
 
-         #region Modules
 
-         public void CreatePanelAction(PanelAction action)
 
-         {
 
-             if (_ribbon.SelectedTabItem is null)
 
-                 return;
 
-             var Actions = FindRibbonBar(_ribbon.SelectedTabItem, x => x.Header.Equals("Actions"));
 
-             if (Actions is not null)
 
-             {
 
-                 if (!CurrentModules.Any(x => x.GetType().Equals(typeof(RibbonSeparator))))
 
-                 {
 
-                     var sep = new RibbonSeparator();
 
-                     CurrentModules.Add(sep);
 
-                     Actions.Items.Add(sep);
 
-                 }
 
-                 var button = new RibbonButton
 
-                 {
 
-                     Label = action.Caption,
 
-                     LargeIcon = action.Image.AsBitmapImage(),
 
-                     SizeForm = SizeForm.Large,
 
-                     MinWidth = 60,
 
-                     Tag = action
 
-                 };
 
-                 button.Click += PaneActionClick;
 
-                 CurrentModules.Add(button);
 
-                 Actions.Items.Add(button);
 
-             }
 
-         }
 
-         private List<ISetupActionItem> PanelSetupActions = new();
 
-         public void CreateSetupAction(PanelAction action)
 
-         {
 
-             if (_ribbon.SelectedTabItem is null)
 
-                 return;
 
-             AddSetupAction(PanelSetupActions, action.Caption, () =>
 
-             {
 
-                 action.Execute();
 
-             }, action.Image);
 
-         }
 
-         private void PaneActionClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var button = (Control)sender;
 
-             var action = (PanelAction)button.Tag;
 
-             action.Execute();
 
-         }
 
-         private void ReloadModules(string sectionName, DataModel model)
 
-         {
 
-             foreach (var module in CurrentModules)
 
-             {
 
-                 if (module.Parent is Fluent.RibbonGroupBox bar)
 
-                     bar.Items.Remove(module);
 
-             }
 
-             CurrentModules.Clear();
 
-             PanelSetupActions.Clear();
 
-             if (CurrentPanel != null)
 
-             {
 
-                 CurrentPanel.CreateToolbarButtons(this);
 
-                 CreateModules(sectionName, model, new Progress<Tuple<string, Bitmap, CustomModule>>(CreateModuleButton));
 
-             }
 
-         }
 
-         private void CreateModules(string section, DataModel model, IProgress<Tuple<string, Bitmap, CustomModule>> progress)
 
-         {
 
-             if (ClientFactory.IsSupported<CustomModule>())
 
-             {
 
-                 foreach (var (module, image) in CustomModuleUtils.LoadCustomModuleThumbnails(section, model))
 
-                 {
 
-                     progress.Report(new Tuple<string, Bitmap, CustomModule>(module.Name ?? "", image, module));
 
-                 }
 
-             }
 
-         }
 
-         private void CreateModuleButton(Tuple<string, Bitmap, CustomModule> module)
 
-         {
 
-             Fluent.RibbonGroupBox? Actions = CurrentTab != null
 
-                 ? FindRibbonBar(CurrentTab, x => x.Header.Equals("Actions"))
 
-                 : null;
 
-             if (Actions != null)
 
-             {
 
-                 if (!CurrentModules.Any(x => x.GetType().Equals(typeof(RibbonSeparator))))
 
-                 {
 
-                     var sep = new RibbonSeparator();
 
-                     CurrentModules.Add(sep);
 
-                     Actions.Items.Add(sep);
 
-                 }
 
-                 if (!CurrentModules.Any(x => x is Fluent.Button button && module.Item1.Equals(button.Header)))
 
-                 {
 
-                     var button = new Fluent.Button
 
-                     {
 
-                         Header = module.Item1,
 
-                         LargeIcon = module.Item2.AsBitmapImage(),
 
-                         MinWidth = 60,
 
-                         Tag = module.Item3
 
-                     };
 
-                     button.Click += Module_Click;
 
-                     CurrentModules.Add(button);
 
-                     Actions.Items.Add(button);
 
-                 }
 
-             }
 
-         }
 
-         private void Module_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             if (CurrentPanel != null)
 
-             {
 
-                 var item = (Fluent.Button)sender;
 
-                 var code = (CustomModule)item.Tag;
 
-                 if (!string.IsNullOrWhiteSpace(code.Script))
 
-                     try
 
-                     {
 
-                         Selection selection;
 
-                         if (code.SelectedRecords && code.AllRecords)
 
-                             selection = RecordSelectionDialog.Execute();
 
-                         else if (code.SelectedRecords)
 
-                             selection = Selection.Selected;
 
-                         else if (code.AllRecords)
 
-                             selection = Selection.All;
 
-                         else
 
-                             selection = Selection.None;
 
-                         var result = ScriptDocument.RunCustomModule(CurrentPanel.DataModel(selection), CurrentPanel.Selected(), code.Script);
 
-                         if (result)
 
-                             CurrentPanel.Refresh();
 
-                     }
 
-                     catch (CompileException c)
 
-                     {
 
-                         MessageBox.Show(c.Message);
 
-                     }
 
-                     catch (Exception err)
 
-                     {
 
-                         MessageBox.Show(CoreUtils.FormatException(err));
 
-                     }
 
-                 else
 
-                     MessageBox.Show("Unable to load " + item.Header);
 
-             }
 
-         }
 
-         private void ManageModules()
 
-         {
 
-             if (CurrentPanel != null)
 
-             {
 
-                 var section = CurrentPanel.SectionName;
 
-                 var dataModel = CurrentPanel.DataModel(Selection.Selected);
 
-                 var manager = new CustomModuleManager()
 
-                 {
 
-                     Section = section,
 
-                     DataModel = dataModel
 
-                 };
 
-                 manager.ShowDialog();
 
-                 ReloadModules(section, dataModel);
 
-             }
 
-         }
 
-         private void ManageModulesClick(object sender, RoutedEventArgs e)
 
-         {
 
-             ManageModules();
 
-         }
 
-         #endregion
 
-         #region Report Buttons
 
-         private void ReloadReports(string section, DataModel model)
 
-         {
 
-             if (CurrentTab is null)
 
-                 return;
 
-             var ReportsBar = FindRibbonBar(CurrentTab, x => x.Header.Equals("Print"));
 
-             if (ReportsBar is not null)
 
-             {
 
-                 ReportsBar.Visibility = Security.IsAllowed<CanPrintReports>() ? Visibility.Visible : Visibility.Collapsed;
 
-                 //ReportsBar.IsLauncherVisible = Security.IsAllowed<CanDesignReports>();
 
-                 ReportsBar.Items.Clear();
 
-                 CreateReports(section, model, new Progress<Tuple<string, Guid>>(CreateReportButton));
 
-             }
 
-         }
 
-         private void CreateReports(string section, DataModel model, IProgress<Tuple<string, Guid>> progress)
 
-         {
 
-             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)));
 
-         }
 
-         public void CreateReportButton(Tuple<string, Guid> report)
 
-         {
 
-             if (CurrentTab is null)
 
-                 return;
 
-             var ReportsBar = FindRibbonBar(CurrentTab, x => x.Header.Equals("Print"));
 
-             if (ReportsBar is not null)
 
-             {
 
-                 var bFound = false;
 
-                 foreach (var item in ReportsBar.Items)
 
-                 {
 
-                     if (item is RibbonButton button && report.Item2.Equals(button.Tag))
 
-                         bFound = true;
 
-                 }
 
-                 if (!bFound)
 
-                 {
 
-                     var button = new RibbonButton
 
-                     {
 
-                         Label = report.Item1,
 
-                         LargeIcon = PRSDesktop.Resources.printer.AsBitmapImage(),
 
-                         Tag = report.Item2,
 
-                         SizeForm = SizeForm.Large,
 
-                         MinWidth = 60
 
-                     };
 
-                     if (Security.IsAllowed<CanDesignReports>())
 
-                     {
 
-                         var menu = new ContextMenu();
 
-                         menu.AddItem("Design Report", PRSDesktop.Resources.pencil, report.Item2, ReportButtonMenu_DesignReport_Click);
 
-                         button.ContextMenu = menu;
 
-                     }
 
-                     button.Click += ReportMenu_Checked;
 
-                     ReportsBar.Items.Add(button);
 
-                 }
 
-             }
 
-         }
 
-         private void ReportButtonMenu_DesignReport_Click(Guid templateID)
 
-         {
 
-             if (CurrentPanel is null)
 
-                 return;
 
-             var template = new Client<ReportTemplate>().Load(new Filter<ReportTemplate>(x => x.ID).IsEqualTo(templateID)).FirstOrDefault();
 
-             if (template is null)
 
-             {
 
-                 Logger.Send(LogType.Error, "", $"No Report Template with ID '{templateID}'");
 
-                 MessageBox.Show("Report does not exist!");
 
-                 return;
 
-             }
 
-             ReportUtils.DesignReport(template, CurrentPanel.DataModel(Selection.None));
 
-         }
 
-         private void ReportMenu_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             if (CurrentPanel is null)
 
-                 return;
 
-             var item = (RibbonButton)sender;
 
-             var id = (Guid)item.Tag;
 
-             var template = new Client<ReportTemplate>().Load(new Filter<ReportTemplate>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
 
-             if (template == null)
 
-             {
 
-                 Logger.Send(LogType.Error, "", $"No Report Template with ID '{id}'");
 
-                 MessageBox.Show("Report does not exist!");
 
-                 return;
 
-             }
 
-             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, CurrentPanel.DataModel(selection), false, Security.IsAllowed<CanDesignReports>());
 
-         }
 
-         private void ManageReports()
 
-         {
 
-             if (CurrentTab is null || CurrentPanel is null)
 
-                 return;
 
-             var section = CurrentPanel.SectionName;
 
-             var model = CurrentPanel.DataModel(Selection.None);
 
-             if (model == null)
 
-             {
 
-                 MessageBox.Show("No DataModel for " + CurrentTab.Header);
 
-                 return;
 
-             }
 
-             var form = new ReportManager { DataModel = model, Section = section, Populate = true };
 
-             form.ShowDialog();
 
-             ReloadReports(section, model);
 
-         }
 
-         private void ManageEmailTemplates()
 
-         {
 
-             if (CurrentTab is null || CurrentPanel is null)
 
-                 return;
 
-             var section = CurrentPanel.SectionName;
 
-             var model = CurrentPanel.DataModel(Selection.None);
 
-             if (model == null)
 
-             {
 
-                 MessageBox.Show("No DataModel for " + CurrentTab.Header);
 
-                 return;
 
-             }
 
-             var window = new EmailTemplateManagerWindow(model);
 
-             window.ShowDialog();
 
-         }
 
-         private void ManageReportsMenu_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ManageReports();
 
-         }
 
-         #endregion
 
-         #region Tracking Kanban
 
-         private void SelectTask_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             ContextMenu menu = new ContextMenu();
 
-             MenuItem others = new MenuItem() { Header = "Other Tasks" };
 
-             using (new WaitCursor())
 
-             {
 
-                 var kanbans = new Client<KanbanSubscriber>().Query(
 
-                     new Filter<KanbanSubscriber>(x => x.Employee.UserLink.ID).IsEqualTo(ClientFactory.UserGuid)
 
-                         .And(x => x.Kanban.Completed).IsEqualTo(DateTime.MinValue)
 
-                         .And(x => x.Kanban.Closed).IsEqualTo(DateTime.MinValue),
 
-                     new Columns<KanbanSubscriber>(x => x.Kanban.ID)
 
-                         .Add(x => x.Kanban.Number)
 
-                         .Add(x => x.Kanban.Title)
 
-                         .Add(x => x.Assignee),
 
-                     new SortOrder<KanbanSubscriber>(x => x.Kanban.Number, SortDirection.Ascending)
 
-                 );
 
-                 foreach (var row in kanbans.Rows)
 
-                 {
 
-                     CreateTaskMenu(row.Get<KanbanSubscriber, bool>(c => c.Assignee) ? menu.Items : others.Items,
 
-                         String.Format("{0} {1}",
 
-                             row.Get<KanbanSubscriber, int>(c => c.Kanban.Number),
 
-                             row.Get<KanbanSubscriber, String>(c => c.Kanban.Title)),
 
-                         row.Get<KanbanSubscriber, Guid>(c => c.Kanban.ID)
 
-                     );
 
-                 }
 
-                 menu.Items.Add(new Separator());
 
-                 menu.Items.Add(others);
 
-                 menu.Items.Add(new Separator());
 
-                 CreateTaskMenu(menu.Items, "(No Task Selected)", Guid.Empty);
 
-             }
 
-             menu.IsOpen = true;
 
-         }
 
-         private Assignment? _kanbantrackingassignment = null;
 
-         private void SetTrackingKanban(Guid kanbanID, string header)
 
-         {
 
-             SelectedTaskName.Content = header;
 
-             var createNewAssignment = false;
 
-             if (_kanbantrackingassignment is not null)
 
-             {
 
-                 if (_kanbantrackingassignment.Actual.Finish < DateTime.Now.TimeOfDay)
 
-                 {
 
-                     _kanbantrackingassignment.Actual.Finish = DateTime.Now.TimeOfDay;
 
-                     new Client<Assignment>().Save(_kanbantrackingassignment, "");
 
-                 }
 
-                 // Update Existing Kanban
 
-                 if (kanbanID == Guid.Empty)
 
-                     _kanbantrackingassignment = null;
 
-                 else if (_kanbantrackingassignment.Task.ID != kanbanID)
 
-                 {
 
-                     createNewAssignment = true;
 
-                 }
 
-             }
 
-             else if (kanbanID != Guid.Empty)
 
-             {
 
-                 createNewAssignment = true;
 
-             }
 
-             if (createNewAssignment)
 
-             {
 
-                 _kanbantrackingassignment = new Assignment();
 
-                 _kanbantrackingassignment.Task.ID = kanbanID;
 
-                 _kanbantrackingassignment.EmployeeLink.ID = App.EmployeeID;
 
-                 _kanbantrackingassignment.Title = header;
 
-                 _kanbantrackingassignment.Date = DateTime.Today;
 
-                 _kanbantrackingassignment.Actual.Start = DateTime.Now.TimeOfDay;
 
-                 _kanbantrackingassignment.Actual.Finish = DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 2, 0));
 
-                 new Client<Assignment>().Save(_kanbantrackingassignment, "");
 
-             }
 
-         }
 
-         private void ClearTrackingKanban()
 
-             => SetTrackingKanban(Guid.Empty, "(No Task Selected)");
 
-         private void CreateTaskMenu(ItemCollection items, String title, Guid id)
 
-         {
 
-             var item = new MenuItem()
 
-             {
 
-                 Header = title,
 
-                 Tag = id
 
-             };
 
-             item.Click += (o, args) =>
 
-             {
 
-                 if (o is not MenuItem menu) return;
 
-                 SetTrackingKanban((Guid)item.Tag, (menu.Header as string) ?? "");
 
-             };
 
-             items.Add(item);
 
-         }
 
-         #endregion
 
-         private void DockPanel_OnIsActiveChanged(object? sender, EventArgs e)
 
-         {
 
-             var layout = sender as LayoutAnchorable;
 
-             if (layout == null)
 
-                 return;
 
-             var content = layout.Content as DependencyObject;
 
-             var dock = content is IDockPanel panel ? panel : content?.FindVisualChildren<IDockPanel>().FirstOrDefault();
 
-             if (dock == null)
 
-                 return;
 
-             if (layout.IsActive && layout.IsVisible)
 
-                 dock.Refresh();
 
-         }
 
-         private void _ribbon_OnPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
 
-         {
 
-             e.Handled = true;
 
-         }
 
-         #region Backstage Functions
 
-         private void DatabaseSettings_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var config = new DataBaseConfiguration();
 
-             if (config.ShowDialog() == true)
 
-             {
 
-                 var newsettings = new LocalConfiguration<DatabaseSettings>(App.Profile).Load();
 
-                 if (newsettings.RestartRequired(App.DatabaseSettings))
 
-                     MessageBox.Show("Please restart the application to apply these changes!");
 
-                 if ((newsettings.DatabaseType == DatabaseType.Standalone) && (newsettings.ColorScheme != App.DatabaseSettings.ColorScheme))
 
-                 {
 
-                     App.DatabaseSettings.ColorScheme = newsettings.ColorScheme;
 
-                     ApplyColorScheme();
 
-                 }
 
-             }
 
-         }
 
-         private void CompanyInformation_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var info = new Client<CompanyInformation>().Load().FirstOrDefault();
 
-             if (info == null)
 
-                 info = new CompanyInformation();
 
-             new DynamicDataGrid<CompanyInformation>().EditItems(new[] { info });
 
-         }
 
-         private void SecurityDefaultsButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var window = new GlobalTokenWindow();
 
-             window.ShowDialog();
 
-             Security.Reset();
 
-         }
 
-         private void SystemLogsButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var logfile = Path.Combine(CoreUtils.GetPath(), string.Format("{0:yyyy-MM-dd}.log", DateTime.Today));
 
-             if (File.Exists(logfile))
 
-             {
 
-                 var startInfo = new ProcessStartInfo("notepad.exe", logfile);
 
-                 startInfo.Verb = "open";
 
-                 startInfo.UseShellExecute = true;
 
-                 Process.Start(startInfo);
 
-             }
 
-             else
 
-             {
 
-                 MessageBox.Show(logfile + " does not exist!");
 
-             }
 
-         }
 
-         private void DocumentTypeList_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(DocumentType));
 
-             list.ShowDialog();
 
-         }
 
-         private void DocumentList_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(Document));
 
-             list.ShowDialog();
 
-         }
 
-         private void QAFormSetupButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var list = new MasterList(typeof(DigitalForm), "AppliesTo", null, true);
 
-             list.ShowDialog();
 
-         }
 
-         private void EditDetailsButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             var employee = new Client<Employee>().Query(
 
-                     new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid))
 
-                 .Rows.FirstOrDefault()?.ToObject<Employee>();
 
-             var item = new MyDetailsConfiguration(employee);
 
-             item.User = ClientFactory.UserGuid;
 
-             var buttons = new DynamicEditorButtons();
 
-             buttons.Add("Change Password", null, item, (sender, item) =>
 
-             {
 
-                 var details = (item as MyDetailsConfiguration)!;
 
-                 var changePassword = new ChangePassword(details.User);
 
-                 if (changePassword.ShowDialog() == true && changePassword.Password != null)
 
-                 {
 
-                     var newUser = new User();
 
-                     newUser.ID = details.User;
 
-                     ChangePassword.ChangeUserPassword(newUser, changePassword.Password);
 
-                     new Client<User>().Save(newUser, "Changed Password");
 
-                     MessageBox.Show("Password changed!");
 
-                 }
 
-             });
 
-             var editor = new DynamicEditorForm(typeof(MyDetailsConfiguration), buttons: buttons);
 
-             if (employee == null)
 
-             {
 
-                 editor.OnFormCustomiseEditor += (sender, items, column, editor) =>
 
-                 {
 
-                     editor.Editable = Editable.Disabled;
 
-                 };
 
-             }
 
-             editor.Items = new BaseObject[] { item };
 
-             if (editor.ShowDialog() == true)
 
-             {
 
-                 if (employee != null)
 
-                 {
 
-                     item.SaveTo(employee);
 
-                     new Client<Employee>().Save(employee, "Edited by user");
 
-                 }
 
-             }
 
-         }
 
-         private void LogoutButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             Logout();
 
-         }
 
-         private void LoginButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             if (DoLogin(false) == ValidationResult.VALID)
 
-                 AfterLogin();
 
-         }
 
-         private void ExitButton_OnClick(object sender, RoutedEventArgs e)
 
-         {
 
-             //_closingFromSystemMenu = true;
 
-             Close();
 
-         }
 
-         #endregion
 
-         
 
-     }
 
- }
 
 
  |