public MachineExcercise(string excerciseName, string comment, ExerciseSet[] excerciseSet) :
            base(excerciseName, comment, EtypeOfExercise.MachineExercise)
        {
            m_amountOfSets        = excerciseSet.Length;
            m_gymTrainingExercise = new ExerciseSet[m_amountOfSets];

            for (int it = 0; it < m_amountOfSets; it++)
            {
                m_gymTrainingExercise[it] = new ExerciseSet();
            }

            m_gymTrainingExercise = excerciseSet;

            calculateAverageWeight();
            calculateMovedWeight();
            calculateMinWeight();
            calculateMaxWeight();
            calculateAverageRepetitions();
        }
        private void parseTraningsDayDataGridView()
        {
            foreach (DataGridViewRow row in trainingsDayDataGridView.Rows)
            {
                string          exerciseName  = Convert.ToString(row.Cells[0].Value);
                string          trainingsInfo = Convert.ToString(row.Cells[2].Value);
                string          comment       = Convert.ToString(row.Cells[3].Value);
                EtypeOfExercise type          = m_mainFormInstance.ExerciseRegister.getTypeOfExercise(exerciseName);

                switch (type)
                {
                case EtypeOfExercise.MachineExercise:
                {
                    string[]      sets         = trainingsInfo.Split(';');
                    int           numberOfSets = sets.Length;
                    ExerciseSet[] exerciseSet  = new ExerciseSet[numberOfSets];
                    for (int it = 0; it < numberOfSets; it++)
                    {
                        string repetition = sets[it].Split('x')[0];
                        string weigtht    = sets[it].Split('x')[1];
                        if (Convert.ToInt32(repetition) < 0 || Convert.ToDouble(weigtht) < 0)
                        {
                            throw new ArgumentOutOfRangeException("\nNo negativ values allowed!");
                        }
                        exerciseSet[it] = new ExerciseSet(Convert.ToDouble(weigtht), Convert.ToInt32(repetition));
                    }
                    m_trainingsDay.addMachineExcercise(exerciseName, comment, exerciseSet);

                    break;
                }

                case EtypeOfExercise.CardioExercise:
                {
                    string[] parameter = trainingsInfo.Split(';');

                    int h        = Convert.ToInt32(parameter[0]);
                    int min      = Convert.ToInt32(parameter[1]);
                    int sec      = Convert.ToInt32(parameter[2]);
                    int distance = Convert.ToInt32(parameter[3]);

                    if (min > 59 || sec > 59)
                    {
                        throw new ArgumentOutOfRangeException("\n Values for min and sec needs to be between 0 and 59!");
                    }
                    if (distance < 0)
                    {
                        throw new ArgumentOutOfRangeException("\n- No negativ values allowed!");
                    }
                    Duration duration = new Duration(h, min, sec);
                    m_trainingsDay.addCardioExcercise(exerciseName, comment, distance, duration);

                    break;
                }

                case EtypeOfExercise.BodyWeightExercise:
                {
                    string[] sets         = trainingsInfo.Split(';');
                    int      numberOfSets = sets.Length;
                    int[]    repetitions  = new int[numberOfSets];
                    for (int it = 0; it < numberOfSets; it++)
                    {
                        string repetition = sets[it];
                        if (Convert.ToInt32(repetition) < 0)
                        {
                            throw new ArgumentOutOfRangeException("\nNo negativ values allowed!");
                        }
                        repetitions[it] = Convert.ToInt32(repetition);
                    }
                    m_trainingsDay.addBodyWeightExcercise(exerciseName, comment, repetitions);
                    break;
                }

                case EtypeOfExercise.SpecialExercise:
                {
                    m_trainingsDay.addSpecialExcercise(exerciseName, comment);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }
示例#3
0
        private void parseLoadString(string loadString)
        {
            try
            {
                if (m_athlete.BodyPartRegister != null)
                {
                    m_athlete.BodyPartRegister = null;
                }
                if (m_athlete.WeightRegister != null)
                {
                    m_athlete.WeightRegister = null;
                }
                if (ExerciseRegister != null)
                {
                    ExerciseRegister = null;
                }
                if (TrainingDayRegister != null)
                {
                    TrainingDayRegister = null;
                }
                if (m_athlete != null)
                {
                    m_athlete = null;
                }
            }
            catch
            {
            }

            List <TrainingsDay> trainingsDaylist = new List <TrainingsDay>();

            string[] athleteString           = getInfoFromXMLFile(loadString, "Athlete");
            string[] bodyPartsRegisterString = getInfoFromXMLFile(loadString, "BodypartsRegister");
            string[] bodyFatRegisterString   = getInfoFromXMLFile(loadString, "BodyFatRegister");
            string[] exerciseRegisterString  = getInfoFromXMLFile(loadString, "ExerciseRegister");
            string[] trainingsDayListString  = getInfoFromXMLFile(loadString, "TrainingsdayList");

            string[] bodyPartsString           = getInfoFromXMLFile(bodyPartsRegisterString[0], "Bodypart");
            string[] bodyFatString             = getInfoFromXMLFile(bodyFatRegisterString[0], "Bodypart");
            string[] registeredExercisesString = getInfoFromXMLFile(exerciseRegisterString[0], "Exercise");
            string[] trainingsDayString        = getInfoFromXMLFile(trainingsDayListString[0], "Trainingsday");

            string[] exerciseOfTheDay;

            #region Restore the Athlete

            Gender gender;
            if (getInfoFromXMLFile(athleteString[0], "Gender")[0] == Gender.Male.ToString())
            {
                gender = Gender.Male;
            }
            else
            {
                gender = Gender.Female;
            }

            string weightString = getInfoFromXMLFile(athleteString[0], "WeightRegister")[0];

            this.m_athlete = new Athlete(
                getInfoFromXMLFile(athleteString[0], "Name")[0],
                Convert.ToInt32(getInfoFromXMLFile(athleteString[0], "Height")[0]),
                Convert.ToInt32(getInfoFromXMLFile(athleteString[0], "Age")[0]),
                this,
                gender);

            //Damit bleibt measurementString lokal
            if (weightString != " ")
            {
                string[] measurementString = getInfoFromXMLFile(weightString, "Measurement");

                for (int it = 0; it < measurementString.Length; it++)
                {
                    m_athlete.WeightRegister.addMeasurement(
                        getInfoFromXMLFile(measurementString[it], "Date")[0],
                        Math.Round(Convert.ToDouble(getInfoFromXMLFile(measurementString[it], "Weight")[0]), 1)
                        );
                }
            }

            #endregion Restore the Athlete

            #region Restore the Bodyparts

            for (int outer_it = 0; outer_it < bodyPartsString.Length; outer_it++)
            {
                string[] measurementString = getInfoFromXMLFile(bodyPartsString[outer_it], "Measurement");

                m_athlete.addBodyPart(
                    getInfoFromXMLFile(bodyPartsString[outer_it], "Name")[0],
                    getInfoFromXMLFile(bodyPartsString[outer_it], "Description")[0]);

                for (int inner_it = 0; inner_it < measurementString.Length; inner_it++)
                {
                    m_athlete.BodyPartRegister[outer_it].Date.Add(getInfoFromXMLFile(measurementString[inner_it], "Date")[0]);
                    m_athlete.BodyPartRegister[outer_it].Diameter.Add(Math.Round(Convert.ToDouble(getInfoFromXMLFile(measurementString[inner_it], "Diameter")[0]), 2));
                }
            }

            #endregion Restore the Bodyparts

            #region Restore the Body Fat Measurements

            for (int outer_it = 0; outer_it < bodyFatString.Length; outer_it++)
            {
                string[] measurementString = getInfoFromXMLFile(bodyFatString[outer_it], "Measurement");

                for (int inner_it = 0; inner_it < measurementString.Length; inner_it++)
                {
                    m_athlete.BodyFatRegister[outer_it].Date.Add(getInfoFromXMLFile(measurementString[inner_it], "Date")[0]);
                    m_athlete.BodyFatRegister[outer_it].Diameter.Add(Math.Round(Convert.ToDouble(getInfoFromXMLFile(measurementString[inner_it], "Diameter")[0]), 2));
                }
            }

            #endregion Restore the Body Fat Measurements

            #region Restore the Exercises

            for (int it = 0; it < registeredExercisesString.Length; it++)
            {
                m_exerciseRegister.RegisteredExercises.Add(new Exercise(
                                                               getInfoFromXMLFile(registeredExercisesString[it], "Name")[0],
                                                               (EtypeOfExercise)Enum.Parse(typeof(EtypeOfExercise), getInfoFromXMLFile(registeredExercisesString[it], "Type")[0]),
                                                               getInfoFromXMLFile(registeredExercisesString[it], "Description")[0]
                                                               ));
            }

            #endregion Restore the Exercises

            #region Restore the Trainingsdays

            for (int outer_it = 0; outer_it < trainingsDayString.Length; outer_it++)
            {
                m_trainingDayRegister.RegisteredTrainingsDays.Add(new TrainingsDay(this, getInfoFromXMLFile(trainingsDayString[outer_it], "Date")[0]));
                exerciseOfTheDay = getInfoFromXMLFile(trainingsDayString[outer_it], "Exercise");
                for (int inner_it = 0; inner_it < exerciseOfTheDay.Length; inner_it++)
                {
                    string[] type = getInfoFromXMLFile(exerciseOfTheDay[inner_it], "TypeOfExercise");
                    if (type[0] == "MachineExercise")
                    {
                        string[]      exerciseSetString = getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Set");
                        ExerciseSet[] exerciseSet       = new ExerciseSet[exerciseSetString.Length];
                        for (int it = 0; it < exerciseSetString.Length; it++)
                        {
                            exerciseSet[it] = new ExerciseSet(
                                Convert.ToDouble(getInfoFromXMLFile(exerciseSetString[it], "Weight")[0]),
                                Convert.ToInt32(getInfoFromXMLFile(exerciseSetString[it], "Repetitions")[0])
                                );
                        }

                        TrainingDayRegister.RegisteredTrainingsDays[outer_it].addMachineExcercise(
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "ExerciseName")[0],
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Comment")[0],
                            exerciseSet
                            );
                    }
                    else if (type[0] == "BodyWeightExercise")
                    {
                        string[] repetitionsString = getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Repetition");
                        int[]    repetitions       = new int[repetitionsString.Length];
                        for (int it = 0; it < repetitionsString.Length; it++)
                        {
                            repetitions[it] = Convert.ToInt32(repetitionsString[it]);
                        }

                        TrainingDayRegister.RegisteredTrainingsDays[outer_it].addBodyWeightExcercise(
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "ExerciseName")[0],
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Comment")[0],
                            repetitions
                            );
                    }
                    else if (type[0] == "CardioExercise")
                    {
                        Duration duration = new Duration(
                            Convert.ToInt32(getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Hour")[0]),
                            Convert.ToInt32(getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Minute")[0]),
                            Convert.ToInt32(getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Seconds")[0])
                            );

                        TrainingDayRegister.RegisteredTrainingsDays[outer_it].addCardioExcercise(
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "ExerciseName")[0],
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Comment")[0],
                            Convert.ToInt32(getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Distance")[0]),
                            duration
                            );
                    }
                    else if (type[0] == "SpecialExercise")
                    {
                        TrainingDayRegister.RegisteredTrainingsDays[outer_it].addSpecialExcercise(
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "ExerciseName")[0],
                            getInfoFromXMLFile(exerciseOfTheDay[inner_it], "Comment")[0]
                            );
                    }
                }
            }

            #endregion Restore the Trainingsdays
        }