Exemplo n.º 1
0
        // Add the user input from the text fields into the movie database
        public void addToTable(TextBox addYear, TextBox addTitle, TextBox addDirector, MDatabase mD)
        {
            // Checks whether the field has been filled and whether the year text field was filled with an int type value
            // If not then, a messagebox will appear telling user to fill all text fields with correct value type

            // Int32.TryParse converts the string representation to its 32-bit signed interger equivalent
            // If string entered can be converted (result = true) then the process continues if not, it will return the same messagebox from earlier
            int num;

            if (addYear.Text != "" && addTitle.Text != "" && addDirector.Text != "" && Int32.TryParse(addYear.Text, out num))
            {
                // Convert the year string into int so it can be used as the key value
                int key = int.Parse(addYear.Text);

                // If the year entered doesn't already exist in the Dictionary, then it will be added into it
                // Else a messagebox will appear telling user the year entered already exists in the database
                if (!mD.MovieTable.ContainsKey(key))
                {
                    Movie temp = new Movie(int.Parse(addYear.Text), addTitle.Text, addDirector.Text);

                    mD.addMovies(temp);
                }
                else
                {
                    MessageBox.Show("The year entered already exists in the database");
                }
            }
            else
            {
                MessageBox.Show("Please fill out all of the year, title and director with the CORRECT value type to add movie");
            }
        }