Beispiel #1
0
        private async void Application_StartupAsync(object sender, StartupEventArgs e)
        {
            if (!mutex.WaitOne(0, false))
            {
                MessageBox.Show("食材管理アプリは既に起動しています。", "二重起動防止", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                mutex.Close();
                mutex = null;
                this.Shutdown();
            }
            // food
            var folder       = ApplicationData.Current.LocalFolder;
            var foodDataPath = System.IO.Path.Combine(folder.Path, "food_data.json");

            if (File.Exists(foodDataPath) == false)
            {
                StorageFile result = await folder.CreateFileAsync("food_data.json");
            }
            //var folder = System.Windows.Storage.ApplicationData.Current.LocalFolder;

            // 食材データを読み込む(既定値はfood_composition.json)
            var ins           = FoodShelfModel.GetInstance();
            var isLoadSuccess = await ins.LoadAsync();

            if (isLoadSuccess == false)
            {
                Application.Current.Shutdown();
            }

            // 食品成分表の読み込みを行う(既定値food_composition_japanese.json)
            string hoge = MVVM_Refregator.Properties.Resources.food_composition_japanese;

            //Assembly assembly = Assembly.GetExecutingAssembly();
            //assembly.GetManifestResourceStream("MVVM_Refregator.App.food_composition_japanese.json");
            //AnalysisPageModel.GetInstance().LoadFoodComposition();
            AnalysisPageModel.GetInstance().LoadFoodComposition((string x) => x, hoge);

            if (this.canNotification)
            {
                if (ins.FoodCollection.Any(x => x.HasUsed == false && x.LimitDate.Date == DateTime.Today.Date))
                {
                    this._notificationManager.Show(this._notificationContent, expirationTime: TimeSpan.FromSeconds(4));
                }
                else if (ins.FoodCollection.Any(x => x.HasUsed == false && x.LimitDate.Date <= DateTime.Today.Date.AddDays(7).Date&& x.LimitDate.Date >= DateTime.Today))
                {
                    this._notificationManager.Show(this.oneDayLimitContent, expirationTime: TimeSpan.FromSeconds(4));
                }
            }

            // Viewの起動
            var view = new StartupWindow();

            view.ShowDialog();

            // Notification消すため
            Application.Current.Shutdown();
        }
        //public ReactiveCommand Send_AddFood { get; }

        /// <summary>
        /// modelを渡したときのctor
        /// </summary>
        public FoodShelfViewModel()
        {
            this._foodShelfModel = FoodShelfModel.GetInstance();
            // FoodCollectionの変更を現行スレッドで即時反映させる
            this.Foods = this._foodShelfModel.FoodCollection
                         .ToReadOnlyReactiveCollection(_foodShelfModel.FoodCollection.ToCollectionChanged(), System.Reactive.Concurrency.Scheduler.CurrentThread)
                         .AddTo(this.Disposable);
            // CollectionChanged時にPropertyChangedを強制的に呼び出す
            _foodShelfModel.FoodCollection.CollectionChangedAsObservable().Subscribe(x => RaisePropertyChanged(nameof(Foods)));

            //this.FutureFoods = new ObservableCollection<FoodModel>(this.Foods.Where(x => x.LimitDate.Date >= DateTime.Today.Date && !x.HasUsed));
            this.FutureFoods = new ObservableCollection <FoodModel>(this.Foods.Where(x => !x.HasUsed));
        }
Beispiel #3
0
 public StartupViewModel()
 {
     this._model = FoodShelfModel.GetInstance();
     InitProperty();
 }
Beispiel #4
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="model"></param>
        public EditPageViewModel()
        {
            // FoodShelfModel関係
            this._foodShelfModel = FoodShelfModel.GetInstance();
            this.Foods           = this._foodShelfModel.FoodCollection
                                   .ToReadOnlyReactiveCollection(_foodShelfModel.FoodCollection.ToCollectionChanged(), System.Reactive.Concurrency.Scheduler.CurrentThread)
                                   .AddTo(this.Disposable);

            this._foodShelfModel.FoodCollection.CollectionChangedAsObservable().Subscribe(x =>
            {
                switch (x.Action)
                {
                // 食材追加時
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    foreach (FoodModel food in x.NewItems)
                    {
                        food.PropertyChanged += this.Afood_PropertyChanged;
                    }
                    break;

                // 食材削除時
                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    foreach (FoodModel food in x.OldItems)
                    {
                        food.PropertyChanged -= this.Afood_PropertyChanged;
                    }
                    break;

                // 食材置き換え時
                case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                    foreach (FoodModel food in x.OldItems)
                    {
                        food.PropertyChanged -= this.Afood_PropertyChanged;
                    }
                    foreach (FoodModel food in x.NewItems)
                    {
                        food.PropertyChanged += this.Afood_PropertyChanged;
                    }
                    break;

                // 食材移動時
                case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                    break;

                // 食材リセット時
                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    foreach (var food in this._foodShelfModel.FoodCollection)
                    {
                        food.PropertyChanged -= this.Afood_PropertyChanged;
                    }
                    break;

                default:
                    break;
                }
            });

            foreach (var afood in this._foodShelfModel.FoodCollection)
            {
                afood.PropertyChanged += this.Afood_PropertyChanged;
            }

            // WorkStepModel関係
            this._workStepModel = WorkStepModel.GetInstance();
            this.WorkSteps      = this._workStepModel.ObserveProperty(x => x.CurrentWorkSteps).ToReactiveProperty().AddTo(this.Disposable);

            // スタンバイモードでなければスタンバイモードに変更する
            if (this._workStepModel.CurrentWorkStepsType != WorkType.StandBy)
            {
                this._workStepModel.SetStandBy();
            }

            // 選択食材プロパティの購読
            //this.SelectedFood.Subscribe((_) =>
            //{
            //    this.IsSelectedFood.Value = this.SelectedFood?.Value != null;
            //});
            this.IsSelectedFood = this.SelectedFood.Select(x => x != null).ToReactiveProperty().AddTo(this.Disposable);

            // 現在の作業の種類プロパティの購読
            this.CurrentWorkStepsType = this._workStepModel.ObserveProperty(m => m.CurrentWorkStepsType).ToReactiveProperty().AddTo(this.Disposable);
            this.ButtonVisibility     = this.CurrentWorkStepsType.Select(x => x == WorkType.StandBy).ToReactiveProperty().AddTo(this.Disposable);
            this.WorkLoadVisibility   = this.CurrentWorkStepsType.Select(x => x != WorkType.StandBy).ToReactiveProperty().AddTo(this.Disposable);

            // 最後のステップ判定プロパティの購読
            this.IsLastStep = this._workStepModel.ObserveProperty(x => x.IsLastStep).ToReactiveProperty().AddTo(this.Disposable);

            this.NextContent = this.CurrentWorkStepsType.CombineLatest(this.IsLastStep, (currentWorkStepsType, isLastStep) =>
            {
                if (isLastStep == false)
                {
                    return("進む");
                }
                switch (currentWorkStepsType)
                {
                case WorkType.Create:
                    return("登録");

                case WorkType.Update:
                    return("変更");

                case WorkType.Delete:
                    return("削除");

                case WorkType.Use:
                    return("使用済");

                case WorkType.None:
                case WorkType.StandBy:
                default:
                    return("---");
                }
            }).ToReactiveProperty().AddTo(this.Disposable);

            // 登録コマンドの購読
            this.Send_NavigateRegister.Subscribe((x) =>
            {
                if (x is NavigationService navigation)
                {
                    this._workStepModel.NavigateAddWork(navigation);
                }
            });

            // 変更コマンドの購読
            this.Send_ModifyFood.Subscribe((x) =>
            {
                if (x is NavigationService navigation)
                {
                    if (this.SelectedFood.Value != null)
                    {
                        this._workStepModel.NavigateUpdateWork(this.SelectedFood.Value, navigation);
                    }
                }
            });

            // 削除コマンドの購読
            this.Send_RemoveFood.Subscribe((x) =>
            {
                if (x is NavigationService navigation)
                {
                    if (this.SelectedFood.Value != null)
                    {
                        this._workStepModel.NavigateDeleteWork(this.SelectedFood.Value, navigation);
                    }
                }
            });

            // 使用コマンドの購読
            this.Send_SetUsed.Subscribe((x) =>
            {
                if (x is NavigationService navigation)
                {
                    if (this.SelectedFood.Value != null)
                    {
                        this._workStepModel.NavigateUseWork(this.SelectedFood.Value, navigation);
                    }
                }
            });

            // 次へコマンドの購読
            this.Send_NextStep.Subscribe(async(navigationService) =>
            {
                if (navigationService is NavigationService navigation)
                {
                    await this._workStepModel.NextStepAsync(navigation);
                }
            });

            // 戻るコマンドの購読
            this.Send_PrevStep.Subscribe((namevigationService) =>
            {
                if (namevigationService is NavigationService navigation)
                {
                    this._workStepModel.PrevStep(navigation);
                }
            });
        }