diff --git a/Index.xaml b/Index.xaml
index 379a446..30add5c 100644
--- a/Index.xaml
+++ b/Index.xaml
@@ -378,6 +378,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Index.xaml.cs b/Index.xaml.cs
index ab1ccb4..87f35b1 100644
--- a/Index.xaml.cs
+++ b/Index.xaml.cs
@@ -65,7 +65,7 @@ namespace Karaoke_Kingpin
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
-
+
// 添加一個新的類來保存房間狀態信息
private class RoomState
{
@@ -145,7 +145,7 @@ namespace Karaoke_Kingpin
MarqueeItems.Add(content);
// Append newEntry to marquee_items.txt
- string filePath = @"txt\marquee_items.txt";
+ string filePath = @"outputfile\txt\marquee_items.txt";
using (StreamWriter sw = File.AppendText(filePath))
{
sw.WriteLine(content);
@@ -191,7 +191,7 @@ namespace Karaoke_Kingpin
}
// Save the updated list to marquee_items.txt
- string filePath = @"txt\marquee_items.txt";
+ string filePath = @"outputfile\txt\marquee_items.txt";
File.WriteAllLines(filePath, MarqueeItems);
// Clear input box
@@ -207,7 +207,7 @@ namespace Karaoke_Kingpin
MarqueeItems.Remove(selectedItem);
// Update marquee_items.txt
- string filePath = @"txt\marquee_items.txt";
+ string filePath = @"outputfile\txt\marquee_items.txt";
var lines = File.ReadAllLines(filePath).ToList();
lines.Remove(selectedItem);
File.WriteAllLines(filePath, lines);
@@ -220,7 +220,7 @@ namespace Karaoke_Kingpin
private void LoadRoomsFromTextFile()
{
- var lines = File.ReadAllLines(@"txt\room.txt");
+ var lines = File.ReadAllLines(@"outputfile\txt\room.txt");
foreach (var line in lines)
{
diff --git a/MainViewModel.cs b/MainViewModel.cs
index bb6e2b7..0b633a7 100644
--- a/MainViewModel.cs
+++ b/MainViewModel.cs
@@ -137,11 +137,11 @@ namespace Karaoke_Kingpin
public MainViewModel()
{
// Initialize with the image filename
- CacheImage = "cache.jpg";
- FilmImage = "film.jpg";
- BugImage = "bug.jpg";
- UserImage = "user.jpg";
- ImagesImage = "images.jpg";
+ CacheImage = @"outputfile\Imagers\cache.jpg";
+ FilmImage = @"outputfile\Imagers\film.jpg";
+ BugImage = @"outputfile\Imagers\bug.jpg";
+ UserImage = @"outputfile\Imagers\user.jpg";
+ ImagesImage = @"outputfile\Imagers\images.jpg";
// Initialize Marquee Items
Marquee1Items = new ObservableCollection(File.ReadAllLines(@"txt\marquee1_items.txt"));
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
index 08ac045..b540dce 100644
--- a/Properties/Resources.resx
+++ b/Properties/Resources.resx
@@ -119,6 +119,6 @@
- ..\images.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+ ..\outputfile\Imagers\images.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
\ No newline at end of file
diff --git a/RoomDetailsWindow.xaml b/RoomDetailsWindow.xaml
new file mode 100644
index 0000000..ae7fb3a
--- /dev/null
+++ b/RoomDetailsWindow.xaml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/RoomDetailsWindow.xaml.cs b/RoomDetailsWindow.xaml.cs
new file mode 100644
index 0000000..4c9b25e
--- /dev/null
+++ b/RoomDetailsWindow.xaml.cs
@@ -0,0 +1,199 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.IO;
+
+namespace Karaoke_Kingpin
+{
+ ///
+ /// RoomDetailsWindow.xaml 的互動邏輯
+ ///
+ public partial class RoomDetailsWindow : Window
+ {
+ private readonly Room _room;
+
+ private readonly TcpServer _tcpServer;
+
+ public RoomDetailsWindow(Room room, TcpServer tcpServer)
+ {
+ InitializeComponent();
+ _room = room;
+ _tcpServer = tcpServer;
+ DataContext = _room;
+ CenterWindowOnMainWindow();
+
+ // 訂閱 TCP 服務器的命令接收事件
+ _tcpServer.CommandReceived += HandleCommand;
+ }
+
+
+ private void CenterWindowOnMainWindow()
+ {
+ if (Application.Current.MainWindow != null)
+ {
+ this.Owner = Application.Current.MainWindow;
+ this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
+ }
+ }
+
+ public async void Start_Click(object sender, RoutedEventArgs e)
+ {
+ Console.WriteLine($"=== 開始執行開機操作 ===");
+ string roomNumber = _room.RoomNumber.Substring(1);
+ Console.WriteLine($"房間號碼: {roomNumber}");
+
+ // 保存原始的時間範圍
+ string originalTimeRange = _room.TimeRange;
+
+ await SendTcpSignal(roomNumber, "O");
+
+ // 發送完成後,更新房間狀態
+ _room.Status = "已占用";
+ _room.TimeRange = originalTimeRange;
+
+ // 保存狀態到文件
+ if (Application.Current.MainWindow is MainWindow mainWindow)
+ {
+ mainWindow.SaveRoomsToFile("roomstates.txt");
+ }
+
+ Console.WriteLine($"傳送開機信號 -> 房號: {roomNumber}, 指令: O");
+ Console.WriteLine($"時間範圍: {_room.TimeRange}");
+ Console.WriteLine("=== 開機操作完成 ===\n");
+ }
+
+ public async void Shutdown_Click(object sender, RoutedEventArgs e)
+ {
+ Console.WriteLine($"=== 開始執行關機操作 ===");
+ string roomNumber = _room.RoomNumber.Substring(1);
+ Console.WriteLine($"房間號碼: {roomNumber}");
+
+ await SendTcpSignal(roomNumber, "X");
+
+ // 手動關機時更新狀態
+ _room.Status = "可用";
+ _room.TimeRange = "Not Set";
+
+ // 保存狀態到文件
+ if (Application.Current.MainWindow is MainWindow mainWindow)
+ {
+ mainWindow.SaveRoomsToFile("roomstates.txt");
+ }
+
+ Console.WriteLine($"傳送關機信號 -> 房號: {roomNumber}, 指令: X");
+ Console.WriteLine("=== 關機操作完成 ===\n");
+ }
+
+ // 添加新的方法來處理 TCP 命令
+ private async void HandleCommand(string roomNumber, string command)
+ {
+ await Dispatcher.InvokeAsync(async () =>
+ {
+ if (roomNumber == _room.RoomNumber.Substring(1))
+ {
+ switch (command)
+ {
+ case "O":
+ await SendTcpSignal(roomNumber, "O");
+ break;
+ case "X":
+ await SendTcpSignal(roomNumber, "X");
+ break;
+ }
+ }
+ });
+ }
+
+ // 在窗口關閉時取消訂閱事件
+ protected override void OnClosed(EventArgs e)
+ {
+ base.OnClosed(e);
+ if (_tcpServer != null)
+ {
+ _tcpServer.CommandReceived -= HandleCommand;
+ }
+ }
+
+ private void Cancel_Click(object sender, RoutedEventArgs e)
+ {
+ MessageBox.Show("取消");
+ }
+
+ private void OpenAccount_Click(object sender, RoutedEventArgs e)
+ {
+ MessageBox.Show("包廂開帳");
+ }
+
+ private void CloseAccount_Click(object sender, RoutedEventArgs e)
+ {
+ MessageBox.Show("包廂關帳");
+ }
+
+ private async Task SendTcpSignal(string roomNumber, string command)
+ {
+ int retryInterval = 10000; // 10秒
+ int maxDuration = 20 * 60 * 1000; // 20分鐘
+ int elapsedTime = 0;
+ bool success = false;
+
+ while (elapsedTime < maxDuration && !success)
+ {
+ try
+ {
+ string message = $"{roomNumber},{command}";
+ LogToFile($"嘗試發送: {message}");
+
+ using (TcpClient client = new TcpClient(_room.RoomPC, 1000))
+ {
+ NetworkStream stream = client.GetStream();
+ byte[] data = Encoding.ASCII.GetBytes(message);
+ await stream.WriteAsync(data, 0, data.Length);
+ Console.WriteLine($"房間 {roomNumber} 發送指令: {command}");
+ success = true;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"發送失敗,10秒後重試");
+ if (!success)
+ {
+ await Task.Delay(retryInterval);
+ elapsedTime += retryInterval;
+ }
+ }
+ }
+
+ if (!success)
+ {
+ Console.WriteLine($"房間 {roomNumber} 發送指令失敗: 超過20分鐘重試時間");
+ }
+ }
+
+ private void LogToFile(string logMessage)
+ {
+ string logFilePath = "log.txt"; // 你可以根據需要更改文件路徑
+ try
+ {
+ using (StreamWriter writer = new StreamWriter(logFilePath, true))
+ {
+ writer.WriteLine($"{DateTime.Now}: {logMessage}");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"寫入日誌失敗: {ex.Message}");
+ }
+ }
+ }
+}
diff --git a/outputfile/Imagers/bug.jpg b/outputfile/Imagers/bug.jpg
new file mode 100644
index 0000000..5d19e2a
Binary files /dev/null and b/outputfile/Imagers/bug.jpg differ
diff --git a/outputfile/Imagers/cache.jpg b/outputfile/Imagers/cache.jpg
new file mode 100644
index 0000000..4631c40
Binary files /dev/null and b/outputfile/Imagers/cache.jpg differ
diff --git a/outputfile/Imagers/film.jpg b/outputfile/Imagers/film.jpg
new file mode 100644
index 0000000..4e8b00d
Binary files /dev/null and b/outputfile/Imagers/film.jpg differ
diff --git a/images.jpg b/outputfile/Imagers/images.jpg
similarity index 100%
rename from images.jpg
rename to outputfile/Imagers/images.jpg
diff --git a/outputfile/Imagers/user.jpg b/outputfile/Imagers/user.jpg
new file mode 100644
index 0000000..03b8839
Binary files /dev/null and b/outputfile/Imagers/user.jpg differ
diff --git a/outputfile/txt/marquee1_items.txt b/outputfile/txt/marquee1_items.txt
new file mode 100644
index 0000000..beaa7dd
--- /dev/null
+++ b/outputfile/txt/marquee1_items.txt
@@ -0,0 +1,11 @@
+
+拾獲您的證件,請至櫃台領取
+請移動你的愛車,謝謝!!
+祝你生日快樂!!
+櫃台有您訪客!!
+警察臨檢不便之處敬請原諒!!
+您的愛車被拖吊了!!
+請移動您的愛車,謝謝
+aaaaaaaaaaaaaaaaaaaaaa
+bbbbbbbbbbbbbbbbbbbbbb
+cccccccccccccccccccccc
diff --git a/outputfile/txt/marquee2_items.txt b/outputfile/txt/marquee2_items.txt
new file mode 100644
index 0000000..ca8e830
--- /dev/null
+++ b/outputfile/txt/marquee2_items.txt
@@ -0,0 +1,8 @@
+
+拾獲您的證件,請至櫃台領取
+請移動你的愛車,謝謝!!
+祝你生日快樂!!
+櫃台有您訪客!!
+警察臨檢不便之處敬請原諒!!
+您的愛車被拖吊了!!
+請移動您的愛車,謝謝
\ No newline at end of file
diff --git a/outputfile/txt/marquee_items.txt b/outputfile/txt/marquee_items.txt
new file mode 100644
index 0000000..33583e1
--- /dev/null
+++ b/outputfile/txt/marquee_items.txt
@@ -0,0 +1,13 @@
+全部(紅色)-本公司消費方式:包廂費(原價 * 時數 * 折數)+ 清潔費(一次)+ 總金額10%服務費(一次)。
+全部(紅色)-一般專案為包廂計費,免收低消及人頭費;如各族群優惠專案為包廂計費、不限人數K歌一口價。
+全部(綠色)-工商專案 上班族趕快來報到 不限人數 包廂計費 歡唱K歌一口價★星期一至星期日 上午08:00 ~ 下午17:00 ★歡唱3小時 小包廂 666元 中包廂 999元 大包廂(臺中公園店為中大包廂) 1299元
+全部(黑色)-趁年輕 一定要大膽瘋狂不限人數 包廂計費 歡唱K歌一口價★星期一至星期五 上午08:00 ~ 下午17:00 ★歡唱3小時(員林中山店為4小時) 小包廂 333元 中包廂 666元 大包廂(臺中公園店為中大包廂) 999元
+全部(藍色)-重拾當年意氣風發的活力 不輸少年人啦不限人數 包廂計費 歡唱K歌一口價 ★星期一至星期五 上午08:00 ~ 下午17:00 ★歡唱4小時 小包廂 333元 中包廂 666元 大包廂 999元
+全部(白色)-各分店皆適用 生日快樂!吹個蠟燭 許個心願吧 壽星們 生日開趴的通通站出來 ★當日壽星限定(須出示相關證件供服務人員確認).享有好禮雙重送 ★好禮一:生日紅酒一瓶🍷.超級巨星6吋特製蛋糕.什錦水果一盤.義式冰淇淋.莓果調酒(五選一) ★好禮二:餐飲券600元(可當日折抵使用)
+全部(白色)-999999
+全部(綠色)-工商專案 上班族趕快來報到 不限人數 包廂計費 歡唱K歌一口價★星期一至星期日 上午08:00 ~ 下午17:00 ★歡唱3小時 小包廂 666元 中包廂 999元 大包廂(臺中公園店為中大包廂) 1399元
+0101(綠色)-12312313213
+0901(紅色)-趁年輕 一定要大膽瘋狂不限人數 包廂計費 歡唱K歌一口價★星期一至星期五 上午08:00 ~ 下午17:00 ★歡唱3小時(員林中山店為4小時) 小包廂 333元 中包廂 666元 大包廂(臺中公園店為中大包廂) 999元
+0901(紅色)-
+全部(綠色)-123132132132
+0901(綠色)-123132132132
diff --git a/outputfile/txt/room.txt b/outputfile/txt/room.txt
new file mode 100644
index 0000000..f05c561
--- /dev/null
+++ b/outputfile/txt/room.txt
@@ -0,0 +1,3 @@
+1樓;pc101,pc102,pc103,pc104,pc105,pc106,pc108
+2樓;pc201,pc202,pc203,pc205
+9樓;pc901,pc902,pc903
\ No newline at end of file