From 9f517c54d4c636da0052a49f0e0ec59ee665786c Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Wed, 9 Apr 2025 17:50:44 +0800 Subject: [PATCH] =?UTF-8?q?SQL=E6=8C=87=E4=BB=A4=E4=BF=AE=E6=94=B9(?= =?UTF-8?q?=E6=AD=8C=E6=98=9F=E8=BD=89=E6=AD=8C=E6=9B=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrimaryFormParts/PrimaryForm.cs | 8 +++----- .../SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs | 7 ++++--- PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index 9d77b77..f5441be 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -1969,11 +1969,9 @@ public class MultiPagePanel : Panel artistLabel.Click += (sender, e) => { - string searchText = artistLabel.Text; // 取得輸入內容 - - // 根據輸入的注音篩選歌曲清單 - var searchResults = PrimaryForm.Instance.allSongs.Where(song => song.ArtistA.StartsWith(searchText) || song.ArtistB.StartsWith(searchText)).ToList(); - + string searchText = artistLabel.Text; // 取得輸入內容 + string query = $"SELECT * FROM SongLibrary WHERE `歌星 A` = '{searchText}' OR `歌星 B` = '{searchText}'"; + List searchResults = PrimaryForm.Instance.SearchSongs_Mysql(query); // 重置分頁 PrimaryForm.Instance.currentPage = 0; currentSongList = searchResults; diff --git a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs index e321ac5..4b68c14 100644 --- a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs +++ b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs @@ -546,18 +546,19 @@ namespace DualScreenDemo /// 查詢歌曲(字數查詢),連接資料庫並執行 SQL 查詢。 /// private void FindWordCountSongs(){ + string searchText = inputBoxWordCountSongs.Text; // 在這裡添加搜尋歌曲的邏輯 // 例如:根據輸入框的內容搜尋歌曲 - string query = "SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = @searchLength "; - string searchText = inputBoxWordCountSongs.Text; + string query; if (int.TryParse(searchText, out int length)) { - query= $"SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = {length} "; + query = $"SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = {length} "; } else { // 處理輸入錯誤,例如顯示提示訊息 //MessageBox.Show("請輸入正確的數字!"); + query = string.Empty; // 清空查詢 return; } List searchResults = SearchSongs_Mysql(query); diff --git a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs index 638c029..3d56af5 100644 --- a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs +++ b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs @@ -146,7 +146,7 @@ namespace DualScreenDemo public List SearchSongs_Mysql(string query) { List searchResults = new List(); - + Console.WriteLine(query); string connectionString = "Server=192.168.22.170;Port=3306;Database=Karaoke-Kingpin;User=Karaoke-Kingpin;Password=ESM7yTPMnavFmbBH;"; using (var connection = new MySqlConnection(connectionString))