示例#1
0
文件: Form1.cs 项目: rNdm74/C-
        private void bAddMovie_Click(object sender, EventArgs e)
        {
            try
            {
                // Checks if textbox fields are valid
                int year = Convert.ToInt16(tbYearAdd.Text);

                String title = tbTitleAdd.Text;
                if (title.Trim() == String.Empty)
                {
                    throw new ArgumentException("Please input the movie title");
                }

                String director = tbDirectorAdd.Text;
                if (director.Trim() == String.Empty)
                {
                    throw new ArgumentException("Please input the movie director");
                }

                // Adds movie to the table
                TMovie movie = new TMovie(year, title, director);
                movieTable.Add(movie.year, movie);

                // Alert for confirmation
                MessageBox.Show("Movie Saved", "Add");

                // Clears the textbox fields
                tbYearAdd.Text     = "";
                tbTitleAdd.Text    = "";
                tbDirectorAdd.Text = "";
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Add");
            }
            catch (FormatException ex)
            {
                MessageBox.Show("Please input the year of the movie", "Add");
            }
        }
示例#2
0
文件: Form1.cs 项目: rNdm74/C-
        private void bSearch_Click(object sender, EventArgs e)
        {
            try
            {
                int key = Convert.ToInt16(tbYearSearch.Text);

                if (movieTable.ContainsKey(key))
                {
                    TMovie currentMovie = movieTable[key];

                    lbDisplay.Items.Clear();
                    lbDisplay.Items.Add(currentMovie.ToString());
                }
                else
                {
                    MessageBox.Show(key.ToString() + " not found");
                }
            }
            catch (FormatException ex)
            {
                MessageBox.Show("Please input the year of the movie", "Search");
            }
        }