Exemplo n.º 1
0
        public static int deleteSongEntry(MyPianoSong pianoSong)
        {
            if (pianoSong.songID <= 0)
            {
                throw new Exception("Unable to delete song, no song ID provided");
            }
            try
            {
                var newQuery = (from p in context.PianoSongs
                                where p.PianoSongID == pianoSong.songID
                                select p);
                PianoSong ps = newQuery.FirstOrDefault();
                Song      s  = ps.Song;
                Artist    a  = ps.Artist;
                Book      b  = ps.Book;
                context.PianoSongs.Remove(ps);
                context.SaveChanges();
                return(ps.PianoSongID);
            }
            catch (Exception ex)
            {
#if (DEBUG)
                Logger.LogError(ex, showDialog: true);
#else
                Logger.LogError(ex);
#endif
                return(-1);
            }
        }
Exemplo n.º 2
0
 public static int addSongEntry(MyPianoSong pianoSong)
 {
     try
     {
         Song      s     = new Song();
         Artist    a     = new Artist();
         Book      b     = new Book();
         PianoSong pSong = new PianoSong();
         s.SongName       = pianoSong.SongTitle;
         a.ArtistName     = pianoSong.SongArtist;
         b.BookName       = pianoSong.SongBook;
         pSong.Song       = s;
         pSong.Artist     = a;
         pSong.Book       = b;
         pSong.PageNumber = pianoSong.PageNum;
         context.PianoSongs.Add(pSong);
         context.SaveChanges();
         return(pSong.PianoSongID);
     }
     catch (Exception ex)
     {
         #if (DEBUG)
         Logger.LogError(ex, showDialog: true);
         #else
         Logger.LogError(ex);
         #endif
         return(-1);
     }
 }
Exemplo n.º 3
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure you want to delete all of the songs shown?", "Delete Songs?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    int count = 0;
                    if (bindingTable.Rows.Count == 0)
                    {
                        MessageBox.Show("No Songs to Delete.");
                        return;
                    }
                    foreach (System.Data.DataRow pianoSong in bindingTable.Rows)
                    {
                        MyPianoSong song = new MyPianoSong();
                        song.songID = Convert.ToInt32(pianoSong["PianoSongID", System.Data.DataRowVersion.Current].ToString().Trim());
                        PianoSongDatabase.deleteSongEntry(song);
                        count++;
                    }
                    bindingTable.AcceptChanges();
                    searchSongs();
                    if (count == 0)
                    {
                        MessageBox.Show("No songs were deleted.");
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Successfully deleted {0} songs!", count));
                    }
                }
            }
            catch (Exception ex)
            {
#if (DEBUG)
                Logger.LogError(ex, showDialog: true);
#else
                Logger.LogError(ex);
#endif
            }
        }
Exemplo n.º 4
0
        private void btnSaveEntries_Click(object sender, RoutedEventArgs e)
        {
            MyPianoSong ps;
            int         count = 0;
            string      artist;
            string      book;
            string      song;

            if (tbSongs.Text.Trim() == String.Empty)
            {
                MessageBox.Show("No songs entered.");
                return;
            }
            if (tbArtist.Text.Trim() == string.Empty)
            {
                MessageBox.Show("You must enter an artist...");
                artist = "";
                return;
            }
            else
            {
                artist = tbArtist.Text;
            }
            if (tbArtist.Text.Trim() == string.Empty)
            {
                MessageBox.Show("No book entered, using NONE for book name");
                book = "NONE";
            }
            else
            {
                book = tbBook.Text;
            }

            WaitDialog.Show("Saving songs, please wait...");
            for (int i = 0; i < tbSongs.LineCount; i++)
            {
                try
                {
                    ps            = new MyPianoSong();
                    ps.SongArtist = artist;
                    ps.SongBook   = book;
                    song          = tbSongs.GetLineText(i);
                    if (song != string.Empty)
                    {
                        string pageNum = "";
                        if (song.Contains("~"))
                        {
                            int index = song.IndexOf("~");
                            if (song.Substring(index + 1).Trim() != string.Empty)
                            {
                                pageNum = song.Substring(index + 1).Trim();
                            }
                            ps.SongTitle = song.Substring(0, index).Trim();
                            if (IsNumeric(pageNum))
                            {
                                ps.PageNum = int.Parse(pageNum);
                            }
                        }
                        else
                        {
                            ps.SongTitle = song.Trim();
                            ps.PageNum   = -1;
                        }
                        PianoSongDatabase.addSongEntry(ps);
                        count++;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                }
            }
            WaitDialog.Hide();
            MessageBox.Show("Successfully saved " + count + " songs!");
            cache.ClearAllCache();
            tbBook.Text   = "";
            tbArtist.Text = "";
            tbSongs.Text  = "";
            tbArtist.SetSource(cache.getArtists(), "artist");
            tbBook.SetSource(cache.getBooks(), "book");
            return;
        }
Exemplo n.º 5
0
        private void btnSaveChanges_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int count = 0;
                foreach (System.Data.DataRow pianoSong in bindingTable.Rows)
                {
                    if (pianoSong.RowState == System.Data.DataRowState.Added)
                    {
                        if (pianoSong["Title"].ToString().Trim() == "" && pianoSong["Artist"].ToString().Trim() == "" &&
                            pianoSong["Book"].ToString().Trim() == "" && pianoSong["PageNumber"].ToString().Trim() == "")
                        {
                            continue;
                        }
                        MyPianoSong song = new MyPianoSong();
                        count++;
                        try
                        {
                            song.SongTitle  = pianoSong["Title"].ToString().Trim();
                            song.SongArtist = pianoSong["Artist"].ToString().Trim();
                            song.SongBook   = pianoSong["Book"].ToString().Trim();
                            if (pianoSong["PageNumber"].ToString().Trim() == "")
                            {
                                song.PageNum = -1;
                            }
                            else
                            {
                                song.PageNum = Convert.ToInt32(pianoSong["PageNumber"].ToString().Trim());
                            }
                        }
                        catch (Exception exc)
                        {
                            Logger.LogMessage("Song title, artist, or book is not valid, unable to save.", level: Logger.logLevel.Error, showDialog: true);
                            return;
                        }
                        string valid = song.songValidMessage();
                        if (valid.Trim() != "")
                        {
                            throw new Exception(valid);
                        }
                        PianoSongDatabase.addSongEntry(song);
                    }
                    else if (pianoSong.RowState == System.Data.DataRowState.Deleted)
                    {
                        count++;
                        MyPianoSong song = new MyPianoSong();
                        song.songID = Convert.ToInt32(pianoSong["PianoSongID", System.Data.DataRowVersion.Original].ToString().Trim());
                        PianoSongDatabase.deleteSongEntry(song);
                    }
                    else if (pianoSong.RowState == System.Data.DataRowState.Modified)
                    {
                        count++;
                        MyPianoSong song = new MyPianoSong();
                        try
                        {
                            song.songID     = Convert.ToInt32(pianoSong["PianoSongID"].ToString().Trim());
                            song.SongTitle  = pianoSong["Title"].ToString().Trim();
                            song.SongArtist = pianoSong["Artist"].ToString().Trim();
                            song.SongBook   = pianoSong["Book"].ToString().Trim();
                            if (pianoSong["PageNumber"].ToString().Trim() == "")
                            {
                                song.PageNum = -1;
                            }
                            else
                            {
                                song.PageNum = Convert.ToInt32(pianoSong["PageNumber"].ToString().Trim());
                            }
                        }
                        catch (Exception exc)
                        {
                            Logger.LogMessage("Song title, artist, or book is not valid, unable to save.", level: Logger.logLevel.Error, showDialog: true);
                            return;
                        }
                        string valid = song.songValidMessage();
                        if (valid.Trim() != "")
                        {
                            throw new Exception(valid);
                        }
                        PianoSongDatabase.updateSongEntry(song);
                    }
                }
                bindingTable.AcceptChanges();
                searchSongs();
                if (count == 0)
                {
                    MessageBox.Show("No changes were made");
                }
                else
                {
                    MessageBox.Show(String.Format("Successfully saved {0} changes!", count));
                }
            }
            catch (Exception ex)
            {
#if (DEBUG)
                Logger.LogError(ex, showDialog: true);
#else
                Logger.LogError(ex);
#endif
            }
        }