private void AddSetButton_Click(object sender, EventArgs e) { try { Sets set = new Sets { Num_Reps = Int32.Parse(RepsTextBox.Text), Weight = Int32.Parse(WeightTextBox.Text) }; set.Workouts.Add(ctx.Workouts.FirstOrDefault(w => w.ID_Workout == workoutId)); ctx.Sets.Add(set); ctx.SaveChanges(); } catch { MessageBox.Show("Неправильний формат даних"); } UpdateListView(); }
private void AddTrainToolStripMenuItem_Click(object sender, EventArgs e) { using (ExerciseChooseForm Window = new ExerciseChooseForm()) { if (Window.ShowDialog() == DialogResult.OK) { Workouts workout = new Workouts { Num_Sets = 0 }; workout.Exercises.Add(ctx.Exercises.FirstOrDefault(ex => ex.Name == Window.exerciseName)); workout.Days.Add(ctx.Days.FirstOrDefault(d => d.ID_Day == dayId)); ctx.Workouts.Add(workout); ctx.SaveChanges(); UpdateTreeView(); (new EditSetsForm(workout.ID_Workout)).ShowDialog(); UpdateTreeView(); } } }
private void CalendarDayClicked(object sender, DateRangeEventArgs e) { var day = ctx.Days.FirstOrDefault(d => d.Users.Any(u => u.Login == user.Login) && d.Date == e.Start.Date); int id = -1; if (day == null) { Days newDay = new Days { Date = e.Start.Date, Comment = "" }; newDay.Users.Add(ctx.Users.FirstOrDefault(u => u.Login == user.Login)); ctx.Days.Add(newDay); ctx.SaveChanges(); day = newDay; } id = day.ID_Day; (new DayForm(e.Start.ToShortDateString(), id)).ShowDialog(); UpdateCalendar(); }
private void CreateAccountButton_Click(object sender, EventArgs e) { if (!ctx.Users.Any(u => u.Login == LoginTextBox.Text)) { Users user = new Users() { Login = LoginTextBox.Text, Password = PassTextBox.Text, Name = NameTextBox.Text }; ctx.Users.Add(user); ctx.SaveChanges(); this.Close(); } else { MessageBox.Show("Користувач з таким логіном уже існує"); } }
private void CreateExerciseButton_Click(object sender, EventArgs e) { if (!ctx.Exercises.Any(x => x.Name == ExerciseNameTextBox.Text)) { Exercises exercise = new Exercises { Name = ExerciseNameTextBox.Text, Information = ExerciseInfoRichTextBox.Text }; string group = ChooseMuscleGroupComboBox.GetItemText(ChooseMuscleGroupComboBox.SelectedItem); exercise.MuscleGroups.Add(ctx.MuscleGroups.FirstOrDefault(g => g.Name == group)); ctx.Exercises.Add(exercise); ctx.SaveChanges(); this.Close(); } else { MessageBox.Show("Дана вправа вже існує"); } }