Пример #1
0
        public void GetExercises()
        {
            _exerciseLocation.Y = 28;
            foreach (ucExercise ex in _exercises)
            {
                Controls.Remove(ex);
            }
            _exercises.Clear();

            DataTable tblExercises = Workout.GetExersises(IdWorkout);
            foreach (DataRow exerciseRow in tblExercises.Rows)
            {
                ucExercise ex = new ucExercise();
                ex.Title = exerciseRow["Name"].ToString();
                ex.IdExercise = (int)exerciseRow["idWorkoutExercise"];
                ex.IdExerciseType = (int)exerciseRow["idExerciseType"];
                ex.SortOrder = (DBNull.Value.Equals(exerciseRow["SortOrder"]) ? 0 : (int)exerciseRow["SortOrder"]);
                ex.ExerciseUpdatedEvent += SetHeight;
                ex.ExerciseReorderedEvent += SetExerciseOrders;
                _exercises.Add(ex);
                Controls.Add(ex);
                ex.GetSets(null, EventArgs.Empty);
            }
            if (Exercises.Count > 0)
            {
                Exercises[0].DisableUpButton();
                Exercises[Exercises.Count - 1].DisableDownButton();
            }
        }
Пример #2
0
        public static ucExercise AddWorkoutExercise(int idWorkout, int idExerciseType, string exerciseName, int sortOrder)
        {
            string sql = "INSERT INTO tblWoWorkoutExercises (idWorkout, idExerciseType, SortOrder) VALUES (@idWorkout, @idExerciseType, @SortOrder);";
            SqlCommand cmd = Global.conn1.CreateCommand();
            cmd.Parameters.AddWithValue("@idWorkout", idWorkout);
            cmd.Parameters.AddWithValue("@idExerciseType", idExerciseType);
            cmd.Parameters.AddWithValue("@SortOrder", sortOrder);
            cmd.CommandText = sql;
            if (Global.conn1.State != ConnectionState.Open)
                Global.conn1.Open();
            cmd.ExecuteNonQuery();
            //Get the new idWorkoutExercise
            int idWorkoutExercise = 0;
            sql = "SELECT idWorkoutExercise FROM tblWoWorkoutExercises WHERE idWorkout=@idWorkout AND idExerciseType = @idExerciseType AND SortOrder = @SortOrder";
            cmd = Global.conn1.CreateCommand();
            cmd.Parameters.AddWithValue("@idWorkout", idWorkout);
            cmd.Parameters.AddWithValue("@idExerciseType", idExerciseType);
            cmd.Parameters.AddWithValue("@SortOrder", sortOrder);
            cmd.CommandText = sql;
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                reader.Read();
                idWorkoutExercise = reader.GetInt32(0);
            }
            reader.Close();
            //Add a new set
            if (idWorkoutExercise > 0)
                AddSet(idWorkoutExercise, idExerciseType, 0, 0, "");
            //Get the ucExercise for the new exercise
            ucExercise ex = new ucExercise();
            ex.Title = exerciseName;
            ex.IdExercise = idWorkoutExercise;
            ex.IdExerciseType = idExerciseType;
            ex.SortOrder = sortOrder;
            Global.conn1.Close();

            return ex;
        }