diff --git a/CommandHandler.cs b/CommandHandler.cs index 6565244..e12020d 100644 --- a/CommandHandler.cs +++ b/CommandHandler.cs @@ -11,7 +11,7 @@ namespace DualScreenDemo /* 關機 queue */ private readonly int _maxHistoryLength = 6; // 最多保留 6 筆 private readonly Queue _indataHistory = new Queue(); - + /* 顯示按鈕設定 */ private int _wrongInputCountfor62 = 0; // 錯誤輸入計數器 private int _wrongInputCountfor61 = 0; // 錯誤輸入計數器 private const int MaxWrongLimit = 3; // 錯誤輸入限制次數 diff --git a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs index bed2ff1..4cf3032 100644 --- a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs +++ b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs @@ -1,6 +1,7 @@ using System.IO; using IniParser; using IniParser.Model; +using DBObj; /* Song Search with ZhuYin */ namespace DualScreenDemo { @@ -299,7 +300,27 @@ namespace DualScreenDemo zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground; // 隱藏注音輸入的所有按鈕與介面元素 SetZhuYinSongsAndButtonsVisibility(false); + FindZhuYiSongs(); // 查詢歌曲 } + /// + /// 查詢歌曲(字數查詢),連接資料庫並執行 SQL 查詢。 + /// + private void FindZhuYiSongs(){ + string searchText = inputBoxZhuYinSongs.Text; + // 在這裡添加搜尋歌曲的邏輯 + // 例如:根據輸入框的內容搜尋歌曲 + string query = $"SELECT * FROM SongLibrary WHERE `歌曲注音` = '{searchText}' "; + + List searchResults = SearchSongs_Mysql(query); + // 重置分頁 + currentPage = 0; + currentSongList = searchResults; + totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); + // 更新多頁面面板的內容 + multiPagePanel.currentPageIndex = 0; + multiPagePanel.LoadSongs(currentSongList); + } + /// /// 初始化注音輸入框 (RichTextBox),設定外觀、事件處理及位置大小 @@ -324,24 +345,6 @@ namespace DualScreenDemo ResizeAndPositionControl(inputBoxZhuYinSongs, inputBoxZhuYinCoords.X, inputBoxZhuYinCoords.Y, inputBoxZhuYinCoords.Width, inputBoxZhuYinCoords.Height); - // 設定文字變更事件,用來即時篩選歌曲 - inputBoxZhuYinSongs.TextChanged += (sender, e) => - { - string searchText = inputBoxZhuYinSongs.Text; // 取得輸入內容 - - // 根據輸入的注音篩選歌曲清單 - var searchResults = allSongs.Where(song => song.PhoneticNotation.StartsWith(searchText)).ToList(); - - // 重置分頁 - currentPage = 0; - currentSongList = searchResults; - totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); - - // 更新多頁面面板的內容 - multiPagePanel.currentPageIndex = 0; - multiPagePanel.LoadSongs(currentSongList); - }; - // 將輸入框加入到 UI 控制項 this.Controls.Add(inputBoxZhuYinSongs); }