Exemple #1
0
        private void addMovie_Click(object sender, EventArgs e)
        {
            if (DirectorBox.Text == "" || ProducerBox.Text == "" || ComposerBox.Text == "" || MovieName.Text == "" || MovieGenre.Text == "")
            {
                MovieStatus.Text      = "Missing Inputs";
                MovieStatus.ForeColor = System.Drawing.Color.Red;
                MovieStatus.Show();
                return;
            }
            int           DirectorID = Convert.ToInt32(((ComboboxItem)DirectorBox.SelectedItem).Key);
            int           ProducerID = Convert.ToInt32(((ComboboxItem)ProducerBox.SelectedItem).Key);
            int           ComposerID = Convert.ToInt32(((ComboboxItem)ComposerBox.SelectedItem).Key);
            String        conString  = @"Data Source=SHERIF\SQLEXPRESS;Initial Catalog=PopCornia;Persist Security Info=True;User ID=sa;Password=123456";
            SqlConnection connection = new SqlConnection(conString);

            connection.Open();
            SqlCommand query = new SqlCommand();

            query.CommandText = "INSERT INTO Movies(Name, Year, Genre, Director_ID, Producer_ID, Composer_ID) VALUES ('" +
                                MovieName.Text + "', '" +
                                MovieDate.Value + "', '" +
                                MovieGenre.Text + "', '" +
                                DirectorID + "', '" +
                                ProducerID + "', '" +
                                ComposerID +
                                "');";
            query.Connection  = connection;
            query.CommandType = CommandType.Text;
            try
            {
                query.ExecuteNonQuery();
                MovieStatus.Text      = "Added!";
                MovieStatus.ForeColor = System.Drawing.Color.LimeGreen;
                MovieStatus.Show();
                MovieName.Clear();
                MovieGenre.SelectedIndex  = -1;
                DirectorBox.SelectedIndex = -1;
                ProducerBox.SelectedIndex = -1;
                ComposerBox.SelectedIndex = -1;
                updateDropLists(1);
                addMovie.Enabled = false;
            }
            catch (Exception x)
            {
                MovieStatus.Text      = "Invalid IDs";
                MovieStatus.ForeColor = System.Drawing.Color.Red;
                MovieStatus.Show();
                MovieName.Clear();
                addMovie.Enabled = false;
            }
        }