Exemplo n.º 1
0
        private void add_movie_button_Click(object sender, RoutedEventArgs e)
        {
            string insertMovie = "movies.sp_AddMovie";

            Movie m = new Movie();

            char[] d = { ':', '-' };
            try
            {
                m.movieId = Convert.ToInt32(movie_id.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Argument Movie Id takes integers only");
                return;
            }

            string[] time = duration.Text.Split(d);
            try
            {
                m.duration = new TimeSpan(Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), Convert.ToInt32(time[2]));
            }
            catch (FormatException)
            {
                MessageBox.Show("Argument Duration takes 3 integers \nFormat: HH:MM:SS");
                return;
            }

            if (description.Text.Length > 500)
            {
                MessageBox.Show("description is too big");
                return;
            }
            else
            {
                m.description = description.Text;
            }

            if (age_restriction.Text == "")
            {
                MessageBox.Show("Please select an Age Restriction");
                return;
            }
            else
            {
                m.age_restriction = age_restriction.Text;
            }

            try
            {
                m.rating = Convert.ToInt32(rating.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Argument Rating takes integers only");
                return;
            }

            if (studios_combo_box.Text == "")
            {
                MessageBox.Show("Please select a Studio");
                return;
            }
            else
            {
                m.studio_id = Convert.ToInt32(studios_combo_box.Text.Split(d)[0]);
            }

            if (directors_combo_box.Text == "")
            {
                MessageBox.Show("Please select a Director");
                return;
            }
            else
            {
                m.director_ssn = Convert.ToInt32(directors_combo_box.Text.Split(d)[0]);
            }


            SqlCommand insertQuery = new SqlCommand(insertMovie, cnn);

            insertQuery.CommandType = CommandType.StoredProcedure;

            DataTable genres = new DataTable();

            genres.Clear();
            genres.Columns.Add("genre");
            foreach (CheckBox s in genre_listbox.Items)
            {
                if (s.IsChecked.HasValue && s.IsChecked.Value)
                {
                    DataRow row = genres.NewRow();
                    row["genre"] = s.Content.ToString();
                    genres.Rows.Add(row);
                }
            }

            DataTable actors = new DataTable();

            actors.Clear();
            actors.Columns.Add("ssn");
            foreach (CheckBox s in add_movie_actors.Items)
            {
                if (s.IsChecked.HasValue && s.IsChecked.Value)
                {
                    DataRow row = actors.NewRow();
                    row["ssn"] = s.Content.ToString().Split(d)[0];
                    actors.Rows.Add(row);
                }
            }

            DataTable writers = new DataTable();

            writers.Clear();
            writers.Columns.Add("ssn");
            foreach (CheckBox s in add_movie_writers.Items)
            {
                if (s.IsChecked.HasValue && s.IsChecked.Value)
                {
                    DataRow row = writers.NewRow();
                    row["ssn"] = s.Content.ToString().Split(d)[0];
                    writers.Rows.Add(row);
                }
            }

            insertQuery.Parameters.AddWithValue("@id", m.movieId);
            insertQuery.Parameters.AddWithValue("@duration", m.duration.ToString(@"hh\:mm\:ss"));
            insertQuery.Parameters.AddWithValue("@description", m.description);
            insertQuery.Parameters.AddWithValue("@age_restriction", m.age_restriction);
            insertQuery.Parameters.AddWithValue("@rating", m.rating);
            insertQuery.Parameters.AddWithValue("@studio_id", m.studio_id);
            insertQuery.Parameters.AddWithValue("@director_ssn", m.director_ssn);
            SqlParameter param_genre = insertQuery.Parameters.AddWithValue("@Genre", genres);

            param_genre.SqlDbType = SqlDbType.Structured;
            param_genre.TypeName  = "movies.genrelist";
            SqlParameter param_actors = insertQuery.Parameters.AddWithValue("@Actors", actors);

            param_actors.SqlDbType = SqlDbType.Structured;
            param_actors.TypeName  = "movies.actorlist";
            SqlParameter param_writers = insertQuery.Parameters.AddWithValue("@Writers", writers);

            param_writers.SqlDbType = SqlDbType.Structured;
            param_writers.TypeName  = "movies.writerlist";

            try
            {
                insertQuery.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("Error on inserting Movie to database");
                return;
            }

            cnn.Close();
            AddReleases add = new AddReleases(m.movieId);

            this.NavigationService.Navigate(add);
        }
Exemplo n.º 2
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            AddReleases addRelease = new AddReleases();

            this.NavigationService.Navigate(addRelease);
        }