Пример #1
0
 private void addDVDToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var dvdEditForm = new EditDvdWin();
     var dvd = new Dvd();
     dvd.SetId();
     dvdEditForm.Execute(dvd);
     Form1_Load(null, null);
 }
Пример #2
0
        public void Execute(Dvd dvd)
        {
            BuildGenreBox();

            titleEdit.Text = dvd.Title;
            yearEdit.Text = dvd.ReleaseYear.ToString();
            genreBox.Text = dvd.Genre.ToString();
            descriptionBox.Text = dvd.Description;
            DvdImageBox.Image = dvd.GetPoster();

            var x = this.ShowDialog();
            if (x == System.Windows.Forms.DialogResult.OK)
            {
                dvd.Title = titleEdit.Text;
                dvd.ReleaseYear = int.Parse(yearEdit.Text);
                if (genreBox.SelectedItem == null)
                {

                    var genre = new Genre()
                    {
                        Id = Database.GetNextID<Genre>(),
                        Name = genreBox.Text
                    };
                    Database.Session.Insert(genre);
                    dvd.Genre = genre.Id;
                }
                else
                {
                    var genre = genreBox.SelectedItem as Genre;
                    dvd.Genre = genre.Id;
                }

                dvd.Description = descriptionBox.Text;
                dvd.SetPoster(DvdImageBox.Image);
                if (dvd.IsNew)
                {
                    Database.Insert(dvd);
                }
                else
                {
                    Database.Session.Update(dvd);
                }
            }
        }