diff --git a/PrototypWPFHAG/MainWindow.xaml b/PrototypWPFHAG/MainWindow.xaml
index d20a05a..8e57ed9 100644
--- a/PrototypWPFHAG/MainWindow.xaml
+++ b/PrototypWPFHAG/MainWindow.xaml
@@ -1,23 +1,32 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PrototypWPFHAG/MainWindow.xaml.cs b/PrototypWPFHAG/MainWindow.xaml.cs
index 233ae88..020e7b2 100644
--- a/PrototypWPFHAG/MainWindow.xaml.cs
+++ b/PrototypWPFHAG/MainWindow.xaml.cs
@@ -23,10 +23,49 @@ public partial class MainWindow : MetroWindow
public MainWindow()
{
InitializeComponent();
+ // TestConnection();
+ // Console.ReadKey();
- TestConnection();
- Console.ReadKey();
+ }
+ private void loginButton_Click(object sender, RoutedEventArgs e)
+ {
+ // 从用户输入中获取用户名和密码
+ string username = UsernameTextBox.Text; // 获取用户名
+ string password = PasswordTextBox.Password; // 获取密码
+
+ // 调用 ValidateUser 方法验证用户凭据
+ if (ValidateUser(username, password))
+ {
+ MessageBox.Show("ok", "Login Successful", MessageBoxButton.OK, MessageBoxImage.Error);
+
+ }
+ else
+ {
+ // 如果验证失败,显示错误信息
+ MessageBox.Show("Invalid username or password.", "Login Failed", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+
+ private bool ValidateUser(string username, string password)
+ {
+ // 获取数据库连接
+ using (var con = GetConnection())
+ {
+ con.Open(); // 打开数据库连接
+ string query = "SELECT COUNT(*) FROM USER WHERE UserName = @username AND Password = @password;";
+
+ using (var cmd = new NpgsqlCommand(query, con))
+ {
+ // 使用参数化查询防止 SQL 注入
+ cmd.Parameters.AddWithValue("@username", username);
+ cmd.Parameters.AddWithValue("@password", password);
+
+ // 执行查询并获取结果
+ int count = (int)cmd.ExecuteScalar();
+ return count > 0; // 如果匹配记录数量大于 0,返回 true
+ }
+ }
}
private static void TestConnection()
diff --git a/PrototypWPFHAG/app.config b/PrototypWPFHAG/app.config
deleted file mode 100644
index db7cf0e..0000000
--- a/PrototypWPFHAG/app.config
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-