Exemple #1
0
        //*PARA QUE FUNCIONE EL GUARDADO SE DEBE INICIAR SIN EL MENU DEPURAR

        private void guardarbtn_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = null;
                string name     = null;

                if (vistalista.SelectedItems.Count == 1)
                {
                    filePath = vistalista.FocusedItem.SubItems[4].Text;
                    name     = vistalista.FocusedItem.SubItems[0].Text;
                    Etiqueta et = new Etiqueta();
                    //Add Save File

                    TagLib.File tagFile = TagLib.File.Create(filePath);
                    TagLib.Id3v2.Tag.DefaultVersion      = 3;
                    TagLib.Id3v2.Tag.ForceDefaultVersion = true;

                    //Change of title
                    tagFile.Tag.Title = null;
                    et.SetTitle(titulotext.Text);
                    tagFile.Tag.Title = et.GetTitle();


                    //Change of Artists
                    et.SetArtist(artistatext.Text);
                    string[] toArtist = et.GetArtist().Split(',');

                    tagFile.Tag.Performers = null;
                    tagFile.Tag.Performers = toArtist; //new string[1]


                    //Change of album
                    tagFile.Tag.Album = null;
                    et.SetAlbum(albumtext.Text);
                    tagFile.Tag.Album = et.GetAlbum();

                    //Change of year
                    et.SetYear(anyotext.Text);
                    uint yesyear;
                    bool probandoanyo = uint.TryParse(et.GetYear(), out yesyear);

                    if (probandoanyo == true)
                    {
                        tagFile.Tag.Year = yesyear;
                    }

                    //Change of Comment
                    tagFile.Tag.Comment = null;
                    et.SetComment(comtext.Text);
                    tagFile.Tag.Comment = et.GetComment();

                    //Change of Genre
                    et.SetGenre(generotext.Text);
                    string[] toGenre = et.GetGenre().Split(',');

                    tagFile.Tag.Genres = null;
                    tagFile.Tag.Genres = toGenre;

                    //Change of Track Number
                    et.SetNumber(pistatext.Text);
                    uint yestrack;
                    bool probandotrack = uint.TryParse(et.GetNumber(), out yestrack);

                    if (probandotrack == true)
                    {
                        tagFile.Tag.Track = yestrack;
                    }

                    //Change of Composer
                    et.SetComp(comptext.Text);
                    string[] toComp = et.GetComp().Split(',');

                    tagFile.Tag.Composers = null;
                    tagFile.Tag.Composers = toComp;

                    //Change of Num CD
                    et.SetNumcd(numtext.Text);
                    uint yesdisc;
                    bool probandodisc = uint.TryParse(et.GetNumcd(), out yesdisc);

                    if (probandodisc == true)
                    {
                        tagFile.Tag.Disc = yesdisc;
                    }

                    tagFile.Save();
                    tagFile.Dispose();

                    string       message = "Etiqueta Guardada";
                    string       caption = "Info";
                    DialogResult result  = MessageBox.Show(message, caption,
                                                           MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (vistalista.SelectedItems.Count < 1)
                {
                    string       message = "Aviso: No se ha seleccionado cancion";
                    string       caption = "Aviso";
                    DialogResult result  = MessageBox.Show(message, caption,
                                                           MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    ListView.SelectedListViewItemCollection select =
                        this.vistalista.SelectedItems;

                    int contEt = 0;

                    Etiqueta et     = new Etiqueta();
                    string   titulo = titulotext.Text;
                    et.SetTitle(titulo);
                    string artista = artistatext.Text;
                    et.SetArtist(artista);
                    string album = albumtext.Text;
                    et.SetAlbum(album);
                    string year = anyotext.Text;
                    et.SetYear(year);
                    string comment = comtext.Text;
                    et.SetComment(comment);
                    string genre = generotext.Text;
                    et.SetGenre(genre);
                    string pista = pistatext.Text;
                    et.SetNumber(pista);
                    string comp = comptext.Text;
                    et.SetComp(comp);
                    string numcd = numtext.Text;
                    et.SetNumcd(numcd);

                    foreach (ListViewItem item in select)
                    {
                        int total = select.Count;
                        contEt++;

                        filePath = item.SubItems[4].Text;
                        name     = item.SubItems[0].Text;

                        //Add Save File

                        TagLib.File tagFile = TagLib.File.Create(filePath);
                        TagLib.Id3v2.Tag.DefaultVersion      = 3;
                        TagLib.Id3v2.Tag.ForceDefaultVersion = true;

                        switch (titulo)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Title = null;
                            break;

                        default:
                            tagFile.Tag.Title = et.GetTitle();
                            break;
                        }

                        switch (artista)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Performers = null;
                            break;

                        default:
                            string[] toArtist = et.GetArtist().Split(',');
                            tagFile.Tag.Performers = toArtist;
                            toArtist = null;
                            break;
                        }

                        switch (album)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Album = null;
                            break;

                        default:
                            tagFile.Tag.Album = et.GetAlbum();
                            break;
                        }

                        switch (year)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Year = 0;
                            break;

                        default:
                            uint yesyear;
                            bool probandoanyo = uint.TryParse(et.GetYear(), out yesyear);

                            if (probandoanyo == true)
                            {
                                tagFile.Tag.Year = yesyear;
                            }
                            break;
                        }

                        switch (comment)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Comment = null;
                            break;

                        default:
                            tagFile.Tag.Comment = et.GetComment();
                            break;
                        }

                        switch (genre)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Genres = null;
                            break;

                        default:
                            string[] toGenre = et.GetGenre().Split(',');
                            tagFile.Tag.Genres = toGenre;
                            toGenre            = null;
                            break;
                        }

                        switch (pista)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Track = 0;
                            break;

                        default:
                            uint yestrack;
                            bool probandotrack = uint.TryParse(et.GetNumber(), out yestrack);

                            if (probandotrack == true)
                            {
                                tagFile.Tag.Track = yestrack;
                            }
                            break;
                        }

                        switch (comp)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Composers = null;
                            break;

                        default:
                            string[] toComp = et.GetComp().Split(',');
                            tagFile.Tag.Composers = toComp;
                            toComp = null;
                            break;
                        }

                        switch (numcd)
                        {
                        case "<mantener>":
                            //Do Nothing
                            break;

                        case "<borrar>":
                            tagFile.Tag.Disc = 0;
                            break;

                        default:
                            uint yesnumcd;
                            bool probandotrack = uint.TryParse(et.GetNumcd(), out yesnumcd);

                            if (probandotrack == true)
                            {
                                tagFile.Tag.Disc = yesnumcd;
                            }
                            break;
                        }

                        if (contEt < total)
                        {
                            AutoClosingMessageBox.Show("Etiqueta " + contEt + " de " +
                                                       total + " Guardadas", "Info", 500);
                        }
                        else
                        {
                            MessageBox.Show("Etiqueta " + contEt + " de " +
                                            total + " Guardadas", "Info");
                        }

                        tagFile.Save();
                        tagFile.Dispose();
                    }
                }
            }
            catch (Exception e_Save)
            {
                string message = "Error: " + e_Save.Message + ": " + e_Save.Source
                                 + Environment.NewLine +
                                 Environment.NewLine +
                                 "Mas informacion en Ayuda";
                string       caption = "Error";
                DialogResult result  = MessageBox.Show(message, caption,
                                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }