예제 #1
0
        public MainPageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;

            MyTaskRefreshCommand = new DelegateCommand(() =>
            {
                RefreshIndex++;
                MyTaskItemList.Clear();
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = $"{RefreshIndex} {item.MyTaskName}",
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
                RefreshingStatus = false;
            });

            MyTaskItemSelectedCommand = new DelegateCommand(async() =>
            {
                var fooPara = new NavigationParameters();
                fooPara.Add("Record", MyTaskItemSelected.Clone());
                await _navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });
        }
예제 #2
0
        public MainPageViewModel(INavigationService navigationService, IPageDialogService dialogService)
        {
            this.navigationService    = navigationService;
            this.dialogService        = dialogService;
            MyTaskItemSelectedCommand = new DelegateCommand(async() =>
            {
                //await _dialogService.DisplayAlertAsync("Info", $"你選取的是 {MyTaskItemSelected.MyTaskName}", "OK");

                NavigationParameters fooPara = new NavigationParameters();
                fooPara.Add("MyTaskItem", MyTaskItemSelected.Clone());
                fooPara.Add("Mode", "Edit");
                await navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });

            MyTaskRefreshCommand = new DelegateCommand(() =>
            {
                RefreshIndex++;
                MyTaskItemList.Clear();
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = $"{RefreshIndex} {item.MyTaskName}",
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
                RefreshingStatus = false;
            });
        }
예제 #3
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     if (parameters.GetNavigationMode() == NavigationMode.New)
     {
         MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
         var fooTasks = fooMyTaskRepository.GetMyTask();
         foreach (var item in fooTasks)
         {
             MyTaskItemList.Add(new MyTaskItem
             {
                 MyTaskName   = item.MyTaskName,
                 MyTaskDate   = item.MyTaskDate,
                 MyTaskStatus = item.MyTaskStatus,
             });
         }
     }
     else
     {
         if (parameters.ContainsKey("Mode"))
         {
             string TaskMode  = parameters.GetValue <string>("Mode");
             var    fooObject = parameters.GetValue <MyTaskItem>("MyTaskItem");
             var    index     = MyTaskItemList.IndexOf(MyTaskItemList.FirstOrDefault(x => x.MyTaskName == fooObject.MyTaskName));
             if (TaskMode == "Update")
             {
                 MyTaskItemList[index] = fooObject;
             }
             else
             {
                 MyTaskItemList.RemoveAt(index);
             }
         }
     }
 }
예제 #4
0
        public void OnNavigatedTo(NavigationParameters parameters)
        {
            if (parameters.ContainsKey("Action"))
            {
                string action = parameters["Action"] as string;
                var    fooObj = parameters["ActionRec"] as MyTaskItem;

                switch (action)
                {
                case "D":
                    var bar = MyTaskItemList.FirstOrDefault(x => x.MyTaskName == fooObj.MyTaskName);
                    if (bar != null)
                    {
                        MyTaskItemList.Remove(bar);
                    }
                    break;

                case "S":
                    var barS = MyTaskItemList.FirstOrDefault(x => x.MyTaskName == fooObj.MyTaskName);
                    if (barS != null)
                    {
                        barS.MyTaskName   = fooObj.MyTaskName;
                        barS.MyTaskStatus = fooObj.MyTaskStatus;
                        barS.MyTaskDate   = fooObj.MyTaskDate;
                    }
                    break;

                case "A":
                    MyTaskItemList.Insert(0, fooObj);
                    break;

                default:
                    break;
                }
            }
            if (MyTaskItemList.Count == 0)
            {
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = item.MyTaskName,
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
            }
        }
예제 #5
0
        public void OnNavigatedTo(NavigationParameters parameters)
        {
            MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
            var fooTasks = fooMyTaskRepository.GetMyTask();

            foreach (var item in fooTasks)
            {
                MyTaskItemList.Add(new MyTaskItem
                {
                    MyTaskName   = item.MyTaskName,
                    MyTaskDate   = item.MyTaskDate,
                    MyTaskStatus = item.MyTaskStatus,
                });
            }
        }
예제 #6
0
        public MainPageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;

            MyTaskRefreshCommand = new DelegateCommand(() =>
            {
                RefreshIndex++;
                MyTaskItemList.Clear();
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = $"{RefreshIndex} {item.MyTaskName}",
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
                RefreshingStatus = false;
            });

            MyTaskItemSelectedCommand = new DelegateCommand(async() =>
            {
                var fooPara = new NavigationParameters();
                fooPara.Add("Record", MyTaskItemSelected.Clone());
                fooPara.Add("Action", "S");
                await _navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });
            AddCommand = new DelegateCommand(async() =>
            {
                var fooPara = new NavigationParameters();
                fooPara.Add("Record", new MyTaskItem()
                {
                    MyTaskName = "請輸入工作名稱"
                });
                fooPara.Add("Action", "A");
                await _navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });
            DeleteCommand = new DelegateCommand <MyTaskItem>(x =>
            {
                var fooEditTask = MyTaskItemList.FirstOrDefault(s => s.MyTaskName == x.MyTaskName);
                if (fooEditTask != null)
                {
                    MyTaskItemList.Remove(fooEditTask);
                }
            });
        }
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     if (parameters.GetNavigationMode() == NavigationMode.New)
     {
         MyTaskRepository repository = new MyTaskRepository();
         var tasks = repository.GetMyTask();
         foreach (var item in tasks)
         {
             MyTaskItemList.Add(item);
         }
     }
     else
     {
         if (parameters.ContainsKey("Mode"))
         {
             var        Mode = parameters.GetValue <string>("Mode");
             MyTaskItem item = parameters
                               .GetValue <MyTaskItem>("MyTaskSelectedItem");
             if (Mode == "修改")
             {
                 MyTaskItem UpdateRecore =
                     MyTaskItemList
                     .FirstOrDefault(x => x.MyTaskName == item.MyTaskName);
                 if (UpdateRecore != null)
                 {
                     UpdateRecore.MyTaskDate   = item.MyTaskDate;
                     UpdateRecore.MyTaskStatus = item.MyTaskStatus;
                 }
             }
             if (Mode == "刪除")
             {
                 MyTaskItem DeleteRecore =
                     MyTaskItemList
                     .FirstOrDefault(x => x.MyTaskName == item.MyTaskName);
                 if (DeleteRecore != null)
                 {
                     MyTaskItemList.Remove(DeleteRecore);
                 }
             }
             if (Mode == "新增")
             {
                 MyTaskItemList.Insert(0, item);
             }
         }
     }
 }
 public MainPageViewModel(INavigationService navigationService)
 {
     this.navigationService = navigationService;
     ItemSelectedCommand    = new DelegateCommand(() =>
     {
         NavigationParameters para = new NavigationParameters();
         para.Add("MyTaskSelectedItem", MyTaskSelectedItem.Clone());
         navigationService.NavigateAsync("DetailPage", para);
     });
     RefreshCommand = new DelegateCommand(() =>
     {
         IsRefreshing = true;
         MyTaskRepository repository = new MyTaskRepository();
         var tasks = repository.GetMyTask();
         foreach (var item in tasks)
         {
             MyTaskItemList.Add(item);
         }
         IsRefreshing = false;
     });
     AddCommand = new DelegateCommand(OnAddCommand);
 }
예제 #9
0
        public MainPageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;

            MyTaskRefreshCommand = new DelegateCommand(() =>
            {
                RefreshIndex++;
                MyTaskItemList.Clear();
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = $"{RefreshIndex} {item.MyTaskName}",
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
                RefreshingStatus = false;
            });
        }
예제 #10
0
        public MainPageViewModel(IPageDialogService dialogService, INavigationService navigationService,
                                 IEventAggregator eventAggregator)
        {
            _eventAggregator   = eventAggregator;
            _navigationService = navigationService;
            _dialogService     = dialogService;

            MyTaskItemSelectedCommand = new DelegateCommand(async() =>
            {
                //await _dialogService.DisplayAlertAsync("Info", $"你選取的是 {MyTaskItemSelected.MyTaskName}", "OK");

                NavigationParameters fooPara = new NavigationParameters();

                // 為什麼這裡需要做 MemberwiseClone,不做,會有甚麼影響
                fooPara.Add("MyTaskItem", MyTaskItemSelected.Clone() as MyTaskItem);
                fooPara.Add("Mode", "Edit");
                await _navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });

            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters fooPara = new NavigationParameters();
                fooPara.Add("Mode", "Add");
                await _navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });

            MyTaskRefreshCommand = new DelegateCommand(() =>
            {
                RefreshIndex++;
                MyTaskItemList.Clear();
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = $"{RefreshIndex} {item.MyTaskName}",
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
                RefreshingStatus = false;
            });

            _eventAggregator.GetEvent <MyTaskItemEvent>().Subscribe(x =>
            {
                var fooEditTask = MyTaskItemList.FirstOrDefault(s => s.MyTaskName == x.MyTaskItemSelected.MyTaskName);
                if (x.TaskMode == "Edit")
                {
                    if (fooEditTask != null)
                    {
                        fooEditTask.MyTaskDate   = x.MyTaskItemSelected.MyTaskDate;
                        fooEditTask.MyTaskStatus = x.MyTaskItemSelected.MyTaskStatus;
                    }
                }
                else if (x.TaskMode == "Delete")
                {
                    if (fooEditTask != null)
                    {
                        MyTaskItemList.Remove(fooEditTask);
                    }
                }
                else
                {
                    MyTaskItemList.Insert(0, x.MyTaskItemSelected);
                }
            });
        }