public void AddTrainingWeek(TrainingWeek training_week) => this.training_weeks.Add(training_week);
/// <summary> /// Loads a program from a file, if file doesn't exist returns bool /// </summary> /// <param name="path"></param> /// <returns></returns> public bool readFromFile(string path) { if (!File.Exists(path)) { return(false); } StreamReader file_reader = new StreamReader(path); string line = file_reader.ReadLine(); TrainingBlock new_block = new TrainingBlock(); string block_type = ""; TrainingWeek new_week = new TrainingWeek(); TrainingDay new_day = new TrainingDay(); while (line != null) { if (line == "Volume" || line == "Intensity" || line == "Transition") { block_type = line; new_block.SetBlockType(block_type); line = file_reader.ReadLine(); } while (line != "block_end") { if (line.Contains("Week")) { string fatique_string = line.Substring(line.LastIndexOf(' ')); int week_fatique; Int32.TryParse(fatique_string, out week_fatique); new_week.SetFatique(week_fatique); new_week.SetBlockType(block_type); line = file_reader.ReadLine(); while (line != "week_end") { if (line == "mon" || line == "tue" || line == "wed" || line == "thu" || line == "fri" || line == "sat" || line == "sun") { new_day.SetWeekDay(line); line = file_reader.ReadLine(); while (line != "day_end") { char[] separators = { ' ' }; string[] strings = line.Split(separators, 20); int strings_last_index = strings.Length - 1; if (strings[strings_last_index] == "ld" || strings[strings_last_index] == "ldg") { double RPE; double.TryParse(strings[strings_last_index - 2], out RPE); int fatique; Int32.TryParse(strings[strings_last_index - 1].Substring(0, 1), out fatique); int reps; Int32.TryParse(strings[strings_last_index - 3].Substring(1, 1), out reps); string name = ""; for (int i = 0; i < strings_last_index - 3; i++) { name = name + strings[i] + " "; } name = name.Substring(0, name.Length - 1); new_day.AddExercise(new exercise(name, reps, fatique, RPE, strings[strings_last_index])); } else if (strings[strings_last_index - 1].Substring(0, 1) == "x") { double RPE; double.TryParse(strings[strings_last_index], out RPE); int sets; Int32.TryParse(strings[strings_last_index - 1].Substring(2, 1), out sets); int reps; Int32.TryParse(strings[strings_last_index - 1].Substring(0, 1), out reps); string name = ""; for (int i = 0; i < strings_last_index - 1; i++) { name = name + strings[i] + " "; } name = name.Substring(0, name.Length - 1); new_day.AddExercise(new exercise(name, reps, sets, RPE)); } else { int sets; Int32.TryParse(strings[strings_last_index].Substring(0, 1), out sets); int reps; Int32.TryParse(strings[strings_last_index].Substring(2, 1), out reps); string name = ""; for (int i = 0; i < strings_last_index; i++) { name = name + strings[i] + " "; } name = name.Substring(0, name.Length - 1); new_day.AddExercise(new exercise(name, reps, sets)); } line = file_reader.ReadLine(); } new_week.AddTrainingDay(new_day); new_day = new TrainingDay(); } line = file_reader.ReadLine(); } new_block.AddTrainingWeek(new_week); new_week = new TrainingWeek(); } line = file_reader.ReadLine(); } this.training_blocks.Add(new_block); new_block = new TrainingBlock(); line = file_reader.ReadLine(); } file_reader.Close(); return(true); }