public void CreateTestData() { data = new List<Song>(); Song s = new Song(); s.Title = "Halo"; s.Artist = "Beyonce"; s.Album = "I Am... Sasha Fierce Deluxe Edition"; s.Length = "04:21"; s.MusicType = "西洋歌曲"; s.Offline = true; s.HasLyrics = true; s.Favorite = true; data.Add(s); Song ss; for(int i= 0 ;i<30000;i++) { ss = new Song(); ss.Title = "累"; ss.Artist = "韋禮安"; ss.Album = "有人在等"; ss.Length = "04:33"; ss.MusicType = "國語歌曲"; data.Add(ss); } }
public void CreateTestDataFromDb() { SongList = new List<Song>(); using (DbConnection conn = new SQLiteConnection("Data source=song.db3")) { conn.ConnectionString = "Data Source=song.db3"; conn.Open(); DbCommand cmd = conn.CreateCommand(); try { cmd.CommandText = "SELECT * FROM song"; DbDataReader sqlite_datareader = cmd.ExecuteReader(); while (sqlite_datareader.Read()) { Song s = new Song(); s.Title = sqlite_datareader["Title"].ToString(); s.Artist = sqlite_datareader["Artist"].ToString(); s.Album = sqlite_datareader["Album"].ToString(); s.Length = sqlite_datareader["Length"].ToString(); s.MusicType = sqlite_datareader["MusicType"].ToString(); s.Offline = Boolean.Parse( sqlite_datareader["Offline"].ToString()); s.HasLyrics = Boolean.Parse(sqlite_datareader["HasLyrics"].ToString()); s.Favorite = Boolean.Parse(sqlite_datareader["Favorite"].ToString()); SongList.Add(s); } } catch { throw; } } }
public void CopyDataToMemory() { SongList = new List<Song>(); for (int i = 0; i < data.Count; i++) { Song s = new Song(); s.Title = data[i].Title; s.Artist = data[i].Artist; s.Album = data[i].Album; s.Length = data[i].Length; s.MusicType = data[i].MusicType; s.Offline = data[i].Offline; s.HasLyrics = data[i].HasLyrics; s.Favorite = data[i].Favorite; SongList.Add(s); } }