300 lines
13 KiB
C#
300 lines
13 KiB
C#
using System.IO;
|
|
using DBObj;
|
|
|
|
namespace DualScreenDemo
|
|
{
|
|
public partial class PrimaryForm
|
|
{
|
|
private PictureBox pictureBoxSongIDSearch;
|
|
private Button[] numberSongIDButtonsForSongs;
|
|
private Button modifyButtonSongIDSearch;
|
|
private Button clearButtonSongIDSearch;
|
|
private Button closeButtonSongIDSearch;
|
|
private Button enterButtonSongIDSearch;
|
|
private RichTextBox inputBoxSongIDSearch;
|
|
|
|
|
|
private void InitializeButtonsForSongIDSearch()
|
|
{
|
|
InitializeNumberSongIDButtons(pictureBoxSongIDSearch, NumberSongIDButton_Click);
|
|
|
|
InitializeInputBoxSongIDSearch();
|
|
|
|
InitializeSongIDButton();
|
|
}
|
|
|
|
private void InitializeSongIDButton()
|
|
{
|
|
// 加載配置數據
|
|
var data = LoadBtnConfigData();
|
|
|
|
|
|
// 初始化「清除」按鈕
|
|
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);
|
|
}
|
|
private void InitializeNumberSongIDButtons(Control control, EventHandler handler)
|
|
{
|
|
// 初始化語音按鈕陣列,總共有 10 個按鈕
|
|
numberSongIDButtonsForSongs = new Button[10];
|
|
|
|
// 設置上排數字按鈕
|
|
int x = 10;
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
private void CreateNumBtnSongIDButton(int index, int x, int y,Control control,EventHandler handler)
|
|
{
|
|
try
|
|
{
|
|
// 加載配置數據
|
|
var data = LoadBtnConfigData();
|
|
// 創建語音按鈕並設置其屬性
|
|
numberSongIDButtonsForSongs[index] = new Button
|
|
{
|
|
Name = $"numberSongIDButtonsForSongs_{numberWordCountSymbols[index]}", // 按鈕名稱設為語音符號名稱
|
|
};
|
|
|
|
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);
|
|
|
|
// 設置按鈕的 Tag 屬性為對應的語音符號
|
|
numberSongIDButtonsForSongs[index].Tag = numberWordCountSymbols[index];
|
|
|
|
// 將按鈕添加到表單的控制項集合中
|
|
control.Controls.Add(numberSongIDButtonsForSongs[index]);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error creating button at index {index}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void ShowImageOnPictureBoxSongIDSearch(string imagePath)
|
|
{
|
|
// 加載原始圖片
|
|
Bitmap originalImage = new Bitmap(imagePath);
|
|
// 設置圖片到 PictureBox
|
|
pictureBoxSongIDSearch.Image = originalImage;
|
|
// 調整 PictureBox 大小和位置
|
|
ResizeAndPositionPictureBox(pictureBoxSongIDSearch, 778, 366, 420, 350);
|
|
// 顯示圖片
|
|
pictureBoxSongIDSearch.Visible = true;
|
|
}
|
|
|
|
private void InitializeInputBoxSongIDSearch()
|
|
{
|
|
try
|
|
{
|
|
// 創建一個 RichTextBox 控件來作為輸入框
|
|
inputBoxSongIDSearch = new RichTextBox
|
|
{
|
|
Name = "inputBoxSongIDSearch",
|
|
ForeColor = Color.Black, // 設定文字顏色
|
|
Font = new Font("Times New Roman", 26, FontStyle.Regular), // 設定字體樣式
|
|
ScrollBars = RichTextBoxScrollBars.None, // 不顯示滾動條
|
|
};
|
|
|
|
// 調整和定位輸入框的位置及大小
|
|
ResizeAndPositionControl(inputBoxSongIDSearch, 10, 55, 400, 60);
|
|
|
|
// 將輸入框加入到窗體的控件集合中
|
|
pictureBoxSongIDSearch.Controls.Add(inputBoxSongIDSearch);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// 如果初始化過程中出現錯誤,則在控制台輸出錯誤信息
|
|
Console.WriteLine("Error initializing inputBoxSongIDSearch: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void SetSongIDSearchAndButtonsVisibility(bool isVisible)
|
|
{
|
|
// 定義一個動作來處理控制項的顯示或隱藏
|
|
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(); // 否則直接執行
|
|
}
|
|
}
|
|
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;
|
|
|
|
// 載入設定檔,取得圖片路徑資訊
|
|
var configData = LoadBtnConfigData();
|
|
|
|
// 取得「注音歌手圖片」的完整路徑
|
|
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);
|
|
|
|
ResetinputBox();
|
|
SetSongIDSearchAndButtonsVisibility(true); // 顯示字數搜尋相關控件
|
|
// 顯示「注音歌手搜尋」的圖片框
|
|
pictureBoxSongIDSearch.Visible = true;
|
|
}
|
|
private void NumberSongIDButton_Click(object sender, EventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
if (button != null && button.Tag != null)
|
|
{
|
|
|
|
if (inputBoxSongIDSearch.Visible)
|
|
{
|
|
inputBoxSongIDSearch.Text += button.Tag.ToString();
|
|
}
|
|
}
|
|
}
|
|
private void ModifyButtonSongIDSearch_Click(object sender, EventArgs e)
|
|
{
|
|
// 如果輸入框不為空,且包含輸入內容,則刪除最後一個字符
|
|
if (pictureBoxSongIDSearch.Controls.Contains(inputBoxSongIDSearch) && inputBoxSongIDSearch.Text.Length > 0)
|
|
{
|
|
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)
|
|
{
|
|
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()
|
|
{
|
|
var data = LoadBtnConfigData();
|
|
|
|
string searchText = inputBoxSongIDSearch.Text;
|
|
// 在這裡添加搜尋歌曲的邏輯
|
|
// 例如:根據輸入框的內容搜尋歌曲
|
|
if (string.IsNullOrEmpty(searchText))
|
|
{
|
|
// 如果輸入框為空,則不進行搜尋
|
|
return;
|
|
}
|
|
string query = $"SELECT * FROM song_library_cache WHERE `song_id` = '{searchText}';";
|
|
|
|
var searchResults = SearchSongs_Mysql(query);
|
|
|
|
// 重置分頁
|
|
currentPage = 0;
|
|
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
|
|
// 更新多頁面面板的內容
|
|
multiPagePanel.currentPageIndex = 0;
|
|
//multiPagePanel.LoadSongs(searchResults);
|
|
|
|
//判斷跳轉點播介面
|
|
if (searchResults.Count != 0 && searchResults[0] is SongData)
|
|
{
|
|
currentSelectedSong = searchResults[0] as SongData;
|
|
this.DoubleBuffered = true;
|
|
this.SuspendLayout();
|
|
|
|
DrawTextOnVodScreenPictureBox(Path.Combine(serverPath, data["SongOrderPanel"]["UIBase"]), currentSelectedSong);
|
|
SetVodScreenPictureBoxAndButtonsVisibility(true);
|
|
this.ResumeLayout(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
} |