Esempio n. 1
0
        //If no validating errors, insert exercise in database and reload page
        private void ExerciseCreateClick(object param)
        {
            IsValidating = true;
            string error = string.Empty;

            if ((error = ValidateName()) == null)
            {
                if ((error = ValidateDescription()) == null)
                {
                    if (!Uri.IsWellFormedUriString(URI, UriKind.RelativeOrAbsolute))
                    {
                        URI = null;
                    }
                    List <double> profile = new List <double>()
                    {
                        TextVisual, ImageVisual, Verbal, Auditory, Tactile, Kinesthetic
                    };
                    UpdateProfileValues(profile);
                    ExerciseDescription exDescription = new ExerciseDescription(Description)
                    {
                        AudioPath = this.AudioPath, VideoPath = this.VideoPath, ImagePaths = this.ImagePaths, SolutionPath = this.SolutionPath
                    };
                    Exercise exercise = new Exercise(Name, exDescription, profile, CurrentUser.UserName, DateTime.Now, URI);
                    try
                    {
                        DBConnection.CreateExercise(exercise);

                        MakeExercisePage makeexercisePage = new MakeExercisePage();
                        makeexercisePage.DataContext = new MakeExerciseViewModel(CurrentUser);
                        Navigator.SubNavigationService.Navigate(makeexercisePage);
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Kunne ikke oprette forbindelse til databasen!");
                    }
                }
                else
                {
                    MessageBox.Show(error);
                }
            }
            else
            {
                MessageBox.Show(error);
            }
        }
Esempio n. 2
0
        //Returns a list of all exercise from database
        public static List <Exercise> GetAllExercises()
        {
            List <Exercise> exerciselist = new List <Exercise>();

            using (SqlConnection conn = new SqlConnection(connString))
            {
                SqlCommand cmd = new SqlCommand("select * from Exercise", conn);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    List <double> profile = new List <double>();
                    for (int i = 4; i < 10; i++)
                    {
                        profile.Add(Convert.ToDouble(reader[i]));
                    }
                    ExerciseDescription desc = new ExerciseDescription(reader[10].ToString())
                    {
                        VideoPath = reader[11].ToString(), AudioPath = reader[12].ToString(), SolutionPath = reader[13].ToString()
                    };
                    Exercise exercise = new Exercise(reader[1].ToString(), desc, profile, reader[3].ToString(), Convert.ToDateTime(reader[2]), reader[14].ToString())
                    {
                        ID = Convert.ToInt32(reader[0])
                    };
                    exerciselist.Add(exercise);
                }
                conn.Close();

                foreach (Exercise exercise in exerciselist)
                {
                    SqlCommand imagecmd = new SqlCommand("select * from ImagePath where exerciseid = @id", conn);
                    imagecmd.Parameters.AddWithValue("@id", exercise.ID);

                    conn.Open();
                    reader = imagecmd.ExecuteReader();
                    while (reader.Read())
                    {
                        exercise.Description.ImagePaths.Add(reader[1].ToString());
                    }
                    conn.Close();
                }
            }
            return(exerciselist);
        }