| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using System.Timers;
 
- using InABox.Clients;
 
- using InABox.Configuration;
 
- using InABox.Core;
 
- using InABox.Mobile;
 
- using Syncfusion.SfPdfViewer.XForms;
 
- using Xamarin.Essentials;
 
- using Xamarin.Forms;
 
- using XF.Material.Forms.UI.Dialogs;
 
- using Timer = System.Threading.Timer;
 
- namespace comal.timesheets
 
- {
 
-     class SettingsBinding : ConnectionSettings
 
-     {
 
-         public String DeviceID { get; set; }
 
-         public String AppVersion { get; set; }
 
-         public void Load(ConnectionSettings settings)
 
-         {
 
-             URL = settings.URL;
 
-             Port = settings.Port;
 
-             UserID = settings.UserID;
 
-             Password = settings.Password;
 
-         }
 
-         public void Unload(ConnectionSettings settings)
 
-         {
 
-             settings.URL = URL;
 
-             settings.Port = Port;
 
-             settings.UserID = UserID;
 
-             settings.Password = Password;
 
-         }
 
-     }
 
-     public partial class Settings : ContentPage
 
-     {
 
-         SettingsBinding binding = new SettingsBinding();
 
-         int count = 0;
 
-         string s = "";
 
-         public bool SettingsChanged { get; private set; }
 
-         public Settings()
 
-         {
 
-             InitializeComponent();
 
-             binding.Load(App.Settings);
 
-             binding.DeviceID = MobileUtils.GetDeviceID();
 
-             binding.AppVersion = MobileUtils.AppVersion.InstalledVersionNumber;
 
-             this.BindingContext = binding;
 
-             NavigationPage.SetHasBackButton(this, false);
 
-         }
 
-         private async void ExitBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Working"))
 
-             {
 
-                 //Syncfusion Masked editor still needs access before popping the page       
 
-                 Thread.Sleep(1000);
 
-                 Navigation.PopAsync();
 
-             }
 
-         }
 
-         private void SaveBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             ValidateAppData();
 
-         }
 
-         private async void ValidateAppData()
 
-         {
 
-             try
 
-             {
 
-                 using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Validating"))
 
-                 {
 
-                     ClientFactory.InvalidateUser();
 
-                     binding.Unload(App.Settings);
 
-                     new LocalConfiguration<ConnectionSettings>().Delete();
 
-                     new LocalConfiguration<ConnectionSettings>().Save(App.Settings);
 
-                     App.Settings = new LocalConfiguration<ConnectionSettings>().Load();
 
-                     ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + GlobalVariables.DeviceString, new object[] { App.Settings.URL, App.Settings.Port, true });
 
-                     GlobalVariables.ChangeUser = true;
 
-                     GlobalVariables.InternalOnAppearing = true;
 
-                     if (App.Current.Properties.ContainsKey("SessionID"))
 
-                         App.Current.Properties.Remove("SessionID");
 
-                     //Syncfusion Masked editor still needs access before popping the page                    
 
-                     Thread.Sleep(1000);
 
-                     Navigation.PopToRootAsync(true);
 
-                     PINLoginPage pin = new PINLoginPage();
 
-                     Navigation.PushAsync(pin, true);
 
-                 }
 
-                 return;
 
-             }
 
-             catch { }
 
-         }
 
-         protected override async void OnAppearing()
 
-         {
 
-             bool isLatest = true;
 
-             try
 
-             {
 
-                 isLatest = await MobileUtils.AppVersion.IsUsingLatestVersion();
 
-             }
 
-             catch (Exception eLatest)
 
-             {
 
-             }
 
-             if (isLatest)
 
-             {
 
-                 updateVersionBtn.IsEnabled = false;
 
-                 updateVersionBtn.Text = "App is up to date";
 
-             }
 
-             else if (!isLatest)
 
-             {
 
-                 string latestVersionNumber = await MobileUtils.AppVersion.GetLatestVersionNumber();
 
-                 updateVersionBtn.IsEnabled = true;
 
-                 updateVersionBtn.Text = "Update App Version (" + latestVersionNumber + ")";
 
-             }
 
-             const string errorFilename = "Fatal.log";
 
-             var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
 
-             var errorFilePath = Path.Combine(libraryPath, errorFilename);
 
-             if (File.Exists(errorFilePath))
 
-             {
 
-                 sendErrorsBtn.IsEnabled = true;
 
-             }
 
-             //if (Application.Current.Properties.ContainsKey("IsSharedDevice"))
 
-             //{
 
-             //    if (Application.Current.Properties["IsSharedDevice"].Equals("True"))
 
-             //    {
 
-             //        sharedDeviceRb.IsChecked = true;
 
-             //    }
 
-             //}
 
-             base.OnAppearing();
 
-         }
 
-         private async void ChangePasswordBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             if (count == 3)
 
-             {
 
-                 DisplayAlert("Alert", "You have attempted incorrectly " + count + " times and cannot try again. Please contact your system administrator.", "OK");
 
-                 return;
 
-             }
 
-             CoreTable table = new Client<User>().Query(new Filter<User>(x => x.UserID).IsEqualTo(ClientFactory.UserID),
 
-                 new Columns<User>(x => x.Password));
 
-             if (table.Rows.Any())
 
-             {
 
-                 string p = table.Rows.FirstOrDefault().Values[0].ToString();
 
-                 string userInput = await DisplayPromptAsync("Alert", "Enter Current Password", "OK", "Cancel");
 
-                 if (!string.IsNullOrWhiteSpace(userInput) && userInput != "Cancel")
 
-                 {
 
-                     if (p != userInput)
 
-                     {
 
-                         count++;
 
-                         DisplayAlert("Alert", "Password is incorrect. You have attempted " + count + " times out of 3.", "OK");
 
-                         return;
 
-                     }
 
-                     else if (p == userInput)
 
-                     {
 
-                         PasswordResetPage page = new PasswordResetPage(ClientFactory.UserID);
 
-                         page.OnPasswordReset += (() =>
 
-                         {
 
-                             Navigation.PopToRootAsync();
 
-                             PINLoginPage pinpage = new PINLoginPage();
 
-                             Navigation.PushAsync(pinpage);
 
-                         });
 
-                         Navigation.PushAsync(page);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private async void UpdateVersionBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             Dispatcher.BeginInvokeOnMainThread(() => { MobileUtils.AppVersion.OpenAppInStore(); });
 
-         }
 
-         private void UserID_Changed(object sender, EventArgs e)
 
-         {
 
-             if (!string.IsNullOrWhiteSpace(UserID.Text))
 
-             {
 
-                 UserID.Text = UserID.Text.Trim();
 
-             }
 
-         }
 
-         private void UserPassword_Changed(object sender, EventArgs e)
 
-         {
 
-             if (!string.IsNullOrWhiteSpace(UserID.Text))
 
-             {
 
-                 Password.Text = Password.Text.Trim();
 
-             }
 
-             //if (!string.IsNullOrWhiteSpace(Password.Value.ToString()))
 
-             //{
 
-             //    Password.Value = Password.Value.ToString().Trim();
 
-             //    s = Password.Value.ToString();
 
-             //    showPassword.Text = s;
 
-             //}
 
-             //else
 
-             //    s = "";
 
-         }
 
-         async void BackgroundLoadProducts()
 
-         {
 
-             await Task.Run(() =>
 
-             {
 
-                 if (!GlobalVariables.ProductsLoaded/* && ClientFactory.IsAllowed<CanViewStockLocations>()*/)
 
-                 {
 
-                     GlobalVariables.ProductsLoaded = false;
 
-                     ProductsLoader productsLoader = new ProductsLoader();
 
-                     GlobalVariables.ProductShells = productsLoader.ProductShells;
 
-                     GlobalVariables.ProductsLoaded = true;
 
-                 }
 
-             });
 
-         }
 
-         private void sharedDeviceRb_Changed(object sender, EventArgs e)
 
-         {
 
-             //string isSharedDevice = "IsSharedDevice";
 
-             //if ((sender as CheckBox).IsChecked)
 
-             //{
 
-             //    if (!Application.Current.Properties.ContainsKey(isSharedDevice))
 
-             //    {
 
-             //        Application.Current.Properties.Add(isSharedDevice, "True");
 
-             //        URL.Text = "http://mobile.com-al.com.au";
 
-             //        UserID.Text = "";
 
-             //        Password.Value = "";
 
-             //    }
 
-             //    else
 
-             //    {
 
-             //        Application.Current.Properties[isSharedDevice] = "True";
 
-             //        URL.Text = "http://mobile.com-al.com.au";
 
-             //        UserID.Text = "";
 
-             //        Password.Value = "";
 
-             //    }
 
-             //}
 
-             //else
 
-             //{
 
-             //    if (Application.Current.Properties.ContainsKey(isSharedDevice))
 
-             //    {
 
-             //        Application.Current.Properties[isSharedDevice] = "False";
 
-             //    }
 
-             //}
 
-         }
 
-         private void ShowPW_Tapped(object sender, EventArgs e)
 
-         {
 
-             //passwordOne.Width = new GridLength(0, GridUnitType.Absolute);
 
-             //passwordTwo.Width = new GridLength(1, GridUnitType.Star);
 
-             //Task.Run(() =>
 
-             //{
 
-             //    Thread.Sleep(2500);
 
-             //    ShowMaskedText();
 
-             //});
 
-         }
 
-         private void ShowMaskedText()
 
-         {
 
-             //Device.BeginInvokeOnMainThread(() =>
 
-             //{
 
-             //    passwordTwo.Width = new GridLength(0, GridUnitType.Absolute);
 
-             //    passwordOne.Width = new GridLength(1, GridUnitType.Star);
 
-             //});
 
-         }
 
-         private async void ClearStorageBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             string chosenOption = await DisplayActionSheet("Confirm Clear? This will also log you out", "Cancel", null, "Yes", "No");
 
-             switch (chosenOption)
 
-             {
 
-                 case "Cancel":
 
-                     return;
 
-                 default:
 
-                     return;
 
-                 case "No":
 
-                     return;
 
-                 case "Yes":
 
-                     RemoveDataFromSecureStorage();
 
-                     ClearConnectionSettings();
 
-                     ValidateAppData();
 
-                     break;
 
-             }
 
-         }
 
-         private void RemoveDataFromSecureStorage()
 
-         {
 
-             try
 
-             {
 
-                 SecureStorage.Remove(GlobalVariables.CacheURLString);
 
-                 SecureStorage.Remove(GlobalVariables.CacheURLString);
 
-                 SecureStorage.Remove(GlobalVariables.CacheURLString);
 
-                 SecureStorage.Remove(GlobalVariables.CacheURLString);
 
-             }
 
-             catch
 
-             { }
 
-         }
 
-         private void ClearConnectionSettings()
 
-         {
 
-             try
 
-             {
 
-                 new LocalConfiguration<ConnectionSettings>().Delete();
 
-                 MobileUtils.LoadDemoSettings(App.Settings);
 
-                 binding.Load(App.Settings);
 
-             }
 
-             catch { }
 
-         }
 
-         //private void DocsURL_Changed(object sender, EventArgs e)
 
-         //{
 
-         //    if (!string.IsNullOrWhiteSpace(docsURL.Text))
 
-         //    {
 
-         //        if (!App.Current.Properties.ContainsKey("DocsURL"))
 
-         //        {
 
-         //            App.Current.Properties.Add("DocsURL", docsURL.Text);
 
-         //        }
 
-         //        else if (App.Current.Properties.ContainsKey("DocsURL"))
 
-         //        {
 
-         //            App.Current.Properties["DocsURL"] = docsURL.Text;
 
-         //        }
 
-         //    }           
 
-         //}
 
-         //private void ClearDocsBtn_Clicked(object sender, EventArgs e)
 
-         //{
 
-         //    if (App.Current.Properties.ContainsKey("DocsURL"))
 
-         //    {
 
-         //        App.Current.Properties.Remove("DocsURL");
 
-         //        DisplayAlert("Success", "", "OK");
 
-         //    }
 
-         //}
 
-         private async void SendErrorsBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             try
 
-             {
 
-                 const string errorFilename = "Fatal.log";
 
-                 string libraryPath = "";
 
-                 if (Device.RuntimePlatform.Equals(Device.Android))               
 
-                     libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);               
 
-                 else if (Device.RuntimePlatform.Equals(Device.iOS))               
 
-                     libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Resources);
 
-                                 
 
-                 var errorFilePath = Path.Combine(libraryPath, errorFilename);
 
-                 if (!File.Exists(errorFilePath))
 
-                 {
 
-                     return;
 
-                 }
 
-                 var errorText = File.ReadAllText(errorFilePath);
 
-                 var message = new EmailMessage
 
-                 {
 
-                     Subject = "Error Logs from " + GlobalVariables.EmpName,
 
-                     Body = errorText,
 
-                     To = new List<string> { "nick@prsdigital.com.au" }
 
-                 };
 
-                 await Email.ComposeAsync(message);
 
-                 File.Delete(errorFilePath);
 
-             }
 
-             catch { }
 
-         }
 
-     }
 
- }
 
 
  |