private void btn_confirm_Click(object sender, EventArgs e) { string s = ""; User user = new User(); if (txt_firstname.Text != "") { user.FirstName = txt_firstname.Text; } else { s += "First name can't be empty\n"; } if (txt_lastname.Text != "") { user.LastName = txt_lastname.Text; } else { s += "Last name can't be empty\n"; } Regex re = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); if (re.IsMatch(txt_email.Text)) { user.Email = txt_email.Text; } else { s += "Invalid Email\n"; txt_email.Text = ""; } if (txt_password1.Text == txt_pasword2.Text) { Regex re1 = new Regex("^(?=.*?[A-Za-z])(?=.*?[0-9])(?=.*?[#?!@$%^_&*-]).{8,}$"); if (re1.IsMatch(txt_password1.Text)) { user.Password = txt_password1.Text; } else { s += "Invalid Password\n"; txt_password1.Text = ""; txt_pasword2.Text = ""; } } if (s == "") { using (var ctx = new MusicContext()) { ctx.Users.Add(user); ctx.SaveChanges(); } this.Close(); } else { MessageBox.Show(s); } }
private void btn_AddNewSong_Click(object sender, EventArgs e) { bool exist = false; foreach (var item in songitems) { if (((Song)cmb_Songs.SelectedItem).SongId == item.SongId) { exist = true; } } if (!exist) { Playlist pl = (Playlist)cmb_playlists.SelectedItem; using (var ctx = new MusicContext()) { ctx.PlaylistSongs.Add(new PlaylistSong { PlaylistId = pl.PlaylistId, SongId = ((Song)cmb_Songs.SelectedItem).SongId }); ctx.SaveChanges(); songitems = ctx.Songs.Join(ctx.PlaylistSongs, c => c.SongId, x => x.SongId, (c, x) => new { PlaylistId = x.PlaylistId, sngitm = new SongItem { Like = "", Title = c.Title, Length = c.Length, Album_Name = c.Album.Name, Artist_Name = c.Artist.Name, CreatedAt = c.CreatedAt, UpdatedAt = c.UpdatedAt, Delete = "🗑 Delete", AlbumId = c.Album.AlbumId, SongId = c.SongId, Al = c.Album, Ar = c.Artist, ArtistId = c.Artist.ArtistId } }) .Join(ctx.Playlists.Where(u => u.User.UserId == Log_In.user.UserId && u.PlaylistId == ((Playlist)cmb_playlists.SelectedItem).PlaylistId), cx => cx.PlaylistId, p => p.PlaylistId, (cx, p) => cx.sngitm).ToList(); } dgvload(); } else { MessageBox.Show("Exists earledy !!"); } }
private void SongsForAlbum(object sender, EventArgs e) { int SongLength; string songTitle = liedje.Text; bool goodSongLengthOrNot = int.TryParse(duur.Text, out SongLength); string albumName = album.Text; if (!string.IsNullOrEmpty(songTitle) && goodSongLengthOrNot != false && !string.IsNullOrEmpty(albumName)) { using (var ctx = new MusicContext()) { var newArtist = (Artists)comboBox1.SelectedItem; Album albums = new Album(); albums.Name = albumName; Song song = new Song(); song.Title = songTitle; song.Length = SongLength; // How do I get the album from the // Zoek voor de laatste item in de ctx.Songs.Add(song); ctx.SaveChanges(); MessageBox.Show("The songs have been added"); } } }
private void btn_Add_Click(object sender, EventArgs e) { if (txt_title.Text != "" && txt_length.Text != "" && cmb_artists.SelectedItem != null && cmb_albums.SelectedItem != null) { Song newsong = new Song(); songitems.Clear(); using (var ctx = new MusicContext()) { newsong = new Song { Artist = ctx.Artists.FirstOrDefault(a => a.ArtistId == ((Artist)cmb_artists.SelectedItem).ArtistId), Album = ctx.Albums.FirstOrDefault(d => d.AlbumId == ((Album)cmb_albums.SelectedItem).AlbumId), Title = txt_title.Text, Length = Convert.ToInt32(txt_length.Text), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; ctx.Songs.Add(newsong); ctx.SaveChanges(); songs = ctx.Songs.ToList(); songitems = ctx.Songs.Join(ctx.PlaylistSongs, c => c.SongId, x => x.SongId, (c, x) => new { PlaylistId = x.PlaylistId, sngitm = new SongItem { Like = "", Title = c.Title, Length = c.Length, Album_Name = c.Album.Name, Artist_Name = c.Artist.Name, CreatedAt = c.CreatedAt, UpdatedAt = c.UpdatedAt, Delete = "🗑 Delete", AlbumId = c.Album.AlbumId, SongId = c.SongId, Al = c.Album, Ar = c.Artist, ArtistId = c.Artist.ArtistId } }) .Join(ctx.Playlists.Where(u => u.User.UserId == Log_In.user.UserId && u.PlaylistId == ((Playlist)cmb_playlists.SelectedItem).PlaylistId), cx => cx.PlaylistId, p => p.PlaylistId, (cx, p) => cx.sngitm).ToList(); } dgvload(); cmb_Songs.DataSource = null; cmb_Songs.DataSource = songs; cmb_Songs.DisplayMember = "Title"; cmb_Songs.ValueMember = "SongId"; pnl_AddSong.Visible = false; } else { MessageBox.Show("Missing input(s) "); } }
private void Main_Load(object sender, EventArgs e) { cmbPlaylists = cmb_playlists; cmbAlbums = cmb_albums; cmbArtists = cmb_artists; using (var ctx = new MusicContext()) { playlists = ctx.Playlists.Where(c => c.User.UserId == Log_In.user.UserId).ToList(); cmb_playlists.DataSource = playlists; cmb_playlists.DisplayMember = "Name"; cmb_playlists.ValueMember = "PlaylistId"; albums = ctx.Albums.ToList(); artists = ctx.Artists.ToList(); songs = ctx.Songs.ToList(); songitems = ctx.Songs.Join(ctx.PlaylistSongs, c => c.SongId, x => x.SongId, (c, x) => new { PlaylistId = x.PlaylistId, sngitm = new SongItem { Like = "", Title = c.Title, Length = c.Length, Album_Name = c.Album.Name, Artist_Name = c.Artist.Name, CreatedAt = c.CreatedAt, UpdatedAt = c.UpdatedAt, Delete = "🗑 Delete", AlbumId = c.Album.AlbumId, SongId = c.SongId, Al = c.Album, Ar = c.Artist, ArtistId = c.Artist.ArtistId } }) .Join(ctx.Playlists.Where(u => u.User.UserId == Log_In.user.UserId && u.PlaylistId == ((Playlist)cmb_playlists.SelectedItem).PlaylistId), cx => cx.PlaylistId, p => p.PlaylistId, (cx, p) => cx.sngitm).ToList(); } cmb_albums.DataSource = albums; cmb_albums.DisplayMember = "Name"; cmb_albums.ValueMember = "AlbumId"; cmb_artists.DataSource = artists; cmb_artists.DisplayMember = "Name"; cmb_artists.ValueMember = "ArtistId"; cmb_Songs.DataSource = songs; cmb_Songs.DisplayMember = "Title"; cmb_Songs.ValueMember = "SongId"; }
private void cmb_playlists_SelectedIndexChanged(object sender, EventArgs e) { using (var ctx = new MusicContext()) { songitems = ctx.Songs.Join(ctx.PlaylistSongs, c => c.SongId, x => x.SongId, (c, x) => new { PlaylistId = x.PlaylistId, sngitm = new SongItem { Like = "", Title = c.Title, Length = c.Length, Album_Name = c.Album.Name, Artist_Name = c.Artist.Name, CreatedAt = c.CreatedAt, UpdatedAt = c.UpdatedAt, Delete = "🗑 Delete", AlbumId = c.Album.AlbumId, SongId = c.SongId, Al = c.Album, Ar = c.Artist, ArtistId = c.Artist.ArtistId } }) .Join(ctx.Playlists.Where(u => u.User.UserId == Log_In.user.UserId && u.PlaylistId == ((Playlist)cmb_playlists.SelectedItem).PlaylistId), cx => cx.PlaylistId, p => p.PlaylistId, (cx, p) => cx.sngitm).ToList(); } dgvload(); }
private void btn_login_Click(object sender, EventArgs e) { using (var ctx = new MusicContext()) { user = ctx.Users.FirstOrDefault(c => c.Email == txt_email.Text && c.Password == txt_password.Text); if (user != null) { Main main = new Main(); main.Show(); } } }
private void New_Album_Load(object sender, EventArgs e) { List <Artist> artists = new List <Artist>(); using (var ctx = new MusicContext()) { artists = ctx.Artists.ToList(); } cmb_Artist.DataSource = artists; cmb_Artist.DisplayMember = "Name"; cmb_Artist.ValueMember = "ArtistId"; }
public NewAlbumOrExistingAlbum() { InitializeComponent(); using (var ctx = new MusicContext()) { var OnlyAlbumsUsers = ctx.Users.Join(ctx.Interactions, u => u.UserId, i => i.UserId, (u, i) => new { u = u.UserId, i = i.UserId }); foreach (var item in ctx.Albums) { Albums.Add(item); } } if (Albums.Count == 0) { label1.Text = "Er zijn nog geen albums in onze records"; label2.Text = "Er zijn nog geen liedjes"; } else { comboBox1.DataSource = Albums; comboBox1.DisplayMember = "Name"; // Als er een album gekozen wordt dan moet try { album = comboBox1.SelectedItem as Album; } catch (InvalidCastException e) { if (e.Data == null) { throw new Exception("Album field was empty:.", e); } else { // Take some action. } } } }
public AddSongsToAlbum() { InitializeComponent(); using (var ctx = new MusicContext()) { var ListOfArtists = ctx.Artists; foreach (var item in ListOfArtists) { Artists.Add(item); } comboBox1.DataSource = Artists; comboBox1.DisplayMember = "Name"; } }
private void AddAlbum(object sender, EventArgs e) { using (var ctx = new MusicContext()) { if (ctx.Artists.FirstOrDefault() == null) { MessageBox.Show("You need to enter a artist before you can add an album"); } else { NewAlbumOrExistingAlbum NAEM = new NewAlbumOrExistingAlbum(); NAEM.Show(); } } }
public void dgvload() { dgv_Songs.DataSource = null; dgv_Songs.DataSource = songitems; dgv_Songs.Columns[1].DataPropertyName = "Title"; dgv_Songs.Columns[1].HeaderText = "⮁ " + dgv_Songs.Columns[1].HeaderText; dgv_Songs.Columns[2].DataPropertyName = "Length"; dgv_Songs.Columns[2].HeaderText = "⮁ " + dgv_Songs.Columns[2].HeaderText; dgv_Songs.Columns[3].DataPropertyName = "Album_Name"; dgv_Songs.Columns[3].HeaderText = "⮁" + dgv_Songs.Columns[3].HeaderText; dgv_Songs.Columns[4].DataPropertyName = "Artist_Name"; dgv_Songs.Columns[4].HeaderText = "⮁" + dgv_Songs.Columns[4].HeaderText; dgv_Songs.Columns[5].DataPropertyName = "CreatedAt"; dgv_Songs.Columns[5].HeaderText = "⮁ " + dgv_Songs.Columns[5].HeaderText; dgv_Songs.Columns[6].DataPropertyName = "UpdatedAt"; dgv_Songs.Columns[6].HeaderText = "⮁ " + dgv_Songs.Columns[6].HeaderText; dgv_Songs.Columns[7].DataPropertyName = "Like"; dgv_Songs.Columns[7].HeaderText = "⮁ " + dgv_Songs.Columns[7].HeaderText; dgv_Songs.Columns[8].DataPropertyName = "Delete"; for (int i = dgv_Songs.Columns.Count - 1; i > 8; i--) { dgv_Songs.Columns.RemoveAt(i); } for (int i = 0; i < dgv_Songs.Rows.Count; i++) { dgv_Songs.Rows[i].Cells[0].Value = "▶ Play"; dgv_Songs.Rows[i].Cells[7].Value = "👍 Like"; } using (var ctx = new MusicContext()) { for (int i = 0; i < dgv_Songs.Rows.Count; i++) { SongItem sngitm = (SongItem)dgv_Songs.Rows[i].DataBoundItem; Interaction inter = ctx.Interactions.FirstOrDefault(c => c.User.UserId == Log_In.user.UserId && c.Song.SongId == sngitm.SongId); if (inter != null && inter.Liked == true) { dgv_Songs.Rows[i].Cells[7].Value = "👎 Unlike"; } } } }
private void btn_Add_Click(object sender, EventArgs e) { if (txt_Name.Text != "" && cmb_Artist.SelectedValue != null) { using (var ctx = new MusicContext()) { ctx.Albums.Add(new Album { Name = txt_Name.Text, Artist = ctx.Artists.FirstOrDefault(c => c.ArtistId == (int)cmb_Artist.SelectedValue), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }); ctx.SaveChanges(); Main.albums = ctx.Albums.ToList(); Main.cmbAlbums.DataSource = null; Main.cmbAlbums.DataSource = Main.albums; Main.cmbAlbums.DisplayMember = "Name"; Main.cmbAlbums.ValueMember = "AlbumId"; } } this.Close(); }
private void btn_Add_Click(object sender, EventArgs e) { if (txt_Name.Text != "") { using (var ctx = new MusicContext()) { ctx.Artists.Add(new Artist { Name = txt_Name.Text, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }); ctx.SaveChanges(); Main.artists = ctx.Artists.ToList(); Main.cmbArtists.DataSource = null; Main.cmbArtists.DataSource = Main.albums; Main.cmbArtists.DisplayMember = "Name"; Main.cmbArtists.ValueMember = "ArtistId"; } } this.Close(); }
private void button1_Click(object sender, EventArgs e) { var artistName = textBox1.Text; using (var ctx = new MusicContext()) { Artists artist = new Artists(); artist.Name = artistName; ctx.Artists.Add(artist); ctx.SaveChanges(); } MessageBox.Show("You have added a new artist"); textBox1.Clear(); // Voeg een artiest toe aan }
private void button1_Click(object sender, EventArgs e) { // Pak de gegevens van de gebruiker // Zet deze in de database string Firstname = textBox1.Text; string LastName = textBox2.Text; string Email = textBox4.Text; string Username = textBox5.Text; string Password = textBox3.Text; CheckEmail(); CheckPassword(); if (CorrectEmail == true && CorrectPassword == true) { using (var ctx = new MusicContext()) { ctx.Users.Add(new User { Firstname = Firstname, Lastname = LastName, Email = Email, Username = Username, Password = Password }); MessageBox.Show("You are signed up"); ctx.SaveChanges(); } } else if (CorrectEmail == false) { MessageBox.Show("You haven't entered a good email address"); } else if (CorrectPassword == false) { MessageBox.Show("You have entered an invalid password"); } }
private void dgv_Songs_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1) { var senderGrid = (DataGridView)sender; SongItem sngitm = (SongItem)senderGrid.Rows[e.RowIndex].DataBoundItem;; Song sng = new Song { SongId = sngitm.SongId, Title = sngitm.Title, Length = sngitm.Length, CreatedAt = sngitm.CreatedAt, UpdatedAt = sngitm.UpdatedAt, Album = sngitm.Al, Artist = sngitm.Ar }; if (e.ColumnIndex == 0 || e.ColumnIndex == 7) { using (var ctx = new MusicContext()) { if (senderGrid.CurrentCell.Value == "▶ Play") { if (ctx.Interactions.FirstOrDefault(c => c.User.UserId == Log_In.user.UserId && c.Song.SongId == sng.SongId) == null) { ctx.Interactions.Add(new Interaction { User = ctx.Users.FirstOrDefault(c => c.UserId == Log_In.user.UserId), Song = ctx.Songs.FirstOrDefault(c => c.SongId == sng.SongId), Liked = false, PlayCount = 1, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }); } else { ctx.Interactions.FirstOrDefault(c => c.User.UserId == Log_In.user.UserId && c.Song.SongId == sng.SongId).PlayCount += 1; } for (int i = 0; i < dgv_Songs.Rows.Count; i++) { dgv_Songs.Rows[i].Cells[0].Value = "▶ Play"; } dgv_Songs.CurrentCell.Value = "⏹ Stop"; } else if (senderGrid.CurrentCell.Value == "⏹ Stop") { senderGrid.CurrentCell.Value = "▶ Play"; } else if (senderGrid.CurrentCell.Value == "👍 Like") { if (ctx.Interactions.FirstOrDefault(c => c.User.UserId == Log_In.user.UserId && c.Song.SongId == sng.SongId) == null) { ctx.Interactions.Add(new Interaction { User = ctx.Users.FirstOrDefault(c => c.UserId == Log_In.user.UserId), Song = ctx.Songs.FirstOrDefault(c => c.SongId == sng.SongId), Liked = true, PlayCount = 0, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }); } else { ctx.Interactions.FirstOrDefault(c => c.User.UserId == Log_In.user.UserId && c.Song.SongId == sng.SongId).Liked = true; } senderGrid.CurrentCell.Value = "👎 Unlike"; } else if (senderGrid.CurrentCell.Value == "👎 Unlike") { ctx.Interactions.FirstOrDefault(c => c.User.UserId == Log_In.user.UserId && c.Song.SongId == sng.SongId).Liked = false; senderGrid.CurrentCell.Value = "👍 Like"; } ctx.SaveChanges(); } } else if (e.ColumnIndex == 8) { Delete d = new Delete(); switch (d.ShowDialog()) { case DialogResult.Yes: SongItem snit = (SongItem)dgv_Songs.Rows[e.RowIndex].DataBoundItem; using (var ctx = new MusicContext()) { ctx.Songs.Remove(ctx.Songs.FirstOrDefault(s => s.SongId == snit.SongId)); ctx.SaveChanges(); songs = ctx.Songs.ToList(); songitems = ctx.Songs.Join(ctx.PlaylistSongs, c => c.SongId, x => x.SongId, (c, x) => new { PlaylistId = x.PlaylistId, sngitm = new SongItem { Like = "", Title = c.Title, Length = c.Length, Album_Name = c.Album.Name, Artist_Name = c.Artist.Name, CreatedAt = c.CreatedAt, UpdatedAt = c.UpdatedAt, Delete = "🗑 Delete", AlbumId = c.Album.AlbumId, SongId = c.SongId, Al = c.Album, Ar = c.Artist, ArtistId = c.Artist.ArtistId } }) .Join(ctx.Playlists.Where(u => u.User.UserId == Log_In.user.UserId && u.PlaylistId == ((Playlist)cmb_playlists.SelectedItem).PlaylistId), cx => cx.PlaylistId, p => p.PlaylistId, (cx, p) => cx.sngitm).ToList(); } dgvload(); cmb_Songs.DataSource = null; cmb_Songs.DataSource = songs; cmb_Songs.DisplayMember = "Title"; cmb_Songs.ValueMember = "SongId"; break; case DialogResult.OK: SongItem snit1 = (SongItem)dgv_Songs.Rows[e.RowIndex].DataBoundItem; Playlist pl = (Playlist)cmb_playlists.SelectedItem; using (var ctx = new MusicContext()) { ctx.PlaylistSongs.Remove(ctx.PlaylistSongs.FirstOrDefault(s => s.SongId == snit1.SongId && s.PlaylistId == pl.PlaylistId)); ctx.SaveChanges(); songitems = ctx.Songs.Join(ctx.PlaylistSongs, c => c.SongId, x => x.SongId, (c, x) => new { PlaylistId = x.PlaylistId, sngitm = new SongItem { Like = "", Title = c.Title, Length = c.Length, Album_Name = c.Album.Name, Artist_Name = c.Artist.Name, CreatedAt = c.CreatedAt, UpdatedAt = c.UpdatedAt, Delete = "🗑 Delete", AlbumId = c.Album.AlbumId, SongId = c.SongId, Al = c.Album, Ar = c.Artist, ArtistId = c.Artist.ArtistId } }) .Join(ctx.Playlists.Where(u => u.User.UserId == Log_In.user.UserId && u.PlaylistId == ((Playlist)cmb_playlists.SelectedItem).PlaylistId), cx => cx.PlaylistId, p => p.PlaylistId, (cx, p) => cx.sngitm).ToList(); } dgvload(); break; } } dgv_Songs.Update(); } else { if (lastcolumn != e.ColumnIndex) { ascending = true; } switch (e.ColumnIndex) { case 7: if (ascending) { songitems.Sort((x, y) => x.Like.CompareTo(y.Like)); ascending = false; lastcolumn = 7; } else { songitems.Sort((x, y) => y.Like.CompareTo(x.Like)); ascending = true; } break; case 1: if (ascending) { songitems.Sort((x, y) => x.Title.CompareTo(y.Title)); ascending = false; lastcolumn = 1; } else { songitems.Sort((x, y) => y.Title.CompareTo(x.Title)); ascending = true; } break; case 2: if (ascending) { songitems.Sort((x, y) => x.Length.CompareTo(y.Length)); ascending = false; lastcolumn = 2; } else { songitems.Sort((x, y) => y.Length.CompareTo(x.Length)); ascending = true; } break; case 3: if (ascending) { songitems.Sort((x, y) => x.Album_Name.CompareTo(y.Album_Name)); ascending = false; lastcolumn = 3; } else { songitems.Sort((x, y) => y.Album_Name.CompareTo(x.Album_Name)); ascending = true; } break; case 4: if (ascending) { songitems.Sort((x, y) => x.Artist_Name.CompareTo(y.Artist_Name)); ascending = false; lastcolumn = 4; } else { songitems.Sort((x, y) => y.Artist_Name.CompareTo(x.Artist_Name)); ascending = true; } break; case 5: if (ascending) { songitems.Sort((x, y) => x.CreatedAt.CompareTo(y.CreatedAt)); ascending = false; lastcolumn = 5; } else { songitems.Sort((x, y) => y.CreatedAt.CompareTo(x.CreatedAt)); ascending = true; } break; case 6: if (ascending) { songitems.Sort((x, y) => x.UpdatedAt.CompareTo(y.UpdatedAt)); ascending = false; lastcolumn = 6; } else { songitems.Sort((x, y) => y.UpdatedAt.CompareTo(x.UpdatedAt)); ascending = true; } break; } dgvload(); } }