Question
THIS IS MY CURRENT CODE: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient;
THIS IS MY CURRENT CODE:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient;
namespace Homework6 { public partial class Form1 : Form { string connectionString; SqlConnection connection; SqlDataAdapter adapter;
public Form1() { InitializeComponent(); InitialDatabaseObjects(); LoadActorListBox(); CloseDatabaseoObjects(); }
public void InitialDatabaseObjects() { connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename= C: \\Users\\Lesley Cadden\\OneDrive\\ANDERSON UNIVERSITY\\Spring 2018\\ACB 421 - OT1\\Homework6\\cinema.mdf; Integrated Security = True; Connect Timeout=30"; connection = new SqlConnection(connectionString); connection.Open(); } public void CloseDatabaseoObjects() { connection.Close(); }
public void LoadActorListBox() { string query = "SELECT * FROM Actor"; DataTable actorTable;
actorTable = new DataTable(); adapter = new SqlDataAdapter(query, connection); adapter.Fill(actorTable);
actorListBox.Items.Clear(); foreach (DataRow row in actorTable.Rows) { actorListBox.Items.Add(row[0] + " " + row[2] + " " + row[1]); } }
private void movieListBox_SelectedIndexChanged(object sender, EventArgs e) { string movieID = ""; string movieTitle, movieYear; directorFName; directorLName; string query; DataTable movieActorTable;
movieTitle = movieListBox.SelectedItem.ToString().Substring(5, 30); movieYear = movieListBox.SelectedItem.ToString().Substring(34); movieID = movieListBox.SelectedItem.ToString().Substring(0, 4); query = "SELECT actorFName, actorLName, cast.movieID, cast.actorID FROM actor, cast WHERE actor.actorID = cast.actorID AND cast.movieID = " + movieID;
movieActorTable = new DataTable(); adapter = new SqlDataAdapter(query, connection); adapter.Fill(movieActorTable);
movieLabel.Text = movieTitle; yearLabel.Text = movieYear; directorLabel.Text = directorFName + " " directorLName;
}
private void actorListBox_SelectedIndexChanged(object sender, EventArgs e) { string actorID = ""; string query; DataTable movieTable;
actorID = actorListBox.SelectedItem.ToString().Substring(0, 4); query = "SELECT * FROM movie WHERE actorID = " + actorID;
movieTable = new DataTable(); adapter = new SqlDataAdapter(query, connection); adapter.Fill(movieTable);
movieListBox.Items.Clear(); foreach (DataRow row in movieTable.Rows) { movieListBox.Items.Add(row[0] + " " + row[1].ToString().PadRight(30) + row[2]); } } } }
You should download a copy of the SQL Server database found at the link Homework #6 Database on Canvas and use it as the data source for your homework project. The database is named cinemamdf, and it contains information about movies, directors, and actors. An entity relationship diagram of the database is shown below: director movie actor PK directolD PK mowicln ast directorFName PK,FK1 movielD movielD movieTille movieYgar actorFName directorLName PK,FK2 actorlD actorLNarme FK directonD You are to create a C# Windows Forms (GUI) application that conforms to the following specifications: 1 Load a list box with information about actors. The each list box item should contain an actor D and an actor name. You will read information from the actor table of the database and use the information that you have retrieved from the database to load the list box. Each time an item is selected in the actor list box, do the following: 2. Retrieve all of the rows in the movie table that are associated with the actorID of the actor that was selected in the list box. Since there is a many-to-many relationship between the actor and movie tables, you will need to make use of the cast table in order to retrieve the correct rows from the movie table. Use the data retrieved from the movie table (as described in the bullet above), and populate a list box with the following information: a. b. i. Movie ID ii. Movie Title iii Movie Year 3. Each time an item is selected from the movie list box, do the following: a. Retrieve the row from the director table that contains the directorID of the movie that was selected in the movie list box. Populate a label with the following information: b. i. The title of the movie that was selected ii. The year of the movie that was selected. iii. The name of the director who directed the movie
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started