//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 = ""; } } }
//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 } }
//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 is required!"); TextBoxMOvieTitle.Focus(); } else if (Year == "") { MessageBox.Show("Movie released year is required!"); TextBoxYear.Focus(); } else if (Genre == "") { MessageBox.Show("Movie genre is required!"); TextBoxGenre.Focus(); } else if (RentCost == "") { MessageBox.Show("Movie rent cost is required!"); } else if (StoryLine == "") { MessageBox.Show("Story Line is required!"); textBoxStoryLine.Focus(); } else if (Rating == "") { MessageBox.Show("Movie rating is required!"); TextBoxStarRating.Focus(); } else { MoviesData data = new MoviesData { Title = Title, Year = Year, Rating = Rating, Genre = Genre, RentCost = int.Parse(RentCost), MovieId = int.Parse(MovieId), StoryLine = StoryLine }; if (new Movies().UpdateMovie(data)) { MoviesGridViewDataBind(); BindDropDownMovie(); btnAddMOvie.Enabled = true; // enable Add movie button MessageBox.Show("Movie Updated Successfully!"); TextBoxMovieID.Text = ""; TextBoxMOvieTitle.Text = "Movie Title..."; TextBoxYear.Text = "Release Year..."; TextBoxStarRating.Text = "Star Rating..."; TextBoxGenre.Text = "Genre..."; TextBoxRent.Text = "($)Rent... "; textBoxStoryLine.Text = "Story Line..."; } else { MessageBox.Show("Unable to update this movie!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); DataBaseConnection.CloseConnection(); // close connection with database when error occured } }
//insert movies 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 is required!"); TextBoxMOvieTitle.Focus(); } else if (Year == "") { MessageBox.Show("Movie released year is required!"); TextBoxYear.Focus(); } else if (Genre == "") { MessageBox.Show("Movie genre is required!"); TextBoxGenre.Focus(); } else if (Rating == "") { MessageBox.Show("Movie rating is required!"); TextBoxStarRating.Focus(); } else if (StoryLine == "") { MessageBox.Show("Story Line is required!"); textBoxStoryLine.Focus(); } else { MoviesData data = new MoviesData { Title = Title, Year = Year, Rating = Rating, Genre = Genre, RentCost = int.Parse(RentCost), StoryLine = StoryLine }; if (new Movies().InsertMovie(data)) { MoviesGridViewDataBind(); // method calling to Bind Grid Movies BindDropDownMovie(); // method calling to Bind dropdown Movies MessageBox.Show("Movie Inseted Successfully!"); TextBoxMOvieTitle.Text = "Movie Title..."; TextBoxYear.Text = "Release Year..."; TextBoxStarRating.Text = "Star Rating..."; TextBoxGenre.Text = "Genre..."; TextBoxRent.Text = "($)Rent... "; textBoxStoryLine.Text = "Story Line..."; } } }