Add email and phone validators
This commit is contained in:
@ -14,14 +14,71 @@ namespace WGneu.Models
|
|||||||
[Column("mgnr")]
|
[Column("mgnr")]
|
||||||
public int MgNr { get; set; }
|
public int MgNr { get; set; }
|
||||||
|
|
||||||
|
[Column("predecessor_mgnr")]
|
||||||
|
public int? PredecessorMgNr { get; set; }
|
||||||
|
|
||||||
|
[Column("prefix")]
|
||||||
|
public string? Prefix { get; set; }
|
||||||
|
|
||||||
[Column("given_name")]
|
[Column("given_name")]
|
||||||
public string GivenName { get; set; }
|
public string GivenName { get; set; }
|
||||||
|
|
||||||
|
[Column("middle_names")]
|
||||||
|
public string? MiddleName { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string[] MiddleNames {
|
||||||
|
get { return (MiddleName != null) ? MiddleName.Split(" ") : Array.Empty<string>(); }
|
||||||
|
set { MiddleName = (value.Length > 0) ? string.Join(" ", value) : null; }
|
||||||
|
}
|
||||||
|
|
||||||
[Column("family_name")]
|
[Column("family_name")]
|
||||||
public string FamilyName { get; set; }
|
public string FamilyName { get; set; }
|
||||||
|
|
||||||
|
[Column("suffix")]
|
||||||
|
public string? Suffix { get; set; }
|
||||||
|
|
||||||
|
[Column("birthday")]
|
||||||
|
public string? Birthday { get; set; }
|
||||||
|
|
||||||
|
[Column("entry_date")]
|
||||||
|
public string? EntryDate { get; set; }
|
||||||
|
|
||||||
|
[Column("exit_date")]
|
||||||
|
public string? ExitDate { get; set; }
|
||||||
|
|
||||||
|
[Column("business_shares")]
|
||||||
|
public int BusinessShares { get; set; }
|
||||||
|
|
||||||
|
[Column("accounting_nr")]
|
||||||
|
public string? AccountingNr { get; set; }
|
||||||
|
|
||||||
[Column("zwstid")]
|
[Column("zwstid")]
|
||||||
public string ZwstId { get; set; }
|
public string? ZwstId { get; set; }
|
||||||
|
|
||||||
|
[Column("lfbis_nr")]
|
||||||
|
public string? LfbisNr { get; set; }
|
||||||
|
|
||||||
|
[Column("ustid")]
|
||||||
|
public string? UstId { get; set; }
|
||||||
|
|
||||||
|
[Column("volllieferant")]
|
||||||
|
public bool VollLieferant { get; set; }
|
||||||
|
|
||||||
|
[Column("buchführend")]
|
||||||
|
public bool Buchführend { get; set; }
|
||||||
|
|
||||||
|
[Column("funktionär")]
|
||||||
|
public bool Funktionär { get; set; }
|
||||||
|
|
||||||
|
[Column("active")]
|
||||||
|
public bool Active { get; set; }
|
||||||
|
|
||||||
|
[Column("iban")]
|
||||||
|
public string? Iban { get; set; }
|
||||||
|
|
||||||
|
[Column("bic")]
|
||||||
|
public string? Bic { get; set; }
|
||||||
|
|
||||||
[Column("country")]
|
[Column("country")]
|
||||||
public string CountryCode { get; set; }
|
public string CountryCode { get; set; }
|
||||||
@ -32,9 +89,30 @@ namespace WGneu.Models
|
|||||||
[Column("address")]
|
[Column("address")]
|
||||||
public string Address { get; set; }
|
public string Address { get; set; }
|
||||||
|
|
||||||
|
[Column("email")]
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
[Column("phone_landline")]
|
||||||
|
public string? PhoneLandline { get; set; }
|
||||||
|
|
||||||
|
[Column("phone_mobile_1")]
|
||||||
|
public string? PhoneMobile1 { get; set; }
|
||||||
|
|
||||||
|
[Column("phone_mobile_2")]
|
||||||
|
public string? PhoneMobile2 { get; set; }
|
||||||
|
|
||||||
[Column("default_kgnr")]
|
[Column("default_kgnr")]
|
||||||
public int DefaultKgNr { get; set; }
|
public int DefaultKgNr { get; set; }
|
||||||
|
|
||||||
|
[Column("default_contact")]
|
||||||
|
public string DefaultContact { get; set; }
|
||||||
|
|
||||||
|
[Column("comment")]
|
||||||
|
public string? Comment { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("PredecessorMgNr")]
|
||||||
|
public virtual Member? Predecessor { get; set; }
|
||||||
|
|
||||||
[ForeignKey("CountryCode")]
|
[ForeignKey("CountryCode")]
|
||||||
public virtual Country Country { get; set; }
|
public virtual Country Country { get; set; }
|
||||||
|
|
||||||
|
@ -10,6 +10,11 @@ namespace WGneu
|
|||||||
{
|
{
|
||||||
static class Validator
|
static class Validator
|
||||||
{
|
{
|
||||||
|
private static readonly string[] MOBILE_NRS = {
|
||||||
|
"650", "651", "652", "653", "655", "657", "659", "660", "661",
|
||||||
|
"663", "664", "665", "666", "667", "668", "669", "67", "68", "69"
|
||||||
|
};
|
||||||
|
|
||||||
public static ValidationResult CheckNumericInput(TextBox input)
|
public static ValidationResult CheckNumericInput(TextBox input)
|
||||||
{
|
{
|
||||||
return CheckNumericInput(input, -1);
|
return CheckNumericInput(input, -1);
|
||||||
@ -36,7 +41,91 @@ namespace WGneu
|
|||||||
input.CaretIndex = Math.Min(pos, maxLen);
|
input.CaretIndex = Math.Min(pos, maxLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ValidationResult(true, "");
|
return new(true, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ValidationResult CheckPhoneNumber(TextBox input)
|
||||||
|
{
|
||||||
|
string text = "";
|
||||||
|
int pos = input.CaretIndex;
|
||||||
|
for (int i = 0, v = 0; i < input.Text.Length; i++)
|
||||||
|
{
|
||||||
|
char ch = input.Text[i];
|
||||||
|
if (v == 0 && ch == '0')
|
||||||
|
{
|
||||||
|
v += 3;
|
||||||
|
text += "+43";
|
||||||
|
}
|
||||||
|
else if (v == 0 && ch == '+')
|
||||||
|
{
|
||||||
|
v++;
|
||||||
|
text += ch;
|
||||||
|
}
|
||||||
|
else if (v > 0 && char.IsDigit(ch))
|
||||||
|
{
|
||||||
|
if (text == "+43")
|
||||||
|
text += " ";
|
||||||
|
else if (v == 6 && MOBILE_NRS.Any(nr => text.StartsWith("+43 " + nr)))
|
||||||
|
text += " ";
|
||||||
|
else if (v == 4 && text.StartsWith("+43 1"))
|
||||||
|
text += " ";
|
||||||
|
else if (v == 7 && text.Length == 8 && text.StartsWith("+43 "))
|
||||||
|
text += " ";
|
||||||
|
v++;
|
||||||
|
text += ch;
|
||||||
|
}
|
||||||
|
if (i == input.CaretIndex - 1)
|
||||||
|
pos = text.Length;
|
||||||
|
}
|
||||||
|
input.Text = text;
|
||||||
|
input.CaretIndex = pos;
|
||||||
|
|
||||||
|
if (text.Length == 0)
|
||||||
|
return new(true, null);
|
||||||
|
if (text.Length < 10)
|
||||||
|
return new(false, "Telefonnummer zu kurz");
|
||||||
|
|
||||||
|
return new(true, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ValidationResult CheckEmailAddress(TextBox input)
|
||||||
|
{
|
||||||
|
string text = "";
|
||||||
|
int pos = input.CaretIndex;
|
||||||
|
bool domain = false;
|
||||||
|
for (int i = 0; i < input.Text.Length; i++)
|
||||||
|
{
|
||||||
|
char ch = input.Text[i];
|
||||||
|
if (domain)
|
||||||
|
{
|
||||||
|
if ((char.IsAscii(ch) && char.IsLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch))
|
||||||
|
{
|
||||||
|
if (!(text.Last() == '.' && ch == '.'))
|
||||||
|
text += char.ToLower(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ch == '@') domain = true;
|
||||||
|
if (!char.IsControl(ch) && !char.IsWhiteSpace(ch))
|
||||||
|
text += ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == input.CaretIndex - 1)
|
||||||
|
pos = text.Length;
|
||||||
|
}
|
||||||
|
input.Text = text;
|
||||||
|
input.CaretIndex = pos;
|
||||||
|
|
||||||
|
if (text.Length == 0)
|
||||||
|
return new(true, null);
|
||||||
|
else if (text[0] == '@' || !domain)
|
||||||
|
return new(false, "E-Mail-Adresse ungültig");
|
||||||
|
var last = text.Split(".").Last();
|
||||||
|
if (last.Length < 2 || !last.All(ch => char.IsAscii(ch) && char.IsLower(ch)))
|
||||||
|
return new(false, "E-Mail-Adresse ungültig");
|
||||||
|
|
||||||
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckLfbisNr(TextBox input)
|
public static ValidationResult CheckLfbisNr(TextBox input)
|
||||||
@ -45,18 +134,18 @@ namespace WGneu
|
|||||||
if (!res.IsValid)
|
if (!res.IsValid)
|
||||||
return res;
|
return res;
|
||||||
if (input.Text.Length == 0)
|
if (input.Text.Length == 0)
|
||||||
return new ValidationResult(true, "");
|
return new(true, null);
|
||||||
if (input.Text.Length != 7)
|
if (input.Text.Length != 7)
|
||||||
return new ValidationResult(false, "Betriebsnummer zu kurz");
|
return new(false, "Betriebsnummer zu kurz");
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
return new ValidationResult(true, "Not implemented yet");
|
return new(true, "Not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckUstIdInput(TextBox input)
|
public static ValidationResult CheckUstIdInput(TextBox input)
|
||||||
{
|
{
|
||||||
return new ValidationResult(false, "Not implemented yet");
|
return new(false, "Not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetInputInvalid(TextBox input)
|
public static void SetInputInvalid(TextBox input)
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
HorizontalAlignment="Left" Margin="0,10,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="48" FontSize="14" Padding="2" Grid.Column="1" TextAlignment="Right"/>
|
HorizontalAlignment="Left" Margin="0,10,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="48" FontSize="14" Padding="2" Grid.Column="1" TextAlignment="Right"/>
|
||||||
|
|
||||||
<Label Content="Vorg.:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="2"/>
|
<Label Content="Vorg.:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="2"/>
|
||||||
<TextBox x:Name="MgNrPredecessorInput" IsReadOnly="True"
|
<TextBox x:Name="PredecessorMgNrInput" IsReadOnly="True"
|
||||||
HorizontalAlignment="Left" Margin="0,10,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="48" FontSize="14" Padding="2" Grid.Column="3" TextAlignment="Right"/>
|
HorizontalAlignment="Left" Margin="0,10,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="48" FontSize="14" Padding="2" Grid.Column="3" TextAlignment="Right"/>
|
||||||
|
|
||||||
<Label Content="Vorname:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="0"/>
|
<Label Content="Vorname:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="0"/>
|
||||||
@ -98,12 +98,12 @@
|
|||||||
Margin="0,70,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1"/>
|
Margin="0,70,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1"/>
|
||||||
|
|
||||||
<Label Content="Suffix:" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="2"/>
|
<Label Content="Suffix:" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="2"/>
|
||||||
<TextBox x:Name="SuffixInpu" IsReadOnly="True"
|
<TextBox x:Name="SuffixInput" IsReadOnly="True"
|
||||||
Margin="0,70,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="3"/>
|
Margin="0,70,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="3"/>
|
||||||
|
|
||||||
<Label Content="Geburtstag:" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="0"/>
|
<Label Content="Geburtstag:" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="0"/>
|
||||||
<TextBox x:Name="BirthdayInput" IsReadOnly="True"
|
<TextBox x:Name="BirthdayInput" IsReadOnly="True"
|
||||||
Grid.Column="1" TextWrapping="NoWrap" Margin="0,100,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="14" Padding="2" Height="25" Width="76" TextAlignment="Right"/>
|
Grid.Column="1" TextWrapping="NoWrap" Margin="0,100,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="14" Padding="2" Height="25" Width="78" TextAlignment="Right"/>
|
||||||
|
|
||||||
<Label Content="Adresse:" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Adresse:" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="AddressInput" IsReadOnly="True"
|
<TextBox x:Name="AddressInput" IsReadOnly="True"
|
||||||
@ -114,6 +114,7 @@
|
|||||||
TextChanged="PlzInput_TextChanged"
|
TextChanged="PlzInput_TextChanged"
|
||||||
HorizontalAlignment="Left" Margin="0,160,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
HorizontalAlignment="Left" Margin="0,160,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
<ComboBox x:Name="OrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
<ComboBox x:Name="OrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
||||||
|
SelectionChanged="ComboBox_SelectionChanged"
|
||||||
Margin="47,160,10,0" VerticalAlignment="Top" FontSize="14" Grid.Column="1" Grid.ColumnSpan="3" Height="25"/>
|
Margin="47,160,10,0" VerticalAlignment="Top" FontSize="14" Grid.Column="1" Grid.ColumnSpan="3" Height="25"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
@ -126,18 +127,22 @@
|
|||||||
|
|
||||||
<Label Content="E-Mail-Adresse:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="E-Mail-Adresse:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="EmailInput" IsReadOnly="True"
|
<TextBox x:Name="EmailInput" IsReadOnly="True"
|
||||||
|
TextChanged="EmailInput_TextChanged" LostFocus="EmailInput_LostFocus"
|
||||||
Margin="0,10,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
Margin="0,10,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
|
|
||||||
<Label Content="Tel.-Nr. (Festnetz):" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Tel.-Nr. (Festnetz):" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="PhoneLandlineInput" IsReadOnly="True"
|
<TextBox x:Name="PhoneLandlineInput" IsReadOnly="True"
|
||||||
|
TextChanged="PhoneNrInput_TextChanged" LostFocus="PhoneNrInput_LostFocus"
|
||||||
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
|
|
||||||
<Label Content="Tel.-Nr. (mobil):" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Tel.-Nr. (mobil):" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="PhoneMobile1Input" IsReadOnly="True"
|
<TextBox x:Name="PhoneMobile1Input" IsReadOnly="True"
|
||||||
|
TextChanged="PhoneNrInput_TextChanged" LostFocus="PhoneNrInput_LostFocus"
|
||||||
Margin="0,70,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
Margin="0,70,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
|
|
||||||
<Label Content="Tel.-Nr. (mobil):" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Tel.-Nr. (mobil):" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="PhoneMobile2Input" IsReadOnly="True"
|
<TextBox x:Name="PhoneMobile2Input" IsReadOnly="True"
|
||||||
|
TextChanged="PhoneNrInput_TextChanged" LostFocus="PhoneNrInput_LostFocus"
|
||||||
Margin="0,100,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
Margin="0,100,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
@ -172,7 +177,7 @@
|
|||||||
<Label Content="BetriebsNr.:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="BetriebsNr.:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="LfbisNrInput" IsReadOnly="True"
|
<TextBox x:Name="LfbisNrInput" IsReadOnly="True"
|
||||||
TextChanged="LfbisNrInput_TextChanged" LostFocus="LfbisNrInput_LostFocus"
|
TextChanged="LfbisNrInput_TextChanged" LostFocus="LfbisNrInput_LostFocus"
|
||||||
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25" Width="64" HorizontalAlignment="Left"/>
|
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25" Width="64" HorizontalAlignment="Left" TextAlignment="Right"/>
|
||||||
|
|
||||||
<CheckBox x:Name="BuchführendInput" Content="Buchführend" IsEnabled="False"
|
<CheckBox x:Name="BuchführendInput" Content="Buchführend" IsEnabled="False"
|
||||||
Grid.Column="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" IsChecked="False"/>
|
Grid.Column="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" IsChecked="False"/>
|
||||||
@ -198,6 +203,7 @@
|
|||||||
TextChanged="PlzInput_TextChanged"
|
TextChanged="PlzInput_TextChanged"
|
||||||
HorizontalAlignment="Left" Margin="0,70,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1"/>
|
HorizontalAlignment="Left" Margin="0,70,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1"/>
|
||||||
<ComboBox x:Name="BillingOrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
<ComboBox x:Name="BillingOrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
||||||
|
SelectionChanged="ComboBox_SelectionChanged"
|
||||||
Margin="47,70,10,0" VerticalAlignment="Top" FontSize="14" Grid.Column="1"/>
|
Margin="47,70,10,0" VerticalAlignment="Top" FontSize="14" Grid.Column="1"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
@ -224,7 +230,7 @@
|
|||||||
<CheckBox x:Name="ActiveInput" Content="Aktiv" IsEnabled="False"
|
<CheckBox x:Name="ActiveInput" Content="Aktiv" IsEnabled="False"
|
||||||
Grid.Column="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" IsChecked="False"/>
|
Grid.Column="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" IsChecked="False"/>
|
||||||
|
|
||||||
<CheckBox x:Name="VolllieferantInput" Content="Volllieferant" IsEnabled="False"
|
<CheckBox x:Name="VollLieferantInput" Content="Volllieferant" IsEnabled="False"
|
||||||
Grid.Column="2" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top" IsChecked="False"/>
|
Grid.Column="2" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top" IsChecked="False"/>
|
||||||
|
|
||||||
<CheckBox x:Name="FunkionärInput" Content="Funktionär" IsEnabled="False"
|
<CheckBox x:Name="FunkionärInput" Content="Funktionär" IsEnabled="False"
|
||||||
@ -232,10 +238,12 @@
|
|||||||
|
|
||||||
<Label Content="StammZwst.:" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="StammZwst.:" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<ComboBox x:Name="BranchInput" ItemTemplate="{StaticResource BranchTemplate}" IsEnabled="False"
|
<ComboBox x:Name="BranchInput" ItemTemplate="{StaticResource BranchTemplate}" IsEnabled="False"
|
||||||
|
SelectionChanged="ComboBox_SelectionChanged"
|
||||||
Margin="0,100,10,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="25" Grid.ColumnSpan="2"/>
|
Margin="0,100,10,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="25" Grid.ColumnSpan="2"/>
|
||||||
|
|
||||||
<Label Content="Stammgemeinde:" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Stammgemeinde:" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<ComboBox x:Name="DefaultKgInput" ItemTemplate="{StaticResource KgTemplate}" IsEnabled="False"
|
<ComboBox x:Name="DefaultKgInput" ItemTemplate="{StaticResource KgTemplate}" IsEnabled="False"
|
||||||
|
SelectionChanged="ComboBox_SelectionChanged"
|
||||||
Margin="0,130,10,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="25" Grid.ColumnSpan="2"/>
|
Margin="0,130,10,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="25" Grid.ColumnSpan="2"/>
|
||||||
|
|
||||||
<Label Content="Anmerkung:" HorizontalAlignment="Left" Margin="10,162,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Anmerkung:" HorizontalAlignment="Left" Margin="10,162,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
@ -243,9 +251,9 @@
|
|||||||
Margin="0,160,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Grid.ColumnSpan="2" TextAlignment="Right"/>
|
Margin="0,160,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Grid.ColumnSpan="2" TextAlignment="Right"/>
|
||||||
|
|
||||||
<Label Content="Kontaktart:" HorizontalAlignment="Left" Margin="10,192,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="Kontaktart:" HorizontalAlignment="Left" Margin="10,192,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<RadioButton x:Name="ContactPostInput" Content="Post" IsEnabled="False"
|
<RadioButton x:Name="ContactPostInput" GroupName="DefaultContact" Content="Post" IsEnabled="False"
|
||||||
HorizontalAlignment="Left" Margin="0,195,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
|
HorizontalAlignment="Left" Margin="0,195,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
|
||||||
<RadioButton x:Name="ContactEmailInput" Content="E-Mail" IsEnabled="False"
|
<RadioButton x:Name="ContactEmailInput" GroupName="DefaultContact" Content="E-Mail" IsEnabled="False"
|
||||||
HorizontalAlignment="Left" Margin="60,195,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
|
HorizontalAlignment="Left" Margin="60,195,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
|
@ -23,42 +23,45 @@ namespace WGneu.Windows
|
|||||||
{
|
{
|
||||||
public partial class MemberListWindow : Window
|
public partial class MemberListWindow : Window
|
||||||
{
|
{
|
||||||
private bool isEditing = false;
|
private bool IsEditing = false;
|
||||||
private bool isCreating = false;
|
private bool IsCreating = false;
|
||||||
private List<string> textFilter = new();
|
private List<string> TextFilter = new();
|
||||||
private static RoutedCommand controlF = new RoutedCommand();
|
private readonly Dictionary<TextBox, bool> Valid = new();
|
||||||
private readonly WgContext context = new();
|
private static readonly RoutedCommand CtrlF = new();
|
||||||
|
private readonly WgContext Context = new();
|
||||||
|
|
||||||
public MemberListWindow()
|
public MemberListWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
|
||||||
|
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
|
||||||
|
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||||
|
if (tb.Name != "SearchInput") Valid[tb] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
RefreshMemberList();
|
RefreshMemberList();
|
||||||
BranchInput.ItemsSource = context.Branches.OrderBy(b => b.Name).ToList();
|
BranchInput.ItemsSource = Context.Branches.OrderBy(b => b.Name).ToList();
|
||||||
DefaultKgInput.ItemsSource = context.WbKgs.Select(k => k.Kg).OrderBy(k => k.Name).ToList();
|
DefaultKgInput.ItemsSource = Context.WbKgs.Select(k => k.Kg).OrderBy(k => k.Name).ToList();
|
||||||
controlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
|
|
||||||
CommandBindings.Add(new CommandBinding(controlF, FocusSearchInput));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosing(CancelEventArgs e)
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
{
|
{
|
||||||
context.Dispose();
|
Context.Dispose();
|
||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int CountMatchesInMember(Member m)
|
private int CountMatchesInMember(Member m)
|
||||||
{
|
{
|
||||||
if (textFilter.Count == 0) return 0;
|
if (TextFilter.Count == 0) return 0;
|
||||||
string[] check = new string[] { m.MgNr.ToString(), m.FamilyName.ToLower(), m.GivenName.ToLower(), m.DefaultKg.Name.ToLower() };
|
string[] check = new string[] { m.MgNr.ToString(), m.FamilyName.ToLower(), m.GivenName.ToLower(), m.DefaultKg.Name.ToLower() };
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (string c in check)
|
foreach (string c in check)
|
||||||
{
|
{
|
||||||
if (textFilter.Any(f => c == f))
|
if (TextFilter.Any(f => c == f))
|
||||||
i += 10;
|
i += 10;
|
||||||
else if (textFilter.Any(f => c.Contains(f)))
|
else if (TextFilter.Any(f => c.Contains(f)))
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
@ -66,10 +69,10 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void RefreshMemberList()
|
private void RefreshMemberList()
|
||||||
{
|
{
|
||||||
context.Members.Load();
|
Context.Members.Load();
|
||||||
List<Member> members = context.Members.OrderBy(m => m.FamilyName + " " + m.GivenName).ToList();
|
List<Member> members = Context.Members.OrderBy(m => m.FamilyName + " " + m.GivenName).ToList();
|
||||||
|
|
||||||
if (textFilter.Count > 0)
|
if (TextFilter.Count > 0)
|
||||||
{
|
{
|
||||||
members = members
|
members = members
|
||||||
.ToDictionary(m => m, m => CountMatchesInMember(m))
|
.ToDictionary(m => m, m => CountMatchesInMember(m))
|
||||||
@ -118,7 +121,7 @@ namespace WGneu.Windows
|
|||||||
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit))
|
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit))
|
||||||
{
|
{
|
||||||
int plz = int.Parse(PlzInput.Text);
|
int plz = int.Parse(PlzInput.Text);
|
||||||
var o = context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
var o = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
||||||
OrtInput.ItemsSource = o;
|
OrtInput.ItemsSource = o;
|
||||||
OrtInput.SelectedItem = null;
|
OrtInput.SelectedItem = null;
|
||||||
}
|
}
|
||||||
@ -126,7 +129,7 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void NewMemberButton_Click(object sender, RoutedEventArgs e)
|
private void NewMemberButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
isCreating = true;
|
IsCreating = true;
|
||||||
MemberList.IsEnabled = false;
|
MemberList.IsEnabled = false;
|
||||||
InitInputs();
|
InitInputs();
|
||||||
HideNewEditDeleteButtons();
|
HideNewEditDeleteButtons();
|
||||||
@ -139,7 +142,7 @@ namespace WGneu.Windows
|
|||||||
if (MemberList.SelectedItem == null)
|
if (MemberList.SelectedItem == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isEditing = true;
|
IsEditing = true;
|
||||||
MemberList.IsEnabled = false;
|
MemberList.IsEnabled = false;
|
||||||
|
|
||||||
HideNewEditDeleteButtons();
|
HideNewEditDeleteButtons();
|
||||||
@ -157,8 +160,8 @@ namespace WGneu.Windows
|
|||||||
"Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
"Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||||
if (r == MessageBoxResult.Yes)
|
if (r == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
context.Remove(m);
|
Context.Remove(m);
|
||||||
context.SaveChanges();
|
Context.SaveChanges();
|
||||||
RefreshMemberList();
|
RefreshMemberList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,42 +170,70 @@ namespace WGneu.Windows
|
|||||||
{
|
{
|
||||||
// TODO only allow to click button, if values were checked
|
// TODO only allow to click button, if values were checked
|
||||||
|
|
||||||
Member? m = null;
|
Member? m = new();
|
||||||
if (isEditing)
|
if (IsEditing)
|
||||||
m = (Member)MemberList.SelectedItem;
|
m = (Member)MemberList.SelectedItem;
|
||||||
else if (isCreating)
|
else if (IsCreating)
|
||||||
m = new();
|
m = new();
|
||||||
|
|
||||||
int newMgNr = int.Parse(MgNrInput.Text);
|
int newMgNr = int.Parse(MgNrInput.Text);
|
||||||
|
m.Prefix = (PrefixInput.Text == "") ? null : PrefixInput.Text;
|
||||||
m.GivenName = GivenNameInput.Text;
|
m.GivenName = GivenNameInput.Text;
|
||||||
m.FamilyName = FamilyNameInput.Text;
|
m.FamilyName = FamilyNameInput.Text;
|
||||||
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
|
m.Suffix = (SuffixInput.Text == "") ? null : SuffixInput.Text;
|
||||||
|
m.Birthday = (BirthdayInput.Text == "") ? null : string.Join("-", BirthdayInput.Text.Split(".").Reverse());
|
||||||
m.CountryCode = "AT";
|
m.CountryCode = "AT";
|
||||||
m.PostalDestId = ((AT_Plz)OrtInput.SelectedItem).Id;
|
m.PostalDestId = ((AT_Plz)OrtInput.SelectedItem).Id;
|
||||||
m.PostalDest = context.PostalDestinations.Find(m.CountryCode, m.PostalDestId);
|
m.PostalDest = Context.PostalDestinations.Find(m.CountryCode, m.PostalDestId);
|
||||||
m.Address = AddressInput.Text;
|
m.Address = AddressInput.Text;
|
||||||
|
|
||||||
|
m.Email = (EmailInput.Text == "") ? null : EmailInput.Text;
|
||||||
|
m.PhoneLandline = (PhoneLandlineInput.Text == "") ? null : PhoneLandlineInput.Text.Replace(" ", "");
|
||||||
|
m.PhoneMobile1 = (PhoneMobile1Input.Text == "") ? null : PhoneMobile1Input.Text.Replace(" ", "");
|
||||||
|
m.PhoneMobile2 = (PhoneMobile2Input.Text == "") ? null : PhoneMobile2Input.Text.Replace(" ", "");
|
||||||
|
|
||||||
|
m.Iban = (IbanInput.Text == "") ? null : IbanInput.Text.Replace(" ", "");
|
||||||
|
m.Bic = (BicInput.Text == "") ? null : BicInput.Text;
|
||||||
|
|
||||||
|
m.UstId = (UstIdInput.Text == "") ? null : UstIdInput.Text;
|
||||||
|
m.LfbisNr = (LfbisNrInput.Text == "") ? null : LfbisNrInput.Text;
|
||||||
|
m.Buchführend = BuchführendInput.IsChecked ?? false;
|
||||||
|
|
||||||
|
// TODO Rechnungsadresse
|
||||||
|
|
||||||
|
m.EntryDate = (EntryDateInput.Text == "") ? null : string.Join("-", EntryDateInput.Text.Split(".").Reverse());
|
||||||
|
m.ExitDate = (ExitDateInput.Text == "") ? null : string.Join("-", ExitDateInput.Text.Split(".").Reverse());
|
||||||
|
m.BusinessShares = (BusinessSharesInput.Text == "") ? 0 : int.Parse(BusinessSharesInput.Text);
|
||||||
|
m.Active = ActiveInput.IsChecked ?? false;
|
||||||
|
m.VollLieferant = VollLieferantInput.IsChecked ?? false;
|
||||||
|
m.Funktionär = FunkionärInput.IsChecked ?? false;
|
||||||
|
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
|
||||||
m.DefaultKgNr = ((AT_Kg)DefaultKgInput.SelectedItem).KgNr;
|
m.DefaultKgNr = ((AT_Kg)DefaultKgInput.SelectedItem).KgNr;
|
||||||
|
m.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
|
||||||
|
if (ContactPostInput.IsChecked ?? false) m.DefaultContact = "post";
|
||||||
|
if (ContactEmailInput.IsChecked ?? false) m.DefaultContact = "email";
|
||||||
|
// TODO Buchhaltungskonto
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (isEditing)
|
if (IsEditing)
|
||||||
context.Update(m);
|
Context.Update(m);
|
||||||
else if (isCreating)
|
else if (IsCreating)
|
||||||
context.Add(m);
|
Context.Add(m);
|
||||||
context.SaveChanges();
|
Context.SaveChanges();
|
||||||
|
|
||||||
if (newMgNr != m.MgNr)
|
if (newMgNr != m.MgNr)
|
||||||
context.Database.ExecuteSql($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}");
|
Context.Database.ExecuteSql($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}");
|
||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
MessageBox.Show(
|
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||||
"Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message.ToString(),
|
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||||
"Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
isEditing = false;
|
IsEditing = false;
|
||||||
isCreating = false;
|
IsCreating = false;
|
||||||
MemberList.IsEnabled = true;
|
MemberList.IsEnabled = true;
|
||||||
HideSaveResetCancelButtons();
|
HideSaveResetCancelButtons();
|
||||||
ShowNewEditDeleteButtons();
|
ShowNewEditDeleteButtons();
|
||||||
@ -212,16 +243,16 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (isEditing)
|
if (IsEditing)
|
||||||
RefreshInputs();
|
RefreshInputs();
|
||||||
else if (isCreating)
|
else if (IsCreating)
|
||||||
InitInputs();
|
InitInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
isEditing = false;
|
IsEditing = false;
|
||||||
isCreating = false;
|
IsCreating = false;
|
||||||
MemberList.IsEnabled = true;
|
MemberList.IsEnabled = true;
|
||||||
HideSaveResetCancelButtons();
|
HideSaveResetCancelButtons();
|
||||||
ShowNewEditDeleteButtons();
|
ShowNewEditDeleteButtons();
|
||||||
@ -231,14 +262,13 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void SearchInput_TextChanged(object sender, RoutedEventArgs e)
|
private void SearchInput_TextChanged(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// TODO implement STRG+F
|
TextFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(s => s != "");
|
||||||
textFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(s => s != "");
|
|
||||||
RefreshMemberList();
|
RefreshMemberList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FocusSearchInput(object sender, RoutedEventArgs e)
|
private void FocusSearchInput(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!isEditing && !isCreating)
|
if (!IsEditing && !IsCreating)
|
||||||
{
|
{
|
||||||
SearchInput.Focus();
|
SearchInput.Focus();
|
||||||
SearchInput.SelectAll();
|
SearchInput.SelectAll();
|
||||||
@ -247,8 +277,8 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private int NextMgNr()
|
private int NextMgNr()
|
||||||
{
|
{
|
||||||
int c = context.Members.Select(m => m.MgNr).Min();
|
int c = Context.Members.Select(m => m.MgNr).Min();
|
||||||
context.Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToList().ForEach(a => { if (a <= c + 100) c = a; });
|
Context.Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToList().ForEach(a => { if (a <= c + 100) c = a; });
|
||||||
return c + 1;
|
return c + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,24 +349,55 @@ namespace WGneu.Windows
|
|||||||
private void FillInputs(Member m)
|
private void FillInputs(Member m)
|
||||||
{
|
{
|
||||||
MgNrInput.Text = m.MgNr.ToString();
|
MgNrInput.Text = m.MgNr.ToString();
|
||||||
|
PredecessorMgNrInput.Text = m.PredecessorMgNr.ToString();
|
||||||
|
PrefixInput.Text = m.Prefix;
|
||||||
GivenNameInput.Text = m.GivenName;
|
GivenNameInput.Text = m.GivenName;
|
||||||
FamilyNameInput.Text = m.FamilyName;
|
FamilyNameInput.Text = m.FamilyName;
|
||||||
BranchInput.SelectedItem = m.Branch;
|
SuffixInput.Text = m.Suffix;
|
||||||
DefaultKgInput.SelectedItem = m.DefaultKg;
|
BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null;
|
||||||
AddressInput.Text = m.Address;
|
AddressInput.Text = m.Address;
|
||||||
|
AT_Plz? p = m.PostalDest.Plz(Context);
|
||||||
AT_Plz? p = m.PostalDest.Plz(context);
|
|
||||||
if (p != null)
|
if (p != null)
|
||||||
{
|
{
|
||||||
PlzInput.Text = p.Plz.ToString();
|
PlzInput.Text = p.Plz.ToString();
|
||||||
OrtInput.ItemsSource = p.Orte(context);
|
OrtInput.ItemsSource = p.Orte(Context);
|
||||||
OrtInput.SelectedItem = p;
|
OrtInput.SelectedItem = p;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
PlzInput.Text = null;
|
||||||
OrtInput.ItemsSource = null;
|
OrtInput.ItemsSource = null;
|
||||||
OrtInput.SelectedItem = null;
|
OrtInput.SelectedItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EmailInput.Text = m.Email;
|
||||||
|
PhoneLandlineInput.Text = m.PhoneLandline;
|
||||||
|
PhoneMobile1Input.Text = m.PhoneMobile1;
|
||||||
|
PhoneMobile2Input.Text = m.PhoneMobile2;
|
||||||
|
|
||||||
|
IbanInput.Text = m.Iban;
|
||||||
|
BicInput.Text = m.Bic;
|
||||||
|
|
||||||
|
UstIdInput.Text = m.UstId;
|
||||||
|
LfbisNrInput.Text = m.LfbisNr;
|
||||||
|
BuchführendInput.IsChecked = m.Buchführend;
|
||||||
|
|
||||||
|
// TODO Rechnungsadresse
|
||||||
|
|
||||||
|
EntryDateInput.Text = (m.EntryDate != null) ? string.Join(".", m.EntryDate.Split("-").Reverse()) : null;
|
||||||
|
ExitDateInput.Text = (m.ExitDate != null) ? string.Join(".", m.ExitDate.Split("-").Reverse()) : null;
|
||||||
|
BusinessSharesInput.Text = m.BusinessShares.ToString();
|
||||||
|
BranchInput.SelectedItem = m.Branch;
|
||||||
|
DefaultKgInput.SelectedItem = m.DefaultKg;
|
||||||
|
CommentInput.Text = m.Comment;
|
||||||
|
ActiveInput.IsChecked = m.Active;
|
||||||
|
VollLieferantInput.IsChecked = m.VollLieferant;
|
||||||
|
FunkionärInput.IsChecked = m.Funktionär;
|
||||||
|
switch (m.DefaultContact)
|
||||||
|
{
|
||||||
|
case "post": ContactPostInput.IsChecked = true; break;
|
||||||
|
case "email": ContactEmailInput.IsChecked = true; break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearInputs()
|
private void ClearInputs()
|
||||||
@ -345,20 +406,82 @@ namespace WGneu.Windows
|
|||||||
if (tb.Name != "SearchInput") tb.Text = "";
|
if (tb.Name != "SearchInput") tb.Text = "";
|
||||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||||
cb.SelectedItem = null;
|
cb.SelectedItem = null;
|
||||||
|
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
|
||||||
|
cb.IsChecked = false;
|
||||||
|
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
|
||||||
|
rb.IsChecked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsValid()
|
||||||
|
{
|
||||||
|
return Valid.All(kv => kv.Value) &&
|
||||||
|
Utils.FindVisualChilds<ComboBox>(this).All(cb => cb.ItemsSource == null || cb.SelectedItem != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateButtons()
|
||||||
|
{
|
||||||
|
if (!IsEditing && !IsCreating) return;
|
||||||
|
bool ch = HasChanged(), v = IsValid();
|
||||||
|
ResetButton.IsEnabled = (ch);
|
||||||
|
SaveButton.IsEnabled = (v && ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HasChanged()
|
||||||
|
{
|
||||||
|
return true; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InputTextChanged(TextBox input, Func<TextBox, ValidationResult> checker)
|
||||||
|
{
|
||||||
|
var res = checker(input);
|
||||||
|
Valid[input] = res.IsValid;
|
||||||
|
if (res.IsValid)
|
||||||
|
Validator.SetInputValid(input);
|
||||||
|
else
|
||||||
|
Validator.SetInputInvalid(input);
|
||||||
|
UpdateButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InputLostFocus(TextBox input, Func<TextBox, ValidationResult> checker, string? msg)
|
||||||
|
{
|
||||||
|
var res = checker(input);
|
||||||
|
if (!res.IsValid)
|
||||||
|
MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
InputTextChanged((TextBox)sender, Validator.CheckPhoneNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PhoneNrInput_LostFocus(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
InputLostFocus((TextBox)sender, Validator.CheckPhoneNumber, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EmailInput_TextChanged(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
InputTextChanged((TextBox)sender, Validator.CheckEmailAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EmailInput_LostFocus(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
InputLostFocus((TextBox)sender, Validator.CheckEmailAddress, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs e)
|
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var res = Validator.CheckLfbisNr(LfbisNrInput);
|
InputTextChanged((TextBox)sender, Validator.CheckLfbisNr);
|
||||||
if (res.IsValid) Validator.SetInputValid(LfbisNrInput);
|
|
||||||
else Validator.SetInputInvalid(LfbisNrInput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e)
|
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var res = Validator.CheckLfbisNr(LfbisNrInput);
|
InputLostFocus((TextBox)sender, Validator.CheckLfbisNr, "Betriebsnummer ungültig");
|
||||||
if (!res.IsValid)
|
|
||||||
MessageBox.Show(res.ErrorContent.ToString(), "Betriebsnummer ungültig", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user