225 lines
11 KiB
C#
225 lines
11 KiB
C#
using MySqlConnector;
|
||
using DBObj;
|
||
using System.Globalization;
|
||
using System.IO;
|
||
namespace DualScreenDemo
|
||
{
|
||
/*
|
||
* 主要視窗 (PrimaryForm) 的部分定義
|
||
* 負責初始化搜尋按鈕並處理歌曲搜尋 UI 相關邏輯
|
||
*/
|
||
public partial class PrimaryForm
|
||
{
|
||
// 各種歌曲搜尋按鈕及其對應的背景圖片 (一般狀態 / 啟動狀態)
|
||
private Button zhuyinSearchSongButton;
|
||
private Bitmap zhuyinSearchSongNormalBackground;
|
||
private Bitmap zhuyinSearchSongActiveBackground;
|
||
private Button englishSearchSongButton;
|
||
private Bitmap englishSearchSongNormalBackground;
|
||
private Bitmap englishSearchSongActiveBackground;
|
||
private Button wordCountSearchSongButton;
|
||
private Bitmap wordCountSearchSongNormalBackground;
|
||
private Bitmap wordCountSearchSongActiveBackground;
|
||
private Button pinyinSearchSongButton;
|
||
private Bitmap pinyinSearchSongNormalBackground;
|
||
private Bitmap pinyinSearchSongActiveBackground;
|
||
private Button handWritingSearchSongButton;
|
||
private Bitmap handWritingSearchSongNormalBackground;
|
||
private Bitmap handWritingSearchSongActiveBackground;
|
||
private Button numberSearchSongButton;
|
||
private Bitmap numberSearchSongNormalBackground;
|
||
private Bitmap numberSearchSongActiveBackground;
|
||
|
||
/// <summary>
|
||
/// 點擊「歌曲搜尋」按鈕時的事件處理函式
|
||
/// 1. 更新導航按鈕的背景圖片,使「歌曲搜尋」按鈕顯示為啟動狀態
|
||
/// 2. 隱藏其他搜尋/分類 UI,僅顯示歌曲搜尋選單
|
||
/// 3. 若有 QR Code 顯示,則將其隱藏
|
||
/// </summary>
|
||
private void SongSearchButton_Click(object sender, EventArgs e)
|
||
{
|
||
// 更新導航按鈕的背景圖片
|
||
newSongAlertButton.BackgroundImage = newSongAlertNormalBackground;
|
||
hotPlayButton.BackgroundImage = hotPlayNormalBackground;
|
||
singerSearchButton.BackgroundImage = singerSearchNormalBackground;
|
||
songSearchButton.BackgroundImage = songSearchActiveBackground;
|
||
languageSearchButton.BackgroundImage = languageSearchNormalBackground;
|
||
groupSearchButton.BackgroundImage = groupSearchNormalBackground;
|
||
categorySearchButton.BackgroundImage = categorySearchNormalBackground;
|
||
orderedSongsButton.BackgroundImage = orderedSongsNormalBackground;
|
||
myFavoritesButton.BackgroundImage = myFavoritesNormalBackground;
|
||
promotionsButton.BackgroundImage = promotionsNormalBackground;
|
||
deliciousFoodButton.BackgroundImage = deliciousFoodNormalBackground;
|
||
isOnOrderedSongsPage = false;
|
||
|
||
// 隱藏其他 UI
|
||
SetHotSongButtonsVisibility(false);
|
||
SetNewSongButtonsVisibility(false);
|
||
SetSingerSearchButtonsVisibility(false);
|
||
SetPictureBoxLanguageButtonsVisibility(false);
|
||
SetGroupButtonsVisibility(false);
|
||
SetPictureBoxCategoryAndButtonsVisibility(false);
|
||
SetZhuYinSingersAndButtonsVisibility(false);
|
||
SetZhuYinSongsAndButtonsVisibility(false);
|
||
SetEnglishSingersAndButtonsVisibility(false);
|
||
SetPinYinSingersAndButtonsVisibility(false);
|
||
SetPinYinSongsAndButtonsVisibility(false);
|
||
SetPictureBoxToggleLightAndButtonsVisibility(false);
|
||
SetPictureBoxSceneSoundEffectsAndButtonsVisibility(false);
|
||
|
||
// 顯示歌曲搜尋選單按鈕
|
||
SetSongSearchButtonsVisibility(true);
|
||
|
||
// 隱藏 QR Code (若有)
|
||
if (pictureBoxQRCode != null)
|
||
{
|
||
pictureBoxQRCode.Visible = false;
|
||
closeQRCodeButton.Visible = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 設定「歌曲搜尋」相關按鈕的可見性
|
||
/// </summary>
|
||
/// <param name="isVisible">是否顯示</param>
|
||
private void SetSongSearchButtonsVisibility(bool isVisible)
|
||
{
|
||
pictureBox4.Visible = isVisible; // 控制搜尋 UI 背景的可見性
|
||
|
||
// 歌曲搜尋的按鈕陣列
|
||
Button[] songSearchButtons = {
|
||
zhuyinSearchSongButton,
|
||
englishSearchSongButton,
|
||
wordCountSearchSongButton,
|
||
pinyinSearchSongButton,
|
||
handWritingSearchSongButton,
|
||
numberSearchSongButton
|
||
};
|
||
|
||
// 設定按鈕可見性,若顯示則移至最前
|
||
foreach (var button in songSearchButtons)
|
||
{
|
||
button.Visible = isVisible;
|
||
if (isVisible)
|
||
{
|
||
button.BringToFront();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化所有「歌曲搜尋」按鈕
|
||
/// 依據不同的搜尋方式 (注音、英文、拼音、筆劃、手寫、數字) 建立對應按鈕
|
||
/// </summary>
|
||
private void InitializeButtonsForSongSearch()
|
||
{
|
||
// 初始化「注音搜尋」按鈕
|
||
InitializeSearchButton(ref zhuyinSearchSongButton, "zhuyinSearchSongButton",
|
||
1214, 230, 209, 59, ref zhuyinSearchSongNormalBackground, ref zhuyinSearchSongActiveBackground,
|
||
normalStateImageSongQuery, mouseDownImageSongQuery, ZhuyinSearchSongsButton_Click);
|
||
|
||
// 初始化「英文搜尋」按鈕
|
||
InitializeSearchButton(ref englishSearchSongButton, "englishSearchSongButton",
|
||
1214, 293, 209, 58, ref englishSearchSongNormalBackground, ref englishSearchSongActiveBackground,
|
||
normalStateImageSongQuery, mouseDownImageSongQuery, EnglishSearchSongsButton_Click);
|
||
|
||
// 初始化「拼音搜尋」按鈕
|
||
InitializeSearchButton(ref pinyinSearchSongButton, "pinyinSearchSongButton",
|
||
1214, 356, 209, 58, ref pinyinSearchSongNormalBackground, ref pinyinSearchSongActiveBackground,
|
||
normalStateImageSongQuery, mouseDownImageSongQuery, PinyinSearchSongsButton_Click);
|
||
|
||
// 初始化「筆劃搜尋」按鈕
|
||
InitializeSearchButton(ref wordCountSearchSongButton, "wordCountSearchSongButton",
|
||
1214, 418, 209, 59, ref wordCountSearchSongNormalBackground, ref wordCountSearchSongActiveBackground,
|
||
normalStateImageSongQuery, mouseDownImageSongQuery, WordCountSearchSongsButton_Click);
|
||
|
||
// 初始化「手寫搜尋」按鈕
|
||
InitializeSearchButton(ref handWritingSearchSongButton, "handWritingSearchSongButton",
|
||
1214, 481, 209, 59, ref handWritingSearchSongNormalBackground, ref handWritingSearchSongActiveBackground,
|
||
normalStateImageSongQuery, mouseDownImageSongQuery, HandWritingSearchButtonForSongs_Click);
|
||
|
||
// 初始化「數字搜尋」按鈕
|
||
InitializeSearchButton(ref numberSearchSongButton, "numberSearchSongButton",
|
||
1214, 544, 209, 58, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground,
|
||
normalStateImageSongQuery, mouseDownImageSongQuery, SongIDSearchSongsButton_Click);
|
||
}
|
||
public List<SongData> SearchSongs_Mysql(string query)
|
||
{
|
||
List<SongData> searchResults = new List<SongData>();
|
||
|
||
string connectionString = "Server=192.168.22.170;Port=3306;Database=Karaoke-Kingpin;User=Karaoke-Kingpin;Password=ESM7yTPMnavFmbBH;";
|
||
|
||
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;
|
||
}
|
||
|
||
|
||
}
|
||
}
|