|
@@ -0,0 +1,212 @@
|
|
|
+using InABox.Clients;
|
|
|
+using InABox.Configuration;
|
|
|
+using InABox.Mobile;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using Xamarin.Essentials;
|
|
|
+using Xamarin.Forms;
|
|
|
+using Xamarin.Forms.Xaml;
|
|
|
+using XF.Material.Forms.UI.Dialogs;
|
|
|
+using Comal.Classes;
|
|
|
+using Email = Xamarin.Essentials.Email;
|
|
|
+using InABox.Core;
|
|
|
+using System.Linq;
|
|
|
+
|
|
|
+namespace comal.timesheets
|
|
|
+{
|
|
|
+ [XamlCompilation(XamlCompilationOptions.Compile)]
|
|
|
+ public partial class SettingsPage : ContentPage
|
|
|
+ {
|
|
|
+ private int count;
|
|
|
+
|
|
|
+ public SettingsPage()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+
|
|
|
+ NavigationPage.SetHasBackButton(this, false);
|
|
|
+
|
|
|
+ Populate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExitBtn_Clicked(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Navigation.PopAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SaveBtn_Clicked(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ ValidateData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void ValidateData()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ App.DBSettings.URLs = stringList.SaveItems();
|
|
|
+ App.DBSettings.UserID = userIDEnt.Text.Trim();
|
|
|
+ App.DBSettings.Password = passwordEnt.Text.Trim();
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Validating"))
|
|
|
+ {
|
|
|
+ ClientFactory.InvalidateUser();
|
|
|
+ new LocalConfiguration<DatabaseSettings>().Delete();
|
|
|
+ new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
|
|
|
+ App.DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
|
|
|
+
|
|
|
+ if (App.Current.Properties.ContainsKey("SessionID"))
|
|
|
+ App.Current.Properties.Remove("SessionID");
|
|
|
+
|
|
|
+ var result = JsonClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
|
|
|
+
|
|
|
+ ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + GlobalVariables.DeviceString, result, true);
|
|
|
+
|
|
|
+ GlobalVariables.ChangeUser = true;
|
|
|
+ GlobalVariables.InternalOnAppearing = true;
|
|
|
+
|
|
|
+ Navigation.PopToRootAsync(true);
|
|
|
+ PINLoginPage pin = new PINLoginPage();
|
|
|
+ Navigation.PushAsync(pin, true);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ DisplayAlert("Error", ex.Message, "OK");
|
|
|
+ }
|
|
|
+ Navigation.PopAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ #region Populate Screen
|
|
|
+
|
|
|
+ private void Populate()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ stringList.LoadList(App.DBSettings.URLs);
|
|
|
+ userIDEnt.Text = App.DBSettings.UserID;
|
|
|
+ passwordEnt.Text = App.DBSettings.Password;
|
|
|
+
|
|
|
+ deviceIDEnt.Text = MobileUtils.GetDeviceID();
|
|
|
+ appVersionEnt.Text = MobileUtils.AppVersion.InstalledVersionNumber;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ base.OnAppearing();
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ #region Buttons
|
|
|
+ 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> { "support@prsdigital.com.au" }
|
|
|
+ };
|
|
|
+
|
|
|
+ await Email.ComposeAsync(message);
|
|
|
+
|
|
|
+ File.Delete(errorFilePath);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
+ private void UpdateVersionBtn_Clicked(Object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Dispatcher.BeginInvokeOnMainThread(() => { MobileUtils.AppVersion.OpenAppInStore(); });
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|