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; using System.Threading; using System.Threading.Tasks; using InABox.Rpc; namespace comal.timesheets { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class SettingsPage { private int count; private DatabaseSettings _settings; public SettingsPage() { _settings = new LocalConfiguration().Load(); InitializeComponent(); <<<<<<< HEAD ======= >>>>>>> 157e2e53c724ac158405ab5d124be7d214b4e5e7 } private void ExitBtn_Clicked(object sender, EventArgs e) { Navigation.PopAsync(); } <<<<<<< HEAD private async void Save_OnClicked(object sender, EventArgs e) ======= private async void Save_OnClicked(object sender, EventArgs args) >>>>>>> 157e2e53c724ac158405ab5d124be7d214b4e5e7 { _settings.URLs = stringList.SaveItems(); _settings.UserID = userIDEnt.Text.Trim(); _settings.Password = passwordEnt.Text.Trim(); new LocalConfiguration().Save(_settings); ClientFactory.InvalidateUser(); if (App.Current.Properties.ContainsKey("SessionID")) App.Current.Properties.Remove("SessionID"); TransportStatus connection = TransportStatus.None; using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Connecting")) { await Task.Run(() => { return connection = App.ConnectTransport(_settings.URLs); }); } if (connection != TransportStatus.OK) { await DisplayAlert("Connection Error", $"Unable to establish a connection!\n\nERR: {connection}", "OK"); return; } //Navigation.PopToRootAsync(true); Navigation.PushAsync(new PinLoginPage()); } #region Populate Screen private void Populate() { try { stringList.LoadList(_settings.URLs); userIDEnt.Text = _settings.UserID; passwordEnt.Text = _settings.Password; deviceIDEnt.Text = MobileUtils.GetDeviceID(); appVersionEnt.Text = MobileUtils.AppVersion.InstalledVersionNumber; } catch { } } protected override async void OnAppearing() { base.OnAppearing(); Populate(); 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) { try { string latestVersionNumber = await MobileUtils.AppVersion.GetLatestVersionNumber(); updateVersionBtn.IsEnabled = true; updateVersionBtn.Text = "Update App Version (" + latestVersionNumber + ")"; } catch { } } } #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 " + App.Data.Me?.Name ?? "Unknown Employee", Body = errorText, To = new List { "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().Query(new Filter(x => x.UserID).IsEqualTo(ClientFactory.UserID), // new Columns(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 void ViewLogsButton_Clicked(object sender, EventArgs e) { Navigation.PushAsync(new LogViewer()); } #endregion } }