Ejemplo n.º 1
0
        private async void Login()
        {
            try
            {
                ViewMode            = LoginPageViewMode.Progress;
                btn_login.IsEnabled = false;
                await Task.Delay(10);

                Personnel user = await Personnel.AuthenticateAsync(App.ApiSettings, tbx_un.Text, pbx_pw.Password);

                App.LoggedUser = user;

                string pairedDeviceSettings = SettingsHelper.GetLocalSetting("ims_pairedDevice");

                Shell clientShell;
                if (pairedDeviceSettings != null)
                {
                    MobileMedAdminSystem system = JsonConvert.DeserializeObject <MobileMedAdminSystem>(pairedDeviceSettings);
                    clientShell = new Shell(typeof(PatientsPage), system);
                }
                else
                {
                    clientShell = new Shell(typeof(Devices.DevicesRegisterPage));
                }
                Window.Current.Content = clientShell;

                Window.Current.Activate();
            }
            catch (ApiException ex)
            {
                //TODO: If the destination URI is unreachable but internet is present, offer to go to setup
                //hbtn_setup.Visibility = Visibility.Visible;

                MessageDialog md = new MessageDialog(ex.Message, ex.Errors);
                md.Commands.Add(new UICommand("Try again", (command) => {
                    ViewMode = LoginPageViewMode.Login;

                    hbtn_setup.Visibility = Visibility.Collapsed;
                }));
                await md.ShowAsync();
            }
            catch (HttpRequestException ex)
            {
                MessageDialog md = new MessageDialog(ex.InnerException.Data["RestrictedDescription"].ToString(), ex.Message);
                md.Commands.Add(new UICommand("Try again", (command) =>
                {
                    hbtn_setup.Visibility = Visibility.Visible;
                    sp_setupdesc.Text     = "Administrator? You may want to check your connection paramters.";

                    ViewMode = LoginPageViewMode.Login;
                }));
                await md.ShowAsync();
            }
        }
Ejemplo n.º 2
0
        private async Task LoginAsync(ContentDialogButtonClickDeferral deferral = null)
        {
            ContentDialogButtonClickDeferral _deferral;

            pbx_pw.IsEnabled       = false;
            tbx_username.IsEnabled = false;
            progress.Visibility    = Visibility.Visible;
            IsPrimaryButtonEnabled = false;

            _deferral = deferral;
            try
            {
                Personnel authenticatedUser = await Personnel.AuthenticateAsync(App.ApiSettings, tbx_username.Text, pbx_pw.Password);

                AuthenticatedUser = authenticatedUser;
                Result            = LoginDialogResult.LoginSuccess;

                if (_deferral != null)
                {
                    _deferral.Complete();
                }

                CanClose = true;
                Hide();
            }
            catch (ApiException ex)
            {
                MessageDialog md = new MessageDialog(ex.Message);
                await md.ShowAsync();

                if (_deferral != null)
                {
                    _deferral.Complete();
                }

                throw ex;
            }
        }