private void btSave_Click(object sender, EventArgs e)
        {
            var capArtist = LyricUtil.CapatalizeString(_mCurrentArtist);
            var capTitle  = LyricUtil.CapatalizeString(_mCurrentTitle);

            var lyrics = LyricUtil.FixLyrics(tbLyrics.Text);

            CurrentLyricsDatabase[DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)].Lyrics = lyrics;
            DatabaseUtil.SerializeDB(CurrentLyricsDatabase);

            if (SettingManager.GetParamAsBool(SettingManager.AutomaticWriteToMusicTag, true))
            {
                TagReaderUtil.WriteLyrics(capArtist, capTitle, lyrics);
            }

            if (CurrentLyricsDatabase.Equals(MyLyricsUtils.LyricsMarkedDB))
            {
                if (SettingManager.GetParamAsBool(SettingManager.MoveLyricFromMarkedDatabase, true))
                {
                    MoveLyricToOtherDatabase();
                }
            }

            var lrc = new SimpleLRC(capArtist, capTitle, lyrics);

            if (lrc.IsValid && _parentMyLyricsSetup.cbUploadLrcAutomatically.Checked)
            {
                LrcFinder.SaveLrcWithGuid(lyrics, _parentMyLyricsSetup.MGuid);
            }

            btSave.Enabled = false;
            treeView.Focus();
        }
        /// <summary>
        /// AddSong with tree parameters adds a lyric to the treeView and the lyric database
        /// </summary>
        /// <param name="artist">artist</param>
        /// <param name="title">title</param>
        /// <param name="lyrics">lyircs</param>
        /// <param name="site">site</param>
        private bool AddSong(string artist, string title, string lyrics, string site)
        {
            var item = new LyricsItem(artist, title, lyrics, site);

            if (DatabaseUtil.IsSongInLyricsDatabase(CurrentLyricsDatabase, artist, title).Equals(DatabaseUtil.LyricNotFound))
            {
                CurrentLyricsDatabase.Add(DatabaseUtil.CorrectKeyFormat(artist, title), item);
                try
                {
                    AddSong(item);
                }
                catch
                {
                    ;
                }
                treeView.Update();
                DatabaseUtil.SerializeDB(CurrentLyricsDatabase);

                if (SettingManager.GetParamAsBool(SettingManager.AutomaticWriteToMusicTag, true))
                {
                    TagReaderUtil.WriteLyrics(artist, title, lyrics);
                }

                return(true);
            }
            return(false);
        }
 private void btSave_Click(object sender, EventArgs e)
 {
     CurrentDB[DatabaseUtil.CorrectKeyFormat(LyricUtil.CapatalizeString(m_CurrentArtist), LyricUtil.CapatalizeString(m_CurrentTitle))].Lyrics = tbLyrics.Text;
     DatabaseUtil.SerializeDB(CurrentDB);
     btSave.Enabled = false;
     treeView.Focus();
 }
        public void RemoveSong(string artist, string title)
        {
            try
            {
                int artistIndex = treeView.Nodes.IndexOfKey(artist);
                int titleIndex  = treeView.Nodes[artistIndex].Nodes.IndexOfKey(title);
                treeView.Nodes[artistIndex].Nodes.RemoveAt(titleIndex);
                --m_NoOfTitles;

                // remove title from treeView
                if (treeView.Nodes[artistIndex].Nodes.Count == 0)
                {
                    treeView.Nodes.RemoveAt(artistIndex);
                    --m_NoOfArtists;
                }
            }
            catch
            {
                if (artist.Length == 0 && title.Length == 0)
                {
                    treeView.Nodes.RemoveAt(0);
                    --m_NoOfArtists;
                    treeView.Update();
                }
            }
            finally
            {
                treeView.Update();

                // remove title from database
                CurrentDB.Remove(DatabaseUtil.CorrectKeyFormat(artist, title));
                DatabaseUtil.SerializeDB(CurrentDB);
            }
        }
        /// <summary>
        /// AddSong with tree parameters adds a lyric to the treeView and the lyric database
        /// </summary>
        /// <param name="artist"></param>
        /// <param name="title"></param>
        /// <param name="lyric"></param>
        private bool AddSong(string artist, string title, string lyrics, string site)
        {
            LyricsItem item = new LyricsItem(artist, title, lyrics, site);

            if (DatabaseUtil.IsTrackInLyricsDatabase(CurrentDB, artist, title).Equals(DatabaseUtil.LYRIC_NOT_FOUND))
            {
                CurrentDB.Add(DatabaseUtil.CorrectKeyFormat(artist, title), item);
                AddSong(item);
                treeView.Update();
                DatabaseUtil.SerializeDB(CurrentDB);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void MoveLyricToOtherDatabase()
        {
            var artist = "";
            var title  = "";

            if (treeView.SelectedNode != null)
            {
                var temp = treeView.SelectedNode.Text;

                if (treeView.SelectedNode.Parent != null)
                {
                    artist = treeView.SelectedNode.Parent.Text;
                    title  = temp;
                }
                else
                {
                    artist = temp;
                }
            }

            if (artist.Length == 0 && title.Length == 0)
            {
                MessageBox.Show("No artist or track selected");
            }
            else if (title.Length == 0)
            {
                var artistNode = treeView.SelectedNode;

                LyricsDatabase otherDatabase;
                if (CurrentLyricsDatabase.Equals(MyLyricsUtils.LyricsDB))
                {
                    otherDatabase = MyLyricsUtils.LyricsMarkedDB;
                }
                else
                {
                    otherDatabase = MyLyricsUtils.LyricsDB;
                }

                foreach (TreeNode node in artistNode.Nodes)
                {
                    var key  = DatabaseUtil.CorrectKeyFormat(artist, node.Text);
                    var item = CurrentLyricsDatabase[key];
                    CurrentLyricsDatabase.Remove(key);

                    if (!DatabaseUtil.IsSongInLyricsDatabase(otherDatabase, artist, item.Title).Equals(DatabaseUtil.LyricNotFound))
                    {
                        otherDatabase.Add(key, item);
                    }
                    else
                    {
                        otherDatabase[key] = item;
                    }
                }
                UpdateLyricsTree(false);
                DatabaseUtil.SerializeDBs();
            }
            else
            {
                var key  = DatabaseUtil.CorrectKeyFormat(artist, title);
                var item = CurrentLyricsDatabase[key];

                // remove song from treeview and current database
                RemoveSong(artist, title, true);

                // add song to other database and serialize it
                if (CurrentLyricsDatabase.Equals(MyLyricsUtils.LyricsDB))
                {
                    MyLyricsUtils.LyricsMarkedDB.Add(key, item);
                    DatabaseUtil.SerializeDB(MyLyricsUtils.LyricsMarkedDB);
                }
                else
                {
                    MyLyricsUtils.LyricsDB.Add(key, item);
                    DatabaseUtil.SerializeDB(MyLyricsUtils.LyricsDB);
                }
                UpdateLyricDatabaseStats();
            }

            treeView.Focus();
        }
        private void btSwitch_Click(object sender, EventArgs e)
        {
            string temp   = "";
            string artist = "";
            string title  = "";

            if (treeView.SelectedNode != null)
            {
                temp = treeView.SelectedNode.Text;

                if (treeView.SelectedNode.Parent != null)
                {
                    artist = treeView.SelectedNode.Parent.Text;
                    title  = temp;
                }
                else
                {
                    artist = temp;
                }
            }

            if (artist.Length == 0 && title.Length == 0)
            {
                MessageBox.Show("No artist or track selected");
            }
            else if (title.Length == 0)
            {
                TreeNode artistNode = treeView.SelectedNode;

                LyricsDatabase otherDatabase = null;
                if (CurrentDB.Equals(MyLyricsSettings.LyricsDB))
                {
                    otherDatabase = MyLyricsSettings.LyricsMarkedDB;
                }
                else
                {
                    otherDatabase = MyLyricsSettings.LyricsDB;
                }

                foreach (TreeNode node in artistNode.Nodes)
                {
                    string     key  = DatabaseUtil.CorrectKeyFormat(artist, node.Text);
                    LyricsItem item = CurrentDB[key];
                    CurrentDB.Remove(key);

                    if (!DatabaseUtil.IsTrackInLyricsDatabase(otherDatabase, artist, item.Title).Equals(DatabaseUtil.LYRIC_NOT_FOUND))
                    {
                        otherDatabase.Add(key, item);
                    }
                    else
                    {
                        otherDatabase[key] = item;
                    }
                }
                updateLyricsTree();
                DatabaseUtil.SerializeDBs();
            }
            else
            {
                string     key  = DatabaseUtil.CorrectKeyFormat(artist, title);
                LyricsItem item = CurrentDB[key];

                // remove song from treeview and current database
                RemoveSong(artist, title);

                // add song to other database and serialize it
                if (CurrentDB.Equals(MyLyricsSettings.LyricsDB))
                {
                    MyLyricsSettings.LyricsMarkedDB.Add(key, item);
                    DatabaseUtil.SerializeDB(MyLyricsSettings.LyricsMarkedDB);
                }
                else
                {
                    MyLyricsSettings.LyricsDB.Add(key, item);
                    DatabaseUtil.SerializeDB(MyLyricsSettings.LyricsDB);
                }
                updateLyricDatabaseStats();
            }

            treeView.Focus();
        }