diff --git a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs index 576e70c..2f24f69 100644 --- a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs +++ b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.WordCountSearch.cs @@ -1,13 +1,11 @@ -using System; using System.IO; -using System.Drawing; using System.Drawing.Imaging; -using System.Linq; -using System.Windows.Forms; -using System.Collections.Generic; using IniParser; using IniParser.Model; using System.Text; +using DBObj; + + /* ZhuYinSingers -> WordCountSongs ZhuYin -> WordCount @@ -541,6 +539,35 @@ namespace DualScreenDemo wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground; // 隱藏與 WordCount 歌手相關的所有按鈕 SetWordCountSongsAndButtonsVisibility(false); + // 錨點 歌曲查詢改版 + FindWordCountSongs(); + } + /// + /// 查詢歌曲(字數查詢),連接資料庫並執行 SQL 查詢。 + /// + private void FindWordCountSongs(){ + // 在這裡添加搜尋歌曲的邏輯 + // 例如:根據輸入框的內容搜尋歌曲 + string query = "SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = @searchLength "; + string searchText = inputBoxWordCountSongs.Text; + if (int.TryParse(searchText, out int length)) + { + query= $"SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = {length} "; + } + else + { + // 處理輸入錯誤,例如顯示提示訊息 + //MessageBox.Show("請輸入正確的數字!"); + return; + } + List searchResults = SearchSongs_Mysql(query); + // 重置分頁 + currentPage = 0; + currentSongList = searchResults; + totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); + // 更新多頁面面板的內容 + multiPagePanel.currentPageIndex = 0; + multiPagePanel.LoadSongs(currentSongList); } @@ -608,7 +635,7 @@ namespace DualScreenDemo ResizeAndPositionControl(inputBoxWordCountSongs, inputBoxWordCountCoords.X, inputBoxWordCountCoords.Y, inputBoxWordCountCoords.Width, inputBoxWordCountCoords.Height); // 設定文本變更事件,當輸入框內容改變時觸發 - inputBoxWordCountSongs.TextChanged += (sender, e) => + /*inputBoxWordCountSongs.TextChanged += (sender, e) => { string searchText = inputBoxWordCountSongs.Text; // 取得輸入內容 if (int.TryParse(searchText, out int length)) @@ -629,7 +656,7 @@ namespace DualScreenDemo } - }; + };*/ // 將輸入框加入到窗體的控件集合中 this.Controls.Add(inputBoxWordCountSongs); } diff --git a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs index 6f442f1..b1e515c 100644 --- a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs +++ b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs @@ -1,7 +1,7 @@ -using System; -using System.Drawing; -using System.Windows.Forms; - +using MySqlConnector; +using DBObj; +using System.Globalization; +using System.IO; namespace DualScreenDemo { /* @@ -143,5 +143,83 @@ namespace DualScreenDemo 1214, 544, 209, 58, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, SongIDSearchSongsButton_Click); } + public List SearchSongs_Mysql(string query) + { + List searchResults = new List(); + + string connectionString = "Server=192.168.22.170;Port=3306;Database=Karaoke-Kingpin;User=Karaoke-Kingpin;Password=ESM7yTPMnavFmbBH;"; + //string query = "SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = @searchLength"; + + using (var connection = new MySqlConnection(connectionString)) + { + connection.Open(); + Console.WriteLine("MyDB 連線成功!"); + + using (var command = new MySqlCommand(query, connection)) + { + + using (var reader = command.ExecuteReader()) + { + 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 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, + songFilePathHost1, songFilePathHost2, + phoneticNotation, pinyinNotation, + artistAPhonetic, artistBPhonetic, + artistASimplified, artistBSimplified, + songSimplified, songGenre, + artistAPinyin, artistBPinyin, + humanVoice + )); + } + } + } + + connection.Close(); + Console.WriteLine("MyDB 連線已關閉!"); + } + + return searchResults; + } + + } } diff --git a/superstar_1.0.0.csproj b/superstar_1.0.0.csproj index 70e6f9f..d78d26c 100644 --- a/superstar_1.0.0.csproj +++ b/superstar_1.0.0.csproj @@ -14,6 +14,7 @@ +