public AlbumSetting(Album a) { InitializeComponent(); music = new MusicSQLEntities(); albm = a; Title.Text = albm.Titre_Album; var emprunt = (from em in music.Emprunter where em.Code_Album == albm.Code_Album && em.Code_Abonné == Form1.currentSubscriber.Code_Abonné select em); empr = emprunt.First(); updateFutureReturnDate(); }
private void viewBox_SelectedIndexChanged(object sender, EventArgs e) { if (viewBox.SelectedItem != null) { if (inLoan) { Album albm = (Album)viewBox.SelectedItem; var newLoan = new Emprunter { Code_Abonné = Form1.currentSubscriber.Code_Abonné, Code_Album = albm.Code_Album, Date_Emprunt = DateTime.Now }; var existingLoan = (from em in music.Emprunter where em.Code_Abonné == newLoan.Code_Abonné where em.Code_Album == newLoan.Code_Album select em).ToList(); if (existingLoan.Count > 0) { music.Emprunter.Remove(existingLoan.First()); music.SaveChanges(); } music.Emprunter.Add(newLoan); music.SaveChanges(); viewBox.Items.Clear(); viewBox.Items.Add("Album emprunté !"); albumDispo_Click(sender, e); label.ForeColor = Color.DarkGreen; label.Text = "Album emprunté !!!"; timer1.Start(); Cursor.Current = Cursors.Default; } else if (inMyAlbums) { AlbumSetting a = new AlbumSetting((Album)viewBox.SelectedItem); a.ShowDialog(); viewBox.Items.Clear(); button1_Click_1(sender, e); } } else { label.ForeColor = Color.DarkRed; label.Text = "Sélectionnez une oeuvre"; } }