Admin view hinzugefügt
This commit is contained in:
+117
-1
@@ -5,6 +5,7 @@ using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Casino
|
||||
@@ -40,7 +41,8 @@ namespace Casino
|
||||
Name = myReader.GetString("name"),
|
||||
Alter = myReader.GetInt32("age"),
|
||||
Passwort = myReader.GetString("passwort"),
|
||||
Geld = myReader.GetDecimal("geld")
|
||||
Geld = myReader.GetDecimal("geld"),
|
||||
Rolle = myReader.GetString("Rolle")
|
||||
};
|
||||
|
||||
user.Add(u);
|
||||
@@ -200,5 +202,119 @@ namespace Casino
|
||||
}
|
||||
}
|
||||
|
||||
public bool SelectAdmin(string userId)
|
||||
{
|
||||
using MySqlConnection connection = new MySqlConnection(myConnectionString);
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string sql = @"
|
||||
SELECT COUNT(*)
|
||||
FROM Nutzer
|
||||
WHERE id = @id
|
||||
AND Rolle = 'Admin'";
|
||||
|
||||
using MySqlCommand command = new MySqlCommand(sql, connection);
|
||||
|
||||
command.Parameters.AddWithValue("@id", userId);
|
||||
|
||||
int count = Convert.ToInt32(command.ExecuteScalar());
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler bei der Admin-Abfrage:\n" + ex.Message,
|
||||
"Datenbankfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DeleteUser(string userId)
|
||||
{
|
||||
using MySqlConnection connection = new MySqlConnection(myConnectionString);
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string sql = @"
|
||||
DELETE FROM Nutzer
|
||||
WHERE id = @id";
|
||||
|
||||
using MySqlCommand command = new MySqlCommand(sql, connection);
|
||||
|
||||
command.Parameters.AddWithValue("@id", userId);
|
||||
|
||||
int affectedRows = command.ExecuteNonQuery();
|
||||
|
||||
return affectedRows > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler beim Löschen des Benutzers:\n" + ex.Message,
|
||||
"Datenbankfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateUser(
|
||||
string userId,
|
||||
string name,
|
||||
int age,
|
||||
string passwort,
|
||||
decimal geld,
|
||||
string rolle)
|
||||
{
|
||||
using MySqlConnection connection = new MySqlConnection(myConnectionString);
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string sql = @"
|
||||
UPDATE Nutzer
|
||||
SET name = @name,
|
||||
age = @age,
|
||||
passwort = @passwort,
|
||||
geld = @geld,
|
||||
Rolle = @rolle
|
||||
WHERE id = @id";
|
||||
|
||||
using MySqlCommand command = new MySqlCommand(sql, connection);
|
||||
|
||||
command.Parameters.AddWithValue("@name", name);
|
||||
command.Parameters.AddWithValue("@age", age);
|
||||
command.Parameters.AddWithValue("@passwort", passwort);
|
||||
command.Parameters.AddWithValue("@geld", geld);
|
||||
command.Parameters.AddWithValue("@rolle", rolle);
|
||||
command.Parameters.AddWithValue("@id", userId);
|
||||
|
||||
int affectedRows = command.ExecuteNonQuery();
|
||||
|
||||
return affectedRows > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler beim Aktualisieren des Benutzers:\n" + ex.Message,
|
||||
"Datenbankfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user