Added ENI style login screen

This commit is contained in:
Daniel Schick 2023-07-13 09:43:08 +02:00
parent 5ca3c7a050
commit 504131c239
6 changed files with 147 additions and 6 deletions

View File

@ -4,6 +4,13 @@
xmlns:local="clr-namespace:BreCalClient" xmlns:local="clr-namespace:BreCalClient"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\StringResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>

View File

@ -7,4 +7,37 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Page Remove="Resources\StringResources.xaml" />
<Page Remove="StringResources.de.xaml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\misc\BreCalApi.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>BreCalApi.yaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\misc\BreCalApi.yaml" Link="BreCalApi.yaml">
<Generator>OpenApiCodeGenerator</Generator>
<LastGenOutput>BreCalApi.cs</LastGenOutput>
</None>
<Resource Include="Resources\StringResources.de.xaml">
<Generator>MSBuild:Compile</Generator>
</Resource>
<Resource Include="Resources\StringResources.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.0" />
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="RestSharp" Version="108.0.2" />
</ItemGroup>
</Project> </Project>

View File

@ -3,10 +3,42 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BreCalClient" xmlns:local="clr-namespace:BreCalClient"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="{DynamicResource textApplicationTitle}" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
</Grid> <xctk:BusyIndicator Name="busyIndicator" IsBusy="True">
<xctk:BusyIndicator.ProgressBarStyle>
<Style TargetType="ProgressBar">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</xctk:BusyIndicator.ProgressBarStyle>
<xctk:BusyIndicator.BusyContent>
<Grid Width="320">
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label Content="{DynamicResource textLoginCaption}" Grid.Row="0" Grid.ColumnSpan="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Label Content="{DynamicResource textUsername}" Grid.Row="1" VerticalContentAlignment="Center" />
<Label Content="{DynamicResource textPassword}" Grid.Row="2" VerticalContentAlignment="Center" />
<TextBox Name="textUsername" Grid.Row="1" Grid.Column="1" Margin="2" VerticalContentAlignment="Center" />
<PasswordBox Name="textPassword" Grid.Row="2" Grid.Column="1" Margin="2" VerticalContentAlignment="Center" PasswordChar="*"/>
<Label Name="labelLoginResult" Grid.Row="3" Grid.ColumnSpan="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Button Name="buttonLogin" Content="{DynamicResource textLogin}" Grid.Row="4" Grid.Column="0" Margin="2" Click="buttonLogin_Click" IsDefault="True" />
<Button Name="buttonExit" Content="{DynamicResource textExit}" Grid.Row="4" Grid.Column="1" Margin="2" Click="buttonExit_Click" />
</Grid>
</xctk:BusyIndicator.BusyContent>
<Grid>
</Grid>
</xctk:BusyIndicator>
</Window> </Window>

View File

@ -13,16 +13,64 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using BreCalClient.misc.Api;
using BreCalClient.misc.Client;
using BreCalClient.misc.Model;
namespace BreCalClient namespace BreCalClient
{ {
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
DefaultApi _api;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
_api = new DefaultApi();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private async void buttonLogin_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.textPassword.Password) || string.IsNullOrEmpty(this.textUsername.Text))
{
this.labelLoginResult.Content = Application.Current.FindResource("textUserNamePasswordEmpty").ToString();
return;
}
Credentials credentials = new(username: textUsername.Text.Trim(),
password: textPassword.Password.Trim());
try
{
LoginResult loginResult = await _api.LoginPostAsync(credentials);
if(loginResult != null)
{
if(loginResult.Id > 0)
{
this.busyIndicator.IsBusy = false;
}
}
}
catch (ApiException ex)
{
this.labelLoginResult.Content = ex.Message;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void buttonExit_Click(object sender, RoutedEventArgs e)
{
this.Close();
} }
} }
} }

View File

@ -0,0 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="textLoginCaption">Benutzer Anmeldung</system:String>
<system:String x:Key="textUsername">Benutzername</system:String>
<system:String x:Key="textPassword">Passwort</system:String>
<system:String x:Key="textLogin">Anmelden</system:String>
<system:String x:Key="textExit">Abbrechen</system:String>
<system:String x:Key="textUserNamePasswordEmpty">Benutzername / Password leer!</system:String>
</ResourceDictionary>

View File

@ -0,0 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="textLoginCaption">User login</system:String>
<system:String x:Key="textUsername">Username</system:String>
<system:String x:Key="textPassword">Password</system:String>
<system:String x:Key="textLogin">Login</system:String>
<system:String x:Key="textExit">Exit</system:String>
<system:String x:Key="textApplicationTitle">Bremen calling</system:String>
<system:String x:Key="textUserNamePasswordEmpty">Username and/or password empty!</system:String>
</ResourceDictionary>