添加我的最愛新建功能
This commit is contained in:
parent
33b6883df2
commit
c4b8b82b64
@ -239,8 +239,8 @@ namespace DualScreenDemo
|
||||
}
|
||||
else
|
||||
{
|
||||
showError = true;
|
||||
isPhoneNumberValid = true;
|
||||
showError = true;
|
||||
isPhoneNumberValid = false;
|
||||
FavoritePictureBox.Invalidate();
|
||||
FavoritePictureBox.Refresh();
|
||||
}
|
||||
@ -254,7 +254,7 @@ namespace DualScreenDemo
|
||||
if (checkPhoneNumberExist(mobileNumber))
|
||||
{
|
||||
isPhoneNumberValid = true;
|
||||
var searchResults = SearchSongs_Mysql(SearchFavoriteSongs_Mysql());
|
||||
var searchResults = SearchSongs_Mysql(SearchFavoriteSongs_Mysql());
|
||||
// 重置分頁
|
||||
currentPage = 0;
|
||||
currentSongList = searchResults;
|
||||
@ -267,22 +267,35 @@ namespace DualScreenDemo
|
||||
}
|
||||
else
|
||||
{
|
||||
/*isPhoneNumberValid = true;
|
||||
SongListManager.Instance.AddNewUser(mobileNumber);
|
||||
SongListManager.Instance.UserLogin(mobileNumber);
|
||||
isPhoneNumberValid = true;
|
||||
InsertNewFavoriteUser(mobileNumber);
|
||||
if (checkPhoneNumberExist(mobileNumber))
|
||||
{
|
||||
var searchResults = SearchSongs_Mysql(SearchFavoriteSongs_Mysql());
|
||||
// 重置分頁
|
||||
currentPage = 0;
|
||||
currentSongList = searchResults;
|
||||
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
|
||||
// 更新多頁面面板的內容
|
||||
multiPagePanel.currentPageIndex = 0;
|
||||
multiPagePanel.LoadSongs(currentSongList);
|
||||
|
||||
ToggleFavoritePictureBoxButtonsVisibility();
|
||||
}
|
||||
else
|
||||
{
|
||||
showError = true;
|
||||
isPhoneNumberValid = false;
|
||||
FavoritePictureBox.Invalidate();
|
||||
FavoritePictureBox.Refresh();
|
||||
}
|
||||
|
||||
|
||||
List<SongData> emptySongList = new List<SongData> { new SongData("", "", "歡迎光臨 " + "(" + mobileNumber + ")", 0, "", "", "", "", DateTime.Now, "", "", "", "", "", "", "", "", "", "", "", "", 1) };
|
||||
|
||||
multiPagePanel.currentPageIndex = 0;
|
||||
multiPagePanel.LoadSongs(emptySongList);*/
|
||||
ToggleFavoritePictureBoxButtonsVisibility();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showError = true;
|
||||
isPhoneNumberValid = true;
|
||||
isPhoneNumberValid = false;
|
||||
FavoritePictureBox.Invalidate();
|
||||
FavoritePictureBox.Refresh();
|
||||
}
|
||||
|
@ -124,9 +124,38 @@ namespace DualScreenDemo{
|
||||
Console.WriteLine("MyDB 連線已關閉!");
|
||||
}
|
||||
}
|
||||
public string SearchFavoriteSongs_Mysql(){
|
||||
public void InsertNewFavoriteUser(string phonenumber){
|
||||
string songlist = phonenumber + "的歌單";
|
||||
string query = $"INSERT INTO FavoriteSongs (userPhone,songNumber) VALUES ('{phonenumber}','{songlist}');";
|
||||
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))
|
||||
{
|
||||
|
||||
connection.Open();
|
||||
Console.WriteLine("MyDB 連線成功!");
|
||||
|
||||
using (var command = new MySqlCommand(query, connection))
|
||||
{
|
||||
int rowsAffected = command.ExecuteNonQuery();
|
||||
if (rowsAffected > 0)
|
||||
{
|
||||
Console.WriteLine("插入成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("插入失敗(沒有資料被新增)");
|
||||
}
|
||||
}
|
||||
connection.Close();
|
||||
Console.WriteLine("MyDB 連線已關閉!");
|
||||
}
|
||||
}
|
||||
public string SearchFavoriteSongs_Mysql()
|
||||
{
|
||||
string query = $"SELECT " +
|
||||
"sl.*"+
|
||||
"sl.*" +
|
||||
"FROM FavoriteSongs fs " +
|
||||
"JOIN song_library_cache sl ON fs.songNumber = sl.song_id " +
|
||||
$"WHERE fs.userPhone = '{userPhone}';";
|
||||
@ -141,25 +170,28 @@ namespace DualScreenDemo{
|
||||
connection.Open();
|
||||
Console.WriteLine("MyDB 連線成功!");
|
||||
string query = $"SELECT COUNT(*) FROM FavoriteSongs WHERE userPhone = '{phonenumber}'";
|
||||
using (var command = new MySqlCommand(query, connection)){
|
||||
int count = Convert.ToInt32(command.ExecuteScalar());
|
||||
if (count > 0)
|
||||
{
|
||||
exists = true; // 存在
|
||||
userPhone= phonenumber;
|
||||
isLoggedIn = true;
|
||||
//點歌我的最愛按鈕,調整按鈕狀態
|
||||
favoriteButton.Enabled = true;
|
||||
favoriteButton.BackColor = Color.Transparent;
|
||||
disabledPanel.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
exists = false; // 不存在
|
||||
}
|
||||
using (var command = new MySqlCommand(query, connection))
|
||||
{
|
||||
int count = Convert.ToInt32(command.ExecuteScalar());
|
||||
if (count > 0)
|
||||
{
|
||||
exists = true; // 存在
|
||||
userPhone = phonenumber;
|
||||
isLoggedIn = true;
|
||||
//點歌我的最愛按鈕,調整按鈕狀態
|
||||
favoriteButton.Enabled = true;
|
||||
favoriteButton.BackColor = Color.Transparent;
|
||||
disabledPanel.Visible = false;
|
||||
this.Invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
exists = false; // 不存在
|
||||
}
|
||||
}
|
||||
connection.Close();
|
||||
Console.WriteLine("MyDB 連線關閉!");
|
||||
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
@ -234,6 +234,7 @@ namespace DualScreenDemo
|
||||
SaveInitialControlStates(this);
|
||||
// 包廂 + port 名稱
|
||||
this.Paint += PrimaryForm_Paint;
|
||||
this.Paint += User_Paint;
|
||||
// 註冊多頁面面板的頁碼改變事件處理
|
||||
multiPagePanel.PageIndexChanged += HandlePageChanged;
|
||||
// 添加 Load 事件處理
|
||||
@ -302,7 +303,36 @@ namespace DualScreenDemo
|
||||
e.Graphics.DrawString(displayName, font, brush, point_PCName);
|
||||
|
||||
}
|
||||
private void User_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(userPhone) && isLoggedIn)
|
||||
{
|
||||
string displayName = "歡迎貴賓 :" + userPhone;
|
||||
float baseWidth = 1920f;
|
||||
float baseHeight = 1080f;
|
||||
|
||||
// 實際螢幕解析度
|
||||
float actualWidth = Screen.PrimaryScreen.Bounds.Width;
|
||||
float actualHeight = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
// 計算縮放比例
|
||||
float scaleX = actualWidth / baseWidth;
|
||||
float scaleY = actualHeight / baseHeight;
|
||||
|
||||
|
||||
// 設定字型:
|
||||
// "微軟正黑體",大小 20,粗體 (Bold)
|
||||
float fontSize = 18 * scaleY;
|
||||
Font font = new Font("微軟正黑體", fontSize, FontStyle.Bold);
|
||||
// 設定畫刷 (Brush):
|
||||
// 使用紅色 (Red) 來繪製文字
|
||||
Brush brush = new SolidBrush(Color.Red);
|
||||
|
||||
// 設定繪製文字的位置 (X=800, Y=30)
|
||||
PointF point_user = new PointF(800 * scaleX, 30 * scaleY);
|
||||
e.Graphics.DrawString(displayName, font, brush, point_user);
|
||||
}
|
||||
}
|
||||
private void buttonMiddle_Click(object sender, EventArgs e)
|
||||
{
|
||||
sequenceManager.ProcessClick("巨");
|
||||
|
Loading…
x
Reference in New Issue
Block a user