source
This commit is contained in:
63
PackagingMallShipper/Views/LoginWindow.xaml.cs
Normal file
63
PackagingMallShipper/Views/LoginWindow.xaml.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user