private void CreateWorkoutForYussuf() //NYI { //show a button that will cancel the workout routine //Variables set up. These will need to be user input via a dialog int numberOfExercises = 2; MuscleGroupEnum muscleGroup = MuscleGroupEnum.Abs; bool highRep = true; //this guy is for high reps low weight, or low reps high weight List <ExerciseItem> exercisesByGroup = AllExerciseItems.Where(x => x.MuscleGroup == muscleGroup).ToList(); if (numberOfExercises > exercisesByGroup.Count) { throw new Exception("There are not enough exercises in the selected group to make a routine of the requested size"); //Handle this a bit better, possibly from within the dialog itself } Random rnd = new Random(); List <ExerciseItem> workoutExercises = exercisesByGroup.OrderBy(x => rnd.Next()).Take(numberOfExercises).ToList(); //this works, but also has the possiblity to get the same item twice, we dont really want that. or do we? List <ExerciseItem> tempStoredExercises = ExerciseItemsToDo.ToList(); //this isnt a permanent solution as temporarily storing things like this means it wont get saved on app close which is rather frustrating. Best action would be to create a new table in the db to store these //At this point we need to figure out the starting weights foreach (ExerciseItem ex in workoutExercises) { //show some dialog to get the starting weight //for now just use the given weight as the starting weight. } ExerciseItemsToDo.Clear(); //remove the old list. Its ok though, it should be stored ;) for (int i = 0; i < numberOfExercises; i++) { } }
private void ShowEditRosterDialog() { var dialogViewModel = new EditRosterViewModel(AllExerciseItems); List <ExerciseItem> temp = AllExerciseItems.ToList(); bool?success = dialogService.ShowDialog <EditRosterView>(this, dialogViewModel); if (success == true) { ExerciseItemsToDo.Clear(); foreach (var rosterItem in dialogViewModel.RosterItems) { ExerciseItem exerciseItem = temp.FirstOrDefault(x => x.GUIDID == rosterItem.GUIDID); exerciseItem.IsUsedInRoster = rosterItem.IsUsedInRoster; dataStore.UpdateIsUsedInRoster(exerciseItem); RaisePropertyChangedEvent("IsUsedInRoster"); if (!temp.Contains(exerciseItem)) { exerciseItem.DueTime = DateTime.Now; } if (exerciseItem.IsUsedInRoster) { ExerciseItemsToDo.Add(exerciseItem); } } RebuildList(); } else //revert it to the way it was { } }
private void LoadExerciseList() { try { //Need to fix the data store to cope when there are new columns added to existing db AllExerciseItems = dataStore.LoadAllExerciseItems(); foreach (ExerciseItem item in AllExerciseItems) { item.MarkExerciseCompletedChanged += OnMarkExerciseCompletedChanged; //attach all the handlers regardless. it should make things a bit easier later on item.DeleteExercise += OnDeleteExercise; item.EditExericse += OnEditExercise; if (item.IsUsedInRoster) { ExerciseItemsToDo.Add(item); } } RebuildList(); OnUpdateTimerTick(null, null); //first time fire to update everything on load } catch (Exception ex) { if (ex is System.IO.DirectoryNotFoundException || ex is System.IO.FileNotFoundException) { Debug.WriteLine("No Exercise Item List found in: " + rootProgramDirectory); } else { throw; } } }
private void OnDeleteExercise(object sender, EventArgs e) { ExerciseItem itemToDelete = sender as ExerciseItem; ExerciseItemsToDo.Remove(itemToDelete); AllExerciseItems.Remove(itemToDelete); dataStore.DeleteExercise(itemToDelete); RebuildList(); }
private void RebuildList() { List <ExerciseItem> temp = ExerciseItemsToDo.OrderBy(x => x.DueTime).ToList(); ExerciseItemsToDo.Clear(); foreach (var item in temp) { ExerciseItemsToDo.Add(item); } }
private void ShowCreateExerciseDialog() { var dialogViewModel = new CreateExerciseViewModel(); bool?success = dialogService.ShowDialog <CreateExerciseView>(this, dialogViewModel); DateTime today = DateTime.Today; if (success == true) { if (dialogViewModel.ItemToAdd.IsDailyRecurrence) { dialogViewModel.ItemToAdd.DueTime = today; } else if (dialogViewModel.ItemToAdd.IsWeeklyRecurrence) { // The (... + 7) % 7 ensures we end up with a value in the range [0, 6] int requiredDueDay = ((int)dialogViewModel.ItemToAdd.WeeklyRecurrenceDay - (int)today.DayOfWeek + 7) % 7; dialogViewModel.ItemToAdd.DueTime = today.AddDays(requiredDueDay); } else if (dialogViewModel.ItemToAdd.IsMonthlyRecurrence) { int requiredDueMonth = ((int)dialogViewModel.ItemToAdd.MonthlyRecurrenceDay - (int)today.Month + DateTime.DaysInMonth(today.Year, today.Month)) % DateTime.DaysInMonth(today.Year, today.Month); dialogViewModel.ItemToAdd.DueTime = today.AddDays(requiredDueMonth + 1); //dont ask me why i need a plus 1. I dont know } AllExerciseItems.Add(dialogViewModel.ItemToAdd); dataStore.AddExercise(dialogViewModel.ItemToAdd); SaveExerciseList(); if (dialogViewModel.ItemToAdd.IsUsedInRoster) { dialogViewModel.ItemToAdd.MarkExerciseCompletedChanged += OnMarkExerciseCompletedChanged; //check that you dont need to explicitly unsub when this item is removed dialogViewModel.ItemToAdd.EditExericse += OnEditExercise; dialogViewModel.ItemToAdd.DeleteExercise += OnDeleteExercise; ExerciseItemsToDo.Add(dialogViewModel.ItemToAdd); OnUpdateTimerTick(null, null); } } RebuildList(); }