diff --git a/DBObj/Artist.cs b/DBObj/Artist.cs index 670e708..75c5ab0 100644 --- a/DBObj/Artist.cs +++ b/DBObj/Artist.cs @@ -3,31 +3,21 @@ namespace DBObj // artist OOP test public class Artist { - public string Name { get; set; } + //public string Phonetic { get; set; } + //public string Category { get; set; } + //public int Strokes { get; set; } - public string Phonetic { get; set; } - - - public string Category { get; set; } - - - public int Strokes { get; set; } - - - public Artist(string name, string phonetic, string category, int strokes) + public Artist(string name) { Name = name; - Phonetic = phonetic; - Category = category; - Strokes = strokes; } - public override string ToString() { - return $"Name: {Name}, Phonetic: {Phonetic}, Category: {Category}, Strokes: {Strokes}"; + //return $"Name: {Name}, Phonetic: {Phonetic}, Category: {Category}, Strokes: {Strokes}"; + return $"Name: {Name}"; } } } \ No newline at end of file diff --git a/DBObj/ArtistManager.cs b/DBObj/ArtistManager.cs index cf64819..65945f6 100644 --- a/DBObj/ArtistManager.cs +++ b/DBObj/ArtistManager.cs @@ -1,5 +1,6 @@ using System.Data.SQLite; -using System.IO; +using System.IO; +using DualScreenDemo; namespace DBObj { /** @@ -29,6 +30,7 @@ namespace DBObj } + /* private void LoadArtists() { string databaseFileName = "KSongDatabase.db"; @@ -87,16 +89,22 @@ namespace DBObj } } - + */ public List GetArtistsByCategoryAndStrokeCountRange(string category, int minStrokes, int maxStrokes) { if (category == "全部") { - return AllArtists.Where(artist => artist.Strokes >= minStrokes && artist.Strokes <= maxStrokes).ToList(); + string query = $"SELECT * FROM ArtistLibrary WHERE 歌手筆畫 >= {minStrokes} AND 歌手筆畫 <={maxStrokes}"; + var searchResults = PrimaryForm.SearchSingers_Mysql(query); + return searchResults; + //return AllArtists.Where(artist => artist.Strokes >= minStrokes && artist.Strokes <= maxStrokes).ToList(); } else { - return AllArtists.Where(artist => artist.Category == category && artist.Strokes >= minStrokes && artist.Strokes <= maxStrokes).ToList(); + string query = $"SELECT * FROM ArtistLibrary WHERE 歌手分類 = '{category}' AND 歌手筆畫 >= {minStrokes} AND 歌手筆畫 <={maxStrokes}"; + var searchResults = PrimaryForm.SearchSingers_Mysql(query); + return searchResults; + //return AllArtists.Where(artist => artist.Category == category && artist.Strokes >= minStrokes && artist.Strokes <= maxStrokes).ToList(); } } } diff --git a/PrimaryFormParts/PrimaryForm.SQLSearch.cs b/PrimaryFormParts/PrimaryForm.SQLSearch.cs index 33dd63f..ebedd9a 100644 --- a/PrimaryFormParts/PrimaryForm.SQLSearch.cs +++ b/PrimaryFormParts/PrimaryForm.SQLSearch.cs @@ -92,7 +92,7 @@ namespace DualScreenDemo{ return searchResults; } - public List SearchSingers_Mysql(string query){ + public static List SearchSingers_Mysql(string query){ List searchResults = new List(); Console.WriteLine(query); string connectionString = "Server=192.168.11.4;Port=3306;Database=Karaoke-Kingpin;User=Karaoke-Kingpin;Password=ESM7yTPMnavFmbBH;"; @@ -111,16 +111,8 @@ namespace DualScreenDemo{ { while (reader.Read()) { - string artist = reader["歌手姓名"].ToString(); - string phonetic = reader["歌手注音"].ToString(); - string category = reader["歌手分類"].ToString(); - string strokesStr = reader["歌手筆畫"].ToString(); - if (double.TryParse(strokesStr, out double strokesDouble)) - { - int strokes = (int)Math.Round(strokesDouble); - searchResults.Add(new Artist(artist, phonetic, category, strokes)); - } - + string artist = reader["name"].ToString(); + searchResults.Add(new Artist(artist)); } } } @@ -205,8 +197,8 @@ namespace DualScreenDemo{ } return exists; } - private int countforSearch = 0; - private void writeLogforSearchTime(long elapsedMs){ + private static int countforSearch = 0; + private static void writeLogforSearchTime(long elapsedMs){ countforSearch++; @@ -214,6 +206,8 @@ namespace DualScreenDemo{ string data = $"{countforSearch}, {elapsedMs} " + Environment.NewLine; File.AppendAllText(logFilePath, data); } + + } } \ No newline at end of file diff --git a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs index d449ef8..4d376b7 100644 --- a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs +++ b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs @@ -522,8 +522,8 @@ namespace DualScreenDemo private void FindZhuYiSingers(){ string searchText = inputBoxZhuYinSingers.Text; string query = string.IsNullOrWhiteSpace(searchText) - ? "SELECT * FROM ArtistLibrary LIMIT 50;" - : $"SELECT * FROM ArtistLibrary WHERE `歌手注音` LIKE '{searchText}%';"; + ? "SELECT * FROM artists LIMIT 50;" + : $"SELECT * FROM artists WHERE `phonetic_abbr` LIKE '{searchText}%';"; //string query = $"SELECT * FROM ArtistLibrary WHERE `歌手注音` LIKE '{searchText}%' "; var searchResults = SearchSingers_Mysql(query); diff --git a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.EnglishSearch.cs b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.EnglishSearch.cs index c3189c4..644486f 100644 --- a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.EnglishSearch.cs +++ b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.EnglishSearch.cs @@ -272,8 +272,8 @@ namespace DualScreenDemo private void FindEnglishSingers(){ string searchText = inputBoxEnglishSingers.Text; string query = string.IsNullOrWhiteSpace(searchText) - ? "SELECT * FROM ArtistLibrary LIMIT 50;" - : $"SELECT * FROM ArtistLibrary WHERE `歌手姓名` LIKE '{searchText}%';"; + ? "SELECT * FROM artists LIMIT 50;" + : $"SELECT * FROM artists WHERE `name` LIKE '{searchText}%';"; //string query = $"SELECT * FROM ArtistLibrary WHERE `歌手姓名` LIKE '{searchText}%' "; var searchResults = SearchSingers_Mysql(query); diff --git a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.HandwritingSearch.cs b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.HandwritingSearch.cs index 10dc374..6b68699 100644 --- a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.HandwritingSearch.cs +++ b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.HandwritingSearch.cs @@ -290,8 +290,8 @@ namespace DualScreenDemo private void FindHandwritingSingers(){ string searchText = handwritingInputBoxForSingers.Text; string query = string.IsNullOrWhiteSpace(searchText) - ? "SELECT * FROM ArtistLibrary LIMIT 50;" - : $"SELECT * FROM ArtistLibrary WHERE `歌手姓名` LIKE '{searchText}%';"; + ? "SELECT * FROM artists LIMIT 50;" + : $"SELECT * FROM artists WHERE `name` LIKE '{searchText}%';"; //string query = $"SELECT * FROM ArtistLibrary WHERE `歌手姓名` LIKE '{searchText}%' "; var searchResults = SearchSingers_Mysql(query); diff --git a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.PinyinSearch.cs b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.PinyinSearch.cs index 4050cd2..797ff1b 100644 --- a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.PinyinSearch.cs +++ b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.PinyinSearch.cs @@ -176,19 +176,17 @@ namespace DualScreenDemo // 在這裡添加搜尋歌曲的邏輯 // 例如:根據輸入框的內容搜尋歌曲 string query = string.IsNullOrWhiteSpace(searchText) - ? "SELECT * FROM SongLibrary ORDER BY `點播次數` DESC LIMIT 200;" - : $"SELECT * FROM SongLibrary WHERE `歌星A拼音` LIKE '{searchText}%' OR `歌星B拼音` LIKE '{searchText}%' "; + ? "SELECT * FROM artists; LIMIT 50" + : $"SELECT * FROM artists WHERE `pinyin_abbr` LIKE '{searchText}%' "; //string query = $"SELECT * FROM SongLibrary WHERE `歌星A拼音` LIKE '{searchText}%' OR `歌星B拼音` LIKE '{searchText}%' "; - var searchResults = SearchSongs_Mysql(query); + var searchResults = SearchSingers_Mysql(query); // 重置分頁 currentPage = 0; - currentSongList = searchResults; + currentArtistList = searchResults; totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); - // 更新多頁面面板的內容 multiPagePanel.currentPageIndex = 0; - multiPagePanel.LoadSongs(currentSongList); - + multiPagePanel.LoadSingers(currentArtistList); } diff --git a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.WordCountSearch.cs b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.WordCountSearch.cs index 1008762..3ad7770 100644 --- a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.WordCountSearch.cs +++ b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.WordCountSearch.cs @@ -541,7 +541,7 @@ namespace DualScreenDemo if (int.TryParse(searchText, out int length)) { //var searchResults = allArtists.Where(artist => artist.Name.Length == length).ToList(); - string query = $"SELECT * FROM ArtistLibrary WHERE CHAR_LENGTH(歌手姓名) = {length} "; + string query = $"SELECT * FROM artists WHERE CHAR_LENGTH(name) = {length} "; var searchResults = SearchSingers_Mysql(query); // 設定當前頁數為 0,並加載搜索結果 currentPage = 0;