歌曲SQL改版(class 修改)

This commit is contained in:
jasonchenwork 2025-04-22 15:25:58 +08:00
parent fec592d94a
commit 67c05a122b
25 changed files with 104 additions and 512 deletions

View File

@ -30,66 +30,6 @@ namespace DBObj
}
/*
private void LoadArtists()
{
string databaseFileName = "KSongDatabase.db";
string databasePath = Path.Combine(Application.StartupPath,"db" ,databaseFileName);
Console.WriteLine(databasePath);
string connectionString = String.Format("Data Source={0};Version=3;", databasePath);
using (var connection = new SQLiteConnection(connectionString))
{
try
{
connection.Open();
string sql = "SELECT 歌手姓名, 歌手注音, 歌手分類, 歌手筆畫 FROM ArtistLibrary";
using (var command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string artist = reader["歌手姓名"].ToString();
string phonetic = reader["歌手注音"].ToString();
string category = reader["歌手分類"].ToString();
string strokesStr = reader["歌手筆畫"].ToString();
if (string.IsNullOrEmpty(strokesStr))
{
// Console.WriteLine("歌手筆畫的值為空或無效");
}
if (double.TryParse(strokesStr, out double strokesDouble))
{
int strokes = (int)Math.Round(strokesDouble);
AllArtists.Add(new Artist(artist, phonetic, category, strokes));
}
else
{
// Console.WriteLine($"Failed to parse '歌手筆畫' value: {strokesStr}");
}
}
}
}
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Failed to load artists from SQLite database: " + ex.Message);
}
}
}
*/
public List<Artist> GetArtistsByCategoryAndStrokeCountRange(string category, int minStrokes, int maxStrokes)
{
if (category == "全部")

View File

@ -3,26 +3,14 @@ namespace DBObj
public class SongData
{
public string SongNumber { get; set; }
public string Category { get; set; }
public string Song { get; set; }
public double Plays { get; set; }
public string ArtistA { get; set; }
public string ArtistB { get; set; }
public string ArtistACategory { get; set; }
public string ArtistBCategory { get; set; }
public DateTime AddedTime { get; set; }
public string SongFilePathHost1 { get; set; }
public string SongFilePathHost2 { get; set; }
public string PhoneticNotation { get; set; }
public string PinyinNotation { get; set; }
public string ArtistAPhonetic { get; set; }
public string ArtistBPhonetic { get; set; }
public string ArtistASimplified { get; set; }
public string ArtistBSimplified { get; set; }
public string SongSimplified { get; set; }
public string SongGenre { get; set; }
public string ArtistAPinyin { get; set; }
public string ArtistBPinyin { get; set; }
public int HumanVoice { get; set; }
/*

View File

@ -12,7 +12,7 @@ namespace DBObj
public static Dictionary<string, List<SongData>> NewSongLists { get; private set; }
public static Dictionary<string, List<SongData>> HotSongLists { get; private set; }
public List<SongData> FavoriteSongs { get; private set; }
public const int SongsPerPage = 9;
//public const int SongsPerPage = 9;
public bool IsUserLoggedIn { get; set; }
public string UserPhoneNumber { get; set; }
@ -25,74 +25,74 @@ namespace DBObj
FavoriteSongs = new List<SongData>();
// 尝试更新数据库,但无论结果如何都继续运行
TryUpdateDatabase();
//TryUpdateDatabase();
// 继续使用可用的数据库(可能是更新后的或原本的本地数据库)
InitializeDatabase();
//InitializeDatabase();
//LoadSongs();
InitializeNewSongLists();
InitializeHotSongLists();
//InitializeNewSongLists();
//InitializeHotSongLists();
}
private bool TryUpdateDatabase()
{
try
/*
private bool TryUpdateDatabase()
{
// 1. 检查是否能连接到 SVR01
if (!Directory.Exists(@"\\SVR01\SuperstarB"))
try
{
Console.WriteLine("未連接到SVR使用本地DB");
return true; // 继续使用本地数据库
}
// 2. 比较本地和服务器文件
string localDbPath = Path.Combine(Application.StartupPath,"db" ,"KSongDatabase.db");
string serverDbPath = @"\\SVR01\SuperstarB\KSongDatabase.db";
if (!File.Exists(localDbPath))
{
Console.WriteLine("本地無db");
}
else
{
FileInfo localFile = new FileInfo(localDbPath);
FileInfo serverFile = new FileInfo(serverDbPath);
if (serverFile.LastWriteTime <= localFile.LastWriteTime)
// 1. 检查是否能连接到 SVR01
if (!Directory.Exists(@"\\SVR01\SuperstarB"))
{
Console.WriteLine("歌單已是最新");
return true;
Console.WriteLine("未連接到SVR使用本地DB");
return true; // 继续使用本地数据库
}
// 2. 比较本地和服务器文件
string localDbPath = Path.Combine(Application.StartupPath,"db" ,"KSongDatabase.db");
string serverDbPath = @"\\SVR01\SuperstarB\KSongDatabase.db";
if (!File.Exists(localDbPath))
{
Console.WriteLine("本地無db");
}
else
{
FileInfo localFile = new FileInfo(localDbPath);
FileInfo serverFile = new FileInfo(serverDbPath);
if (serverFile.LastWriteTime <= localFile.LastWriteTime)
{
Console.WriteLine("歌單已是最新");
return true;
}
}
// 3. 需要更新时,复制新文件
Process copyProcess = new Process();
copyProcess.StartInfo.FileName = "cmd.exe";
copyProcess.StartInfo.Arguments = "/C copy /Y \\\\SVR01\\SuperstarB\\KSongDatabase.db \\db\\KSongDatabase.db";
copyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
copyProcess.StartInfo.CreateNoWindow = true;
copyProcess.Start();
copyProcess.WaitForExit();
if (copyProcess.ExitCode == 0)
{
Console.WriteLine("歌單更新成功");
}
else
{
Console.WriteLine("歌單複製失敗,使用本地歌單");
}
return true;
}
// 3. 需要更新时,复制新文件
Process copyProcess = new Process();
copyProcess.StartInfo.FileName = "cmd.exe";
copyProcess.StartInfo.Arguments = "/C copy /Y \\\\SVR01\\SuperstarB\\KSongDatabase.db \\db\\KSongDatabase.db";
copyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
copyProcess.StartInfo.CreateNoWindow = true;
copyProcess.Start();
copyProcess.WaitForExit();
if (copyProcess.ExitCode == 0)
catch (Exception ex)
{
Console.WriteLine("歌單更新成功");
Console.WriteLine($"更新歌單失敗:{ex.Message}");
return true; // 出错时继续使用本地数据库
}
else
{
Console.WriteLine("歌單複製失敗,使用本地歌單");
}
return true;
}
catch (Exception ex)
{
Console.WriteLine($"更新歌單失敗:{ex.Message}");
return true; // 出错时继续使用本地数据库
}
}
*/
public static SongListManager Instance
{
get
@ -179,180 +179,7 @@ namespace DBObj
}
}
}
/*
private void LoadSongs()
{
string databaseFileName = "KSongDatabase.db";
string databasePath = Path.Combine(Application.StartupPath, "db", databaseFileName);
Console.WriteLine(databasePath);
string connectionString = String.Format("Data Source={0};Version=3;", databasePath);
using (var connection = new SQLiteConnection(connectionString))
{
try
{
connection.Open();
string sql = "SELECT 歌曲編號, 語別, 歌曲名稱, 點播次數, [歌星 A], [歌星 B], 新增日期, [路徑 1], [路徑 2], 歌曲檔名, 歌曲注音, 歌曲拼音, 歌星A分類, 歌星B分類, 歌星A注音, 歌星B注音, 歌星A簡體, 歌星B簡體, 歌名簡體, 分類, 歌星A拼音, 歌星B拼音, 人聲 FROM SongLibrary";
using (var command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader 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 (System.FormatException)
{
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["人聲"]);
AllSongs.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();
}
catch (Exception ex)
{
Console.WriteLine("Failed to load songs from SQLite database: " + ex.Message);
}
}
}
public void LoadFavoriteSongs()
{
if (!IsUserLoggedIn || string.IsNullOrEmpty(UserPhoneNumber))
return;
string databaseFileName = "KSongDatabase.db";
string databasePath = Path.Combine(Application.StartupPath, "db", databaseFileName);
string connectionString = String.Format("Data Source={0};Version=3;", databasePath);
FavoriteSongs.Clear();
FavoriteSongs.Add(new SongData("", "", UserPhoneNumber + " 的歌單", 0, "", "", "", "", DateTime.MinValue, "", "", "", "", "", "", "", "", "", "", "", "", 1));
using (var connection = new SQLiteConnection(connectionString))
{
try
{
connection.Open();
string sql = @"
SELECT
sl., sl., sl., sl.,
sl.[ A], sl.[ B], sl., sl.[ 1],
sl.[ 2], sl., sl., sl.,
sl.A分類, sl.B分類, sl.A注音, sl.B注音,
sl.A簡體, sl.B簡體, sl., sl.,
sl.A拼音, sl.B拼音, sl.
FROM
FavoriteSongs fs
JOIN
SongLibrary sl
ON
fs.SongNumber = sl.
WHERE
fs.PhoneNumber = @PhoneNumber";
using (var command = new SQLiteCommand(sql, connection))
{
command.Parameters.AddWithValue("@PhoneNumber", UserPhoneNumber);
using (SQLiteDataReader 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();
DateTime addedTime;
try
{
addedTime = DateTime.ParseExact(reader["新增日期"].ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
}
catch (System.FormatException)
{
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["人聲"]);
FavoriteSongs.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));
}
PrimaryForm.Instance.multiPagePanel.currentPageIndex = 0;
PrimaryForm.Instance.multiPagePanel.LoadSongs(FavoriteSongs);
}
}
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Failed to load favorite songs from SQLite database: " + ex.Message);
}
}
}
*/
public void AddToFavorite(string songNumber)
{
if (!IsUserLoggedIn || string.IsNullOrEmpty(UserPhoneNumber))
@ -448,165 +275,5 @@ namespace DBObj
return null;
}
private void InitializeNewSongLists()
{
int songLimit = PrimaryForm.ReadNewSongLimit();
string[] categories = new string[] { "國語", "台語", "粵語", "英文", "日語", "韓語" };
foreach (var category in categories)
{
var songsInCategory = AllSongs
.Where(s => s.Category == category)
.OrderByDescending(s => s.AddedTime)
.Take(songLimit)
.ToList();
NewSongLists.Add(category, songsInCategory);
}
}
private void InitializeHotSongLists()
{
int songLimit = PrimaryForm.ReadHotSongLimit();
string[] categories = new string[] { "國語", "台語", "英文", "日語", "韓語" };
foreach (var category in categories)
{
var songsInCategory = AllSongs
.Where(s => s.Category == category)
.OrderByDescending(s => s.Plays)
.Take(songLimit)
.ToList();
HotSongLists.Add(category, songsInCategory);
}
}
public List<SongData> GetNewSongsByCategory(string category)
{
if (NewSongLists.ContainsKey(category))
return NewSongLists[category];
else
return new List<SongData>();
}
public List<SongData> GetHotSongsByCategory(string category)
{
if (HotSongLists.ContainsKey(category))
return HotSongLists[category];
else
return new List<SongData>();
}
/*
public List<SongData> GetFavoriteSongsByPhoneNumber()
{
List<SongData> favoriteSongs = new List<SongData>();
if (string.IsNullOrEmpty(UserPhoneNumber))
return favoriteSongs;
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
sl., sl., sl., sl.,
sl.[ A], sl.[ B], sl., sl.[ 1],
sl.[ 2], sl., sl., sl.,
sl.A分類, sl.B分類, sl.A注音, sl.B注音,
sl.A簡體, sl.B簡體, sl., sl.,
sl.A拼音, sl.B拼音, sl.
FROM
FavoriteSongs fs
JOIN
SongLibrary sl
ON
fs.SongNumber = sl.
WHERE
fs.PhoneNumber = @PhoneNumber";
using (var command = new SQLiteCommand(sql, connection))
{
command.Parameters.AddWithValue("@PhoneNumber", UserPhoneNumber);
using (SQLiteDataReader 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();
DateTime addedTime;
try
{
addedTime = DateTime.ParseExact(reader["新增日期"].ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
}
catch (System.FormatException)
{
addedTime = DateTime.Now;
}
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["人聲"]);
favoriteSongs.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();
}
catch (Exception ex)
{
Console.WriteLine("Failed to load favorite songs from SQLite database: " + ex.Message);
}
}
return favoriteSongs;
}
*/
}
}

View File

@ -252,7 +252,7 @@ namespace DualScreenDemo
}
private string SetQueryforSQL(string contains){
string query = $"SELECT * FROM SongLibrary WHERE `分類` LIKE '%{contains}%' ORDER BY `點播次數` DESC";
string query = $"SELECT * FROM song_library_cache WHERE situation LIKE '%{contains}%' ORDER BY `song_id` DESC";
return query;
}
}

View File

@ -14,7 +14,7 @@ namespace DualScreenDemo
/*guoYuSongs = allSongs.Where(song => song.Category == "國語" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '國語' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '國語' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var guoYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = guoYuSongs;

View File

@ -14,7 +14,7 @@ namespace DualScreenDemo
/*hanYuSongs = allSongs.Where(song => song.Category == "韓語" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '韓語' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '韓語' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var hanYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = hanYuSongs;

View File

@ -14,7 +14,8 @@ namespace DualScreenDemo
/*riYuSongs = allSongs.Where(song => song.Category == "日語" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '日語' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '日語' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var riYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = riYuSongs;

View File

@ -14,7 +14,7 @@ namespace DualScreenDemo
/*taiYuSongs = allSongs.Where(song => song.Category == "台語" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '台語' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '台語' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var taiYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = taiYuSongs;

View File

@ -14,7 +14,7 @@ namespace DualScreenDemo
/*yingWenSongs = allSongs.Where(song => song.Category == "英文" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '英文' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '英文' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var yingWenSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = yingWenSongs;

View File

@ -14,7 +14,8 @@ namespace DualScreenDemo
/*yueYuSongs = allSongs.Where(song => song.Category == "粵語" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '粵語' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '粵語' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var yueYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = yueYuSongs;

View File

@ -131,7 +131,7 @@ namespace DualScreenDemo
/*guoYuSongs = allSongs.Where(song => song.Category == "國語" && (song.ArtistACategory == "團" || song.ArtistBCategory == "團"))
.OrderByDescending(song => song.Plays)
.ToList();*/
String query = "SELECT * FROM SongLibrary WHERE `語別` = '國語' AND (`歌星A分類` = '團' OR `歌星B分類` = '團') ORDER BY `點播次數` DESC";
string query = "SELECT * FROM song_library_cache WHERE language_name = '國語' AND (`artistA_category` = '團' OR `artistB_category` = '團') ORDER BY song_id DESC";
var guoYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = guoYuSongs;

View File

@ -62,7 +62,7 @@ namespace DualScreenDemo
isOnOrderedSongsPage = false;
int songLimit = ReadHotSongLimit();
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '國語' ORDER BY `點播次數` DESC LIMIT {songLimit}";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '國語' ORDER BY `song_id` DESC LIMIT {songLimit}";
var guoYuSongs = SearchSongs_Mysql(query);
UpdateSongList(guoYuSongs);
@ -92,7 +92,7 @@ namespace DualScreenDemo
UpdateHotSongButtons(activeButton, activeBackground);
int songLimit = ReadHotSongLimit();
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '{category}' ORDER BY `點播次數` DESC LIMIT {songLimit}";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '{category}' ORDER BY `song_id` DESC LIMIT {songLimit}";
var selectedSongs = SearchSongs_Mysql(query);
UpdateSongList(selectedSongs);

View File

@ -8,8 +8,7 @@ namespace DualScreenDemo
UpdateHotSongButtons(guoYuNewSongButtonHotSong, guoYuNewSongHotSongActiveBackground);
int songLimit = ReadHotSongLimit();
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '國語' ORDER BY `新增日期` DESC ,`點播次數` DESC LIMIT {songLimit}";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '國語' ORDER BY `add_date` DESC LIMIT {songLimit}";
var selectedSongs = PrimaryForm.Instance.SearchSongs_Mysql(query);
currentPage = 0;

View File

@ -9,7 +9,7 @@ namespace DualScreenDemo
int songLimit = ReadHotSongLimit();
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '台語' ORDER BY `新增日期` DESC ,`點播次數` DESC LIMIT {songLimit}";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '台語' ORDER BY `add_date` DESC LIMIT {songLimit}";
var selectedSongs = SearchSongs_Mysql(query);
currentPage = 0;

View File

@ -73,7 +73,8 @@ namespace DualScreenDemo
hanYuButton.BackgroundImage = hanYuNormalBackground;
keYuButton.BackgroundImage = keYuNormalBackground;
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '國語' ORDER BY `點播次數` DESC LIMIT 100;";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '國語' ORDER BY song_id DESC LIMIT 100";
var guoYuSongs = SearchSongs_Mysql(query);
currentPage = 0;
currentSongList = guoYuSongs;
@ -121,7 +122,7 @@ namespace DualScreenDemo
activeButton.BackgroundImage = activeBackground;
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '{category}' ORDER BY `點播次數` DESC LIMIT 100;";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '{category}' ORDER BY song_id DESC LIMIT 100";
var selectedSongs = SearchSongs_Mysql(query);
/*var selectedSongs = allSongs.Where(song => song.Category == category)
.OrderByDescending(song => song.Plays)

View File

@ -251,7 +251,8 @@ namespace DualScreenDemo
return 100;
}
private string setQueryforNewSong(string category){
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '{category}' ORDER BY `新增日期` DESC LIMIT {ReadNewSongLimit()}";
string query = $"SELECT * FROM song_library_cache WHERE language_name = '{category}' ORDER BY add_date DESC LIMIT {ReadNewSongLimit()}";
return query;
}
}

View File

@ -324,7 +324,7 @@ namespace DualScreenDemo
{
string searchText = artistLabel.Text; // 取得輸入內容
// 歌星 轉 歌曲
string query = $"SELECT * FROM SongLibrary WHERE `歌星 A` = '{searchText}' OR `歌星 B` = '{searchText}'";
string query = $"SELECT * FROM song_library_cache WHERE artistA ='{searchText}' OR artistB='{searchText}' ";
var searchResults = PrimaryForm.Instance.SearchSongs_Mysql(query);
// 重置分頁
PrimaryForm.Instance.currentPage = 0;
@ -426,6 +426,7 @@ namespace DualScreenDemo
(!string.IsNullOrEmpty(song.SongSimplified) ? song.SongSimplified : song.Song) :
song.Song;
// 歌手名稱設置點
string artistText = IsSimplified ?
(!string.IsNullOrEmpty(song.ArtistASimplified) ? song.ArtistASimplified : song.ArtistA) :
song.ArtistA;

View File

@ -1,6 +1,5 @@
using MySqlConnector;
using DBObj;
using System.Globalization;
using System.IO;
using System.Diagnostics;
@ -9,12 +8,12 @@ namespace DualScreenDemo{
{
public bool isLoggedIn = false;
public string userPhone = string.Empty;
public List<SongData> SearchSongs_Mysql(string query)
public List<SongData> SearchSongs_Mysql(string query)
{
List<SongData> searchResults = new List<SongData>();
Console.WriteLine(query);
string connectionString = "Server=192.168.11.4;Port=3306;Database=Karaoke-Kingpin;User=Karaoke-Kingpin;Password=ESM7yTPMnavFmbBH;";
using (var connection = new MySqlConnection(connectionString))
{
Stopwatch stopwatch = new Stopwatch();
@ -32,17 +31,17 @@ namespace DualScreenDemo{
{
while (reader.Read())
{
string songNumber = reader["歌曲編號"].ToString();
string song = reader["歌曲名稱"].ToString();
string artistA = reader["歌星 A"].ToString();
string artistB = reader["歌星 B"].ToString();
string fileName = reader["歌曲檔名"].ToString();
string songNumber = reader["song_id"].ToString();
string song = reader["song_name"].ToString();
string artistA = reader["artistA"].ToString();
string artistB = reader["artistB"].ToString();
string fileName = reader["song_filename"].ToString();
string songFilePathHost1 = Path.Combine(@"\\SVR01\DISK05", fileName); // \SVR01\DISK01\
string songFilePathHost2 = Path.Combine(@"\\SVR02\DISK01", fileName); // \SVR02\DISK01\
string artistASimplified = reader["歌星A簡體"].ToString();
string artistBSimplified = reader["歌星B簡體"].ToString();
string songSimplified = reader["歌名簡體"].ToString();
int humanVoice = Convert.ToInt32(reader["人聲"]);
string artistASimplified = reader["artistA_simplified"].ToString();
string artistBSimplified = reader["artistB_simplified"].ToString();
string songSimplified = reader["song_simplified"].ToString();
int humanVoice = Convert.ToInt32(reader["vocal"]);
searchResults.Add(new SongData(
songNumber, song, artistA, artistB,
@ -126,14 +125,9 @@ namespace DualScreenDemo{
}
public string SearchFavoriteSongs_Mysql(){
string query = $"SELECT " +
"sl.歌曲編號, sl.語別, sl.歌曲名稱, sl.點播次數, " +
"sl.`歌星 A`, sl.`歌星 B`, sl.新增日期, " +
"sl.`路徑 1`, sl.`路徑 2`, sl.歌曲檔名, sl.歌曲注音, sl.歌曲拼音, " +
"sl.歌星A分類, sl.歌星B分類, sl.歌星A注音, sl.歌星B注音, " +
"sl.歌星A簡體, sl.歌星B簡體, sl.歌名簡體, sl.分類, " +
"sl.歌星A拼音, sl.歌星B拼音, sl.人聲 " +
"sl.*"+
"FROM FavoriteSongs fs " +
"JOIN SongLibrary sl ON fs.SongNumber = sl.歌曲編號 " +
"JOIN song_library_cache sl ON fs.SongNumber = sl.song_id " +
$"WHERE fs.Phonenumber = '{userPhone}';";
return query;

View File

@ -133,7 +133,7 @@ namespace DualScreenDemo
private void AlbumButton_Click(object sender, EventArgs e)
{
string name = currentSelectedSong.ArtistA;
string query = $"SELECT * FROM SongLibrary WHERE `歌星 A` = '{name}' ORDER BY `新增日期` DESC";
string query = $"SELECT * FROM song_library_cache WHERE artistA = '{name}' ORDER BY add_date DESC";
var selectedSongs = SearchSongs_Mysql(query);
/*var selectedSongs = allSongs.Where(song => song.ArtistA == currentSelectedSong.ArtistA)
.OrderByDescending(song => song.AddedTime)

View File

@ -309,11 +309,12 @@ namespace DualScreenDemo
string searchText = inputBoxZhuYinSongs.Text;
// 在這裡添加搜尋歌曲的邏輯
// 例如:根據輸入框的內容搜尋歌曲
string query = string.IsNullOrWhiteSpace(searchText)
? "SELECT * FROM SongLibrary ORDER BY `點播次數` DESC LIMIT 200;"
: $"SELECT * FROM SongLibrary WHERE `歌曲注音` LIKE '{searchText}%' ORDER BY `點播次數` DESC;";
? "SELECT * FROM song_library_cache ORDER BY `song_id` DESC LIMIT 200;"
: $"SELECT * FROM song_library_cache WHERE `phonetic_abbr` LIKE '{searchText}%' ORDER BY `song_id`;";
var searchResults = SearchSongs_Mysql(query);
var searchResults = SearchSongs_Mysql(query);
// 重置分頁
currentPage = 0;
currentSongList = searchResults;

View File

@ -230,8 +230,8 @@ namespace DualScreenDemo
string searchText = inputBoxEnglishSongs.Text;
// 檢查是否為空字串或空白字元
string query = string.IsNullOrWhiteSpace(searchText)
? "SELECT * FROM SongLibrary ORDER BY `點播次數` DESC LIMIT 200;"
: $"SELECT * FROM SongLibrary WHERE `歌曲名稱` LIKE '{searchText}%' ORDER BY `點播次數` DESC;";
? "SELECT * FROM song_library_cache ORDER BY song_id DESC LIMIT 200;"
: $"SELECT * FROM song_library_cache WHERE song_name LIKE '{searchText}%' ORDER BY song_id DESC;";
var searchResults = SearchSongs_Mysql(query);
// 重置分頁

View File

@ -287,8 +287,8 @@ namespace DualScreenDemo
// 在這裡添加搜尋歌曲的邏輯
// 例如:根據輸入框的內容搜尋歌曲
string query = string.IsNullOrWhiteSpace(searchText)
? "SELECT * FROM SongLibrary ORDER BY `點播次數` DESC LIMIT 200;"
: $"SELECT * FROM SongLibrary WHERE `歌曲名稱` LIKE '{searchText}%' ORDER BY `點播次數` DESC;";
? "SELECT * FROM song_library_cache ORDER BY song_id DESC LIMIT 200;"
: $"SELECT * FROM song_library_cache WHERE song_name LIKE '{searchText}%' ORDER BY song_id DESC;";
var searchResults = SearchSongs_Mysql(query);

View File

@ -550,7 +550,7 @@ namespace DualScreenDemo
// 如果輸入框為空,則不進行搜尋
return;
}
string query = $"SELECT * FROM SongLibrary WHERE `歌曲編號` = '{searchText}' ";
string query = $"SELECT * FROM song_library_cache WHERE `song_id` = '{searchText}' ";
var searchResults = SearchSongs_Mysql(query);
// 重置分頁

View File

@ -266,8 +266,8 @@ namespace DualScreenDemo
// 在這裡添加搜尋歌曲的邏輯
// 例如:根據輸入框的內容搜尋歌曲
string query = string.IsNullOrWhiteSpace(searchText)
? "SELECT * FROM SongLibrary ORDER BY `點播次數` DESC LIMIT 200;"
: $"SELECT * FROM SongLibrary WHERE `歌曲拼音` LIKE '{searchText}%' ORDER BY `點播次數` DESC;";
? "SELECT * FROM song_library_cache ORDER BY song_id DESC LIMIT 200;"
: $"SELECT * FROM song_library_cache WHERE pinyin_abbr LIKE '{searchText}%' ORDER BY `song_id` DESC;";
var searchResults = SearchSongs_Mysql(query);
// 重置分頁
currentPage = 0;
@ -276,8 +276,6 @@ namespace DualScreenDemo
// 更新多頁面面板的內容
multiPagePanel.currentPageIndex = 0;
multiPagePanel.LoadSongs(currentSongList);
}
/// <summary>
/// 初始化拼音輸入框 (RichTextBox),並從 config.ini 讀取相關設定。

View File

@ -477,7 +477,7 @@ namespace DualScreenDemo
string query;
if (int.TryParse(searchText, out int length))
{
query = $"SELECT * FROM SongLibrary WHERE CHAR_LENGTH(歌曲名稱) = {length} ";
query = $"SELECT * FROM song_library_cache WHERE CHAR_LENGTH(song_name) = {length} ";
}
else
{