예제 #1
0
        public EditWorkoutForm(Data data, Workout workout)
            : this(data)
        {
            // disabling the name field to avoid renaming of existing workouts
              txtName.Enabled = false;

              foreach (var wsc in workout.Steps.Select(t => new WorkoutStepControl
              {
            Location = new Point(_stepControls.Count == 0 ? labName.Left : _stepControls.Last().Right + ControlPadding, butAddStep.Top),
            Parent = this,
            Step = t
              }))
              {
            _stepControls.Add(wsc);
              }

              txtName.Text = workout.Name;

              // assign the category name but also change the dropdownstyle
              // since the combobox doesn't have the category names yet
              comCategory.DropDownStyle = ComboBoxStyle.Simple;
              comCategory.Text = workout.CategoryName;

              butAddStep.Left = _stepControls.Last().Right + ControlPadding;
              butRemoveStep.Left = _stepControls.Last().Right + ControlPadding;
        }
 public WorkoutChangedEventArgs(Workout workout, bool workoutAdded)
 {
     Workout = workout;
       WorkoutAdded = workoutAdded;
 }
예제 #3
0
    /// <summary>
    /// Adds a new workout to the data model.
    /// </summary>
    /// <param name="workout">New workout to add.</param>
    private void AddWorkout(Workout workout)
    {
      var index = _workouts.FindIndex(w => string.Compare(w.Name, workout.Name, StringComparison.InvariantCulture) > 0);
      _workouts.Insert(index == -1 ? _workouts.Count : index, workout);

      Logger.Debug("Triggering WorkoutChanged event");
      WorkoutChanged(this, new WorkoutChangedEventArgs(workout, true));
    }
예제 #4
0
    /// <summary>
    /// Removes a workout from the data model.
    /// </summary>
    /// <param name="workout">Workout to remove.</param>
    public void RemoveWorkout(Workout workout)
    {
      if (!_workouts.Contains(workout))
      {
        return;
      }

      _workouts.Remove(workout);

      // (no need to sort)

      Logger.Debug("Triggering WorkoutChanged event");
      WorkoutChanged(this, new WorkoutChangedEventArgs(workout, false));
    }
예제 #5
0
    /// <summary>
    /// Adds a new workout if no workout exists with the provided workout's name or
    /// replaces the existing workout with the same name.
    /// </summary>
    /// <param name="workout">Workout to add or update.</param>
    public void AddOrUpdateWorkout(Workout workout)
    {
      // TODO: (add/edit/update) Add proper updating of workout
      var existing = _workouts.FirstOrDefault(c => c.Name == workout.Name);

      if (existing != null)
      {
        // NOTE: Removing workout "under the hood" which means that the
        // WorkoutChanged-event is not triggered (which will be triggered afterwards)
        _workouts.Remove(existing);
      }
      AddWorkout(workout);
    }