コード例 #1
0
ファイル: Bdd.cs プロジェクト: psymon75/WebradioManager
        /**
        // \fn public List<AudioFile> LoadLibrary()
        //
        // \brief Loads the library from db.
        //
        // \author Simon Menetrey
        // \date 26.05.2014
        //
        // \return The library list.
        **/
        public List<AudioFile> LoadLibrary()
        {
            List<AudioFile> audios = new List<AudioFile>();
            //Music
            SQLiteDataReader reader = this.Controls.ExecuteDataReader("SELECT m.id, m.filename, m.title, m.artist, m.album, m.year, m.label, m.duration, t.name AS AudioType, g.name AS GenderName FROM tmusic m, taudiotype t, tgender g WHERE m.typeid = t.id AND m.genderid = g.id");
            while (reader.Read())
            {
                string[] time = reader["duration"].ToString().Split(':');
                TimeSpan duration = new TimeSpan(int.Parse(time[0]), int.Parse(time[1]), int.Parse(time[2]));
                AudioFile af = null;
                if (reader["AudioType"].ToString() == AudioType.Ad.ToString())
                    af = new Ad(int.Parse(reader["id"].ToString()),
                        reader["filename"].ToString(),
                        reader["title"].ToString(),
                        reader["artist"].ToString(),
                        reader["album"].ToString(),
                        int.Parse(reader["year"].ToString()),
                        reader["label"].ToString(),
                        duration,
                        reader["GenderName"].ToString());
                else if (reader["AudioType"].ToString() == AudioType.Music.ToString())
                    af = new Music(int.Parse(reader["id"].ToString()),
                        reader["filename"].ToString(),
                        reader["title"].ToString(),
                        reader["artist"].ToString(),
                        reader["album"].ToString(),
                        int.Parse(reader["year"].ToString()),
                        reader["label"].ToString(),
                        duration,
                        reader["GenderName"].ToString());

                audios.Add(af);
            }
            reader.Close();

            return audios;
        }
コード例 #2
0
ファイル: WMModel.cs プロジェクト: psymon75/WebradioManager
        /**
        // \fn public bool ImportFilesToLibrary(string[] filenames, AudioType type)
        //
        // \brief Import files to library.
        //
        // \author Simon Menetrey
        // \date 26.05.2014
        //
        // \param filenames The filenames array.
        // \param type      The type.
        //
        // \return true if it succeeds, false if it fails.
        **/
        public bool ImportFilesToLibrary(string[] filenames, AudioType type)
        {
            AudioFile file;
            bool state = true;
            foreach (string filename in filenames)
            {
                try
                {
                    TagLib.File tagFile = TagLib.File.Create(filename);
                    if (type == AudioType.Music)
                        file = new Music(filename,
                            tagFile.Tag.Title,
                            tagFile.Tag.FirstPerformer,
                            tagFile.Tag.Album,
                            (int)tagFile.Tag.Year,
                            tagFile.Tag.Copyright,
                            tagFile.Properties.Duration,
                            tagFile.Tag.FirstGenre);
                    else
                        file = new Ad(filename,
                            tagFile.Tag.Title,
                            tagFile.Tag.FirstPerformer,
                            tagFile.Tag.Album,
                            (int)tagFile.Tag.Year,
                            tagFile.Tag.Copyright,
                            tagFile.Properties.Duration,
                            tagFile.Tag.FirstGenre);

                    int id = this.Bdd.AddAudioFile(file);
                    if (id != Bdd.ERROR)
                    {
                        file.Id = id;
                        this.Library.Add(file);
                        this.UpdateObservers();
                    }
                    state = true;
                }
                catch
                {

                }
            }
            return state;
        }
コード例 #3
0
ファイル: AdminView.cs プロジェクト: psymon75/WebradioManager
 /**
 // \fn private void dgvCellEndEdit(object sender, DataGridViewCellEventArgs e)
 //
 // \brief Dgv cell end edit.
 //
 // \author Simon Menetrey
 // \date 23.05.2014
 //
 // \param sender Source of the event.
 // \param e      Data grid view cell event information.
 **/
 private void dgvCellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     DataGridView dgv = (sender as DataGridView);
     DataGridViewRow row = dgv.Rows[e.RowIndex];
     AudioFile file;
     if (dgv.Tag.ToString() == AudioType.Music.ToString())
     {
         file = new Music(int.Parse(row.Cells["colId" + dgv.Tag.ToString()].Value.ToString()),
             row.Cells["colPath" + dgv.Tag.ToString()].Value.ToString(),
             row.Cells["colTitle" + dgv.Tag.ToString()].Value.ToString(),
             row.Cells["colArtist" + dgv.Tag.ToString()].Value.ToString(),
             row.Cells["colAlbum" + dgv.Tag.ToString()].Value.ToString(),
             int.Parse(row.Cells["colYear" + dgv.Tag.ToString()].Value.ToString()),
             row.Cells["colLabel" + dgv.Tag.ToString()].Value.ToString(),
             new TimeSpan(),
             row.Cells["colGender" + dgv.Tag.ToString()].Value.ToString());
     }
     else
     {
         file = new Ad(int.Parse(row.Cells["colId" + dgv.Tag.ToString()].Value.ToString()),
             row.Cells["colPath" + dgv.Tag.ToString()].Value.ToString(),
         row.Cells["colTitle" + dgv.Tag.ToString()].Value.ToString(),
         row.Cells["colArtist" + dgv.Tag.ToString()].Value.ToString(),
         row.Cells["colAlbum" + dgv.Tag.ToString()].Value.ToString(),
         int.Parse(row.Cells["colYear" + dgv.Tag.ToString()].Value.ToString()),
         row.Cells["colLabel" + dgv.Tag.ToString()].Value.ToString(),
         new TimeSpan(),
         row.Cells["colGender" + dgv.Tag.ToString()].Value.ToString());
     }
     if (!this.Controller.UpdateAudioFile(file))
         MessageBox.Show("An error has occured", "Error");
 }