-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
102 lines (92 loc) · 3.63 KB
/
MainWindow.xaml.cs
File metadata and controls
102 lines (92 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Threading.Tasks;
using mydatamigration.includes;
using mydatamigration.dashboard;
namespace mydatamigration
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private bool IsFirstTimeInstallation()
{
string configFilePath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "config.json"); // Make sure path is correct
return !File.Exists(configFilePath); // If the file doesn't exist, it's the first time
}
private async void LoginButton_Click(object sender, RoutedEventArgs e)
{
// Show the preloader overlay
PreloaderOverlay.Visibility = Visibility.Visible;
try
{
// Simulate login processing (e.g., call API, validate credentials)
await Task.Run(() =>
{
// Simulating delay for login process (replace this with actual login logic)
System.Threading.Thread.Sleep(3000);
});
// Simulating user input for username and password
string username = UsernameTextBox.Text; // Assuming you have a TextBox named UsernameTextBox
string password = PasswordBox.Password; // Assuming you have a PasswordBox named PasswordBox
// Validate credentials
if (ValidateCredentials(username, password))
{
// Check if it's the first time installation
if (IsFirstTimeInstallation())
{
// Show the Database Connection Window
DatabaseConnectionWindow dbWindow = new DatabaseConnectionWindow();
dbWindow.Show(); // Open the Database Connection Window
this.Close(); // Optionally, close the current window
}
else
{
// Show the Dashboard
DashboardWindow dashboard = new DashboardWindow();
dashboard.Show(); // Open the Dashboard Window
this.Close(); // Close the Login Window
}
}
else
{
// Invalid credentials
MessageBox.Show("Invalid username or password.", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
catch (Exception ex)
{
// Handle any unexpected errors
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
// Hide the preloader overlay
PreloaderOverlay.Visibility = Visibility.Collapsed;
}
}
private bool ValidateCredentials(string username, string password)
{
// Replace with actual validation logic (e.g., call to a database or API)
return username == "admin" && password == "admin";
}
}
}