3 Schichten Model

3 Schichten Model umgesetzt
This commit is contained in:
BlackViron
2024-07-01 16:21:03 +02:00
parent fe3e428f31
commit 068ba16156
16 changed files with 372 additions and 304 deletions

View File

@@ -0,0 +1,139 @@
<Window x:Class="bib_talk.Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Login"
Height="380"
Width="600"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="InvisibleButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="NoHoverButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HoverUnderlineTextBlockStyle" TargetType="TextBlock">
<Setter Property="TextDecorations" Value="None"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=Button}}" Value="True">
<Setter Property="TextDecorations" Value="Underline"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Border CornerRadius="15" BorderThickness="20" BorderBrush="#FF282828">
<Grid Margin="-10,-10,-10,-10" Background="#FF282828">
<!-- Draggable Area -->
<Image HorizontalAlignment="Left" Height="450" Margin="237,-162,0,0" VerticalAlignment="Top" Width="591" Source="/logo.png"/>
<Grid VerticalAlignment="Top" Height="45" Background="Transparent" MouseLeftButtonDown="DraggableArea_MouseLeftButtonDown" Margin="0,-21,0,0">
</Grid>
<!-- Close Button -->
<Button Style="{StaticResource InvisibleButtonStyle}"
Width="30"
Height="30"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,0,0,0"
Click="CloseButton_Click">
<TextBlock Text="❌"
FontSize="20"
Foreground="White"
FontWeight="Bold"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Button>
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Left" Margin="23,29,0,0" Height="324">
<TextBlock Text="Willkommen zurück!"
FontSize="24"
Foreground="White"
HorizontalAlignment="Center"/>
<!-- Email TextBox -->
<TextBlock Text="Benutzername"
Foreground="White"
FontSize="16"
Margin="0,40,0,-30"/>
<TextBox Width="300"
x:Name="usernbox"
Height="30"
FontSize="20"
BorderBrush="Transparent"
Margin="0,30,0,0"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<!-- Benutzername TextBox -->
<TextBlock Text="Passwort"
Foreground="White"
FontSize="16"
Margin="0,20,0,-30"/>
<PasswordBox Width="300"
x:Name="passwordbox"
PasswordChanged="passwordbox_PasswordChanged"
Height="30"
FontSize="20"
BorderBrush="Transparent"
Margin="0,30,0,0"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<Button x:Name="weiterbutton" Content="Weiter" Foreground="Gray" Background="#FF323134" BorderThickness="0" Margin="0,30,0,0" Height="30" BorderBrush="{x:Null}" Click="WeiterButton_Click" Style="{StaticResource NoHoverButtonStyle}"/>
<TextBlock Text="Noch keinen Account?"
Foreground="White"
FontSize="12"
Width="136"
Margin="20,20,0,0"/>
<Button Style="{StaticResource InvisibleButtonStyle}" Click="Register_Click">
<TextBlock Text="Registrieren"
Foreground="#FF6332A0"
FontSize="12"
Width="66"
Margin="8,5,0,0"
Style="{StaticResource HoverUnderlineTextBlockStyle}"/>
</Button>
</StackPanel>
</Grid>
</Border>
</Window>

View File

@@ -0,0 +1,80 @@
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows;
using bib_talk.Repository;
namespace bib_talk
{
public partial class Login : Window
{
LoginDatabase loginDatabase;
// Field to store logged in user
public static string loggedInUser;
public Login()
{
InitializeComponent();
loginDatabase = new LoginDatabase(this);
}
private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
DragMove();
}
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
RegisterWindow register = new RegisterWindow();
register.Show();
this.Close();
}
private async void WeiterButton_Click(object sender, RoutedEventArgs e)
{
if (usernbox.Text != "" && passwordbox.Password != "")
{
await loginDatabase.LoginServer();
}
}
private void passwordbox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (usernbox.Text != "" && passwordbox.Password != "")
{
SolidColorBrush customBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF6332A0"));
weiterbutton.Foreground = Brushes.White;
weiterbutton.Background = customBrush;
}
else
{
SolidColorBrush customBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF323134"));
weiterbutton.Foreground = Brushes.Gray;
weiterbutton.Background = customBrush;
}
}
private void Register_Click(object sender, RoutedEventArgs e)
{
RegisterWindow register = new RegisterWindow();
register.Show();
this.Close();
}
}
}

View File

@@ -0,0 +1,184 @@
<Window x:Class="bib_talk.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow"
Height="700"
Width="1000"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Window.Resources>
<Style x:Key="InvisibleButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="NoHoverButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Border CornerRadius="15" BorderThickness="20" BorderBrush="#FF282828">
<Grid Margin="-10,-10,-10,-10" Background="#FF282828">
<Grid.RowDefinitions>
<RowDefinition Height="289*"/>
<RowDefinition Height="392*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="747*"/>
<ColumnDefinition Width="118*"/>
<ColumnDefinition Width="115*"/>
</Grid.ColumnDefinitions>
<!-- Draggable Area -->
<Grid VerticalAlignment="Top" Height="45" Background="Transparent" MouseLeftButtonDown="DraggableArea_MouseLeftButtonDown" Margin="0,-21,0,0" Grid.ColumnSpan="3">
</Grid>
<Rectangle HorizontalAlignment="Left" Height="22" Margin="0,-5,0,0" Stroke="Black" Fill="Black" VerticalAlignment="Top" Width="980" Grid.ColumnSpan="3"/>
<!-- Close Button -->
<Button Style="{StaticResource InvisibleButtonStyle}"
Width="21"
Height="22"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Click="CloseButton_Click" Grid.Column="2" RenderTransformOrigin="0.057,0.564" Margin="0,-5,0,0">
<TextBlock Text="❌"
FontSize="15"
Foreground="White"
FontWeight="Bold"
HorizontalAlignment="Center"
VerticalAlignment="Top"/>
</Button>
<Grid Margin="298,17,0,176" Grid.ColumnSpan="3">
<Popup x:Name="popup" Placement="Center" IsOpen="False" LostFocus="Popup_LostFocus">
<StackPanel Background="White" Orientation="Vertical" Width="200" Height="150" Margin="10">
<Button Content="Button 1" Click="Button1_Click" Margin="5"/>
<Button Content="Button 2" Click="Button2_Click" Margin="5"/>
<Button Content="Button 3" Click="Button3_Click" Margin="5"/>
</StackPanel>
</Popup>
<Rectangle Stroke="#FF6332A0" Fill="#FF6332A0" Width="682"/>
<TextBlock Text="Name" Margin="108,18,134,18" FontSize="40" Foreground="White" />
<Image Source="/PICA.jpg" Width="80" Height="80" Stretch="Fill" Margin="10,8,592,7">
<Image.Clip>
<EllipseGeometry Center="40,40" RadiusX="40" RadiusY="40"/>
</Image.Clip>
</Image>
<Button Content="⋮" HorizontalAlignment="Left" Margin="638,8,0,0" VerticalAlignment="Top" Width="19" Height="70" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="White" FontSize="58" Click="ChatFenster_Click"/>
</Grid>
<Grid Margin="76,17,454,176">
<Rectangle Stroke="#FF282828" Fill="#FF282828"/>
<TextBlock Text="Chats" Foreground="White" FontSize="22" Margin="10,18,134,39" />
<TextBox
FontSize="20"
BorderBrush="Transparent"
Margin="10,61,10,10"
Background="#FF6332A0"
Foreground="White"
SelectionBrush="#FF6332A0" KeyDown="messageBOX_KeyDown" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="-1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
</Grid>
<Grid Margin="0,17,676,0" Grid.RowSpan="2">
<Rectangle Stroke="#FF323134" Fill="#FF323134"/>
</Grid>
<ListBox x:Name="onlineUsersListBox" Margin="76,112,454,0" d:ItemsSource="{d:SampleData ItemCount=5}" Background="#FF323134" BorderBrush="{x:Null}" SelectionChanged="onlineUsersListBox_SelectionChanged" Grid.RowSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="205" Height="60">
<Ellipse Width="10" Height="10" Fill="Green" Margin="5"/>
<Image Source="/PICA.jpg" Width="50" Height="50" Stretch="Fill">
<Image.Clip>
<EllipseGeometry Center="25,25" RadiusX="25" RadiusY="25"/>
</Image.Clip>
</Image>
<TextBlock Text="{Binding Username}" FontWeight="Bold" Foreground="#FF6332A0" RenderTransformOrigin="0.51,0.532" FontSize="18" Width="123" Height="30" Margin="10,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock HorizontalAlignment="Left" x:Name="loggedinuser" Margin="247,113,0,0" TextWrapping="Wrap" Text="xxxx" VerticalAlignment="Top" Height="84" Width="46" Foreground="White" RenderTransformOrigin="0.6,0.591"/>
<ListBox x:Name="chatlistbox" Margin="298,112,0,50" d:ItemsSource="{d:SampleData ItemCount=5}" Background="#FF323134" BorderBrush="{x:Null}" Foreground="#FF6332A0" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Grid.ColumnSpan="3" Grid.RowSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<TextBlock Text="{Binding Username}" FontWeight="Bold" FontSize="20"/>
<TextBlock Text="{Binding Timestamp, StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}" Foreground="Gray"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Text}" FontSize="16"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox
x:Name="messageBOX"
FontSize="20"
BorderBrush="Transparent"
Margin="298,346,76,0"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0" KeyDown="messageBOX_KeyDown" Grid.ColumnSpan="3" Grid.Row="1"/>
<Button x:Name="weiterbutton" Click="send_Click" Content="Weiter" Foreground="White" Background="#FF6332A0" BorderThickness="0" Margin="44,346,10,10" BorderBrush="{x:Null}" Style="{StaticResource NoHoverButtonStyle}" RenderTransformOrigin="0.279,0.633" Grid.Column="2" Grid.Row="1"/>
</Grid>
</Border>
</Window>

View File

@@ -0,0 +1,157 @@
using bib_talk.Repository;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
namespace bib_talk
{
public partial class MainWindow : Window
{
MainWindowDatabase database;
private DispatcherTimer _timer;
public string loggedinUser;
private bool isFirstLoad = true;
public MainWindow()
{
InitializeComponent();
InitializeTimer();
LoadData();
database = new MainWindowDatabase(this);
}
public MainWindow(string user)
{
loggedinUser = user;
InitializeComponent();
InitializeTimer();
LoadData();
database = new MainWindowDatabase(this);
database.LoadMessages();
}
private void InitializeTimer()
{
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(2)
};
_timer.Tick += (sender, e) => { database.LoadMessages(); database.LoadOnlineUsers(); };
_timer.Start();
}
public void LoadData()
{
loggedinuser.Text = "Logged in as: " + loggedinUser;
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
database.LogoutUser();
this.Close();
}
private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
DragMove();
}
}
private async void messageBOX_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
database.SendMessage();
}
}
private async void send_Click(object sender, RoutedEventArgs e)
{
database.SendMessage();
}
private void ChatFenster_Click(object sender, RoutedEventArgs e)
{
if (popup.IsOpen = true)
{
popup.Focus();
}
else
{
popup.IsOpen = true;
}
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button 1 wurde geklickt!");
ClosePopup();
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button 2 wurde geklickt!");
ClosePopup();
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button 3 wurde geklickt!");
ClosePopup();
}
private void Popup_LostFocus(object sender, RoutedEventArgs e)
{
ClosePopup();
}
private void ClosePopup()
{
popup.IsOpen = false;
}
private void onlineUsersListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
public class Message
{
public int Id { get; set; }
public string Username { get; set; }
public string Text { get; set; }
public DateTime Timestamp { get; set; }
}
public class MessageDto
{
public string Username { get; set; }
public string Message { get; set; }
public DateTime Timestamp { get; set; }
}
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string Birthday { get; set; }
public string IsOnline { get; set; }
}
}

View File

@@ -0,0 +1,234 @@
<Window x:Class="bib_talk.RegisterWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Register"
Height="530"
Width="400"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="InvisibleButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="CustomCheckBoxStyle" TargetType="CheckBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<Grid>
<Ellipse x:Name="OuterEllipse"
Width="20"
Height="20"
Fill="#FF323134"
Margin="0,0,10,0"
StrokeThickness="1"/>
<Ellipse x:Name="InnerEllipse"
Width="14"
Height="14"
Fill="#FF323134"
StrokeThickness="0"
Margin="3,8,13,7"/>
<Path x:Name="CheckMark"
Stroke="#FF6332A0"
StrokeThickness="2"
Data="M 3,8 L 7,12 L 14,5"
Visibility="Visible" Stretch="Fill" Margin="3,10,13,9" RenderTransformOrigin="0.967,1.39"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="NoHoverButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HoverUnderlineTextBlockStyle" TargetType="TextBlock">
<Setter Property="TextDecorations" Value="None"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=Button}}" Value="True">
<Setter Property="TextDecorations" Value="Underline"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="Hyperlink">
<EventSetter Event="RequestNavigate" Handler="Hyperlink_RequestNavigate"/>
</Style>
</Window.Resources>
<Border CornerRadius="15" BorderThickness="20" BorderBrush="#FF282828">
<Grid Margin="-10,-10,-10,-10" Background="#FF282828">
<!-- Draggable Area -->
<Grid VerticalAlignment="Top" Height="40" Background="Transparent" MouseLeftButtonDown="DraggableArea_MouseLeftButtonDown">
</Grid>
<!-- Close Button -->
<Button Style="{StaticResource InvisibleButtonStyle}"
Width="30"
Height="30"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,0,0,0"
Click="CloseButton_Click">
<TextBlock Text="❌"
FontSize="20"
Foreground="White"
FontWeight="Bold"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Button>
<!-- Centered Content -->
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,40,0,0" Height="473">
<!-- Account erstellen Text -->
<TextBlock Text="Account erstellen"
FontSize="24"
Foreground="White"
HorizontalAlignment="Center"/>
<!-- Email TextBox -->
<TextBlock Text="E-Mail"
Foreground="White"
FontSize="16"
Margin="0,40,0,-30"/>
<TextBox Width="300"
Height="30"
FontSize="20"
x:Name="emailbox"
BorderBrush="Transparent"
Margin="0,30,0,0"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<!-- Benutzername TextBox -->
<TextBlock Text="Benutzername"
Foreground="White"
FontSize="16"
Margin="0,20,0,-30"/>
<TextBox Width="300"
Height="30"
FontSize="20"
x:Name="usernbox"
BorderBrush="Transparent"
Margin="0,30,0,0"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<!-- Passwort PasswordBox -->
<TextBlock Text="Passwort"
FontSize="16"
Foreground="White"
Margin="0,20,0,-30"/>
<PasswordBox Width="300"
Height="30"
FontSize="20"
x:Name="passwordbox"
BorderBrush="Transparent"
Margin="0,30,0,0"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<!-- Geburtsdatum Text -->
<TextBlock Text="Geburtsdatum"
Foreground="White"
FontSize="16"
Margin="0,20,0,-30"/>
<StackPanel Orientation="Horizontal" Margin="0,30,0,0">
<TextBox Width="100"
Height="30"
FontSize="20"
x:Name="bday1"
BorderBrush="Transparent"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<TextBox Width="100"
Height="30"
FontSize="20"
x:Name="bday2"
BorderBrush="Transparent"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
<TextBox Width="100"
Height="30"
FontSize="20"
x:Name="bday3"
BorderBrush="Transparent"
Background="#FF323134"
Foreground="White"
SelectionBrush="#FF6332A0"/>
</StackPanel>
<!-- Checkbox -->
<Grid Margin="0,20,0,0" Height="30.1" Width="250">
<CheckBox x:Name="checkboxAGB" Style="{StaticResource CustomCheckBoxStyle}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Margin="-25,0,235,0"/>
<TextBlock FontSize="9" TextWrapping="Wrap" VerticalAlignment="Center" Height="24" Margin="15,0,-28,0">
<Run Text="Ich habe die " Foreground="White"/>
<Run x:Name="nutzungsbedingungenRun" Text="Nutzungsbedingungen" Foreground="#FF6332A0"/>
<Run Text=" und die " Foreground="White"/>
<Run x:Name="datenschutzRun" Text="Datenschutzerklärung" Foreground="#FF6332A0"/>
<Run Text=" von bib-talk gelesen und akzeptiert." Foreground="White"/>
</TextBlock>
</Grid>
<Button x:Name="weiterbutton" Content="Weiter" Foreground="Gray" Background="#FF323134" BorderThickness="0" Margin="0,20,0,0" Height="30" BorderBrush="{x:Null}" Click="WeiterButton_Click" Style="{StaticResource NoHoverButtonStyle}"/>
<Button Style="{StaticResource InvisibleButtonStyle}" Click="Login_Click">
<TextBlock Text="Ich habe bereits einen Account"
Foreground="#FF6332A0"
FontSize="12"
Width="167"
Margin="-130,5,0,0"
Style="{StaticResource HoverUnderlineTextBlockStyle}"/>
</Button>
</StackPanel>
</Grid>
</Border>
</Window>

View File

@@ -0,0 +1,133 @@
using bib_talk.Repository;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
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;
namespace bib_talk
{
public partial class RegisterWindow : Window
{
public RegisterWindow()
{
InitializeComponent();
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
e.Handled = true;
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
DragMove();
}
}
private void Login_Click(object sender, RoutedEventArgs e)
{
Login login = new Login();
login.Show();
this.Close();
}
private async void WeiterButton_Click(object sender, RoutedEventArgs e)
{
if (checkboxAGB.IsChecked == true)
{
if (ValidateRegistration())
{
RegisterDatabase registerDatabase = new RegisterDatabase(this);
await registerDatabase.RegisterServer();
Login login = new Login();
login.Show();
this.Close();
}
}
else
{
MessageBox.Show("Bitte akzeptieren Sie die AGB.");
}
}
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
SolidColorBrush customBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF6332A0"));
weiterbutton.Foreground = Brushes.White;
weiterbutton.Background = customBrush;
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
SolidColorBrush customBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF323134"));
weiterbutton.Foreground = Brushes.Gray;
weiterbutton.Background = customBrush;
}
private bool ValidateRegistration()
{
string username = usernbox.Text;
string password = passwordbox.Password;
string email = emailbox.Text;
string day = bday1.Text;
string month = bday2.Text;
string year = bday3.Text;
// Benutzername validieren
if (string.IsNullOrWhiteSpace(username) || username.Length < 3)
{
MessageBox.Show("Der Benutzername muss mindestens 3 Zeichen lang sein.");
return false;
}
// Passwort validieren
if (string.IsNullOrWhiteSpace(password) || password.Length < 6 || !Regex.IsMatch(password, @"^(?=.*[A-Za-z])(?=.*\d).{6,}$"))
{
MessageBox.Show("Das Passwort muss mindestens 6 Zeichen lang sein und sowohl Buchstaben als auch Zahlen enthalten.");
return false;
}
// E-Mail validieren
if (string.IsNullOrWhiteSpace(email) || !Regex.IsMatch(email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
{
MessageBox.Show("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
return false;
}
// Geburtsdatum validieren
if (!int.TryParse(day, out int dayInt) || !int.TryParse(month, out int monthInt) || !int.TryParse(year, out int yearInt) ||
!DateTime.TryParse($"{yearInt}-{monthInt}-{dayInt}", out DateTime birthDate) || birthDate > DateTime.Now.AddYears(-14))
{
MessageBox.Show("Bitte geben Sie ein gültiges Geburtsdatum ein. Sie müssen mindestens 18 Jahre alt sein.");
return false;
}
return true;
}
}
}