private void swapTrainingsDayElement(int index1, int index2)
        {
            TrainingsDay tempTrainingsDay = m_registeredTrainingsDays[index1];

            m_registeredTrainingsDays[index1] = m_registeredTrainingsDays[index2];
            m_registeredTrainingsDays[index2] = tempTrainingsDay;
        }
        private void refillDataGrid(TrainingsDay trainingsDay)
        {
            foreach (Exercise exercise in trainingsDay.ExercisesOfTheDay)
            {
                string trainingsInfo = "";
                if (exercise is MachineExcercise)
                {
                    ExerciseSet[] exerciseSet = ((MachineExcercise)exercise).GymTrainingExercise;

                    trainingsInfo = Convert.ToString(
                        exerciseSet[0].Repetitions
                        + "x"
                        + exerciseSet[0].Weight
                        );
                    for (int i = 1; i < exerciseSet.Length; i++)
                    {
                        trainingsInfo = trainingsInfo + ";" + exerciseSet[i].Repetitions + "x" + exerciseSet[i].Weight;
                    }
                }
                if (exercise is CardioExercise)
                {
                    Duration duration = ((CardioExercise)exercise).ExerciseDuration;
                    int      distance = ((CardioExercise)exercise).Distance;
                    trainingsInfo = Convert.ToString(duration.H + ";" + duration.Min + ";" + duration.Sec + ";" + distance);
                }
                if (exercise is BodyWeightExercise)
                {
                    int[] repetitions = ((BodyWeightExercise)exercise).Repetitions;
                    trainingsInfo = Convert.ToString(repetitions[0]);
                    for (int i = 1; i < repetitions.Length; i++)
                    {
                        trainingsInfo = trainingsInfo + ";" + repetitions[i];
                    }
                }
                if (exercise is SpecialExercise)
                {
                    trainingsInfo = "";
                }
                trainingsDayDataGridView.Rows.Add(exercise.ExerciseName, exercise.TypeOfExcercise.ToString(), trainingsInfo, exercise.Comment);

                int checkItemIndex = exerciseSelectionCheckedListBox.Items.IndexOf(trainingsDayDataGridView.Rows[trainingsDayDataGridView.Rows.Count - 1].Cells[0].Value);
                this.exerciseSelectionCheckedListBox.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.exerciseSelectionCheckedListBox_ItemCheck);
                exerciseSelectionCheckedListBox.SetItemCheckState(checkItemIndex, CheckState.Checked);
                m_exerciseRowList.Add(exerciseSelectionCheckedListBox.Items[checkItemIndex]);
                this.exerciseSelectionCheckedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.exerciseSelectionCheckedListBox_ItemCheck);
            }
        }
 /// <summary>
 /// For editing an existing Trainingsday
 /// </summary>
 /// <param name="mainFormInstance"></param>
 /// <param name="trainingsDay"></param>
 public NewTrainingsDayForm(MainForm mainFormInstance, TrainingsDay trainingsDay)
 {
     InitializeComponent();
     m_mainFormInstance = mainFormInstance;
     m_trainingsDay     = trainingsDay;
     string[] dateString = trainingsDay.Date.Split('.');
     dayComboBox.SelectedItem   = dateString[0];
     monthComboBox.SelectedItem = dateString[1];
     yearComboBox.SelectedItem  = dateString[2];
     for (int it = 0; it < mainFormInstance.ExerciseRegister.RegisteredExercises.Count; it++)
     {
         exerciseSelectionCheckedListBox.Items.Add(mainFormInstance.ExerciseRegister.RegisteredExercises[it].ExerciseName);
     }
     m_exerciseRowList = new List <object>();
     refillDataGrid(trainingsDay);
     m_isEditMode = true;
 }
        private void addTrainingsDayButton_Click(object sender, EventArgs e)
        {
            if (trainingsDayDataGridView.Rows.Count > 0)
            {
                if (m_isEditMode)
                {
                    m_mainFormInstance.TrainingDayRegister.RegisteredTrainingsDays.RemoveAt(m_mainFormInstance.TrainingDayRegister.getTrainingsDayIndex(m_trainingsDay.Date));
                }
                m_trainingsDay = new TrainingsDay(m_mainFormInstance);

                try
                {
                    parseTraningsDayDataGridView();
                }
                catch
                {
                    //TODO behandlung und erkennung von Syntax errors implementieren
                }
                StringBuilder dateString = new StringBuilder();
                dateString.Append(dayComboBox.Text + "." + monthComboBox.Text + "." + yearComboBox.Text);
                m_trainingsDay.Date = dateString.ToString();
                if (m_mainFormInstance.TrainingDayRegister.trainingsDayExist(dateString.ToString()))
                {
                    m_mainFormInstance.TrainingDayRegister.RegisteredTrainingsDays[m_mainFormInstance.TrainingDayRegister.getTrainingsDayIndex(dateString.ToString())].ExercisesOfTheDay.AddRange(m_trainingsDay.ExercisesOfTheDay);
                    MessageBox.Show("There is allready a Training on the " + dateString.ToString() + "\nThe Exercises will be added to the existing Trainingsday", "Info");
                }
                else
                {
                    m_mainFormInstance.TrainingDayRegister.RegisteredTrainingsDays.Add(m_trainingsDay);
                }

                m_mainFormInstance.updateGui();
                this.Close();
            }
            else
            {
                MessageBox.Show("You need to add Exercises first", "Warning");
            }
        }