Exemplo n.º 1
0
        public void searchSongs()
        {
            System.Windows.Data.CollectionViewSource pianoSongViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("pianoSongViewSource")));
            bool displayAll = false;

            if (prvtSongFilter == -1 && prvtArtistFilter == -1 && prvtBookFilter == -1)
            {
                displayAll = true;
            }
            else if (prvtSongText.Trim() == "" && prvtArtistText.Trim() == "" && prvtBookText.Trim() == "")
            {
                displayAll = true;
            }
            if (displayAll)
            {
                bindingTable = PianoSongDatabase.getAllData();
            }
            else
            {
                bindingTable = PianoSongDatabase.searchData(prvtSongFilter, prvtArtistFilter, prvtBookFilter, prvtSongText.Trim(), prvtArtistText.Trim(), prvtBookText.Trim());
            }
            bindingTable.AcceptChanges();
            pianoSongViewSource.Source = bindingTable;
            lblCount.Content           = "Count: " + bindingTable.Rows.Count.ToString();
        }
Exemplo n.º 2
0
 public DataTable getAllData()
 {
     if (m_PianoSongs == null)
     {
         m_PianoSongs = PianoSongDatabase.getAllData();
     }
     return(m_PianoSongs);
 }
Exemplo n.º 3
0
 public DataTable getBooks()
 {
     if (m_Books == null)
     {
         m_Books = PianoSongDatabase.getAllBooks();
     }
     return(m_Books);
 }
Exemplo n.º 4
0
 public DataTable getArtists()
 {
     if (m_Artists == null)
     {
         m_Artists = PianoSongDatabase.getAllArtists();
     }
     return(m_Artists);
 }
Exemplo n.º 5
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.º 6
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.º 7
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
            }
        }