Beispiel #1
0
        private void Save(object sender, EventArgs e)
        {
            var IsFormValid = ValidateForm();

            CancelClicked = false;
            if (!IsFormValid)
            {
                return;
            }
            if (Mode == SongSelect.Modes.Create)
            {
                Setlist = new Setlist();
                Setlist.SetlistEntries = new List <SetlistEntry>();
            }
            Setlist.Title = SetlistTitle.Text;
            Setlist.Band  = SetlistBand.SelectedValue.ToString();
            DetermineSetOrder();
            /****************************************************/
            // In a larger volume situation, it would make sense
            // to build three lists: Add, Removed and Reorder.
            // Here we're talking about a set list, which likely has
            // fewer than 20 entries.  So let's just do the easy thing,
            // Remove all of them and just add everything back into the
            // database.
            /****************************************************/
            RemoveExistingSongs();
            AddSelectedSongs();
            var recordsUpdated = SongLibrary.SaveChanges();

            Close();
        }
Beispiel #2
0
        private void Save(object sender, EventArgs e)
        {
            var IsFormValid = ValidateForm();

            CancelClicked = false;
            if (!IsFormValid)
            {
                return;
            }
            if (Mode == SongSelect.Modes.Create)
            {
                Song = new Song();
            }
            Song.Title      = SongTitle.Text;
            Song.Artist     = SongArtist.Text;
            Song.Instrument = SongInstrument.SelectedItem.ToString();
            Song.Key        = SongKey.SelectedItem.ToString();;
            Song.Major      = true;
            Song.Filepath   = SongFilename.Text;
            if (SongFirstNote.SelectedItem != null)
            {
                Song.FirstNote = SongFirstNote.SelectedItem.ToString();
            }
            else
            {
                Song.FirstNote = null;
            }
            if (Mode == SongSelect.Modes.Create)
            {
                SongLibrary.Songs.Add(Song);
            }
            // Another place where the small volume makes it not worth while to selectively remove.
            // Just remove them all and add them back in.
            foreach (var SItem in this.Libraries.Items)
            {
                var Library = SongLibrary.Libraries.Where(t => t.Title == SItem.ToString()).FirstOrDefault();
                if (Library.Songs.Contains(Song))
                {
                    Library.Songs.Remove(Song);
                }
            }
            foreach (var SItem in this.Libraries.SelectedItems)
            {
                var Library = SongLibrary.Libraries.Where(t => t.Title == SItem.ToString()).FirstOrDefault();
                if (!Library.Songs.Contains(Song))
                {
                    Library.Songs.Add(Song);
                }
            }
            SongLibrary.SaveChanges();
            Close();
        }
Beispiel #3
0
        private void Save(object sender, EventArgs e)
        {
            ErrorMessages.Visible = false;
            ErrorMessages.Rows.Clear();
            var IsFormValid = ValidateForm();

            CancelClicked = false;
            if (!IsFormValid)
            {
                return;
            }
            if (Mode == SongSelect.Modes.Create)
            {
                Library = new Library();
            }
            Library.Title       = LibraryTitle.Text;
            Library.Description = LibraryDescription.Text;
            if (Mode == SongSelect.Modes.Create)
            {
                SongLibrary.Libraries.Add(Library);
            }
            var Songs_Start = SongsAtStart.Items.Cast <ListViewItem>();
            var Songs_End   = SongsInLibrary.Items.Cast <ListViewItem>();
            // Except() Items in the first set that don't appear in the second.
            var SongsToRemoveFromLibrary = Songs_Start.Except <ListViewItem>(Songs_End, new ListViewItemComparer()).ToList();
            var SongsToAddToLibrary      = Songs_End.Except <ListViewItem>(Songs_Start, new ListViewItemComparer()).ToList();
            int SongId;

            foreach (ListViewItem SongToRemove in SongsToRemoveFromLibrary)
            {
                var rc = int.TryParse(SongToRemove.SubItems[3].Text, out SongId);
                if (rc)
                {
                    Library.Songs.Remove(SongLibrary.Songs.Where(s => s.Id == SongId).FirstOrDefault());
                }
            }
            // Update the list of songs.
            foreach (ListViewItem SongToAdd in SongsToAddToLibrary)
            {
                var rc = int.TryParse(SongToAdd.SubItems[3].Text, out SongId);
                if (rc)
                {
                    Library.Songs.Add(SongLibrary.Songs.Where(s => s.Id == SongId).FirstOrDefault());
                }
            }
            SongLibrary.SaveChanges();
            Close();
        }
Beispiel #4
0
 private void Delete(object sender, EventArgs e)
 {
     if (Song == null)
     {
         MessageBox.Show("Not found");
     }
     else
     {
         DialogResult rc = MessageBox.Show("Delete " + Song.Title + "?", "Confirm Delete", MessageBoxButtons.YesNoCancel);
         if (rc == DialogResult.Yes)
         {
             SongLibrary.Songs.Remove(Song);
             SongLibrary.SaveChanges();
             Close();
         }
     }
 }
Beispiel #5
0
        private void DeleteSetlist(object sender, EventArgs e)
        {
            var     lastSubItem = SetlistList.SelectedItems[0].SubItems.Count - 1;
            var     SetlistId   = int.Parse(SetlistList.SelectedItems[0].SubItems[lastSubItem].Text);
            Setlist setlist     = SongLibrary.Setlists.Where(l => l.Id == SetlistId).FirstOrDefault();
            var     rc          = MessageBox.Show("Are you sure you want to delete the library '" + setlist.Title + "'?", "Delete Setlist", MessageBoxButtons.YesNoCancel);

            if (rc == DialogResult.Yes)
            {
                foreach (var entry in setlist.SetlistEntries.ToList())
                {
                    SongLibrary.SetlistEntries.Remove(entry);
                }
                SongLibrary.Setlists.Remove(setlist);
                SongLibrary.SaveChanges();
            }
            LoadSetlistList();
            EnableButtons(sender, e);
        }