private async Task Refresh()
        {
            var fooOnCallPhoneRepository = new OnCallPhoneRepository();
            await fooOnCallPhoneRepository.ReadAsync();

            OnCallPhoneList.Clear();
            foreach (var item in fooOnCallPhoneRepository.Items)
            {
                OnCallPhoneList.Add(item);
            }
        }
        public OnCallPageViewModel(INavigationService navigationService,
                                   IPageDialogService dialogService)
        {
            _navigationService = navigationService;
            _dialogService     = dialogService;

            CallPhoneCommand = new DelegateCommand <OnCallPhone>(async x =>
            {
                Plugin.Messaging.CrossMessaging.Current.PhoneDialer.MakePhoneCall(
                    x.PhoneNumber, x.Title);
            });

            DoRefreshCommand = new DelegateCommand(async() =>
            {
                IsRefreshing = true;
                #region 進行緊急電話清單更新
                APIResult fooResult;
                var fooProgressDialogConfig = new ProgressDialogConfig()
                {
                    Title           = "請稍後,正在進行緊急電話清單更新中...",
                    IsDeterministic = false,
                };
                using (Acr.UserDialogs.UserDialogs.Instance.Progress(fooProgressDialogConfig))
                {
                    var fooOnCallPhoneRepository = new OnCallPhoneRepository();
                    fooResult = await fooOnCallPhoneRepository.GetAsync();
                    if (fooResult.Success == false)
                    {
                        try
                        {
                            var fooAlertConfig = new AlertConfig()
                            {
                                Title   = "警告",
                                Message = $"更新資料發生了錯誤 {Environment.NewLine}{fooResult.Message}",
                                OkText  = "確定"
                            };
                            CancellationTokenSource fooCancelSrc = new CancellationTokenSource(3000);
                            await Acr.UserDialogs.UserDialogs.Instance.AlertAsync(fooAlertConfig, fooCancelSrc.Token);
                        }
                        catch (OperationCanceledException)
                        {
                        }
                    }
                }
                if (fooResult.Success == true)
                {
                    await Refresh();
                }
                IsRefreshing = false;
                #endregion
            });
        }
Ejemplo n.º 3
0
        public async void OnNavigatedTo(NavigationParameters parameters)
        {
            var fooAllSuccess = true;

            if (Plugin.Connectivity.CrossConnectivity.Current.IsConnected == false)
            {
                fooAllSuccess = false;
            }
            else
            {
                LoadingMessage = "正在更新 請假單分類清單 中";
                var fooLeaveCategoryRepository = new LeaveCategoryRepository();
                APIResult = await fooLeaveCategoryRepository.GetAsync();

                if (APIResult.Success == false)
                {
                    using (Acr.UserDialogs.UserDialogs.Instance.Toast(
                               $"無法進行 更新 請假單分類清單 中 ({APIResult.Message})", TimeSpan.FromMilliseconds(1500)))
                    {
                        await Task.Delay(2000);
                    }
                    fooAllSuccess = false;
                }
                else
                {
                    LoadingMessage = "正在更新 專案清單 中";
                    var fooProjectRepository = new ProjectRepository();
                    APIResult = await fooProjectRepository.GetAsync();

                    if (APIResult.Success == false)
                    {
                        using (Acr.UserDialogs.UserDialogs.Instance.Toast(
                                   $"無法進行 更新 專案清單 中({APIResult.Message})", TimeSpan.FromMilliseconds(1500)))
                        {
                            await Task.Delay(2000);
                        }
                        fooAllSuccess = false;
                    }
                    else
                    {
                        LoadingMessage = "正在更新 緊急連絡電話清單 中";
                        var fooOnCallPhoneRepository = new OnCallPhoneRepository();
                        APIResult = await fooOnCallPhoneRepository.GetAsync();

                        if (APIResult.Success == false)
                        {
                            using (Acr.UserDialogs.UserDialogs.Instance.Toast(
                                       $"無法進行 更新 緊急連絡電話清單 中({APIResult.Message})", TimeSpan.FromMilliseconds(1500)))
                            {
                                await Task.Delay(2000);
                            }
                            fooAllSuccess = false;
                        }
                    }
                }
            }

            if (fooAllSuccess == true)
            {
                LoadingMessage = "系統資料更新完成";
                var fooSystemStatusRepository = new SystemStatusRepository();
                await fooSystemStatusRepository.ReadAsync();

                if (string.IsNullOrEmpty(fooSystemStatusRepository.Item.AccessToken))
                {
                    await _navigationService.NavigateAsync("xf:///LoginPage");
                }
                else
                {
                    await _navigationService.NavigateAsync("xf:///MDPage/NaviPage/AboutPage");
                }
            }
            else
            {
                var config = new Acr.UserDialogs.ConfirmConfig()
                {
                    Title      = "警告",
                    Message    = "可能因為網路問題,無法進行系統資料更新,您確定要繼續執行嗎? (強制繼續執行 App,但有可能造成 App 不正常運作)",
                    OkText     = "確定",
                    CancelText = "停止"
                };
                await Task.Delay(1000);

                var fooConfirmResult =
                    await Acr.UserDialogs.UserDialogs.Instance.ConfirmAsync(config);

                if (fooConfirmResult == false)
                {
                    LoadingMessage = "請強制關閉 App,檢查網路是否可用,並且重新啟動 App";
                    return;
                }
                else
                {
                    LoadingMessage = "強制繼續執行 App";
                }
            }

            // 切換到首頁或者登入頁面
        }