BaseDataWindow: implement client data saving
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
using Elwig.Models;
|
using Elwig.Models;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Elwig.Helpers {
|
namespace Elwig.Helpers {
|
||||||
public class ClientParameters {
|
public class ClientParameters {
|
||||||
@ -24,8 +26,8 @@ namespace Elwig.Helpers {
|
|||||||
Ort = value.AtPlz.Ort.Name;
|
Ort = value.AtPlz.Ort.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int Plz { get; private set; }
|
public int Plz;
|
||||||
public string Ort { get; private set; }
|
public string Ort;
|
||||||
public string Address;
|
public string Address;
|
||||||
public string Sender1 => $"{NameShort} | {Address} | {Plz} {Ort}";
|
public string Sender1 => $"{NameShort} | {Address} | {Plz} {Ort}";
|
||||||
public string Sender2;
|
public string Sender2;
|
||||||
@ -73,7 +75,6 @@ namespace Elwig.Helpers {
|
|||||||
UstIdNr = parameters.GetValueOrDefault("CLIENT_USTIDNR");
|
UstIdNr = parameters.GetValueOrDefault("CLIENT_USTIDNR");
|
||||||
Bic = parameters.GetValueOrDefault("CLIENT_BIC");
|
Bic = parameters.GetValueOrDefault("CLIENT_BIC");
|
||||||
Iban = parameters.GetValueOrDefault("CLIENT_IBAN");
|
Iban = parameters.GetValueOrDefault("CLIENT_IBAN");
|
||||||
Sender2 = parameters.GetValueOrDefault("DOCUMENT_SENDER") ?? "";
|
|
||||||
|
|
||||||
DeliveryObligation = int.Parse(parameters["DELIVERY_OBLIGATION"] ?? "");
|
DeliveryObligation = int.Parse(parameters["DELIVERY_OBLIGATION"] ?? "");
|
||||||
DeliveryRight = int.Parse(parameters["DELIVERY_RIGHT"] ?? "");
|
DeliveryRight = int.Parse(parameters["DELIVERY_RIGHT"] ?? "");
|
||||||
@ -81,10 +82,58 @@ namespace Elwig.Helpers {
|
|||||||
VatReduced = decimal.Parse((parameters["VAT_REDUCED"] ?? "").Replace(".", ","));
|
VatReduced = decimal.Parse((parameters["VAT_REDUCED"] ?? "").Replace(".", ","));
|
||||||
VatFlatRate = decimal.Parse((parameters["VAT_FLATRATE"] ?? "").Replace(".", ","));
|
VatFlatRate = decimal.Parse((parameters["VAT_FLATRATE"] ?? "").Replace(".", ","));
|
||||||
|
|
||||||
TextDeliveryNote = parameters.GetValueOrDefault("TEXT_DELIVERY_NOTE");
|
Sender2 = parameters.GetValueOrDefault("DOCUMENT_SENDER") ?? "";
|
||||||
|
TextDeliveryNote = parameters.GetValueOrDefault("TEXT_DELIVERYNOTE");
|
||||||
} catch {
|
} catch {
|
||||||
throw new KeyNotFoundException();
|
throw new KeyNotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<(string, string?)> GetParamValues() {
|
||||||
|
return new (string, string?)[] {
|
||||||
|
("CLIENT_NAME_TOKEN", NameToken),
|
||||||
|
("CLIENT_NAME_SHORT", NameShort),
|
||||||
|
("CLIENT_NAME", Name),
|
||||||
|
("CLIENT_NAME_SUFFIX", NameSuffix),
|
||||||
|
("CLIENT_NAME_TYPE", NameType),
|
||||||
|
("CLIENT_PLZ", Plz.ToString()),
|
||||||
|
("CLIENT_ORT", Ort),
|
||||||
|
("CLIENT_ADDRESS", Address),
|
||||||
|
("CLIENT_PHONE", PhoneNr),
|
||||||
|
("CLIENT_FAX", FaxNr),
|
||||||
|
("CLIENT_EMAIL", EmailAddress),
|
||||||
|
("CLIENT_WEBSITE", Website),
|
||||||
|
("CLIENT_LFBISNR", LfbisNr),
|
||||||
|
("CLIENT_USTIDNR", UstIdNr),
|
||||||
|
("CLIENT_BIC", Bic),
|
||||||
|
("CLIENT_IBAN", Iban),
|
||||||
|
("DELIVERY_OBLIGATION", DeliveryObligation.ToString()),
|
||||||
|
("DELIVERY_RIGHT", DeliveryRight.ToString()),
|
||||||
|
("VAT_NORMAL", VatNormal.ToString().Replace(",", ".")),
|
||||||
|
("VAT_REDUCED", VatReduced.ToString().Replace(",", ".")),
|
||||||
|
("VAT_FLATRATE", VatFlatRate.ToString().Replace(",", ".")),
|
||||||
|
("DOCUMENT_SENDER", Sender2),
|
||||||
|
("TEXT_DELIVERYNOTE", TextDeliveryNote),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateValues() {
|
||||||
|
using var cnx = await AppDbContext.ConnectAsync();
|
||||||
|
using var cmd = cnx.CreateCommand();
|
||||||
|
var pv = GetParamValues();
|
||||||
|
cmd.CommandText = "INSERT INTO client_parameter (param, value) VALUES " +
|
||||||
|
string.Join(", ", pv.Select((pv, i) => $"(@p{i}, " + (pv.Item2 != null ? $"@v{i}" : "NULL") + ")")) +
|
||||||
|
" ON CONFLICT DO UPDATE SET value = excluded.value";
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var (p, v) in pv) {
|
||||||
|
cmd.Parameters.Add(new SqliteParameter($"@p{i}", p));
|
||||||
|
if (v != null)
|
||||||
|
cmd.Parameters.Add(new SqliteParameter($"@v{i}", v));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</Style>
|
</Style>
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
<Grid>
|
<Grid>
|
||||||
<TabControl Margin="10,10,10,50">
|
<TabControl Margin="10,10,10,42">
|
||||||
<TabItem Header="Mandant">
|
<TabItem Header="Mandant">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@ -71,13 +71,16 @@
|
|||||||
<Label Content="Kürzel/Kurzform:"
|
<Label Content="Kürzel/Kurzform:"
|
||||||
VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Margin="10,130,0,10"/>
|
VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Margin="10,130,0,10"/>
|
||||||
<TextBox x:Name="ClientNameTokenInput"
|
<TextBox x:Name="ClientNameTokenInput"
|
||||||
|
TextChanged="TextBox_TextChanged"
|
||||||
VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="1" Margin="0,130,10,10" Width="70"/>
|
VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="1" Margin="0,130,10,10" Width="70"/>
|
||||||
<TextBox x:Name="ClientNameShortInput"
|
<TextBox x:Name="ClientNameShortInput"
|
||||||
|
TextChanged="TextBox_TextChanged"
|
||||||
VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Margin="75,130,10,10"/>
|
VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Margin="75,130,10,10"/>
|
||||||
|
|
||||||
<Label Content="Adresse:"
|
<Label Content="Adresse:"
|
||||||
VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Margin="10,160,0,10"/>
|
VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="0" Margin="10,160,0,10"/>
|
||||||
<TextBox x:Name="ClientAddressInput"
|
<TextBox x:Name="ClientAddressInput"
|
||||||
|
TextChanged="TextBox_TextChanged"
|
||||||
VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Margin="0,160,10,10"/>
|
VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="1" Margin="0,160,10,10"/>
|
||||||
|
|
||||||
<Label Content="PLZ/Ort:"
|
<Label Content="PLZ/Ort:"
|
||||||
@ -85,7 +88,8 @@
|
|||||||
<TextBox x:Name="ClientPlzInput"
|
<TextBox x:Name="ClientPlzInput"
|
||||||
Margin="0,190,0,0" Width="42" Grid.Column="1" HorizontalAlignment="Left"
|
Margin="0,190,0,0" Width="42" Grid.Column="1" HorizontalAlignment="Left"
|
||||||
TextChanged="PlzInput_TextChanged" LostFocus="PlzInput_LostFocus"/>
|
TextChanged="PlzInput_TextChanged" LostFocus="PlzInput_LostFocus"/>
|
||||||
<TextBox x:Name="ClientOrtInput" Margin="47,190,10,0" Grid.Column="1"/>
|
<TextBox x:Name="ClientOrtInput" Margin="47,190,10,0" Grid.Column="1"
|
||||||
|
TextChanged="TextBox_TextChanged"/>
|
||||||
|
|
||||||
<Label Content="IBAN:" Margin="10,220,0,0" Grid.Column="0"/>
|
<Label Content="IBAN:" Margin="10,220,0,0" Grid.Column="0"/>
|
||||||
<TextBox x:Name="ClientIbanInput" Margin="0,220,10,0" Grid.Column="1"
|
<TextBox x:Name="ClientIbanInput" Margin="0,220,10,0" Grid.Column="1"
|
||||||
@ -153,5 +157,18 @@
|
|||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|
||||||
|
<Button x:Name="EditButton" Content="Bearbeiten"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,10" Width="120"
|
||||||
|
Click="EditButton_Click"/>
|
||||||
|
<Button x:Name="SaveButton" Content="Speichern" IsEnabled="False"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,250,10" Width="120"
|
||||||
|
Click="SaveButton_Click"/>
|
||||||
|
<Button x:Name="ResetButton" Content="Zurücksetzen" IsEnabled="False" Visibility="Hidden"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,10" Width="120"
|
||||||
|
Click="ResetButton_Click"/>
|
||||||
|
<Button x:Name="CancelButton" Content="Abbrechen" IsEnabled="False" IsCancel="True"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="250,0,0,10" Width="120"
|
||||||
|
Click="CancelButton_Click"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</local:AdministrationWindow>
|
</local:AdministrationWindow>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using Elwig.Helpers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
@ -5,34 +6,122 @@ namespace Elwig.Windows {
|
|||||||
public partial class BaseDataWindow : AdministrationWindow {
|
public partial class BaseDataWindow : AdministrationWindow {
|
||||||
public BaseDataWindow() {
|
public BaseDataWindow() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
RequiredInputs = new Control[] {
|
||||||
|
ClientNameInput, ClientNameTypeInput, ClientNameTokenInput, ClientNameShortInput,
|
||||||
|
ClientAddressInput, ClientPlzInput, ClientOrtInput,
|
||||||
|
};
|
||||||
|
ExemptInputs = new Control[] {
|
||||||
|
ClientNameFull,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||||
ClientNameInput.Text = App.Client.Name;
|
LockInputs();
|
||||||
ClientNameSuffixInput.Text = App.Client.NameSuffix;
|
FillInputs(App.Client);
|
||||||
ClientNameTypeInput.Text = App.Client.NameType;
|
|
||||||
ClientNameTokenInput.Text = App.Client.NameToken;
|
|
||||||
ClientNameShortInput.Text = App.Client.NameShort;
|
|
||||||
ClientAddressInput.Text = App.Client.Address;
|
|
||||||
ClientPlzInput.Text = App.Client.Plz.ToString();
|
|
||||||
ClientOrtInput.Text = App.Client.Ort;
|
|
||||||
ClientIbanInput.Text = App.Client.Iban;
|
|
||||||
ClientBicInput.Text = App.Client.Bic;
|
|
||||||
ClientUstIdNrInput.Text = App.Client.UstIdNr;
|
|
||||||
ClientLfbisNrInput.Text = App.Client.LfbisNr;
|
|
||||||
ClientPhoneNrInput.Text = App.Client.PhoneNr;
|
|
||||||
ClientFaxNrInput.Text = App.Client.FaxNr;
|
|
||||||
ClientEmailAddressInput.Text = App.Client.EmailAddress;
|
|
||||||
ClientWebsiteInput.Text = App.Client.Website;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateButtons() {
|
protected override void UpdateButtons() {
|
||||||
|
if (!IsEditing && !IsCreating) return;
|
||||||
|
bool ch = HasChanged, v = IsValid;
|
||||||
|
CancelButton.IsEnabled = true;
|
||||||
|
ResetButton.IsEnabled = ch;
|
||||||
|
SaveButton.IsEnabled = ch && v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EditButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
IsEditing = true;
|
||||||
|
EditButton.Visibility = Visibility.Hidden;
|
||||||
|
ResetButton.Visibility = Visibility.Visible;
|
||||||
|
|
||||||
|
UnlockInputs();
|
||||||
|
UpdateButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
IsEditing = false;
|
||||||
|
IsCreating = false;
|
||||||
|
EditButton.Visibility = Visibility.Visible;
|
||||||
|
ResetButton.Visibility = Visibility.Hidden;
|
||||||
|
CancelButton.IsEnabled = false;
|
||||||
|
SaveButton.IsEnabled = false;
|
||||||
|
ResetButton.IsEnabled = false;
|
||||||
|
|
||||||
|
ClearInputStates();
|
||||||
|
FillInputs(App.Client);
|
||||||
|
LockInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
ClearInputStates();
|
||||||
|
FillInputs(App.Client);
|
||||||
|
UpdateButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
UpdateClientParameters(App.Client);
|
||||||
|
|
||||||
|
IsEditing = false;
|
||||||
|
IsCreating = false;
|
||||||
|
EditButton.Visibility = Visibility.Visible;
|
||||||
|
ResetButton.Visibility = Visibility.Hidden;
|
||||||
|
CancelButton.IsEnabled = false;
|
||||||
|
SaveButton.IsEnabled = false;
|
||||||
|
ResetButton.IsEnabled = false;
|
||||||
|
|
||||||
|
ClearInputStates();
|
||||||
|
FillInputs(App.Client);
|
||||||
|
LockInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FillInputs(ClientParameters p) {
|
||||||
|
ClearOriginalValues();
|
||||||
|
ClearDefaultValues();
|
||||||
|
|
||||||
|
ClientNameInput.Text = p.Name;
|
||||||
|
ClientNameSuffixInput.Text = p.NameSuffix;
|
||||||
|
ClientNameTypeInput.Text = p.NameType;
|
||||||
|
ClientNameTokenInput.Text = p.NameToken;
|
||||||
|
ClientNameShortInput.Text = p.NameShort;
|
||||||
|
ClientAddressInput.Text = p.Address;
|
||||||
|
ClientPlzInput.Text = p.Plz.ToString();
|
||||||
|
ClientOrtInput.Text = p.Ort;
|
||||||
|
ClientIbanInput.Text = p.Iban;
|
||||||
|
ClientBicInput.Text = p.Bic;
|
||||||
|
ClientUstIdNrInput.Text = p.UstIdNr;
|
||||||
|
ClientLfbisNrInput.Text = p.LfbisNr;
|
||||||
|
ClientPhoneNrInput.Text = p.PhoneNr;
|
||||||
|
ClientFaxNrInput.Text = p.FaxNr;
|
||||||
|
ClientEmailAddressInput.Text = p.EmailAddress;
|
||||||
|
ClientWebsiteInput.Text = p.Website;
|
||||||
|
|
||||||
|
FinishInputFilling();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void UpdateClientParameters(ClientParameters p) {
|
||||||
|
p.Name = ClientNameInput.Text;
|
||||||
|
p.NameSuffix = ClientNameSuffixInput.Text.Length > 0 ? ClientNameSuffixInput.Text : null;
|
||||||
|
p.NameType = ClientNameTypeInput.Text;
|
||||||
|
p.NameToken = ClientNameTokenInput.Text;
|
||||||
|
p.NameShort = ClientNameShortInput.Text;
|
||||||
|
p.Address = ClientAddressInput.Text;
|
||||||
|
p.Plz = int.Parse(ClientPlzInput.Text);
|
||||||
|
p.Ort = ClientOrtInput.Text;
|
||||||
|
p.Iban = ClientIbanInput.Text.Length > 0 ? ClientIbanInput.Text.Replace(" ", "") : null;
|
||||||
|
p.Bic = ClientBicInput.Text.Length > 0 ? ClientBicInput.Text : null;
|
||||||
|
p.UstIdNr = ClientUstIdNrInput.Text.Length > 0 ? ClientUstIdNrInput.Text : null;
|
||||||
|
p.LfbisNr = ClientLfbisNrInput.Text.Length > 0 ? ClientLfbisNrInput.Text : null;
|
||||||
|
p.PhoneNr = ClientPhoneNrInput.Text.Length > 0 ? ClientPhoneNrInput.Text : null;
|
||||||
|
p.FaxNr = ClientFaxNrInput.Text.Length > 0 ? ClientFaxNrInput.Text : null;
|
||||||
|
p.EmailAddress = ClientEmailAddressInput.Text.Length > 0 ? ClientEmailAddressInput.Text : null;
|
||||||
|
p.Website = ClientWebsiteInput.Text.Length > 0 ? ClientWebsiteInput.Text : null;
|
||||||
|
|
||||||
|
await p.UpdateValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientNames_TextChanged(object sender, TextChangedEventArgs evt) {
|
private void ClientNames_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||||
var suffix = ClientNameSuffixInput.Text.Length > 0 ? ClientNameSuffixInput.Text : null;
|
var suffix = ClientNameSuffixInput.Text.Length > 0 ? ClientNameSuffixInput.Text : null;
|
||||||
ClientNameFull.Text = $"{ClientNameInput.Text}{(suffix != null ? $", {suffix}," : "")} {ClientNameTypeInput.Text}";
|
ClientNameFull.Text = $"{ClientNameInput.Text}{(suffix != null ? $", {suffix}," : "")} {ClientNameTypeInput.Text}";
|
||||||
|
TextBox_TextChanged(sender, evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user