/** // \fn public int AddAudioFile(AudioFile file) // // \brief Adds an audio file. // // \author Simon Menetrey // \date 26.05.2014 // // \param file The audiofile. // // \return The new audio file's id. **/ public int AddAudioFile(AudioFile file) { if(this.AudioFileExist(file.Filename)) return ERROR; int genderId = this.GetGenderId(file.Gender); //If return error, gender doesn't exist in DB, so add it if (genderId == ERROR) //Get the new id genderId = AddGender(file.Gender); Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("filename", file.Filename.Replace('\'', ' ')); data.Add("title", file.Title); data.Add("artist", file.Artist); data.Add("album", file.Album); data.Add("year", file.Year.ToString()); data.Add("label", file.Label); data.Add("duration", file.Duration.ToString(@"hh\:mm\:ss")); data.Add("genderid", genderId.ToString()); data.Add("typeid", ((int)file.Type).ToString()); this.Controls.Insert("tmusic", data); //Get the new id SQLiteDataReader reader = this.Controls.ExecuteDataReader("SELECT id FROM tmusic WHERE filename = '" + file.Filename.Replace('\'', ' ') + "'"); reader.Read(); int id = int.Parse(reader["id"].ToString()); reader.Close(); return id; }
/** // \fn public bool UpdateAudioFile(AudioFile file) // // \brief Updates the audio file with param one's value. // Retag file. // // \author Simon Menetrey // \date 26.05.2014 // // \param file The file. // // \return true if it succeeds, false if it fails. **/ public bool UpdateAudioFile(AudioFile file) { if (this.Bdd.UpdateAudioFile(file)) { try { TagLib.File tagFile = TagLib.File.Create(file.Filename); tagFile.Tag.Title = file.Title; tagFile.Tag.Performers = new string[] { file.Artist }; tagFile.Tag.Album = file.Album; tagFile.Tag.Year = (uint)file.Year; tagFile.Tag.Copyright = file.Label; tagFile.Tag.Genres = new string[] { file.Gender }; tagFile.Save(); foreach (AudioFile af in this.Library) { if (af.Id == file.Id) { af.Title = file.Title; af.Artist = file.Artist; af.Album = file.Album; af.Year = file.Year; af.Label = file.Label; af.Gender = file.Gender; break; } } this.UpdateObservers(); return true; } catch { return false; } } else return false; }
/** // \fn public bool UpdateAudioFile(AudioFile file) // // \brief Updates the audio file described by file. // // \author Simon Menetrey // \date 23.05.2014 // // \param file The file. // // \return true if it succeeds, false if it fails. **/ public bool UpdateAudioFile(AudioFile file) { return this.Model.UpdateAudioFile(file); }
/** // \fn public bool UpdateAudioFile(AudioFile file) // // \brief Updates the audio file's values // // \author Simon Menetrey // \date 26.05.2014 // // \param file The audio file. // // \return true if it succeeds, false if it fails. **/ public bool UpdateAudioFile(AudioFile file) { try { int genderId = this.GetGenderId(file.Gender); //If return error, gender doesn't exist in DB, so add it if (genderId == ERROR) //Get the new id genderId = AddGender(file.Gender); Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("title", file.Title); data.Add("artist", file.Artist); data.Add("album", file.Album); data.Add("year", file.Year.ToString()); data.Add("label", file.Label); data.Add("genderid", genderId.ToString()); data.Add("typeid", ((int)file.Type).ToString()); this.Controls.Update("tmusic", data, "id = " + file.Id); return true; } catch { return false; } }