This commit is contained in:
2023-02-04 23:57:38 +01:00
commit 33d2ae1b84
14 changed files with 500 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
WGneu/obj/
WGneu/bin/

25
WGneu.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WGneu", "WGneu\WGneu.csproj", "{00868460-16F6-4B48-AA9B-998F6263693B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00868460-16F6-4B48-AA9B-998F6263693B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00868460-16F6-4B48-AA9B-998F6263693B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00868460-16F6-4B48-AA9B-998F6263693B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00868460-16F6-4B48-AA9B-998F6263693B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D8CCFDDD-517C-4462-BDDD-C69B3364A4FB}
EndGlobalSection
EndGlobal

9
WGneu/App.xaml Normal file
View File

@ -0,0 +1,9 @@
<Application x:Class="WGneu.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WGneu"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

17
WGneu/App.xaml.cs Normal file
View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WGneu
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

10
WGneu/AssemblyInfo.cs Normal file
View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,38 @@
<Window x:Class="WGneu.BankDetailsWindow"
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"
xmlns:local="clr-namespace:WGneu"
mc:Ignorable="d"
Title="Bankverbindung" Height="295" Width="440" ResizeMode="NoResize" MinWidth="440" MinHeight="295">
<Grid>
<GroupBox Header="IBAN" Margin="10,10,10,0" Height="60" VerticalAlignment="Top">
<Grid>
<TextBox x:Name="Iban" HorizontalAlignment="Left" Margin="105,0,-0.6,0" TextWrapping="NoWrap" Width="280" VerticalAlignment="Center" TextChanged="Iban_TextChanged" LostFocus="Iban_LostFocus"/>
<TextBlock HorizontalAlignment="Left" Margin="5,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center" Width="90"><Run Language="de-de" Text="IBAN:"/></TextBlock>
</Grid>
</GroupBox>
<GroupBox Header="Bank/Kontonummer" Margin="10,80,10,0" Height="135" VerticalAlignment="Top">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<ComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Width="280" Height="22" Margin="5,-0.3,0,0" Grid.Column="2"/>
<TextBox x:Name="BankCode" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Width="80" TextChanged="BankCode_TextChanged" Height="18" Grid.Column="2" Grid.Row="1" Margin="5,0,0,0"/>
<TextBox x:Name="AccountNumber" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Width="280" Height="18" Grid.Column="1" Grid.Row="2" Margin="5,0,0,0" TextChanged="AccountNumber_TextChanged"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Land:" VerticalAlignment="Center" Height="16" Width="90" Margin="5,0,0,0"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Bank:" VerticalAlignment="Center" Height="16" Width="90" Grid.Row="1" Margin="5,0,0,0" Grid.RowSpan="1"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Kontonummer:" VerticalAlignment="Center" Grid.Row="2" Margin="5,0,0,0"/>
<ComboBox Margin="92,0,0,0" VerticalAlignment="Center" Height="22" HorizontalAlignment="Left" Width="193" Grid.Column="2" Grid.Row="1"/>
</Grid>
</GroupBox>
<Button Content="Übernehmen" HorizontalAlignment="Right" Margin="0,0,20,10" VerticalAlignment="Bottom" Padding="5,1,5,1"/>
</Grid>
</Window>

View File

@ -0,0 +1,171 @@
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.Shapes;
namespace WGneu
{
/// <summary>
/// Interaktionslogik für BankDetailsWindow.xaml
/// </summary>
public partial class BankDetailsWindow : Window
{
public BankDetailsWindow()
{
InitializeComponent();
}
private void Iban_TextChanged(object sender, TextChangedEventArgs e)
{
string iban = "";
int pos = Iban.CaretIndex;
for (int i = 0, v = 0; i < Iban.Text.Length && v < 34; i++)
{
char ch = Iban.Text[i];
if (Char.IsLetterOrDigit(ch) && Char.IsAscii(ch))
{
if (v != 0 && v % 4 == 0)
iban += ' ';
v++;
iban += Char.ToUpper(ch);
}
if (i == Iban.CaretIndex - 1)
pos = iban.Length;
if (iban.StartsWith("AT") && v >= 20)
break;
}
Iban.Text = iban;
Iban.CaretIndex = pos;
if (Iban.IsFocused)
GenerateBankDetails();
}
private void Iban_LostFocus(object sender, EventArgs e)
{
// TODO vaildate checksum
}
private void BankCode_TextChanged(object sender, TextChangedEventArgs e)
{
string cc = "AT";
string code = "";
int pos = BankCode.CaretIndex;
if (cc == "AT")
{
for (int i = 0, v = 0; i < BankCode.Text.Length && v < 5; i++)
{
char ch = BankCode.Text[i];
if (Char.IsDigit(ch))
{
v++;
code += ch;
}
if (i == BankCode.CaretIndex - 1)
pos = code.Length;
}
}
BankCode.Text = code;
BankCode.CaretIndex = pos;
if (BankCode.IsFocused)
GenerateIban();
}
private void AccountNumber_TextChanged(object sender, TextChangedEventArgs e)
{
string cc = "AT";
string num = "";
int pos = AccountNumber.CaretIndex;
if (cc == "AT")
{
for (int i = 0, v = 0; i < AccountNumber.Text.Length && v < 11; i++)
{
char ch = AccountNumber.Text[i];
if (Char.IsLetterOrDigit(ch) && Char.IsAscii(ch))
{
v++;
num += ch;
}
if (i == AccountNumber.CaretIndex - 1)
pos = num.Length;
}
}
AccountNumber.Text = num;
AccountNumber.CaretIndex = pos;
if (AccountNumber.IsFocused)
GenerateIban();
}
private void GenerateIban()
{
string cc = "AT";
string iban = cc + "00";
if (cc == "AT")
{
iban += BankCode.Text.PadLeft(5, '0') + AccountNumber.Text.PadLeft(11, '0');
}
// TODO calculate checksum
Iban.Text = iban;
Iban.CaretIndex = iban.Length;
}
private void GenerateBankDetails()
{
BankCode.Text = "";
AccountNumber.Text = "";
string iban = Iban.Text.Replace(" ", "");
if (iban.Length <= 2)
return;
string cc = iban.Substring(0, 2);
if (cc == "AT")
{
if (iban.Length > 4)
{
string bankCodeStr = iban.Substring(4, Math.Min(5, iban.Length - 4));
if (bankCodeStr.All(Char.IsDigit))
{
int bankCode = int.Parse(bankCodeStr);
BankCode.Text = bankCode.ToString();
}
if (iban.Length > 9)
{
string accNumStr = iban.Substring(9, Math.Min(11, iban.Length - 9));
if (accNumStr.All(Char.IsDigit))
{
int accNum = int.Parse(accNumStr);
AccountNumber.Text = (accNum != 0) ? accNum.ToString() : "";
}
else
{
AccountNumber.Text = accNumStr;
}
}
}
}
BankCode.CaretIndex = BankCode.Text.Length;
AccountNumber.CaretIndex = AccountNumber.Text.Length;
}
}
}

25
WGneu/Country.cs Normal file
View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu
{
[Table("country"), PrimaryKey("Alpha2")]
public class Country
{
[Column("alpha2")]
public String Alpha2 { get; set; }
[Column("alpha3")]
public String Alpha3 { get; set; }
[Column("num")]
public int Num { get; set; }
[Column("name")]
public String Name { get; set; }
[Column("is_visible")]
public int IsVisible {get; set; }
}
}

63
WGneu/Gradation.cs Normal file
View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu
{
// 1 °KMW =
// 1 °NM = kg/100L = 10g/L
// 1 °Oe =
// 1 °Bé =
// 1 °Bx = g/100g (x Gramm Zucker pro 100 Gramm Flüssigkeit)
internal class Gradation
{
/// <summary>
/// Gradation in mg/L.
/// </summary>
uint mgpl;
public Gradation(uint mgpl)
{
this.mgpl = mgpl;
}
public static double relativeDensity(double todo)
{
return 0;
}
public static double KmwToOe(double kmw)
{
return 0; // TODO
}
public static double OeToKmw(double oe)
{
return 0; // TODO
}
public static Gradation FromKmw(double kwm)
{
return new Gradation(0); // TODO
}
public static Gradation FromKmw(double kmw, double t)
{
// The temperature can be ignored, because no volumetric unit is involved.
// 1 °KMW = 1g/100g
return FromKmw(kmw);
}
public static Gradation FromOe(double oe)
{
return new Gradation(0); // TODO
}
public static Gradation FromOe(double oe, double t)
{
return null;
}
}
}

22
WGneu/MainWindow.xaml Normal file
View File

@ -0,0 +1,22 @@
<Window x:Class="WGneu.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"
xmlns:local="clr-namespace:WGneu"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" ResizeMode="CanResize" SizeToContent="Manual"
Loaded="Window_Loaded">
<Window.Resources>
<CollectionViewSource x:Key="countryViewSource"/>
<DataTemplate x:Key="asdf">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<Button x:Name="Button1" Content="Bankverbindung" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button1_Click"/>
<ComboBox HorizontalAlignment="Left" Margin="175,149,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Source={StaticResource countryViewSource}}" ItemTemplate="{StaticResource asdf}" SelectionChanged="ComboBox_SelectionChanged" IsEditable="True"/>
</Grid>
</Window>

62
WGneu/MainWindow.xaml.cs Normal file
View File

@ -0,0 +1,62 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Intrinsics.X86;
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;
namespace WGneu
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly WGContext _context = new WGContext();
private CollectionViewSource countryViewSource;
public MainWindow()
{
InitializeComponent();
countryViewSource = (CollectionViewSource)FindResource("countryViewSource");
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_context.Countries.Load();
countryViewSource.Source = _context.Countries.Local.ToObservableCollection();
}
protected override void OnClosing(CancelEventArgs e)
{
_context.Dispose();
base.OnClosing(e);
}
private void Button1_Click(object sender, EventArgs e)
{
BankDetailsWindow w = new BankDetailsWindow();
w.Show();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}

19
WGneu/WGContext.cs Normal file
View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu
{
public class WGContext : DbContext
{
public DbSet<Country> Countries { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=\"C:\\Users\\Lorenz\\Desktop\\wgtest.sqlite3\"");
optionsBuilder.UseLazyLoadingProxies();
}
}
}

15
WGneu/WGneu.csproj Normal file
View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" />
</ItemGroup>
</Project>

22
WGneu/WGneu.csproj.user Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<ApplicationDefinition Update="App.xaml">
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Compile Update="BankDetailsWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="BankDetailsWindow.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="MainWindow.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>