superstar_v2/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.NumberSearch.cs

301 lines
13 KiB
C#
Raw Normal View History

2025-04-07 16:54:10 +08:00
using System.IO;
2025-07-31 16:36:58 +08:00
using DBObj;
2025-04-07 16:54:10 +08:00
namespace DualScreenDemo
{
public partial class PrimaryForm
{
private PictureBox pictureBoxSongIDSearch;
private Button[] numberSongIDButtonsForSongs;
private Button modifyButtonSongIDSearch;
private Button clearButtonSongIDSearch;
private Button closeButtonSongIDSearch;
2025-08-06 10:47:43 +08:00
private Button enterButtonSongIDSearch;
2025-04-07 16:54:10 +08:00
private RichTextBox inputBoxSongIDSearch;
private void InitializeButtonsForSongIDSearch()
2025-04-07 16:54:10 +08:00
{
InitializeNumberSongIDButtons(pictureBoxSongIDSearch, NumberSongIDButton_Click);
InitializeInputBoxSongIDSearch();
InitializeSongIDButton();
2025-04-07 16:54:10 +08:00
}
private void InitializeSongIDButton()
2025-04-07 16:54:10 +08:00
{
// 加載配置數據
var data = LoadBtnConfigData();
2025-04-07 16:54:10 +08:00
// 初始化「清除」按鈕
clearButtonSongIDSearch = new Button { Name = "clearButtonSongIDSearch" };
ConfigureButton(clearButtonSongIDSearch, 55, 274, 72, 67,
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesSongID"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesSongID"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesSongID"]["mouseDown"])),
ClearButtonSongIDSearch_Click);
pictureBoxSongIDSearch.Controls.Add(clearButtonSongIDSearch);
// 初始化「重填」按鈕
modifyButtonSongIDSearch = new Button { Name = "modifyButtonSongIDSearch" };
ConfigureButton(modifyButtonSongIDSearch, 136, 274, 72, 67,
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesSongID"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesSongID"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesSongID"]["mouseDown"])),
ModifyButtonSongIDSearch_Click);
pictureBoxSongIDSearch.Controls.Add(modifyButtonSongIDSearch);
// 初始化「確認」按鈕
enterButtonSongIDSearch = new Button { Name = "btnEnterWordCountSongs" };
ConfigureButton(enterButtonSongIDSearch, 217, 274, 72, 67,
new Bitmap(Path.Combine(serverPath, data["EnterButtonImagesSongID"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["EnterButtonImagesSongID"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["EnterButtonImagesSongID"]["mouseDown"])),
SongIDSearch_Click);
pictureBoxSongIDSearch.Controls.Add(enterButtonSongIDSearch);
// 初始化「關閉」按鈕
closeButtonSongIDSearch = new Button { Name = "closeButtonSongIDSearch" };
ConfigureButton(closeButtonSongIDSearch, 298, 274, 72, 67,
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesSongID"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesSongID"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesSongID"]["mouseDown"])),
CloseButtonClick);
pictureBoxSongIDSearch.Controls.Add(closeButtonSongIDSearch);
2025-04-07 16:54:10 +08:00
}
private void InitializeNumberSongIDButtons(Control control, EventHandler handler)
2025-04-07 16:54:10 +08:00
{
// 初始化語音按鈕陣列,總共有 10 個按鈕
numberSongIDButtonsForSongs = new Button[10];
// 設置上排數字按鈕
int x = 10;
for (int i = 0; i < 5; i++)
2025-04-07 16:54:10 +08:00
{
CreateNumBtnSongIDButton(i, x, 120, control, handler);
x += 82;
}
// 設置下排數字按鈕
x = 10;
for (int i = 5; i < 10; i++)
{
CreateNumBtnSongIDButton(i, x, 197, control, handler);
x += 82;
2025-04-07 16:54:10 +08:00
}
}
private void CreateNumBtnSongIDButton(int index, int x, int y,Control control,EventHandler handler)
2025-04-07 16:54:10 +08:00
{
try
{
// 加載配置數據
var data = LoadBtnConfigData();
2025-04-07 16:54:10 +08:00
// 創建語音按鈕並設置其屬性
numberSongIDButtonsForSongs[index] = new Button
{
Name = $"numberSongIDButtonsForSongs_{numberWordCountSymbols[index]}", // 按鈕名稱設為語音符號名稱
2025-04-07 16:54:10 +08:00
};
ConfigureButton(numberSongIDButtonsForSongs[index], x, y, 72, 67,
new Bitmap(Path.Combine(serverPath, data["NumberSongIDButtonImages"][$"button{index}_normal"])),
new Bitmap(Path.Combine(serverPath, data["NumberSongIDButtonImages"][$"button{index}_mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["NumberSongIDButtonImages"][$"button{index}_mouseDown"])),
handler);
2025-04-07 16:54:10 +08:00
// 設置按鈕的 Tag 屬性為對應的語音符號
numberSongIDButtonsForSongs[index].Tag = numberWordCountSymbols[index];
2025-04-07 16:54:10 +08:00
// 將按鈕添加到表單的控制項集合中
control.Controls.Add(numberSongIDButtonsForSongs[index]);
2025-04-07 16:54:10 +08:00
}
catch (Exception ex)
{
Console.WriteLine($"Error creating button at index {index}: {ex.Message}");
}
}
private void ShowImageOnPictureBoxSongIDSearch(string imagePath)
2025-04-07 16:54:10 +08:00
{
// 加載原始圖片
Bitmap originalImage = new Bitmap(imagePath);
// 設置圖片到 PictureBox
pictureBoxSongIDSearch.Image = originalImage;
// 調整 PictureBox 大小和位置
ResizeAndPositionPictureBox(pictureBoxSongIDSearch, 778, 366, 420, 350);
// 顯示圖片
pictureBoxSongIDSearch.Visible = true;
2025-04-07 16:54:10 +08:00
}
private void InitializeInputBoxSongIDSearch()
2025-04-07 16:54:10 +08:00
{
try
2025-04-07 16:54:10 +08:00
{
// 創建一個 RichTextBox 控件來作為輸入框
inputBoxSongIDSearch = new RichTextBox
2025-04-07 16:54:10 +08:00
{
Name = "inputBoxSongIDSearch",
ForeColor = Color.Black, // 設定文字顏色
Font = new Font("Times New Roman", 26, FontStyle.Regular), // 設定字體樣式
ScrollBars = RichTextBoxScrollBars.None, // 不顯示滾動條
};
2025-04-07 16:54:10 +08:00
// 調整和定位輸入框的位置及大小
ResizeAndPositionControl(inputBoxSongIDSearch, 10, 55, 400, 60);
2025-04-07 16:54:10 +08:00
// 將輸入框加入到窗體的控件集合中
pictureBoxSongIDSearch.Controls.Add(inputBoxSongIDSearch);
}
catch (Exception ex)
{
// 如果初始化過程中出現錯誤,則在控制台輸出錯誤信息
Console.WriteLine("Error initializing inputBoxSongIDSearch: " + ex.Message);
}
2025-04-07 16:54:10 +08:00
}
private void SetSongIDSearchAndButtonsVisibility(bool isVisible)
2025-04-07 16:54:10 +08:00
{
// 定義一個動作來處理控制項的顯示或隱藏
System.Action action = () =>
{
try
{
// 暫停控制項佈局的重新排版,提高效率
SuspendLayout();
if (isVisible) SetUIVisible(pictureBoxSongIDSearch);
else CloseUI(pictureBoxSongIDSearch);
}
catch (Exception ex)
{
Console.WriteLine("Error in SetSongIDSearchAndButtonsVisibility: " + ex.Message);
}
};
// 檢查是否需要在主執行緒外執行
if (this.InvokeRequired)
{
this.Invoke(action); // 如果需要,透過主執行緒執行
}
else
{
action(); // 否則直接執行
}
2025-04-07 16:54:10 +08:00
}
private void SongIDSearchSongsButton_Click(object sender, EventArgs e)
{
// 設定按鈕背景,將「注音搜尋」設為啟動狀態,其餘按鈕恢復為正常狀態
zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground;
englishSearchSongButton.BackgroundImage = englishSearchSongNormalBackground;
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongNormalBackground;
wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground;
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongNormalBackground;
numberSearchSongButton.BackgroundImage = numberSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
// 載入設定檔,取得圖片路徑資訊
var configData = LoadBtnConfigData();
2025-04-07 16:54:10 +08:00
// 取得「注音歌手圖片」的完整路徑
string imagePath = Path.Combine(serverPath, configData["ImagePaths"]["SongIDSearch"]);
// 在 PictureBox 中顯示對應的「注音歌手」圖片
ShowImageOnPictureBoxSongIDSearch(Path.Combine(serverPath, imagePath));
// 鍵盤UI介面顯示設定
SetWordCountSongsAndButtonsVisibility(false);
SetEnglishSongsAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetHandWritingForSongsAndButtonsVisibility(false);
SetSongIDSearchAndButtonsVisibility(true);
SetZhuYinSongsAndButtonsVisibility(false);
2025-04-07 16:54:10 +08:00
ResetinputBox();
SetSongIDSearchAndButtonsVisibility(true); // 顯示字數搜尋相關控件
// 顯示「注音歌手搜尋」的圖片框
pictureBoxSongIDSearch.Visible = true;
2025-04-07 16:54:10 +08:00
}
private void NumberSongIDButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button != null && button.Tag != null)
{
2025-04-07 16:54:10 +08:00
if (inputBoxSongIDSearch.Visible)
{
inputBoxSongIDSearch.Text += button.Tag.ToString();
Console.WriteLine(inputBoxSongIDSearch.Text);
}
}
}
2025-04-07 16:54:10 +08:00
private void ModifyButtonSongIDSearch_Click(object sender, EventArgs e)
{
// 如果輸入框不為空,且包含輸入內容,則刪除最後一個字符
if (pictureBoxSongIDSearch.Controls.Contains(inputBoxSongIDSearch) && inputBoxSongIDSearch.Text.Length > 0)
2025-04-07 16:54:10 +08:00
{
inputBoxSongIDSearch.Text = inputBoxSongIDSearch.Text.Substring(0, inputBoxSongIDSearch.Text.Length - 1);
}
}
private void ClearButtonSongIDSearch_Click(object sender, EventArgs e)
{
// 如果輸入框不為空,則清空該框的文本內容
if (pictureBoxSongIDSearch.Controls.Contains(inputBoxSongIDSearch) && inputBoxSongIDSearch.Text.Length > 0)
2025-04-07 16:54:10 +08:00
{
inputBoxSongIDSearch.Text = "";
}
}
private void CloseButtonClick(object sender, EventArgs e)
{
CloseUI(pictureBoxSongIDSearch);
// 隱藏 SongID 歌手圖片框
numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground;
// 隱藏與 SongID 歌手相關的所有按鈕
}
private void SongIDSearch_Click(object sender, EventArgs e)
{
FindNumberSongs(); // 搜尋歌曲
inputBoxSongIDSearch.Text = "";
}
private void FindNumberSongs()
{
2025-08-13 16:42:22 +08:00
var data = LoadBtnConfigData();
string searchText = inputBoxSongIDSearch.Text;
// 在這裡添加搜尋歌曲的邏輯
// 例如:根據輸入框的內容搜尋歌曲
2025-04-15 10:59:03 +08:00
if (string.IsNullOrEmpty(searchText))
{
// 如果輸入框為空,則不進行搜尋
return;
}
2025-05-28 11:04:03 +08:00
string query = $"SELECT * FROM song_library_cache WHERE `song_id` = '{searchText}';";
2025-07-31 16:36:58 +08:00
var searchResults = SearchSongs_Mysql(query);
2025-08-01 11:42:56 +08:00
// 重置分頁
currentPage = 0;
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
// 更新多頁面面板的內容
multiPagePanel.currentPageIndex = 0;
2025-07-31 16:36:58 +08:00
//multiPagePanel.LoadSongs(searchResults);
2025-08-01 11:42:56 +08:00
//判斷跳轉點播介面
if (searchResults.Count != 0 && searchResults[0] is SongData)
{
2025-08-01 11:42:56 +08:00
currentSelectedSong = searchResults[0] as SongData;
this.DoubleBuffered = true;
this.SuspendLayout();
2025-08-13 16:42:22 +08:00
DrawTextOnVodScreenPictureBox(Path.Combine(serverPath, data["SongOrderPanel"]["UIBase"]), currentSelectedSong);
2025-08-01 11:42:56 +08:00
SetVodScreenPictureBoxAndButtonsVisibility(true);
this.ResumeLayout(true);
}
}
2025-04-07 16:54:10 +08:00
}
}