//add movies to table
        private void btnAddMOvie_Click(object sender, EventArgs e)
        {
            string Title, RentCost, Year, Rating, Genre, StoryLine;

            Title     = TextBoxMOvieTitle.Text;
            RentCost  = TextBoxRent.Text;
            Rating    = TextBoxStarRating.Text;
            Year      = TextBoxYear.Text;
            Genre     = TextBoxGenre.Text;
            StoryLine = textBoxStoryLine.Text;

            if (Title == "")
            {
                MessageBox.Show("Movie title required!");
                TextBoxMOvieTitle.Focus();
            }
            else if (Year == "")
            {
                MessageBox.Show("Movie released year required!");
                TextBoxYear.Focus();
            }
            else if (Genre == "")
            {
                MessageBox.Show("Movie genre required!");
                TextBoxGenre.Focus();
            }
            else if (Rating == "")
            {
                MessageBox.Show("Movie rating required!");
                TextBoxStarRating.Focus();
            }
            else if (StoryLine == "")
            {
                MessageBox.Show("Story required!");
                textBoxStoryLine.Focus();
            }
            else
            {
                MoviesDataTbl data = new MoviesDataTbl();
                data.Title     = Title;
                data.Year      = Year;
                data.Rating    = Rating;
                data.Genre     = Genre;
                data.RentCost  = int.Parse(RentCost);
                data.StoryLine = StoryLine;
                if (new Movies().InsertMovie(data))
                {
                    MoviesTableGridDataBind(); // method calling to Bind Grid Movies
                    BindDropDownMovie();       // method calling to Bind dropdown Movies
                    MessageBox.Show("Movie Saved to Database!!");

                    TextBoxMOvieTitle.Text = "";
                    TextBoxYear.Text       = "";
                    TextBoxStarRating.Text = "";
                    TextBoxGenre.Text      = "";
                    TextBoxRent.Text       = "";
                    textBoxStoryLine.Text  = "";
                }
            }
        }
Exemplo n.º 2
0
        // Insert Movie
        public bool InsertMovie(MoviesDataTbl data)
        {
            SqlCommand cmd = DataBaseConnection.OpenConnection().CreateCommand();

            cmd.CommandText = "InsertMovieTbl";
            cmd.CommandType = CommandType.StoredProcedure; // store procedure
            cmd.Parameters.AddWithValue("@Title", data.Title);
            cmd.Parameters.AddWithValue("@Year", data.Year);
            cmd.Parameters.AddWithValue("@RentCost", data.RentCost);
            cmd.Parameters.AddWithValue("@Genre", data.Genre);
            cmd.Parameters.AddWithValue("@Rating", data.Rating);
            cmd.Parameters.AddWithValue("@StoryLine", data.StoryLine);
            bool ans = cmd.ExecuteNonQuery() > 0;

            cmd.Dispose();
            return(ans);
        }
Exemplo n.º 3
0
        // Update Movie
        public bool UpdateMovie(MoviesDataTbl data)
        {
            SqlCommand cmd = DataBaseConnection.OpenConnection().CreateCommand();

            cmd.CommandText = "UpdateMovieTbl";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@movieId", data.MovieId);
            cmd.Parameters.AddWithValue("@title", data.Title);
            cmd.Parameters.AddWithValue("@year", data.Year);
            cmd.Parameters.AddWithValue("@rating", data.RentCost);
            cmd.Parameters.AddWithValue("@genre", data.Genre);
            cmd.Parameters.AddWithValue("@rentcost", data.Rating);
            cmd.Parameters.AddWithValue("@StoryLine", data.StoryLine);
            bool ans = cmd.ExecuteNonQuery() > 0;

            cmd.Dispose();
            return(ans);
        }
Exemplo n.º 4
0
        // Show Movies Information
        public MoviesDataTbl ShowMovieInfoById(int movieID)
        {
            SqlCommand cmd = DataBaseConnection.OpenConnection().CreateCommand();

            cmd.CommandText = "ShowMovieFromID";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@movieID", movieID);
            MoviesDataTbl data   = null;
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                data           = new MoviesDataTbl();
                data.Title     = reader[2].ToString();
                data.Rating    = reader[1].ToString();
                data.RentCost  = int.Parse(reader[4].ToString());
                data.Year      = reader[3].ToString();
                data.StoryLine = reader[5].ToString();
                data.Genre     = reader[6].ToString();
            }
            reader.Dispose();
            cmd.Dispose();
            return(data);
        }
        //Update movie
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                string MovieId = TextBoxMovieID.Text;

                string Title, RentCost, Year, Rating, Genre, StoryLine;
                Title     = TextBoxMOvieTitle.Text;
                RentCost  = TextBoxRent.Text;
                Rating    = TextBoxStarRating.Text;
                Year      = TextBoxYear.Text;
                Genre     = TextBoxGenre.Text;
                StoryLine = textBoxStoryLine.Text;

                if (Title == "")
                {
                    MessageBox.Show("Movie title required!");
                    TextBoxMOvieTitle.Focus();
                }
                else if (Year == "")
                {
                    MessageBox.Show("Movie released year required!");
                    TextBoxYear.Focus();
                }

                else if (Genre == "")
                {
                    MessageBox.Show("Movie genre required!");
                    TextBoxGenre.Focus();
                }
                else if (RentCost == "")
                {
                    MessageBox.Show("Movie rent cost required!");
                }
                else if (StoryLine == "")
                {
                    MessageBox.Show("Story required!");
                    textBoxStoryLine.Focus();
                }
                else if (Rating == "")
                {
                    MessageBox.Show("Movie rating required!");
                    TextBoxStarRating.Focus();
                }

                else
                {
                    MoviesDataTbl data = new MoviesDataTbl();
                    data.Title     = Title;
                    data.Year      = Year;
                    data.Rating    = Rating;
                    data.Genre     = Genre;
                    data.RentCost  = int.Parse(RentCost);
                    data.MovieId   = int.Parse(MovieId);
                    data.StoryLine = StoryLine;
                    if (new Movies().UpdateMovie(data))
                    {
                        MoviesTableGridDataBind();
                        BindDropDownMovie();

                        btnAddMOvie.Enabled = true; // enable Add movie button
                        MessageBox.Show("Movie Updated!!");
                        TextBoxMovieID.Text    = "";
                        TextBoxMOvieTitle.Text = "";
                        TextBoxYear.Text       = "";
                        TextBoxStarRating.Text = "";
                        TextBoxGenre.Text      = "";
                        TextBoxRent.Text       = "";
                        textBoxStoryLine.Text  = "";
                    }
                    else
                    {
                        MessageBox.Show("Unable to update this movie!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close connection with database when error occured
            }
        }