Przeglądaj źródła

Added ability to have multiple database profiles on Mobile
Fixed KanbanSubscribers

Frank van den Bos 2 lat temu
rodzic
commit
42a466bf9a

+ 1 - 1
prs.mobile.new/PRS.Mobile.Droid/Properties/AndroidManifest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="737000" android:versionName="7.37.0" package="comal.timesheets.Android">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="738000" android:versionName="7.38.0" package="comal.timesheets.Android">
 	<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="33" />
 	<queries>
 		<intent>

+ 1 - 1
prs.mobile.new/PRS.Mobile.iOS/Info.plist

@@ -27,7 +27,7 @@
 	<key>CFBundleIdentifier</key>
 	<string>com.prsdigital.prssiteapp</string>
 	<key>CFBundleVersion</key>
-	<string>7.37.0</string>
+	<string>7.38.0</string>
 	<key>UILaunchStoryboardName</key>
 	<string>LaunchScreen</string>
 	<key>CFBundleName</key>

+ 9 - 4
prs.mobile.new/PRS.Mobile/CustomControls/StringList.xaml.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-
+using InABox.Mobile;
 using Xamarin.Forms;
 using Xamarin.Forms.Xaml;
 
@@ -106,7 +106,7 @@ namespace PRS.Mobile
             var edt = new Entry
             {
                 Text = Text,
-                FontSize = 16,
+                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Entry)),
                 Keyboard = Keyboard.Plain,
                 BackgroundColor = Color.LightYellow,
                 TextColor = Color.Black
@@ -115,9 +115,14 @@ namespace PRS.Mobile
             {
                 Text = edt.Text;
             };
-            Grid.SetColumn(edt, 1);
+
+            MobileCard card = new MobileCard()
+            {
+                Content = edt
+            };
+            Grid.SetColumn(card,1);
             
-            Children.Add(edt);
+            Children.Add(card);
             Children.Add(img);
         }
         

+ 1 - 1
prs.mobile.new/PRS.Mobile/Data Models/Archive/Requisition/StoreRequiItemShell.cs

@@ -39,7 +39,7 @@ namespace PRS.Mobile
             Colour = Color.Default;
             JobID = Guid.Empty;
             StyleID = Guid.Empty;
-            Dimensions = new StockDimensions(() => this);
+            Dimensions = new StockDimensions();
         }
     }
 }

+ 1 - 1
prs.mobile.new/PRS.Mobile/Data Models/Archive/StockHolding/StockHoldingShell_Old2.cs

@@ -31,7 +31,7 @@ namespace PRS.Mobile
             StyleID = Guid.Empty;
             StyleCode = "";
             StyleDescription = "";
-            Dimensions = new StockDimensions(() => this);
+            Dimensions = new StockDimensions();
         }            
     }
 }

+ 1 - 1
prs.mobile.new/PRS.Mobile/Data Models/Lists/Kanban/BaseKanbanShell.cs

@@ -155,7 +155,7 @@ namespace PRS.Mobile
         public override void Save(string auditmessage)
         {
             base.Save(auditmessage);
-            KanbanSubscriberSet subscribers = new KanbanSubscriberSet(new Guid[] { ID });
+            var subscribers = new ClientKanbanSubscriberSet(new Guid[] { ID });
             subscribers.EnsureAssignee(ID, EmployeeID);
             subscribers.EnsureManager(ID,ManagerID);
             subscribers.Save(false);

+ 4 - 4
prs.mobile.new/PRS.Mobile/Data Models/Lists/Kanban/KanbanShell.cs

@@ -13,10 +13,10 @@ namespace PRS.Mobile
         public override void Save(string auditmessage)
         {
             base.Save(auditmessage);
-            KanbanSubscriberSet subscribers = new KanbanSubscriberSet(new Guid[] { ID });
-            subscribers.EnsureAssignee(ID, EmployeeID);
-            subscribers.EnsureManager(ID,ManagerID);
-            subscribers.Save(false);
+            // var subscribers = new ClientKanbanSubscriberSet(new Guid[] { ID });
+            // subscribers.EnsureAssignee(ID, EmployeeID);
+            // subscribers.EnsureManager(ID,ManagerID);
+            // subscribers.Save(false);
         }
     }
 }

+ 11 - 0
prs.mobile.new/PRS.Mobile/Main/MobileDatabaseSettings.cs

@@ -0,0 +1,11 @@
+using System;
+using Comal.Classes;
+
+namespace PRS.Mobile
+{
+    public class MobileDatabaseSettings : DatabaseSettings
+    {
+        public bool IsDefault { get; set; }
+        public Guid CacheID { get; set; }
+    }
+}

+ 97 - 45
prs.mobile.new/PRS.Mobile/Main/PINLoginPage.xaml.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using Comal.Classes;
@@ -26,8 +27,9 @@ namespace PRS.Mobile
         private SubPage _page;
         private String _pin = "";
         private String _2fa = "";
-        
-        private DatabaseSettings _settings { get; set; }
+
+        private Dictionary<String, MobileDatabaseSettings> _settings = new Dictionary<string, MobileDatabaseSettings>();
+        private MobileDatabaseSettings _default = new MobileDatabaseSettings();
         
         public PinLoginPage()
         {
@@ -73,16 +75,19 @@ namespace PRS.Mobile
                 _status.Text = "Connecting...";
                 await Task.Run(() =>
                 {
-                    if ((_settings.URLs?.Any(x=>!String.IsNullOrWhiteSpace(x)) == true)
-                        && !string.IsNullOrWhiteSpace(_settings.UserID) 
-                        && !string.IsNullOrWhiteSpace(_settings.Password)
-                        )
-                        connection = App.ConnectTransport(_settings.URLs);
+                    if ((_default.URLs?.Any(x => !String.IsNullOrWhiteSpace(x)) == true)
+                        && !string.IsNullOrWhiteSpace(_default.UserID)
+                        && !string.IsNullOrWhiteSpace(_default.Password)
+                       )
+                    {
+                        CoreRepository.CacheID = _default.CacheID;
+                        connection = App.ConnectTransport(_default.URLs);
+                    }
                 });
                 
                 if (connection != TransportStatus.OK)
                 {
-                    if(_settings.URLs.Any() && !string.IsNullOrWhiteSpace(_settings.UserID))
+                    if(_default.URLs.Any() && !string.IsNullOrWhiteSpace(_default.UserID))
                         await DisplayAlert("Connection Error", $"Unable to establish a connection!\n\nERR: {connection}", "OK");
 
                     Navigation.PushAsync(new SettingsPage());
@@ -112,7 +117,7 @@ namespace PRS.Mobile
                     
                     // If we _should_ have been able to log in (ie we have a username)
                     // show an error message.  Otherwise, jump to the PIN page
-                    if (!String.IsNullOrWhiteSpace(_settings.UserID))
+                    if (!String.IsNullOrWhiteSpace(_default.UserID))
                         await DisplayAlert("Error logging in", "Invalid User ID, Password or PIN", "OK");
                     
                     SelectSubPage(SubPage.Pin);
@@ -187,11 +192,15 @@ namespace PRS.Mobile
                             DateTime expiry = DateTime.Parse(settings[2]);
                             if (expiry > DateTime.Now)
                             {
-                                _settings = new DatabaseSettings();
-                                _settings.URLs = urls;
-                                _settings.UserID = user;
-                                _settings.Password = password;
-                                new LocalConfiguration<DatabaseSettings>().Save(_settings);
+                                _default = new MobileDatabaseSettings();
+                                _default.URLs = urls;
+                                _default.UserID = user;
+                                _default.Password = password;
+                                _default.IsDefault = true;
+                                _default.CacheID = Guid.NewGuid();
+                                _settings.Clear();
+                                _settings["Autoconfigured"] = _default;
+                                new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
                                 DisplayAlert("Autoconfiguration", "Configuration Updated Successfully!!", "OK");
                             }
                             else
@@ -214,34 +223,77 @@ namespace PRS.Mobile
 
         private void LoadSettings()
         {
+
+            // var old = new DatabaseSettings()
+            // {
+            //     URLs = new String[]
+            //     {
+            //         "demo.prsdigital.com.au:8033",
+            //         "demo2.prsdigital.com.au:8033",
+            //     },
+            //     UserID = "GUEST",
+            //     Password = "guest"
+            // };
+            // new LocalConfiguration<DatabaseSettings>().Save(old);
+            // _settings = new LocalConfiguration<MobileDatabaseSettings>().LoadAll();
+            // foreach (var key in _settings.Keys)
+            //     new LocalConfiguration<MobileDatabaseSettings>(key).Delete();
+                 
+            _settings = new LocalConfiguration<MobileDatabaseSettings>().LoadAll();
+            
+            // Migrate from Old Database Settings (if present)
+            if (!_settings.Any())
+            {
+                var oldsettings = new LocalConfiguration<DatabaseSettings>().LoadAll();
+                foreach (var key in oldsettings.Keys)
+                {
+                    if (oldsettings[key].URLs?.Any() == true)
+                    {
+                        var newsetting = new MobileDatabaseSettings()
+                        {
+                            URLs = oldsettings[key].URLs,
+                            UserID = oldsettings[key].UserID,
+                            Password = oldsettings[key].Password,
+                            IsDefault = String.IsNullOrWhiteSpace(key),
+                            CacheID = Guid.NewGuid()
+                        };
+                        _settings[String.IsNullOrWhiteSpace(key) ? "Default Profile" : key] = newsetting;
+                    }
+
+                    new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
+                    new LocalConfiguration<DatabaseSettings>().Delete();
+                }
+            }
             
-            _settings = new LocalConfiguration<DatabaseSettings>().Load();
+            // Contruct Defaults if required
+            if (!_settings.Any())
+            {
+                _default = new MobileDatabaseSettings();
+                _default.URLs = new String[]
+                {
+                    "demo.prsdigital.com.au:8033",
+                    "demo2.prsdigital.com.au:8033",
+                };
+                _default.UserID = "GUEST";
+                _default.Password = "guest";
+                _default.IsDefault = true;
+                _default.CacheID = Guid.NewGuid();
+                _settings["Demo Database"] = _default;
+                new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
+            }
+
+            // Retrieve the Default (or the first, if there is no default)
+            _default = _settings.Any(x => x.Value.IsDefault)
+                ? _settings.FirstOrDefault(x => x.Value.IsDefault).Value
+                : _settings.First().Value;
+            if (_default.CacheID == Guid.Empty)
+            {
+                _default.CacheID = Guid.NewGuid();
+                new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
+            }
 
-             // Nothing?  Populate with Defaults
-             if (!_settings.URLs.Any())
-             {
-                 _settings.URLs = new String[]
-                 {
-                     //"remote.com-al.com.au:8050",
-                     //"192.168.0.247:8050",
-                     //"192.168.100.54:8050",3
-                     //"remote.com-al.com.au:8030",
-                     //"192.168.100.242:8030",
-                     "demo.prsdigital.com.au:8033",
-                     "demo2.prsdigital.com.au:8033",
-                     //"demo3.prsdigital.com.au:8003"
-                 };
-                 //_settings.UserID = "frank";
-                 //_settings.Password = "frankvb22";
-                 _settings.UserID = "GUEST";
-                 _settings.Password = "guest";
-                 //_settings.UserID = "ADMIN";
-                 //_settings.Password = "admin";
-                 new LocalConfiguration<DatabaseSettings>().Save(_settings);
-             }
-             
-             //TODO - re enable this when this app is not just the site module
-             //App.IsSharedDevice = String.IsNullOrWhiteSpace(_settings.UserID);
+            //TODO - re enable this when this app is not just the site module
+            //App.IsSharedDevice = String.IsNullOrWhiteSpace(_settings.UserID);
 
         }
         
@@ -259,8 +311,8 @@ namespace PRS.Mobile
 
             if (result == ValidationStatus.INVALID)
             {
-                if (!String.IsNullOrWhiteSpace(_settings.UserID) && !String.IsNullOrWhiteSpace(_settings.Password))
-                    result = ClientFactory.Validate(_settings.UserID, _settings.Password);
+                if (!String.IsNullOrWhiteSpace(_default.UserID) && !String.IsNullOrWhiteSpace(_default.Password))
+                    result = ClientFactory.Validate(_default.UserID, _default.Password);
             }
             
             return result;
@@ -285,7 +337,7 @@ namespace PRS.Mobile
 
         private void LaunchMainPage()
         {
-            Device.BeginInvokeOnMainThread(() => SelectSubPage(String.IsNullOrWhiteSpace(_settings.UserID) ? SubPage.Pin : SubPage.Autologin));
+            Device.BeginInvokeOnMainThread(() => SelectSubPage(String.IsNullOrWhiteSpace(_default.UserID) ? SubPage.Pin : SubPage.Autologin));
             
             App.Data.Setup();
             
@@ -419,8 +471,8 @@ namespace PRS.Mobile
                 var user = new User() { ID = ClientFactory.UserGuid };
                 user.Password = NewPassword.Text;
                 new Client<User>().Save(user, "Password updated by User from Timebench");
-                _settings.Password = user.Password;
-                new LocalConfiguration<DatabaseSettings>().Save(_settings);
+                _default.Password = user.Password;
+                new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
                 
                 LaunchMainPage();
             }

+ 91 - 38
prs.mobile.new/PRS.Mobile/Main/SettingsPage.xaml

@@ -22,6 +22,7 @@
                 <RowDefinition Height="auto"/>
                 <RowDefinition Height="auto"/>
                 <RowDefinition Height="auto"/>
+                <RowDefinition Height="auto"/>
                 <RowDefinition Height="*"/>
                 <RowDefinition Height="auto"/>
             </Grid.RowDefinitions>
@@ -30,91 +31,143 @@
                 <ColumnDefinition Width="auto"/>
                 <ColumnDefinition Width="*"/>
             </Grid.ColumnDefinitions>
-
+            
             <Label 
                 Grid.Row="0" 
                 Grid.Column="0" 
-                Text="URLs:" 
+                Text="Profile" 
                 TextColor="Black"
+                FontSize="Small"
                 HorizontalOptions="Start" 
                 VerticalOptions="Center"/>
             
-            <local:StringList 
-                Grid.Row="0" 
-                Grid.Column="1" 
-                HorizontalOptions="Fill" 
-                x:Name="stringList" 
-                VerticalOptions="Start"/>
+            <Grid 
+                Grid.Row="0"
+                Grid.Column="1">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="*"/>
+                    <ColumnDefinition Width="Auto"/>
+                </Grid.ColumnDefinitions>
+                <mobile:MobileCard>
+                    <Entry 
+                        HorizontalOptions="Fill" 
+                        x:Name="profileName" 
+                        Text="(Default)"
+                        FontSize="Small"
+                        Keyboard="Plain"
+                        BackgroundColor="LightYellow"
+                        TextColor="Black"
+                    />
+                </mobile:MobileCard>
+                
+                <mobile:MobileCard 
+                    Grid.Column="1"
+                    Padding="0"
+                    WidthRequest="35"
+                    x:Name="profileButton">
+                    <mobile:MobileMenuButton
+                        x:Name="profileMenu"
+                        Image="lines"
+                        WidthRequest="24"
+                        HeightRequest="24">
+                        <mobile:MobileMenuButton.Items>
+                            <mobile:MobileMenuSeparator />
+                            <mobile:MobileMenuItem x:Name="_addProfile" Text="Add New" Clicked="AddProfile_Clicked" />
+                            <mobile:MobileMenuItem x:Name="_deleteProfile" Text="Delete" Clicked="DeleteProfile_Clicked" />
+                        </mobile:MobileMenuButton.Items>
+                    </mobile:MobileMenuButton>
+                </mobile:MobileCard>
+            </Grid>
             
-            <Label
+            <Label 
                 Grid.Row="1" 
                 Grid.Column="0" 
-                Text="User ID:"
+                Text="URLs" 
                 TextColor="Black"
+                FontSize="Small"
                 HorizontalOptions="Start" 
                 VerticalOptions="Center"/>
             
-            <Entry 
+            <local:StringList 
                 Grid.Row="1" 
                 Grid.Column="1" 
                 HorizontalOptions="Fill" 
-                x:Name="userIDEnt" 
-                VerticalOptions="Start" 
-                FontSize="16"
-                TextColor="Black"
-                Keyboard="Plain"
-                BackgroundColor="LightYellow"/>
+                x:Name="stringList" 
+                VerticalOptions="Start"/>
             
-            <Label 
+            <Label
                 Grid.Row="2" 
                 Grid.Column="0" 
-                Text="Password:" 
+                Text="UserID"
                 TextColor="Black"
+                FontSize="Small"
                 HorizontalOptions="Start" 
                 VerticalOptions="Center"/>
             
-            <Entry 
+            <mobile:MobileCard
                 Grid.Row="2" 
-                Grid.Column="1" 
-                HorizontalOptions="Fill" 
-                x:Name="passwordEnt" 
-                VerticalOptions="Start" 
-                FontSize="16"
-                TextColor="Black"
-                Keyboard="Plain"
-                IsPassword="true"
-                BackgroundColor="LightYellow"/>
+                Grid.Column="1">
+                <Entry 
+                    x:Name="userIDEnt" 
+                    FontSize="Small"
+                    TextColor="Black"
+                    Keyboard="Plain"
+                    BackgroundColor="LightYellow"/>
+            </mobile:MobileCard>
             
             <Label 
                 Grid.Row="3" 
                 Grid.Column="0" 
-                Text="Device ID:" 
+                Text="Password" 
+                FontSize="Small"
+                TextColor="Black"
+                HorizontalOptions="Start" 
+                VerticalOptions="Center"/>
+            
+            <mobile:MobileCard
+                Grid.Row="3" 
+                Grid.Column="1">
+                <Entry 
+                    x:Name="passwordEnt" 
+                    FontSize="Small"
+                    TextColor="Black"
+                    Keyboard="Plain"
+                    IsPassword="true"
+                    BackgroundColor="LightYellow"/>
+            </mobile:MobileCard>
+            
+            <Label 
+                Grid.Row="4" 
+                Grid.Column="0" 
+                Text="Device" 
+                FontSize="Small"
                 TextColor="Black"
                 HorizontalOptions="Start" 
                 VerticalOptions="Center" />
                 
             <Entry 
-                Grid.Row="3" 
+                Grid.Row="4" 
                 Grid.Column="1" 
                 HorizontalOptions="Fill" 
                 IsReadOnly="True" 
                 x:Name="deviceIDEnt" 
-                FontSize="16"
+                FontSize="Small"
                 Keyboard="Plain"
                 BackgroundColor="LightGray"
                 TextColor="DimGray"
             />
             
             <Label 
-                Grid.Row="4" 
+                Grid.Row="5" 
                 Grid.Column="0" 
-                Text="S/W Version:" 
+                Text="Version" 
+                FontSize="Small"
                 TextColor="Black"
                 HorizontalOptions="Start" 
                 VerticalOptions="Center" />
                 
             <Grid
-                Grid.Row="4"
+                Grid.Row="5"
                 Grid.Column="1"
                 Grid.ColumnSpacing="5">
                 
@@ -128,7 +181,7 @@
                     HorizontalOptions="Fill" 
                     IsReadOnly="True" 
                     x:Name="swVersion" 
-                    FontSize="16"
+                    FontSize="Small"
                     Keyboard="Plain"
                     BackgroundColor="LightGray"
                     TextColor="DimGray"
@@ -147,7 +200,7 @@
             </Grid>
             
             <mobile:MobileCard
-                Grid.Row="5"
+                Grid.Row="6"
                 Grid.Column="0"
                 Grid.ColumnSpan="2"
                 BackgroundColor="WhiteSmoke">
@@ -163,7 +216,7 @@
             </mobile:MobileCard>
             
             <Grid                
-                Grid.Row="6"
+                Grid.Row="7"
                 Grid.Column="0"
                 Grid.ColumnSpan="2"
                 Grid.ColumnSpacing="5"

+ 125 - 34
prs.mobile.new/PRS.Mobile/Main/SettingsPage.xaml.cs

@@ -24,15 +24,41 @@ namespace PRS.Mobile
     {
         private int count;
 
-        private DatabaseSettings _settings;
+        private Dictionary<String,MobileDatabaseSettings> _settings;
+        private string _current = "";
+
+        private Guid[] _caches;
         
         public SettingsPage()
         {
-            _settings = new LocalConfiguration<DatabaseSettings>().Load();
+            _settings = new LocalConfiguration<MobileDatabaseSettings>().LoadAll();
+            
+            _caches = _settings.Select(x => x.Value.CacheID).ToArray();
+            
+            _current = _settings.Any(x => x.Value.IsDefault)
+                ? _settings.First(x => x.Value.IsDefault).Key
+                : _settings.First().Key;
             
             InitializeComponent();
             ProgressVisible = true;
 
+            profileButton.BackgroundColor = XF.Material.Forms.Material.Color.Secondary;
+            ReloadProfiles();
+        }
+
+        private void ReloadProfiles()
+        {
+            while (profileMenu.Items.Count > 3)
+                profileMenu.Items.RemoveAt(0);
+            int i = 0;
+            foreach (var key in _settings.Keys)
+            {
+                var profile = new MobileMenuItem() { Text = String.IsNullOrWhiteSpace(key) ? "Default Profile" : key };
+                profile.Clicked += SelectProfile_Click;
+                profile.BindingContext = key;
+                profileMenu.Items.Insert(i, profile);
+                i++;
+            }
         }
 
         private void ExitBtn_Clicked(object sender, EventArgs e)
@@ -43,19 +69,9 @@ namespace PRS.Mobile
         private async void Save_OnClicked(object sender, EventArgs args)
         {
 
-            var urls = stringList.SaveItems();
-            var user = userIDEnt.Text?.Trim() ?? "";
-            var pass = passwordEnt.Text?.Trim() ?? "";
-
-            if (!urls.SequenceEqual(_settings.URLs) ||
-                (!String.Equals(user, _settings.UserID) || !String.Equals(pass, _settings.Password)))
-            {
-                _settings.URLs = urls;
-                _settings.UserID = user;
-                _settings.Password = pass;
-                new LocalConfiguration<DatabaseSettings>().Save(_settings);
-                DoClearCaches();
-            }
+            StoreProfileSettings();
+            new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
+            DoClearCaches();
 
             ClientFactory.InvalidateUser();
             if (App.Current.Properties.ContainsKey("SessionID"))
@@ -68,7 +84,8 @@ namespace PRS.Mobile
             {
                 await Task.Run(() =>
                 {
-                    return connection = App.ConnectTransport(_settings.URLs);
+                    CoreRepository.CacheID = _settings[_current].CacheID;
+                    return connection = App.ConnectTransport(_settings[_current].URLs);
                 });
             }
 
@@ -81,18 +98,28 @@ namespace PRS.Mobile
             //Navigation.PopToRootAsync(true);
             Navigation.PushAsync(new PinLoginPage());
         }
-        
+
+        private void StoreProfileSettings()
+        {
+            if (!String.Equals(profileName.Text, _current))
+            {
+                var current = _settings[_current];
+                _settings.Remove(_current);
+                _current = profileName.Text;
+                _settings[_current] = current;
+                ReloadProfiles();
+            }
+            _settings[_current].URLs = stringList.SaveItems();
+            _settings[_current].UserID = userIDEnt.Text?.Trim() ?? "";
+            _settings[_current].Password = passwordEnt.Text?.Trim() ?? "";
+        }
+
         #region Populate Screen
 
         private void Populate()
         {
-            if (_settings.URLs?.Any() ?? false)
-                stringList.LoadList(_settings.URLs);
-            else
-                stringList.LoadList(new String[] { });
 
-            userIDEnt.Text = _settings.UserID;
-            passwordEnt.Text = _settings.Password;
+            PopulateConnection();
 
             deviceIDEnt.Text = MobileUtils.GetDeviceID();
             swVersion.Text = MobileUtils.AppVersion.InstalledVersionNumber;
@@ -105,7 +132,7 @@ namespace PRS.Mobile
                             swVersion.BackgroundColor = bt.Result
                                 ? Color.LightGray
                                 : Color.Red;
-                            swVersion.TextColor = !bt.Result
+                            swVersion.TextColor = bt.Result
                                 ? Color.DimGray
                                 : Color.WhiteSmoke;
                         }
@@ -123,7 +150,19 @@ namespace PRS.Mobile
                 
             });
         }
-        
+
+        private void PopulateConnection()
+        {
+            profileName.Text = _current;
+
+            if (_settings[_current].URLs?.Any() ?? false)
+                stringList.LoadList(_settings[_current].URLs);
+            else
+                stringList.LoadList(new String[] { });
+            userIDEnt.Text = _settings[_current].UserID;
+            passwordEnt.Text = _settings[_current].Password;
+        }
+
         protected override async void OnAppearing()
         {
         
@@ -141,16 +180,21 @@ namespace PRS.Mobile
                 "Confirm Reset", "OK", "Cancel");
             if (confirm == true)
             {
-                _settings.URLs = new String[]
+                _settings.Clear();
+                _current = "Demo Database";
+                _settings[_current] = new MobileDatabaseSettings();
+                _settings[_current].URLs = new String[]
                 {
                     "demo.prsdigital.com.au:8033",
                     "demo2.prsdigital.com.au:8033",
                 };
-                _settings.UserID = "GUEST";
-                _settings.Password = "guest";
-                new LocalConfiguration<DatabaseSettings>().Save(_settings);
+                _settings[_current].UserID = "GUEST";
+                _settings[_current].Password = "guest";
+                _settings[_current].IsDefault = true;
+                _settings[_current].CacheID = Guid.NewGuid();
+                new LocalConfiguration<MobileDatabaseSettings>().SaveAll(_settings);
                 DoClearCaches();
-                Device.BeginInvokeOnMainThread(Populate);
+                Device.BeginInvokeOnMainThread(PopulateConnection);
             }
         }
         
@@ -184,12 +228,19 @@ namespace PRS.Mobile
         private void DoClearCaches()
         {
             ProgressVisible = true;
-            var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
-            var files = Directory.GetFiles(path);
             Task.Run(() =>
             {
-                foreach (var file in files)
-                    File.Delete(file);
+                foreach (var _cache in _caches)
+                {
+                    var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),_cache.ToString());
+                    if (Directory.Exists(path))
+                    {
+                        var files = Directory.GetFiles(path);
+                        foreach (var file in files)
+                            File.Delete(file);
+                        Directory.Delete(path);
+                    }
+                }
             }).Wait();
             ProgressVisible = false;
         }
@@ -198,5 +249,45 @@ namespace PRS.Mobile
         {
             MobileUtils.AppVersion.OpenAppInStore();
         }
+
+        private void SelectProfile_Click(object sender, EventArgs args)
+        {
+            if (sender is MobileMenuItem menu)
+            {
+                StoreProfileSettings();
+                foreach (var key in _settings.Keys)
+                    _settings[key].IsDefault = String.Equals(key, menu.BindingContext);
+                _current = menu.BindingContext as String ?? "";
+                PopulateConnection();
+            }
+        }
+        
+        private void AddProfile_Clicked(object sender, EventArgs e)
+        {
+            StoreProfileSettings();
+            var newsettings = new MobileDatabaseSettings();
+            int i = 1;
+            String profile = $"New Connection";
+            while (_settings.ContainsKey(profile))
+                profile = $"New Connection ({i++})";
+            _current = profile;
+            _settings[profile] = new MobileDatabaseSettings();
+            foreach (var key in _settings.Keys)
+                _settings[key].IsDefault = String.Equals(key, _current);
+            ReloadProfiles();
+            PopulateConnection();
+        }
+
+        private void DeleteProfile_Clicked(object sender, EventArgs e)
+        {
+            _settings.Remove(_current);
+            if (!_settings.Any())
+            {
+                _current = "New Connection";
+                _settings[_current] = new MobileDatabaseSettings() { IsDefault = true};
+            }
+            ReloadProfiles();
+        }
+        
     }
 }