From b5f46e2f279fa504eda6c3522775fdf080f71853 Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Mon, 21 Apr 2025 11:33:31 +0800 Subject: [PATCH] =?UTF-8?q?song=20class=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DBObj/SongData.cs | 41 +++++++++++------ DBObj/SongListManager.cs | 56 ++--------------------- HttpServer.cs | 7 +-- PrimaryFormParts/PrimaryForm.SQLSearch.cs | 39 ++-------------- PrimaryFormParts/PrimaryForm.cs | 48 +++++++++---------- TCPServer.cs | 6 +-- VideoPlayerForm.cs | 25 ++++------ 7 files changed, 79 insertions(+), 143 deletions(-) diff --git a/DBObj/SongData.cs b/DBObj/SongData.cs index cc965fc..b74e02d 100644 --- a/DBObj/SongData.cs +++ b/DBObj/SongData.cs @@ -25,30 +25,45 @@ namespace DBObj public string ArtistBPinyin { get; set; } public int HumanVoice { get; set; } - + /* public SongData(string songNumber, string category, string song, double plays, string artistA, string artistB, string artistACategory, string artistBCategory, DateTime addedTime, string songFilePathHost1, string songFilePathHost2, string phoneticNotation, string pinyinNotation, string artistAPhonetic, string artistBPhonetic, string artistASimplified, string artistBSimplified, string songSimplified, string songGenre, string artistAPinyin, string artistBPinyin, int humanVoice) { SongNumber = songNumber; - Category = category; + // Category = category; Song = song; - Plays = plays; + // Plays = plays; ArtistA = artistA; ArtistB = artistB; - ArtistACategory = artistACategory; - ArtistBCategory = artistBCategory; - AddedTime = addedTime; + //ArtistACategory = artistACategory; + //ArtistBCategory = artistBCategory; + //AddedTime = addedTime; + SongFilePathHost1 = songFilePathHost1; + SongFilePathHost2 = songFilePathHost2; + //PhoneticNotation = phoneticNotation; + //PinyinNotation = pinyinNotation; + //ArtistAPhonetic = artistAPhonetic; + //ArtistBPhonetic = artistBPhonetic; + ArtistASimplified = artistASimplified; + ArtistBSimplified = artistBSimplified; + SongSimplified = songSimplified; + //SongGenre = songGenre; + //ArtistAPinyin = artistAPinyin; + //ArtistBPinyin = artistBPinyin; + HumanVoice = humanVoice; + } + + */ + public SongData(string songNumber, string song, string artistA, string artistB, string songFilePathHost1, string songFilePathHost2, string artistASimplified, string artistBSimplified, string songSimplified, int humanVoice) + { + SongNumber = songNumber; + Song = song; + ArtistA = artistA; + ArtistB = artistB; SongFilePathHost1 = songFilePathHost1; SongFilePathHost2 = songFilePathHost2; - PhoneticNotation = phoneticNotation; - PinyinNotation = pinyinNotation; - ArtistAPhonetic = artistAPhonetic; - ArtistBPhonetic = artistBPhonetic; ArtistASimplified = artistASimplified; ArtistBSimplified = artistBSimplified; SongSimplified = songSimplified; - SongGenre = songGenre; - ArtistAPinyin = artistAPinyin; - ArtistBPinyin = artistBPinyin; HumanVoice = humanVoice; } diff --git a/DBObj/SongListManager.cs b/DBObj/SongListManager.cs index 430ce2d..f047522 100644 --- a/DBObj/SongListManager.cs +++ b/DBObj/SongListManager.cs @@ -110,55 +110,6 @@ namespace DBObj return AllSongs.Where(song => song.ArtistA == artistName || song.ArtistB == artistName).ToList(); } - - public bool CheckIfPhoneNumberExists(string phoneNumber) - { - string databaseFileName = "KSongDatabase.db"; - string databasePath = Path.Combine(Application.StartupPath, "db", databaseFileName); - string connectionString = String.Format("Data Source={0};Version=3;", databasePath); - - using (var connection = new SQLiteConnection(connectionString)) - { - try - { - connection.Open(); - string sql = "SELECT COUNT(1) FROM FavoriteSongs WHERE PhoneNumber = @PhoneNumber"; - using (var command = new SQLiteCommand(sql, connection)) - { - command.Parameters.AddWithValue("@PhoneNumber", phoneNumber); - int count = Convert.ToInt32(command.ExecuteScalar()); - return count > 0; - } - } - catch (Exception ex) - { - Console.WriteLine("Failed to check phone number in SQLite database: " + ex.Message); - return false; - } - finally - { - connection.Close(); - } - } - } - - - public void UserLogin(string phoneNumber) - { - IsUserLoggedIn = true; - UserPhoneNumber = phoneNumber; - LoadFavoriteSongs(); - Console.WriteLine(String.Format("UserLoggedIn: {0}, PhoneNumber: {1}", IsUserLoggedIn, UserPhoneNumber)); - } - - - public void UserLogout() - { - IsUserLoggedIn = false; - UserPhoneNumber = null; - FavoriteSongs.Clear(); - } - public void InitializeDatabase() { string databaseFileName = "KSongDatabase.db"; @@ -229,6 +180,7 @@ namespace DBObj } } + /* private void LoadSongs() { string databaseFileName = "KSongDatabase.db"; @@ -298,7 +250,7 @@ namespace DBObj } } } - + public void LoadFavoriteSongs() { if (!IsUserLoggedIn || string.IsNullOrEmpty(UserPhoneNumber)) @@ -400,7 +352,7 @@ namespace DBObj } } } - + */ public void AddToFavorite(string songNumber) { if (!IsUserLoggedIn || string.IsNullOrEmpty(UserPhoneNumber)) @@ -555,6 +507,7 @@ namespace DBObj else return new List(); } + /* public List GetFavoriteSongsByPhoneNumber() { List favoriteSongs = new List(); @@ -654,5 +607,6 @@ namespace DBObj return favoriteSongs; } + */ } } \ No newline at end of file diff --git a/HttpServer.cs b/HttpServer.cs index 8a5470f..79ad3e1 100644 --- a/HttpServer.cs +++ b/HttpServer.cs @@ -1060,7 +1060,7 @@ namespace DualScreenDemo // 启动服务器的公共方法 private static async Task HandleFavoriteRequest(HttpListenerContext context) { - try + /* try { if (PrimaryForm.isPhoneNumberValid && !string.IsNullOrEmpty(PrimaryForm.phonenumber)) { @@ -1144,10 +1144,11 @@ namespace DualScreenDemo context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await SendResponseAsyncs(context, jsonResponse); - } + }*/ } // 异步响应发送方法 + /* private static async Task SendResponseAsyncs(HttpListenerContext context, string responseContent) { try @@ -1162,7 +1163,7 @@ namespace DualScreenDemo Console.WriteLine("Error sending response: " + ex.Message); } } - + */ private static async Task HandleGetRequest(HttpListenerContext context, string baseDirectory, string requestedFile) { try diff --git a/PrimaryFormParts/PrimaryForm.SQLSearch.cs b/PrimaryFormParts/PrimaryForm.SQLSearch.cs index ebedd9a..ace0c51 100644 --- a/PrimaryFormParts/PrimaryForm.SQLSearch.cs +++ b/PrimaryFormParts/PrimaryForm.SQLSearch.cs @@ -33,51 +33,22 @@ namespace DualScreenDemo{ while (reader.Read()) { string songNumber = reader["歌曲編號"].ToString(); - string category = reader["語別"].ToString(); string song = reader["歌曲名稱"].ToString(); - int plays = Convert.ToInt32(reader["點播次數"]); string artistA = reader["歌星 A"].ToString(); string artistB = reader["歌星 B"].ToString(); - string artistACategory = reader["歌星A分類"].ToString(); - string artistBCategory = reader["歌星B分類"].ToString(); - string dateValue = reader["新增日期"]?.ToString() ?? ""; - DateTime addedTime; - try - { - addedTime = DateTime.Parse(dateValue, CultureInfo.InvariantCulture).Date; - } - catch - { - addedTime = DateTime.Today; - } - - string basePathHost1 = reader["路徑 1"].ToString(); - string basePathHost2 = reader["路徑 2"].ToString(); string fileName = reader["歌曲檔名"].ToString(); - string songFilePathHost1 = Path.Combine(basePathHost1, fileName); - string songFilePathHost2 = Path.Combine(basePathHost2, fileName); - string phoneticNotation = reader["歌曲注音"].ToString(); - string pinyinNotation = reader["歌曲拼音"].ToString(); - string artistAPhonetic = reader["歌星A注音"].ToString(); - string artistBPhonetic = reader["歌星B注音"].ToString(); - string artistASimplified = reader["歌星A簡體"].ToString(); + string songFilePathHost1 = Path.Combine("\\SVR01\\DISK01\\", fileName); // \SVR01\DISK01\ + string songFilePathHost2 = Path.Combine("\\SVR01\\DISK01\\", fileName); // \SVR02\DISK01\ + string artistASimplified = reader["歌星A簡體"].ToString(); string artistBSimplified = reader["歌星B簡體"].ToString(); string songSimplified = reader["歌名簡體"].ToString(); - string songGenre = reader["分類"].ToString(); - string artistAPinyin = reader["歌星A拼音"].ToString(); - string artistBPinyin = reader["歌星B拼音"].ToString(); int humanVoice = Convert.ToInt32(reader["人聲"]); searchResults.Add(new SongData( - songNumber, category, song, plays, artistA, artistB, - artistACategory, artistBCategory, addedTime, + songNumber, song, artistA, artistB, songFilePathHost1, songFilePathHost2, - phoneticNotation, pinyinNotation, - artistAPhonetic, artistBPhonetic, artistASimplified, artistBSimplified, - songSimplified, songGenre, - artistAPinyin, artistBPinyin, - humanVoice + songSimplified, humanVoice )); } } diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index 3f4ab2e..d71be39 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -1589,26 +1589,26 @@ namespace DualScreenDemo SongData song = new SongData( songNumber, // songNumber - "", // songNumberB + //"", // songNumberB songName, // song - 0, // songLength + //0, // songLength "", // artistA "", // artistB - "", // language - "", // category - DateTime.Now, // dateAdded + //"", // language + //"", // category + //DateTime.Now, // dateAdded songPath, // songFilePathHost1 "", // songFilePathHost2 "", // songFilePathHost3 "", // songFilePathHost4 "", // songFilePathHost5 - "", // songFilePathHost6 - "", // songFilePathHost7 - "", // songFilePathHost8 - "", // songFilePathHost9 - "", // songFilePathHost10 - "", // humanVoice - "", // songType + //"", // songFilePathHost6 + //"", // songFilePathHost7 + //"", // songFilePathHost8 + //"", // songFilePathHost9 + //"", // songFilePathHost10 + //"", // humanVoice + //"", // songType 1 // priority ); publicSongList.Add(song); @@ -1617,26 +1617,26 @@ namespace DualScreenDemo { SongData song = new SongData( "", // songNumber - "", // songNumberB + //"", // songNumberB "", // song - 0, // songLength + //0, // songLength "", // artistA "", // artistB - "", // language - "", // category - DateTime.Now, // dateAdded + //"", // language + //"", // category + //DateTime.Now, // dateAdded songPath, // songFilePathHost1 "", // songFilePathHost2 "", // songFilePathHost3 "", // songFilePathHost4 "", // songFilePathHost5 - "", // songFilePathHost6 - "", // songFilePathHost7 - "", // songFilePathHost8 - "", // songFilePathHost9 - "", // songFilePathHost10 - "", // humanVoice - "", // songType + //"", // songFilePathHost6 + //"", // songFilePathHost7 + //"", // songFilePathHost8 + //"", // songFilePathHost9 + //"", // songFilePathHost10 + //"", // humanVoice + //"", // songType 1 // priority ); publicSongList.Add(song); diff --git a/TCPServer.cs b/TCPServer.cs index 5c3accc..f3a5e83 100644 --- a/TCPServer.cs +++ b/TCPServer.cs @@ -146,9 +146,9 @@ namespace DualScreenDemo if (File.Exists(closePath)) { SongData closeSong = new SongData( - "", "", "結束播放", 0, "", "", "", "", - DateTime.Now, closePath, "", "", "", "", - "", "", "", "", "", "", "", 1 + "0", "結束播放", "", "", + closePath, "", "", "", "", + 1 ); VideoPlayerForm.publicPlaylist = new List(); VideoPlayerForm.playingSongList = new List(); diff --git a/VideoPlayerForm.cs b/VideoPlayerForm.cs index 76659ed..0c898ff 100644 --- a/VideoPlayerForm.cs +++ b/VideoPlayerForm.cs @@ -570,9 +570,8 @@ namespace DualScreenDemo if (File.Exists(welcomePath)) { publicPlaylist.Add(new SongData( - "0", "", "歡迎光臨", 0, "", "", "", "", - DateTime.Now, welcomePath, "", "", "", "", - "", "", "", "", "", "", "", 1 + "0", "歡迎光臨", "", "", welcomePath, + "", "", "", "", 1 )); } @@ -583,9 +582,8 @@ namespace DualScreenDemo if (File.Exists(bgmPath)) { publicPlaylist.Add(new SongData( - i.ToString(), "", $"背景音樂{i:D2}", 0, "", "", "", "", - DateTime.Now, bgmPath, "", "", "", "", - "", "", "", "", "", "", "", 1 + i.ToString(), $"背景音樂{i:D2}", + "", "", bgmPath, "", "", "", "", 1 )); } } @@ -599,9 +597,9 @@ namespace DualScreenDemo { string fileName = Path.GetFileNameWithoutExtension(songPath); publicPlaylist.Add(new SongData( - "0", "", fileName, 0, "", "", "", "", - DateTime.Now, songPath, "", "", "", "", - "", "", "", "", "", "", "", 1 + "0", fileName, "", "", + songPath, "", "", "", "", + 1 )); } } @@ -879,9 +877,7 @@ namespace DualScreenDemo if (File.Exists(welcomePath)) { publicPlaylist.Add(new SongData( - "0", "", "歡迎光臨", 0, "", "", "", "", - DateTime.Now, welcomePath, "", "", "", "", - "", "", "", "", "", "", "", 1 + "0", "歡迎光臨", "", "", welcomePath, "", "", "", "", 1 )); } @@ -892,9 +888,8 @@ namespace DualScreenDemo if (File.Exists(bgmPath)) { publicPlaylist.Add(new SongData( - i.ToString(), "", $"背景音樂{i:D2}", 0, "", "", "", "", - DateTime.Now, bgmPath, "", "", "", "", - "", "", "", "", "", "", "", 1 + i.ToString(), $"背景音樂{i:D2}", "", "", bgmPath, + "", "", "", "", 1 )); } }