Beispiel #1
0
        public string Analy()
        {
            var model = _basicDataService.GetBasicData();

            var currentWeight     = model.BodyWeight;
            var currentHeight     = model.Height;
            var bmi               = float.Parse(ViewModelCommonUtil.CulculateBmi(currentHeight, currentWeight).ToString("0.0000"));
            var appropriateWeight = float.Parse(CulculateAppropriate(currentHeight, currentWeight).ToString("0.0000"));
            var difference        = currentWeight - float.Parse(appropriateWeight.ToString("0.0000"));

            var sb = new StringBuilder();

            sb.AppendLine(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat1, model.Height.ToString(), appropriateWeight));
            sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat2, difference, bmi));
            sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat3));
            if (difference > 0)
            {
                sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat4));
                sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat8));
            }
            else
            {
                if (bmi < 18.5)
                {
                    sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat7));
                }
                else
                {
                    sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat5));
                }
            }

            return(sb.ToString());
        }
        /// <summary>
        /// フォトライブラリ選択アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandTakeLibraryAction()
        {
            _takePhotoFromCamera = false;

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Error),
                                                                LanguageUtils.Get(LanguageKeys.PictureLibraryCanNotOpen), LanguageUtils.Get(LanguageKeys.OK));

                return;
            }
            var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
            {
                PhotoSize = PhotoSize.Medium
            });

            if (file == null)
            {
                return;
            }

            BodyImage = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return(stream);
            });

            var imgData = ViewModelCommonUtil.ConvertToByteArrayFromStream(file.GetStream());

            _base64String = Convert.ToBase64String(imgData);
        }
        /// <summary>
        ///     体格画像のロード
        /// </summary>
        public void LoadBodyImage()
        {
            // 表示する体格画像を取得
            var bodyImageModel = BodyImageService.GetBodyImage();

            if (bodyImageModel != null)
            {
                var imageAsBytes = Convert.FromBase64String(bodyImageModel.ImageBase64String);

                BodyImage = ImageSource.FromStream(() =>
                                                   new MemoryStream(ViewModelCommonUtil.GetResizeImageBytes(imageAsBytes, 300, 425)));
                BodyImageRegistedDateString =
                    LanguageUtils.Get(LanguageKeys.RegistedDate) +
                    ViewModelCommonUtil.FormatDateString(bodyImageModel.RegistedDate);
            }
            else
            {
                // 登録されている体格画像がない場合はイメージなし用の画像を表示する
                var imageAsBytes = Convert.FromBase64String(ViewModelConst.NoImageString64);
                BodyImage = ImageSource.FromStream(() =>
                                                   new MemoryStream(ViewModelCommonUtil.GetResizeImageBytes(imageAsBytes, 300, 425)));
                BodyImageRegistedDateString =
                    LanguageUtils.Get(LanguageKeys.RegistedDate) + StringConst.Empty;
            }
        }
        private async Task CommandRegistAction()
        {
            if (_bodyImageService.CheckExitTargetDayData(DateTime.Now))
            {
                var result =
                    await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                    LanguageUtils.Get(LanguageKeys.TodayDataUpdateConfirm), LanguageUtils.Get(LanguageKeys.OK),
                                                                    LanguageUtils.Get(LanguageKeys.Cancel));

                if (result)
                {
                    _bodyImageService.UpdateBodyImage(_id, _base64String);
                }
            }
            else
            {
                _bodyImageService.RegistBodyImage(_base64String);
            }

            if (_takePhotoFromCamera)
            {
                //TODO 確認のダイアログを表示する
                //TODO ViewModelCommonUtilに移動する?
                DependencyService.Get <IImageService>().DeleteImageFile(_filePath);
            }

            // ホーム画面をリロードする
            ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingHomeReload);
            ViewModelCommonUtil.DataBackPage();
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // ViewModel Logic
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region ViewModel Logic

        /// <summary>
        /// エラーラベルを生成します
        /// </summary>
        /// <param name="key"></param>
        /// <param name="errorType"></param>
        /// <returns></returns>
        public Label CreateErrorLabel(string key, string errorType)
        {
            return(new Label
            {
                Text = LanguageUtils.Get(errorType, LanguageUtils.Get(key)),
                TextColor = Color.Red
            });
        }
        /**
         * Set address text into address bar game object
         */
        public void SetAddressBarText(AddressObject buildingAddress)
        {
            if (buildingAddress == null)
            {
                UiUtils.SetText(AddressText, LanguageUtils.Get(StringIds.IdMainSceneUnknownAddress));
                return;
            }

            var addressBarText = buildingAddress.Street + " " + buildingAddress.StreetNumber;

            UiUtils.SetText(AddressText, addressBarText);
        }
        /// <summary>
        ///     トレーニングスケジュール画面遷移
        /// </summary>
        private static void CommandEditTrainingScheduleAction()
        {
            var check = TrainingMasterService.GetTrainingMasterDataList();

            if (check == null || check.Count == 0)
            {
                Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                          LanguageUtils.Get(LanguageKeys.NotExistTraining), LanguageUtils.Get(LanguageKeys.OK));
                return;
            }

            ViewModelConst.TrainingPageNavigation.PushAsync(new TrainingScheduleListView());
        }
        private static void CommandTrainingReportAction()
        {
            var check = TrainingResultService.GeTrainingResultDataList();

            if (check.Count == 0)
            {
                Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                          LanguageUtils.Get(LanguageKeys.NotExistTrainingReport), LanguageUtils.Get(LanguageKeys.OK));
            }
            else
            {
                ViewModelConst.TrainingPageNavigation.PushAsync(new TrainingReportListView());
            }
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        /// カメラ撮影アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandTakeCameraAction()
        {
            _takePhotoFromCamera = true;

            try
            {
                // カメラが有効であるか判定
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Error),
                                                                    LanguageUtils.Get(LanguageKeys.CameraNotAvailable), LanguageUtils.Get(LanguageKeys.OK));

                    return;
                }

                // 画像ファイルの名前を決定
                var fileName = BodyImageNameHead + ViewModelCommonUtil.FormatDateStringWithoutSymbol(DateTime.Now) +
                               BodyImageExtension;
                var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    PhotoSize   = PhotoSize.Medium,
                    Directory   = BodyImageFileDirectory,
                    Name        = fileName,
                    SaveToAlbum = false
                });

                if (file == null)
                {
                    return;
                }

                _filePath = file.Path;

                BodyImage = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return(stream);
                });

                var imgData = ViewModelCommonUtil.ConvertToByteArrayFromStream(file.GetStream());
                _base64String = Convert.ToBase64String(imgData);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
        }
        /// <summary>
        ///  体格遷移画面遷移
        /// </summary>
        public async Task CommandBodyImageListAction()
        {
            var check = BodyImageService.GetBodyImageList();

            if (check == null || check.Count == 0)
            {
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                LanguageUtils.Get(LanguageKeys.NotExistBodyImage), LanguageUtils.Get(LanguageKeys.OK));

                await ViewModelConst.DataPageNavigation.PushAsync(new RegistBodyImageView());
            }
            else
            {
                await ViewModelConst.DataPageNavigation.PushAsync(new BodyImageView());
            }
        }
        /// <summary>
        ///  データチャート画面遷移
        /// </summary>
        public async Task CommandDataChartAction()
        {
            var check = BasicDataService.GetBasicData();

            if (check != null)
            {
                await ViewModelConst.DataPageNavigation.PushAsync(new DataSelectView());
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                LanguageUtils.Get(LanguageKeys.NotExistBasicData), LanguageUtils.Get(LanguageKeys.OK));

                await ViewModelConst.DataPageNavigation.PushAsync(new InputBasicDataView());
            }
        }
Beispiel #12
0
 /// <summary>
 /// 基本データ表示用文字列返却
 /// </summary>
 /// <param name="basicData"></param>
 /// <returns></returns>
 public static string DisplayString(this BasicDataEnum basicData)
 {
     string[] names =
     {
         LanguageUtils.Get(LanguageKeys.Name),
         LanguageUtils.Get(LanguageKeys.Gender),
         LanguageUtils.Get(LanguageKeys.Age),
         LanguageUtils.Get(LanguageKeys.Height),
         LanguageUtils.Get(LanguageKeys.BodyWeight),
         LanguageUtils.Get(LanguageKeys.BodyFatPercentage),
         LanguageUtils.Get(LanguageKeys.MaxBloodPressure),
         LanguageUtils.Get(LanguageKeys.MinBloodPressure),
         LanguageUtils.Get(LanguageKeys.BasicMetabolism),
         LanguageUtils.Get(LanguageKeys.Location)
     };
     return(names[(int)basicData]);
 }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append("\t\t" + LanguageUtils.Get(LanguageKeys.TrainingName) + " : " + TrainingName);
            sb.Append("\n");
            sb.Append("\t\t" + LanguageUtils.Get(LanguageKeys.SetCount) + " : " + TrainingSetCount);
            sb.Append("\n");
            sb.Append("\t\t" + LanguageUtils.Get(LanguageKeys.LoadMethod));
            sb.Append("\n");
            foreach (var loadContentViewStructure in LoadContentList)
            {
                sb.Append("\t\t\t" + loadContentViewStructure.LoadName);
                sb.Append(" : ");
                sb.Append("" + loadContentViewStructure.Nums + " " + loadContentViewStructure.LoadUnitName);
                sb.Append("\n");
            }

            return(sb.ToString());
        }
Beispiel #14
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append((WeekEnum)Week);
            sb.Append("\n");
            if (Off)
            {
                sb.Append(LanguageUtils.Get(LanguageKeys.Rest));
            }
            else
            {
                if (TrainingContentList == null || TrainingContentList.Count == 0)
                {
                    sb.Append("\t" + "未設定");
                    return(sb.ToString());
                }

                foreach (var trainingListViewStructure in TrainingContentList)
                {
                    sb.Append("\t" + LanguageUtils.Get(LanguageKeys.No) + trainingListViewStructure.TrainingNo);
                    sb.Append("\n");
                    sb.Append("\t\t" + LanguageUtils.Get(LanguageKeys.TrainingName) + " : " + trainingListViewStructure.TrainingName);
                    sb.Append("\n");
                    sb.Append("\t\t" + LanguageUtils.Get(LanguageKeys.SetCount) + " : " + trainingListViewStructure.TrainingSetCount);
                    sb.Append("\n");
                    sb.Append("\t\t" + LanguageUtils.Get(LanguageKeys.LoadMethod));
                    sb.Append("\n");
                    foreach (var loadContentViewStructure in trainingListViewStructure.LoadContentList)
                    {
                        sb.Append("\t\t\t" + loadContentViewStructure.LoadName);
                        sb.Append(" : ");
                        sb.Append("" + loadContentViewStructure.Nums + " " + loadContentViewStructure.LoadUnitName);
                        sb.Append("\n");
                    }
                }
            }
            return(sb.ToString());
        }
        /// <summary>
        ///     トレーニング画面遷移
        /// </summary>
        private static void CommandStartTrainingAction()
        {
            var check = TrainingResultService.CheckExitTargetDayData(DateTime.Now);

            if (check)
            {
                Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                          LanguageUtils.Get(LanguageKeys.TodayTrainingAlreadyCompleted), LanguageUtils.Get(LanguageKeys.OK));
            }
            else
            {
                var exits = TrainingScheduleService.GetTrainingSchedule((int)DateTime.Now.DayOfWeek);

                if (exits == null)
                {
                    Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                              LanguageUtils.Get(LanguageKeys.NotSettingTrainingSchedule), LanguageUtils.Get(LanguageKeys.OK));
                }
                else
                {
                    var training = JsonConvert
                                   .DeserializeObject <TrainingScheduleStructure>(
                        TrainingScheduleService.GetTrainingSchedule((int)DateTime.Now.DayOfWeek).TrainingMenu);

                    if (training.Off)
                    {
                        Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                  LanguageUtils.Get(LanguageKeys.TodayIsRest), LanguageUtils.Get(LanguageKeys.OK));
                    }
                    else
                    {
                        ViewModelConst.TrainingPageNavigation.PushAsync(new TrainingView());
                    }
                }
            }
        }
        private async Task CommandCompleteTrainingAction()
        {
            PauseTimer();

            var result =
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                LanguageUtils.Get(LanguageKeys.IsDoneTraining), LanguageUtils.Get(LanguageKeys.OK),
                                                                LanguageUtils.Get(LanguageKeys.Cancel));

            if (result)
            {
                _trainingEndDateTime = DateTime.Now;
                TrainingResultService.RegistTrainingResult(trainingContent: JsonConvert.SerializeObject(_trainingScheduleSViewtructure), weather: null,
                                                           targetDate: _pageOpenDateTime, startDate: _trainingStartDateTime, endDate: _trainingEndDateTime);

                // 遷移元画面をリロードする
                ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingHomeReload);
                await ViewModelConst.TrainingPageNavigation.PopAsync();
            }
            else
            {
                _timer.Start();
            }
        }
        /**
         * Set version number into label in Settings
         */
        public static void SetVersion()
        {
            var versionText = LanguageUtils.Get(StringIds.IdSettingsVersionInfo);

            UiUtils.SetText("InfoVersionText", versionText + Version);
        }
        private async Task CommandSaveAction()
        {
            try
            {
                if (!Validate())
                {
                    ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingSelfScroll);
                    return;
                }

                IsLoading = true;
                var trainingContentList = new List <TrainingListStructure>();

                if (!Off)
                {
                    // トレーニング一覧
                    var trainingStack = TrainingStack.Children;
                    foreach (var training in trainingStack)
                    {
                        var insert     = new TrainingListStructure();
                        var trainingId =
                            ((TrainingMasterModel)((Picker)((StackLayout)training).Children[1]).SelectedItem).Id;
                        var trainingseCount = ((Entry)((StackLayout)training).Children[3]).Text;

                        var loadContentList = new List <LoadContentStructure>();
                        var loadStack       = ((StackLayout)((StackLayout)training).Children[4]).Children;
                        foreach (var load in loadStack)
                        {
                            var insertload = new LoadContentStructure();
                            var subLoad    = ((StackLayout)load).Children[1];
                            var loadId     = ((LoadUnitModel)((Picker)((StackLayout)subLoad).Children[1]).SelectedItem)
                                             .LoadId;
                            var nums       = ((Entry)((StackLayout)subLoad).Children[0]).Text;
                            var loadUnitId =
                                ((LoadUnitModel)((Picker)((StackLayout)subLoad).Children[1]).SelectedItem).Id;
                            insertload.LoadId     = loadId;
                            insertload.LoadUnitId = loadUnitId;
                            insertload.Nums       = float.Parse(nums);
                            loadContentList.Add(insertload);
                        }

                        insert.LoadContentList  = loadContentList;
                        insert.TrainingId       = trainingId;
                        insert.TrainingSetCount = int.Parse(trainingseCount);
                        trainingContentList.Add(insert);
                    }
                }

                var trainingScheduleStructure =
                    new TrainingScheduleStructure
                {
                    TrainingContentList = trainingContentList,
                    Off  = Off,
                    Week = _week
                };

                var trainingScheduleStructureJson = JsonConvert.SerializeObject(trainingScheduleStructure);

                if (_isUpdate)
                {
                    TrainingScheduleService.UpdateTrainingSchedule(_id, trainingScheduleStructureJson,
                                                                   _week);
                }
                else
                {
                    TrainingScheduleService.RegistTrainingSchedule(trainingScheduleStructureJson,
                                                                   _week);
                }

                IsLoading = false;

                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete),
                                                                LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK));

                // ホーム画面をリロードする
                ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingPrevPageReload);
                ViewModelCommonUtil.TrainingBackPage();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
        public void CommandAddTrainingAction(TrainingListStructure training)
        {
            var mainStack     = new StackLayout();
            var trainingLabel = new Label
            {
                Text           = LanguageUtils.Get(LanguageKeys.TrainingName),
                FontAttributes = FontAttributes.Bold,
                Margin         = new Thickness(0, 20, 0, 0)
            };

            mainStack.Children.Add(trainingLabel);
            var trainingPicker = new Picker
            {
                ItemsSource        = TrainingMasterService.GetTrainingMasterDataList(),
                ItemDisplayBinding = new Binding("TrainingName"),
                SelectedIndex      = 0
            };

            mainStack.Children.Add(trainingPicker);

            var trainingSetCountLabel = new Label
            {
                Text           = LanguageUtils.Get(LanguageKeys.SetCount),
                FontAttributes = FontAttributes.Bold,
                Margin         = new Thickness(0, 0, 0, 0)
            };

            mainStack.Children.Add(trainingSetCountLabel);

            var trainingSetCountEntry =
                new Entry {
                Text = training.TrainingSetCount.ToString(), Keyboard = Keyboard.Numeric
            };

            mainStack.Children.Add(trainingSetCountEntry);

            var trainingLoadStack = new StackLayout();


            trainingPicker.SelectedItem =
                ((List <TrainingMasterModel>)trainingPicker.ItemsSource).First(data => data.Id == training.TrainingId);

            foreach (var load in training.LoadContentList)
            {
                var loadModdel = LoadService.GetLoad(load.LoadId);

                var loadStack = new StackLayout();
                loadStack.Children.Add(new Label
                {
                    Text           = loadModdel.LoadName,
                    FontAttributes = FontAttributes.Bold,
                    Margin         = new Thickness(0, 0, 0, 0)
                });

                var subLoadStack = new StackLayout {
                    Orientation = StackOrientation.Horizontal
                };
                subLoadStack.Children.Add(new Entry
                {
                    Text         = load.Nums.ToString(),
                    Keyboard     = Keyboard.Numeric,
                    WidthRequest = 145
                });
                var loadUnitPick = new Picker
                {
                    ItemsSource        = LoadUnitService.GetLoadUnitList(load.LoadId),
                    ItemDisplayBinding = new Binding("UnitName"),
                    SelectedIndex      = 0,
                    WidthRequest       = 145
                };
                loadUnitPick.SelectedItem =
                    ((List <LoadUnitModel>)loadUnitPick.ItemsSource).First(data => data.Id == load.LoadUnitId);

                subLoadStack.Children.Add(loadUnitPick);

                loadStack.Children.Add(subLoadStack);
                trainingLoadStack.Children.Add(loadStack);
            }

            trainingPicker.SelectedIndexChanged += (sender, args) =>
            {
                trainingLoadStack.Children.Clear();
                var loadList =
                    JsonConvert.DeserializeObject <LoadStructure>(((TrainingMasterModel)trainingPicker.SelectedItem)
                                                                  .Load);
                foreach (var load in loadList.LoadList)
                {
                    var loadStack = new StackLayout();
                    loadStack.Children.Add(new Label
                    {
                        Text           = load.LoadName,
                        FontAttributes = FontAttributes.Bold,
                        Margin         = new Thickness(0, 0, 0, 0)
                    });

                    var subLoadStack = new StackLayout {
                        Orientation = StackOrientation.Horizontal
                    };
                    subLoadStack.Children.Add(new Entry {
                        Keyboard = Keyboard.Numeric, WidthRequest = 145
                    });
                    subLoadStack.Children.Add(new Picker
                    {
                        ItemsSource        = LoadUnitService.GetLoadUnitList(load.Id),
                        ItemDisplayBinding = new Binding("UnitName"),
                        SelectedIndex      = 0,
                        WidthRequest       = 145
                    });
                    loadStack.Children.Add(subLoadStack);
                    trainingLoadStack.Children.Add(loadStack);
                }
            };

            mainStack.Children.Add(trainingLoadStack);
            TrainingStack.Children.Add(mainStack);
        }
        /**
         * Set touch listener for SpaceBar/A key
         */
        private void SetSpaceBarKeyListener(GameObject buildingPickerCanvas, GameObject exitCanvasDialog, Text buildingNameLabel)
        {
            if (!ControlUtils.ConfirmAction())
            {
                return;
            }

            //exit of scene
            if (exitCanvasDialog.activeSelf)
            {
                FileUtils.CheckSaveFolder();
                Main.Map.Save();
                //todo wait, ukazat vysledek a pak vykonat zbytek
                ReturnToPreviousScene();
                return;
            }

            //hide building picker
            //load object
            if (buildingPickerCanvas.activeSelf)
            {
                var loadObjectIEnumerator = LoadObjectFromDisk(
                    resourceBuildings[indexResourceList],
                    Main.Settings.StorageType,
                    BuildingPlacer.GetMousePos(),
                    BuildingPlacer.customObjectSize,
                    RotationDefault,
                    true
                    );
                StartCoroutine(loadObjectIEnumerator);
                buildingPickerCanvas.SetActive(false);
                return;
            }

            //show building picker
            if (BuildingPlacer.customObject == null && !BuildingPlacer.putted)
            {
                var        directoryInfo = new DirectoryInfo(FileUtils.GetFullCustomObjectPath());
                FileInfo[] info          = directoryInfo.GetFiles("*.*");
                var        fileNames     = new List <string>();
                foreach (var fileInfo in info)
                {
                    if (!fileInfo.Name.EndsWith(".meta"))
                    {
                        fileNames.Add(fileInfo.Name);
                    }
                }

                if (fileNames.Count != 0)
                {
                    buildingPickerCanvas.SetActive(true);
                    resourceBuildings      = fileNames.ToArray();
                    indexResourceList      = 0;
                    buildingNameLabel.text = resourceBuildings[indexResourceList];
                }
                //show message -- empty 3DObjects folder
                else
                {
                    AddressBackground.SetActive(true);
                    AddressText.SetActive(true);
                    UiUtils.SetText(AddressText, LanguageUtils.Get(StringIds.IdMainSceneEmpty3DFolder));
                }
            }
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        ///     トレーニング保存アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandSaveAction()
        {
            try
            {
                if (!ValidationInputData(TrainingName))
                {
                    ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingSelfScroll);
                    return;
                }

                IsLoading = true;

                var partStructureList = new List <PartStructure>();
                PartStack.Children.ForEach(child =>
                {
                    var stack        = (StackLayout)child;
                    var partModel    = ((PartModel)((Picker)stack.Children[0]).SelectedItem);
                    var subPartModel = ((SubPartModel)((Picker)stack.Children[1]).SelectedItem);

                    if (!partStructureList.Any(
                            data => data.Part.Id == partModel.Id && data.SubPart.Id == subPartModel.Id))
                    {
                        partStructureList.Add(new PartStructure
                        {
                            Part    = partModel,
                            SubPart = subPartModel
                        });
                    }
                });

                var loadList = new List <LoadModel>();
                LoadStack.Children.ForEach(child =>
                {
                    var stack     = (StackLayout)child;
                    var loadModel = ((LoadModel)((Picker)stack.Children[0]).SelectedItem);
                    if (loadList.All(data => data.Id != loadModel.Id))
                    {
                        loadList.Add(loadModel);
                    }
                });

                var loadStructure = new LoadStructure {
                    LoadList = loadList
                };

                if (_targetTrainingMasterModel != null)
                {
                    TrainingMasterService.UpdateTrainingMaster(
                        _targetTrainingMasterModel.Id,
                        TrainingName,
                        JsonConvert.SerializeObject(loadStructure),
                        JsonConvert.SerializeObject(partStructureList));
                }
                else
                {
                    TrainingMasterService.RegistTrainingMaster(
                        TrainingName,
                        JsonConvert.SerializeObject(loadStructure),
                        JsonConvert.SerializeObject(partStructureList));
                }

                IsLoading = false;

                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete),
                                                                LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK));

                // ホーム画面をリロードする
                ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingPrevPageReload);
                ViewModelCommonUtil.TrainingBackPage();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Beispiel #22
0
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        ///  基本データ保存アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandSaveAction()
        {
            try
            {
                if (!ValidationInputData(Name, Gender, Height,
                                         BodyWeight, BodyFatPercentage,
                                         MaxBloodPressure,
                                         MinBloodPressure, BasalMetabolism))
                {
                    ScrollRequest = ScrollRequest.SendScrollRequest(ScrollRequestType.RequestTypeToTop);
                    return;
                }

                IsLoading = true;
                if (_basicDataService.CheckExitTargetDayData(DateTime.Now))
                {
                    var result =
                        await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                        LanguageUtils.Get(LanguageKeys.TodayDataUpdateConfirm), LanguageUtils.Get(LanguageKeys.OK),
                                                                        LanguageUtils.Get(LanguageKeys.Cancel));

                    if (result)
                    {
                        _basicDataService.UpdateBasicData(_id, Name, 1, Gender, height: Height, birthday: Birthday,
                                                          bodyWeight: BodyWeight, bodyFatPercentage: BodyFatPercentage,
                                                          maxBloodPressure: MaxBloodPressure,
                                                          minBloodPressure: MinBloodPressure, basalMetabolism: BasalMetabolism);
                    }
                    else
                    {
                        IsLoading = false;
                        return;
                    }
                }
                else
                {
                    _basicDataService.RegistBasicData(Name, 1, Gender, height: Height, birthday: Birthday,
                                                      bodyWeight: BodyWeight, bodyFatPercentage: BodyFatPercentage,
                                                      maxBloodPressure: MaxBloodPressure,
                                                      minBloodPressure: MinBloodPressure, basalMetabolism: BasalMetabolism);
                }

                IsLoading = false;
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete),
                                                                LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK));

                if (_isUpdate)
                {
                    // ホーム画面をリロードする
                    ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingHomeReload);
                    ViewModelCommonUtil.DataBackPage();
                }
                else
                {
                    ViewModelCommonUtil.BackHome();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }