예제 #1
0
        private void button_AddMovie_Click(object sender, EventArgs e)
        {
            try
            {
                int key = Convert.ToInt16(tb_AddYear.Text);
                if (!movieTable.ContainsKey(key))
                {
                    String movieTitle = tb_AddTitle.Text;
                    String movieDirector = tb_Director.Text;
                    Movie newMovie = new Movie(key, movieTitle, movieDirector);
                    movieTable.Add(key, newMovie);

                    tb_AddTitle.Clear();
                    tb_AddYear.Clear();
                    tb_Director.Clear();
                    listBox_Movie.Items.Clear();
                    listBox_Movie.Items.Add(newMovie.Title + " has been added");
                }
                else
                {
                    MessageBox.Show(key.ToString() + " already exists");
                }
            }
            catch (FormatException)
            {
                tb_AddTitle.Clear();
                tb_AddYear.Clear();
                tb_Director.Clear();
                MessageBox.Show("Please enter valid data");
            }
        }
예제 #2
0
        public Form1()
        {
            InitializeComponent();

            //Dictionary<int, Movie> movieTable = new Dictionary<int, Movie>();
            // Seed data
            Movie movie1 = new Movie(1961, "West SideStory", "Jerome Robbins");
            Movie movie2 = new Movie(1972, "The Godfather", "Francis Ford Coppola");
            Movie movie3 = new Movie(1984, "Amadeus", "Milos Forman");
            Movie movie4 = new Movie(2015, "The Revenant", "Alejandro G. Iñárritu");

            movieTable.Add(movie1.Year, movie1);
            movieTable.Add(movie2.Year, movie2);
            movieTable.Add(movie3.Year, movie3);
            movieTable.Add(movie4.Year, movie4);
        }