70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using PackagingMallShipper.Services;
|
|
using PackagingMallShipper.ViewModels;
|
|
|
|
namespace PackagingMallShipper.Views
|
|
{
|
|
public partial class LoginWindow : Window
|
|
{
|
|
private readonly LoginViewModel _viewModel;
|
|
private readonly IAuthService _authService;
|
|
|
|
public LoginWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
_authService = new AuthService();
|
|
_viewModel = new LoginViewModel(_authService);
|
|
DataContext = _viewModel;
|
|
|
|
_viewModel.OnLoginSuccess += OnLoginSuccess;
|
|
|
|
if (_authService.IsLoggedIn)
|
|
{
|
|
OpenMainWindow();
|
|
}
|
|
}
|
|
|
|
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is PasswordBox pb)
|
|
{
|
|
_viewModel.Password = pb.Password;
|
|
}
|
|
}
|
|
|
|
private void CaptchaImage_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
_viewModel.RefreshCaptchaCommand.Execute(null);
|
|
}
|
|
|
|
private void OnLoginSuccess()
|
|
{
|
|
OpenMainWindow();
|
|
}
|
|
|
|
private void OpenMainWindow()
|
|
{
|
|
var orderService = new OrderService();
|
|
var syncService = new SyncService(_authService);
|
|
var shipService = new ShipService(_authService);
|
|
var excelService = new ExcelService(orderService, shipService);
|
|
var orderListViewModel = new OrderListViewModel(orderService, syncService, shipService, excelService);
|
|
|
|
var mainViewModel = new MainViewModel(_authService, orderListViewModel);
|
|
|
|
var mainWindow = new MainWindow(mainViewModel);
|
|
mainViewModel.OnLogout += () =>
|
|
{
|
|
var loginWindow = new LoginWindow();
|
|
loginWindow.Show();
|
|
mainWindow.Close();
|
|
};
|
|
|
|
mainWindow.Show();
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|