コード例 #1
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            // The user clicked on the AddAlbum OK button

            int albumYear;

            int.TryParse(this.yearTextBox.Text, out albumYear);
            int artistId;

            int.TryParse(artistComboBox.SelectedValue.ToString(), out artistId);
            string albumTitle  = this.albumTitleTextBox.Text;
            int    albumRating = ratingComboBox.SelectedIndex;
            int    genreId;

            int.TryParse(genreComboBox.SelectedValue.ToString(), out genreId);

            // todo: validation

            int    AlbumId = Album.AddAlbum(albumYear, artistId, albumTitle, albumRating, genreId);
            string msg     = "AlbumID=" + AlbumId.ToString();

            MessageBox.Show(msg);

            if (AlbumId > 0)
            {
                bool repeat = true;
                while (repeat)
                {
                    // This creates an AddSong pop-up.
                    AddSongWF    frm = new AddSongWF();
                    DialogResult dr  = frm.ShowDialog(this);

                    // If the user clicked the OK button on the AddSong pop-up
                    if (dr == DialogResult.Yes)
                    {
                        MessageBox.Show("AddAlbum: AddSong - User clicked Yes button");
                        repeat = true;
                    }
                    else if (dr == DialogResult.OK)
                    {
                        MessageBox.Show("AddAlbum: AddSong - User clicked OK button");
                        this.Close();
                        repeat = false;
                    }
                    // if the Cancel button or the X was clicked on the AddSong pop-up...
                    else if (dr == DialogResult.Cancel)
                    {
                        MessageBox.Show("AddAlbum: AddSong - User clicked Cancel button");
                        this.Close();
                        repeat = false;
                    }
                }
            }

            // Close the AddAlbum form
            this.Close();
        }
コード例 #2
0
        public ActionResult Index()
        {
            Album album1 = new Album();

            album1.AddAlbum("Dark Side of the Moon", "Pink Floyd", "Vinyl", 9.99M);
            albums.Add(album1);

            Album album2 = new Album();

            album2.AddAlbum("Tubular Bells", "Mike Oldfield", "Vinyl", 8.99M);
            albums.Add(album2);

            Album album3 = new Album();

            album3.AddAlbum("Alright, Still", "Lily Allen", "CD", 13.99M);
            albums.Add(album3);


            return(View(albums));
        }