async Task ReloadData()
        {
            #region 讀取 相關定義資料
            using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...",
                                                                                     null, null, true, MaskType.Black))
            {
                await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);

                #region 檢查 Access Token 是否還可以使用
                bool refreshTokenResult = await RefreshTokenHelper
                                          .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                systemStatusService, appStatus);

                if (refreshTokenResult == false)
                {
                    return;
                }
                #endregion

                #region 取得 專案清單
                fooIProgressDialog.Title = "請稍後,取得 專案清單";
                var apiResultssss = await projectService.GetAsync();

                if (apiResultssss.Status == true)
                {
                    await projectService.WriteToFileAsync();
                }
                else
                {
                    await DialogHelper.ShowAPIResultIsFailureMessage(dialogService, apiResultssss);

                    return;
                }
                #endregion

                #region 取得 工作日誌明細
                fooIProgressDialog.Title = "請稍後,取得 工作日誌明細";
                apiResultssss            = await workingLogDetailService.GetAsync(MasterItem.Id);

                if (apiResultssss.Status == true)
                {
                    await workingLogDetailService.WriteToFileAsync();
                    await RefreshData();
                }
                else
                {
                    await DialogHelper.ShowAPIResultIsFailureMessage(dialogService, apiResultssss);

                    return;
                }
                #endregion
            }
            #endregion
        }
コード例 #2
0
        private async System.Threading.Tasks.Task LoadDataAsync(bool isDownload = true)
        {
            if (isDownload)
            {
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
                {
                    bool fooRefreshTokenResult = await RefreshTokenHelper.CheckAndRefreshToken(dialogService, refreshTokenManager, systemStatusManager, appStatus);

                    if (fooRefreshTokenResult == false)
                    {
                        return;
                    }
                    var fooResult = await leaveFormsManager.GetAsync();
                }
            }
            //await leaveFormsManager.ReadFromFileAsync();
            LeaveFormItemsSource.Clear();
            foreach (var item in leaveFormsManager.Items)
            {
                LeaveFormModel leaveFormModel = new LeaveFormModel()
                {
                    Id   = item.Id,
                    user = new UserDTO()
                    {
                        Id = item.user.Id
                    },
                    BeginTime     = item.BeginTime,
                    EndTime       = item.EndTime,
                    TotalHours    = item.TotalHours,
                    leaveFormType = new LeaveFormTypeModel()
                    {
                        Id = item.leaveFormType.Id
                    },
                    Description = item.Description,
                };
                var fooItem = leaveFormTypesManager.Items.FirstOrDefault(x => x.Id == item.leaveFormType.Id);
                leaveFormModel.leaveFormType.Name = fooItem.Name;

                LeaveFormItemsSource.Add(leaveFormModel);
            }
        }
コード例 #3
0
 public SuggestionPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                RefreshTokenManager refreshTokenManager, SystemStatusManager systemStatusManager,
                                AppStatus appStatus, SuggestionsManager suggestionsManager)
 {
     this.navigationService   = navigationService;
     this.dialogService       = dialogService;
     this.refreshTokenManager = refreshTokenManager;
     this.systemStatusManager = systemStatusManager;
     this.appStatus           = appStatus;
     this.suggestionsManager  = suggestionsManager;
     OKCommand = new DelegateCommand(async() =>
     {
         using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
         {
             bool fooRefreshTokenResult = await RefreshTokenHelper.CheckAndRefreshToken(dialogService, refreshTokenManager, systemStatusManager, appStatus);
             if (fooRefreshTokenResult == false)
             {
                 return;
             }
             var fooResult = await suggestionsManager.PostAsync(new SuggestionRequestDTO()
             {
                 Subject    = SuggestionModel.Subject,
                 Message    = SuggestionModel.Message,
                 SubmitTime = DateTime.Now,
                 User       = new UserDTO()
                 {
                     Id = appStatus.SystemStatus.UserID
                 },
             });
             if (fooResult.Status == true)
             {
                 await dialogService.DisplayAlertAsync("通知", "已經成功提交", "確定");
             }
             else
             {
                 await dialogService.DisplayAlertAsync("錯誤", $"已經發生例外異常:{fooResult.Message}", "確定");
             }
         }
     });
 }
コード例 #4
0
        public TravelExpenseDetailRecordPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                                      TravelExpenseDetailService travelExpenseDetailService,
                                                      RefreshTokenService refreshTokenService,
                                                      SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService          = navigationService;
            this.dialogService              = dialogService;
            this.travelExpenseDetailService = travelExpenseDetailService;
            this.refreshTokenService        = refreshTokenService;
            this.systemStatusService        = systemStatusService;
            this.appStatus = appStatus;

            #region 新增 儲存 按鈕命令
            SaveCommand = new DelegateCommand(async() =>
            {
                #region 進行資料完整性檢查
                var checkResult = SelectedItem.Validation();
                if (!string.IsNullOrEmpty(checkResult))
                {
                    await dialogService.DisplayAlertAsync("錯誤", $"請檢查並且修正錯誤{Environment.NewLine}{Environment.NewLine}" +
                                                          $"{checkResult}", "確定");
                    return;
                }
                #endregion

                #region 進行記錄儲存
                APIResult apiResult = new APIResult();
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,儲存資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    if (CrudAction == MagicStringHelper.CrudAddAction)
                    {
                        #region 新增 差旅費用明細紀錄
                        fooIProgressDialog.Title = "請稍後,新增 差旅費用明細紀錄";
                        SelectedItem.Id          = 0;
                        apiResult = await travelExpenseDetailService.PostAsync(SelectedItem);
                        if (apiResult.Status == true)
                        {
                            ToastHelper.ShowToast($"差旅費用明細紀錄 已經新增");

                            NavigationParameters paras = new NavigationParameters();
                            paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                            await navigationService.GoBackAsync(paras);
                        }
                        else
                        {
                            await dialogService.DisplayAlertAsync("錯誤", $"差旅費用明細紀錄 儲存失敗:{apiResult.Message}", "確定");
                        }
                        #endregion
                    }
                    else
                    {
                        #region 儲存 差旅費用明細紀錄
                        fooIProgressDialog.Title = "請稍後,儲存 差旅費用明細紀錄";
                        apiResult = await travelExpenseDetailService.PutAsync(SelectedItem);
                        if (apiResult.Status == true)
                        {
                            ToastHelper.ShowToast($"差旅費用明細紀錄 已經儲存");

                            NavigationParameters paras = new NavigationParameters();
                            paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                            await navigationService.GoBackAsync(paras);
                        }
                        else
                        {
                            await dialogService.DisplayAlertAsync("錯誤", $"差旅費用明細紀錄 儲存失敗:{apiResult.Message}", "確定");
                        }
                        #endregion
                    }

                    #region 取得 差旅費用明細紀錄
                    fooIProgressDialog.Title = "請稍後,取得 差旅費用明細紀錄";
                    apiResult = await travelExpenseDetailService.GetAsync(MasterItem.Id);
                    if (apiResult.Status == true)
                    {
                        await travelExpenseDetailService.WriteToFileAsync();
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"取得 差旅費用明細紀錄 失敗:{apiResult.Message}", "確定");
                    }
                    #endregion
                }
                #endregion
            });
            #endregion

            #region 刪除 按鈕命令
            DeleteCommand = new DelegateCommand(async() =>
            {
                #region 進行記錄刪除
                var confirm = await dialogService.DisplayAlertAsync(
                    "警告", "是否要刪除這筆紀錄?", "確定", "取消");
                if (confirm == false)
                {
                    return;
                }

                APIResult apiResult = new APIResult();
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,刪除資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    #region 刪除 差旅費用明細紀錄
                    fooIProgressDialog.Title = "請稍後,刪除 差旅費用明細紀錄";
                    apiResult = await travelExpenseDetailService.DeleteAsync(SelectedItem);
                    if (apiResult.Status == true)
                    {
                        ToastHelper.ShowToast($"差旅費用明細紀錄 已經刪除");

                        NavigationParameters paras = new NavigationParameters();
                        paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                        await navigationService.GoBackAsync(paras);
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"差旅費用明細紀錄 刪除失敗:{apiResult.Message}", "確定");
                    }
                    #endregion

                    #region 取得 差旅費用明細紀錄
                    fooIProgressDialog.Title = "請稍後,取得 差旅費用明細紀錄";
                    apiResult = await travelExpenseDetailService.GetAsync(MasterItem.Id);
                    if (apiResult.Status == true)
                    {
                        await travelExpenseDetailService.WriteToFileAsync();
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"取得 差旅費用明細紀錄 失敗:{apiResult.Message}", "確定");
                    }
                    #endregion
                }
                #endregion
            });
            #endregion
        }
        public TravelExpensePageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                          TravelExpenseService travelExpenseService,
                                          MyUserService myUserService, TravelExpenseDetailService travelExpenseDetailService,
                                          RefreshTokenService refreshTokenService,
                                          SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService          = navigationService;
            this.dialogService              = dialogService;
            this.travelExpenseService       = travelExpenseService;
            this.myUserService              = myUserService;
            this.travelExpenseDetailService = travelExpenseDetailService;
            this.refreshTokenService        = refreshTokenService;
            this.systemStatusService        = systemStatusService;
            this.appStatus = appStatus;

            #region 新增紀錄
            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject       = new TravelExpenseDto();
                fooObject.ApplyDate = DateTime.Now.Date;

                #region 設定該使用者為預設紀錄申請者
                var myUser = myUserService.Items
                             .FirstOrDefault(x => x.Id == appStatus.SystemStatus.UserID);
                if (myUser != null)
                {
                    fooObject.MyUserId   = myUser.Id;
                    fooObject.MyUserName = myUser.Name;
                }
                #endregion

                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudAddAction);
                await navigationService.NavigateAsync("TravelExpenseRecordPage", paras);
            });
            #endregion

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject = SelectedItem.Clone();
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudEditAction);
                await navigationService.NavigateAsync("TravelExpenseRecordPage", paras);
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion

            #region 顯示明細頁面
            ShowDetailCommand = new DelegateCommand <TravelExpenseDto>(async x =>
            {
                #region 讀取該筆明細清單
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    #region 取得 差旅費用明細紀錄
                    fooIProgressDialog.Title = "請稍後,取得 差旅費用明細紀錄";
                    var apiResultssss        = await travelExpenseDetailService.GetAsync(x.Id);
                    if (apiResultssss.Status == true)
                    {
                        await travelExpenseDetailService.WriteToFileAsync();

                        NavigationParameters paras = new NavigationParameters();
                        paras.Add(MagicStringHelper.MasterRecordActionName, x);
                        await navigationService.NavigateAsync("TravelExpenseDetailPage", paras);
                    }
                    else
                    {
                        await DialogHelper.ShowAPIResultIsFailureMessage(dialogService, apiResultssss);
                        return;
                    }
                    #endregion
                }
                #endregion
            });
            #endregion
        }
コード例 #6
0
        public HomePageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                 OnlyAdministratorService OnlyAdministratorService, OnlyUserService OnlyUserService,
                                 RefreshTokenService refreshTokenService,
                                 SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            onlyAdministratorService = OnlyAdministratorService;
            onlyUserService          = OnlyUserService;
            this.refreshTokenService = refreshTokenService;
            this.systemStatusService = systemStatusService;
            this.appStatus           = appStatus;

            #region OnlyAdministratorCommand
            OnlyAdministratorCommand = new DelegateCommand(async() =>
            {
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,執行中...", null, null, true, MaskType.Black))
                {
                    bool fooRefreshTokenResult = await RefreshTokenHelper
                                                 .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                       systemStatusService, appStatus);
                    if (fooRefreshTokenResult == false)
                    {
                        return;
                    }
                    var fooResult = await OnlyAdministratorService.GetAsync();
                    if (fooResult.Status == false)
                    {
                        Message = fooResult.Message;
                    }
                    else
                    {
                        Message = fooResult.Payload.ToString();
                    }
                }
            });
            #endregion
            #region OnlyUserCommand
            OnlyUserCommand = new DelegateCommand(async() =>
            {
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,執行中...", null, null, true, MaskType.Black))
                {
                    bool fooRefreshTokenResult = await RefreshTokenHelper
                                                 .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                       systemStatusService, appStatus);
                    if (fooRefreshTokenResult == false)
                    {
                        return;
                    }
                    var fooResult = await OnlyUserService.GetAsync();
                    if (fooResult.Status == false)
                    {
                        Message = fooResult.Message;
                    }
                    else
                    {
                        Message = fooResult.Payload.ToString();
                    }
                }
            });
            #endregion
            #region 故意拋出例外
            ThrowExceptionrCommand = new DelegateCommand(async() =>
            {
                throw new Exception("魔鬼藏在細節中");
            });
            #endregion
        }
コード例 #7
0
 public LeaveFormDetailPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                     RefreshTokenManager refreshTokenManager,
                                     SystemStatusManager systemStatusManager, AppStatus appStatus,
                                     LeaveFormsManager leaveFormsManager, LeaveFormTypesManager leaveFormTypesManager)
 {
     this.navigationService     = navigationService;
     this.dialogService         = dialogService;
     this.leaveFormsManager     = leaveFormsManager;
     this.leaveFormTypesManager = leaveFormTypesManager;
     SaveCommand = new DelegateCommand(async() =>
     {
         if (IsAddMode == true)
         {
             using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
             {
                 bool fooRefreshTokenResult = await RefreshTokenHelper.CheckAndRefreshToken(dialogService, refreshTokenManager, systemStatusManager, appStatus);
                 if (fooRefreshTokenResult == false)
                 {
                     return;
                 }
                 var fooResult = await leaveFormsManager.PostAsync(new LeaveFormRequestDTO()
                 {
                     id            = 0,
                     BeginTime     = LeaveFormItemModel.BeginDate + LeaveFormItemModel.BeginTime,
                     EndTime       = LeaveFormItemModel.EndDate + LeaveFormItemModel.EndTime,
                     Description   = LeaveFormItemModel.Description,
                     TotalHours    = LeaveFormItemModel.TotalHours,
                     leaveFormType = new LeaveFormTypeDTO()
                     {
                         Id = LeaveFormTypeSelectedItem.Id
                     }
                 });
             }
         }
         else
         {
             using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
             {
                 bool fooRefreshTokenResult = await RefreshTokenHelper.CheckAndRefreshToken(dialogService, refreshTokenManager, systemStatusManager, appStatus);
                 if (fooRefreshTokenResult == false)
                 {
                     return;
                 }
                 var fooResult = await leaveFormsManager.PutAsync(LeaveFormSelectedItem.Id, new LeaveFormRequestDTO()
                 {
                     id            = LeaveFormSelectedItem.Id,
                     BeginTime     = LeaveFormItemModel.BeginDate + LeaveFormItemModel.BeginTime,
                     EndTime       = LeaveFormItemModel.EndDate + LeaveFormItemModel.EndTime,
                     Description   = LeaveFormItemModel.Description,
                     TotalHours    = LeaveFormItemModel.TotalHours,
                     leaveFormType = new LeaveFormTypeDTO()
                     {
                         Id = LeaveFormTypeSelectedItem.Id
                     }
                 });
             }
         }
         var queryString      = "NeedRefresh=true";
         var navigationParams = new NavigationParameters(queryString);
         await navigationService.GoBackAsync(navigationParams);
     });
     DeleteCommand = new DelegateCommand(async() =>
     {
         using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
         {
             bool fooRefreshTokenResult = await RefreshTokenHelper.CheckAndRefreshToken(dialogService, refreshTokenManager, systemStatusManager, appStatus);
             if (fooRefreshTokenResult == false)
             {
                 return;
             }
             var fooResult = await leaveFormsManager.DeleteAsync(LeaveFormSelectedItem.Id);
         }
         var queryString      = "NeedRefresh=true";
         var navigationParams = new NavigationParameters(queryString);
         await navigationService.GoBackAsync(navigationParams);
     });
 }