圖檔與文檔改到outputfileI資料夾 20250321

This commit is contained in:
allen.yan 2025-03-21 09:38:57 +08:00
parent aef9d2b304
commit 32d47bcf20
15 changed files with 311 additions and 11 deletions

View File

@ -378,6 +378,35 @@
</Grid>
</Grid>
</TabItem>
<TabItem Header="包廂設定" Height="19" VerticalAlignment="Top">
<Grid Background="#F4EAD5">
<ItemsControl ItemsSource="{Binding Rooms}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="1" Margin="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding RoomNumber}" FontWeight="Bold" FontSize="16" HorizontalAlignment="Left" Margin="5,0"/>
<TextBlock Text="{Binding Status}" Foreground="Blue" FontSize="14" HorizontalAlignment="Center" Grid.Row="1"/>
<TextBlock Text="{Binding TimeRange}" FontSize="14" HorizontalAlignment="Center" Grid.Row="2"/>
<Rectangle Fill="Transparent" MouseDown="Rectangle_MouseDown" Grid.Row="0" Grid.RowSpan="3"/>
<Rectangle Width="20" Height="10" HorizontalAlignment="Right" VerticalAlignment="Center" Style="{StaticResource StatusRectangleStyle}" Grid.Row="1"/>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</TabItem>
<TabItem Header="歌庫目錄" Height="19" VerticalAlignment="Top">
<Grid>
<Grid.RowDefinitions>

View File

@ -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)
{

View File

@ -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<string>(File.ReadAllLines(@"txt\marquee1_items.txt"));

View File

@ -119,6 +119,6 @@
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="images" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<value>..\outputfile\Imagers\images.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

37
RoomDetailsWindow.xaml Normal file
View File

@ -0,0 +1,37 @@
<Window x:Class="Karaoke_Kingpin.RoomDetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Karaoke_Kingpin"
mc:Ignorable="d"
Title="RoomDetailsWindow" Height="200" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.ColumnSpan="6" Background="DarkGray">
<TextBlock Text="{Binding RoomNumber}" FontSize="20" FontWeight="Bold" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5"/>
</StackPanel>
<!-- 第一行按钮 -->
<Button Content="開機" Margin="10" Click="Start_Click" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"/>
<Button Content="關機" Margin="10" Click="Shutdown_Click" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2"/>
<Button Content="取消" Margin="10" Click="Cancel_Click" Grid.Row="1" Grid.Column="4" Grid.ColumnSpan="2"/>
<!-- 第二行按钮 -->
<Button Content="包廂開帳" Margin="10" Click="OpenAccount_Click" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3"/>
<Button Content="包廂關帳" Margin="10" Click="CloseAccount_Click" Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="3"/>
</Grid>
</Window>

199
RoomDetailsWindow.xaml.cs Normal file
View File

@ -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
{
/// <summary>
/// RoomDetailsWindow.xaml 的互動邏輯
/// </summary>
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}");
}
}
}
}

BIN
outputfile/Imagers/bug.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
outputfile/Imagers/film.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
outputfile/Imagers/user.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@ -0,0 +1,11 @@
拾獲您的證件,請至櫃台領取
請移動你的愛車,謝謝!!
祝你生日快樂!!
櫃台有您訪客!!
警察臨檢不便之處敬請原諒!!
您的愛車被拖吊了!!
請移動您的愛車,謝謝
aaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccc

View File

@ -0,0 +1,8 @@
拾獲您的證件,請至櫃台領取
請移動你的愛車,謝謝!!
祝你生日快樂!!
櫃台有您訪客!!
警察臨檢不便之處敬請原諒!!
您的愛車被拖吊了!!
請移動您的愛車,謝謝

View File

@ -0,0 +1,13 @@
全部(紅色)-本公司消費方式:包廂費(原價 * 時數 * 折數)+ 清潔費(一次)+ 總金額10%服務費(一次)。
全部(紅色)-一般專案為包廂計費免收低消及人頭費如各族群優惠專案為包廂計費、不限人數K歌一口價。
全部(綠色)-工商專案 上班族趕快來報到 不限人數 包廂計費 歡唱K歌一口價★星期一至星期日 上午0800 ~ 下午1700 ★歡唱3小時 小包廂 666元 中包廂 999元 大包廂(臺中公園店為中大包廂) 1299元
全部(黑色)-趁年輕 一定要大膽瘋狂不限人數 包廂計費 歡唱K歌一口價★星期一至星期五 上午0800 ~ 下午1700 ★歡唱3小時(員林中山店為4小時) 小包廂 333元 中包廂 666元 大包廂(臺中公園店為中大包廂) 999元
全部(藍色)-重拾當年意氣風發的活力 不輸少年人啦不限人數 包廂計費 歡唱K歌一口價 ★星期一至星期五 上午0800 ~ 下午1700 ★歡唱4小時 小包廂 333元 中包廂 666元 大包廂 999元
全部(白色)-各分店皆適用 生日快樂!吹個蠟燭 許個心願吧 壽星們 生日開趴的通通站出來 ★當日壽星限定(須出示相關證件供服務人員確認).享有好禮雙重送 ★好禮一生日紅酒一瓶🍷超級巨星6吋特製蛋糕什錦水果一盤義式冰淇淋莓果調酒(五選一) ★好禮二餐飲券600元(可當日折抵使用)
全部(白色)-999999
全部(綠色)-工商專案 上班族趕快來報到 不限人數 包廂計費 歡唱K歌一口價★星期一至星期日 上午0800 ~ 下午1700 ★歡唱3小時 小包廂 666元 中包廂 999元 大包廂(臺中公園店為中大包廂) 1399元
0101(綠色)-12312313213
0901(紅色)-趁年輕 一定要大膽瘋狂不限人數 包廂計費 歡唱K歌一口價★星期一至星期五 上午0800 ~ 下午1700 ★歡唱3小時(員林中山店為4小時) 小包廂 333元 中包廂 666元 大包廂(臺中公園店為中大包廂) 999元
0901(紅色)-
全部(綠色)-123132132132
0901(綠色)-123132132132

3
outputfile/txt/room.txt Normal file
View File

@ -0,0 +1,3 @@
1樓;pc101,pc102,pc103,pc104,pc105,pc106,pc108
2樓;pc201,pc202,pc203,pc205
9樓;pc901,pc902,pc903