/// <summary> /// Load lên tất cả bài hát có trong file filename lưu vào List /// </summary> /// <param name="filename"></param> /// <param name="List"></param> private void loadAllSongs(string filename, BindingList <songs> List) { var reader = new StreamReader(filename); var count = int.Parse(reader.ReadLine()); if (filename == "SuperList.txt") { _lastIndex = int.Parse(reader.ReadLine()); } for (int i = 0; i < count; i++) { var tokens = reader.ReadLine().Split(new string[] { "@" }, StringSplitOptions.None); var song = new songs(); song.pathfile = new FileInfo(tokens[0]); song.singer = tokens[1]; song.duration = tokens[2]; if (int.Parse(tokens[3]) == 1) { song.isPlaying = true; } else { song.isPlaying = false; } List.Add(song); } reader.Close(); }
/// <summary> /// Thêm một bài hát vào danh sách tổng /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenSongButton_Click(object sender, RoutedEventArgs e) { var screen = new Microsoft.Win32.OpenFileDialog(); if (screen.ShowDialog() == true) { var info = new FileInfo(screen.FileName); //Thêm bài hát vào danh sách trên màn hình hiện tại var song = new songs() { pathfile = info, //duration = player.showDuration(), //Index = _lastIndex }; if (File.Exists(Directory.GetCurrentDirectory() + $"\\SuperList.txt") == false) { Convert = BigestList; operationListBox.ItemsSource = Convert; } //BigestList.Add(song); Convert.Add(song); //operationListBox.ItemsSource = null; //operationListBox.ItemsSource = BigestList; } }
/// <summary> /// /// </summary> /// <param name="song"></param> /// <param name="writer"></param> private void writeSongToFile(songs song, StreamWriter writer) { var data = new StringBuilder(); data.Append(song.pathfile.ToString()); data.Append("@"); data.Append(song.singer); data.Append("@"); data.Append(song.duration); data.Append("@"); if (song.isPlaying) { data.Append("1"); } else { data.Append("0"); } writer.WriteLine(data); }