리크 테스트 gui
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

155 lines
4.7 KiB

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
namespace leak_test_project
{
public partial class MainWindow : Window
{
private DispatcherTimer _timer;
private bool _isClosingForcefully = false;
public MainWindow()
{
InitializeComponent();
StartClock();
DisplayLoginInfo();
this.Closing += MainWindow_Closing;
}
private void Window_ContentRendered(object sender, EventArgs e)
{
ShowLoginDialog();
}
private void ShowLoginDialog()
{
try
{
var loginWindow = new Housing.Login.StartupLoginWindow();
loginWindow.Owner = this; // 소유자 지정으로 항상 위에 모달 형식으로 띄움
if (loginWindow.ShowDialog() == true)
{
App.LoginResult = loginWindow.Result;
DisplayLoginInfo();
}
else
{
_isClosingForcefully = true;
this.Close(); // 로그인 취소 시 프로그램 종료
}
}
catch (Exception ex)
{
MessageBox.Show(this, $"로그인 로드 실패: {ex.Message}", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
_isClosingForcefully = true;
this.Close();
}
}
private void DisplayLoginInfo()
{
if (App.LoginResult != null)
{
txtOperatorInfo.Text = App.LoginResult.Operator;
txtModelInfo.Text = App.LoginResult.Model;
txtLineInfo.Text = App.LoginResult.LineNo;
}
else
{
txtOperatorInfo.Text = "---";
txtModelInfo.Text = "---";
txtLineInfo.Text = "---";
}
}
private void BtnLogout_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show(this, "로그아웃 하시겠습니까?", "로그아웃", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
App.LoginResult = null;
DisplayLoginInfo();
ShowLoginDialog();
}
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (_isClosingForcefully)
{
DisposeResources();
return;
}
var result = MessageBox.Show(this, "프로그램을 종료하시겠습니까?", "종료 확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
e.Cancel = true;
return;
}
DisposeResources();
}
private void DisposeResources()
{
// ViewModel의 Dispose를 호출하여 모든 통신 연결 해제
if (this.DataContext is IDisposable disposable)
{
disposable.Dispose();
}
_timer?.Stop();
}
private void StartClock()
{
_timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
_timer.Tick += (s, e) => UpdateDateTime();
_timer.Start();
UpdateDateTime();
}
private void UpdateDateTime()
{
string dayOfWeek = DateTime.Now.ToString("ddd");
txtCurrentDateTime.Text = DateTime.Now.ToString($"yyyy-MM-dd [{dayOfWeek}] HH:mm:ss");
}
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void BtnMaximize_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
txtMaximizeIcon.Text = "1"; // Maximize icon
btnMaximize.ToolTip = "최대화";
}
else
{
this.WindowState = WindowState.Maximized;
txtMaximizeIcon.Text = "2"; // Restore icon
btnMaximize.ToolTip = "창 모드";
}
}
private void TopBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
BtnMaximize_Click(sender, e);
}
else
{
this.DragMove();
}
}
}
}