private void okButton_Click(object sender, EventArgs e) { dbIO dataHandler = new dbIO(); Movie newMovie = new Movie(0,titleTextBox.Text,descriptionTextBox.Text,publisherTextBox.Text,releaseDateMaskedTextBox.Text,ratingTextBox.Text,double.Parse(priceMaskedTextBox.Text),(int)numberOfCopiesUpDown.Value); dataHandler.addMovie(newMovie,(Int32)numberOfCopiesUpDown.Value); titleTextBox.Text = ""; descriptionTextBox.Text = ""; publisherTextBox.Text = ""; releaseDateMaskedTextBox.Text = ""; ratingTextBox.Text = ""; priceMaskedTextBox.Text = ""; numberOfCopiesUpDown.Value = 0; }
public void updateMovie(Movie obj) { try { database = new OleDbConnection(connectionString); database.Open(); string queryString = "UPDATE Movie " + "SET Title = '" + obj.Title + "', Description = '" + obj.Description + "', Publisher = '" + obj.Publisher + "', ReleaseDate = '" + obj.ReleaseDate + "', Rating = '" + obj.Rating + "', PurchasePrice = " + obj.Price + ", Copies = " + obj.Copies + " WHERE ID = " + obj.Id; OleDbCommand cmd = new OleDbCommand(queryString, database); count = cmd.ExecuteNonQuery(); if (count >= 1) MessageBox.Show(obj.Title + "'s record has been updated!"); else MessageBox.Show("Error: No movie by that title!"); database.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); database.Close(); } }
public List<Movie> searchMovie(string name) { movieList.Clear(); try { database = new OleDbConnection(connectionString); database.Open(); string queryString = "SELECT * FROM Movie Where Title LIKE ('%" +name+ "%')"; OleDbCommand cmd = new OleDbCommand(queryString, database); reader = cmd.ExecuteReader(); while (reader.Read()) { Movie temp = new Movie(); temp.Id =(Int32) reader["ID"]; temp.Title = reader["Title"].ToString(); temp.Description = reader["Description"].ToString(); temp.Publisher = reader["Publisher"].ToString(); temp.ReleaseDate = reader["ReleaseDate"].ToString(); temp.Rating = reader["Rating"].ToString(); temp.Price =(double) reader["PurchasePrice"]; temp.Copies =(Int32) reader["Copies"]; movieList.Add(temp); } reader.Close(); database.Close(); return movieList; } catch (Exception ex) { MessageBox.Show(ex.Message); movieList.Clear(); reader.Close(); database.Close(); return movieList; } }
public void addMovie(Movie obj, int num) { try { database = new OleDbConnection(connectionString); database.Open(); string queryString = "INSERT INTO Movie (Title, Description, Publisher, ReleaseDate, Rating, PurchasePrice, Copies) " + "VALUES ('" + obj.Title + "', '" + obj.Description + "', '" + obj.Publisher + "', '" + obj.ReleaseDate + "', '" + obj.Rating + "', '" + obj.Price + "', '" + obj.Copies + "')"; string queryString2 = "SELECT * FROM Movie WHERE Title = '" +obj.Title+ "'"; string queryString3; OleDbCommand cmd = new OleDbCommand(queryString, database); OleDbCommand cmd2 = new OleDbCommand(queryString2, database); count = cmd.ExecuteNonQuery(); reader = cmd2.ExecuteReader(); Movie temp = new Movie(); reader.Read(); temp.Id = Int32.Parse(reader["ID"].ToString()); temp.Title = reader["Title"].ToString(); temp.Description = reader["Description"].ToString(); temp.Publisher = reader["Publisher"].ToString(); temp.ReleaseDate = reader["ReleaseDate"].ToString(); temp.Rating = reader["Rating"].ToString(); temp.Price = Double.Parse(reader["PurchasePrice"].ToString()); temp.Copies = Int32.Parse(reader["Copies"].ToString()); queryString3 = "INSERT INTO MovieCopy (CheckedOut, MovieID) " + "VALUES (false, '" + temp.Id + "')"; OleDbCommand cmd3 = new OleDbCommand(queryString3, database); for (int i = 0; i < num; i++) count2 = cmd3.ExecuteNonQuery(); if (count >= 1) MessageBox.Show(obj.Title + " has been added!"); else MessageBox.Show("Error: Could not add movie!"); reader.Close(); database.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); reader.Close(); database.Close(); } }