Change code formatting
This commit is contained in:
@ -6,12 +6,10 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace WGneu
|
||||
{
|
||||
namespace WGneu {
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public partial class App : Application {
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("AT_gem"), PrimaryKey("Gkz")]
|
||||
public class AT_Gem
|
||||
{
|
||||
public class AT_Gem {
|
||||
[Column("gkz")]
|
||||
public int Gkz { get; set; }
|
||||
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("AT_kg"), PrimaryKey("KgNr")]
|
||||
public class AT_Kg
|
||||
{
|
||||
public class AT_Kg {
|
||||
[Column("kgnr")]
|
||||
public int KgNr { get; set; }
|
||||
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("AT_ort"), PrimaryKey("Okz")]
|
||||
public class AT_Ort
|
||||
{
|
||||
public class AT_Ort {
|
||||
[Column("okz")]
|
||||
public int Okz { get; set; }
|
||||
|
||||
|
@ -7,11 +7,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("AT_plz"), PrimaryKey("Plz", "Okz"), Index("Id", IsUnique = true)]
|
||||
public class AT_Plz
|
||||
{
|
||||
public class AT_Plz {
|
||||
[Column("plz")]
|
||||
public int Plz { get; set; }
|
||||
|
||||
@ -33,9 +31,8 @@ namespace WGneu.Models
|
||||
[ForeignKey("CountryCode")]
|
||||
public virtual Country Country { get; set; }
|
||||
|
||||
public ISet<AT_Plz> Orte(WgContext ctx)
|
||||
{
|
||||
public ISet<AT_Plz> Orte(WgContext ctx) {
|
||||
return ctx.Postleitzahlen.Where(p => p.Plz == Plz).ToHashSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("branch"), PrimaryKey("ZwstId")]
|
||||
public class Branch
|
||||
{
|
||||
public class Branch {
|
||||
[Column("zwstid")]
|
||||
public string ZwstId { get; set; }
|
||||
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("country"), PrimaryKey("Alpha2")]
|
||||
public class Country
|
||||
{
|
||||
public class Country {
|
||||
[Column("alpha2")]
|
||||
public string Alpha2 { get; set; }
|
||||
|
||||
|
@ -4,59 +4,49 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
// 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
|
||||
{
|
||||
internal class Gradation {
|
||||
/// <summary>
|
||||
/// Gradation in mg/L.
|
||||
/// </summary>
|
||||
uint mgpl;
|
||||
|
||||
public Gradation(uint mgpl)
|
||||
{
|
||||
public Gradation(uint mgpl) {
|
||||
this.mgpl = mgpl;
|
||||
}
|
||||
|
||||
public static double relativeDensity(double todo)
|
||||
{
|
||||
public static double relativeDensity(double todo) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double KmwToOe(double kmw)
|
||||
{
|
||||
public static double KmwToOe(double kmw) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
public static double OeToKmw(double oe)
|
||||
{
|
||||
public static double OeToKmw(double oe) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
public static Gradation FromKmw(double kwm)
|
||||
{
|
||||
public static Gradation FromKmw(double kwm) {
|
||||
return new Gradation(0); // TODO
|
||||
}
|
||||
|
||||
public static Gradation FromKmw(double kmw, double t)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public static Gradation FromOe(double oe) {
|
||||
return new Gradation(0); // TODO
|
||||
}
|
||||
|
||||
public static Gradation FromOe(double oe, double t)
|
||||
{
|
||||
public static Gradation FromOe(double oe, double t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("member"), PrimaryKey("MgNr")]
|
||||
public class Member
|
||||
{
|
||||
public class Member {
|
||||
[Column("mgnr")]
|
||||
public int MgNr { get; set; }
|
||||
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("postal_dest"), PrimaryKey("CountryCode", "Id")]
|
||||
public class PostalDest
|
||||
{
|
||||
public class PostalDest {
|
||||
[Column("country")]
|
||||
public string CountryCode { get; set; }
|
||||
|
||||
@ -20,8 +18,7 @@ namespace WGneu.Models
|
||||
[ForeignKey("CountryCode")]
|
||||
public virtual Country Country { get; set; }
|
||||
|
||||
public AT_Plz? Plz(WgContext ctx)
|
||||
{
|
||||
public AT_Plz? Plz(WgContext ctx) {
|
||||
if (CountryCode != "AT") return null;
|
||||
return ctx.Postleitzahlen.Where(p => p.Id == Id).FirstOrDefault();
|
||||
}
|
||||
|
@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Models
|
||||
{
|
||||
namespace WGneu.Models {
|
||||
[Table("wb_kg"), PrimaryKey("KgNr")]
|
||||
public class WbKg
|
||||
{
|
||||
public class WbKg {
|
||||
[Column("kgnr")]
|
||||
public int KgNr { get; set; }
|
||||
|
||||
|
@ -6,16 +6,12 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
|
||||
namespace WGneu
|
||||
{
|
||||
class Utils
|
||||
{
|
||||
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject
|
||||
{
|
||||
namespace WGneu {
|
||||
class Utils {
|
||||
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject {
|
||||
if (depObj == null)
|
||||
yield return (T)Enumerable.Empty<T>();
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
|
||||
{
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) {
|
||||
DependencyObject ithChild = VisualTreeHelper.GetChild(depObj, i);
|
||||
if (ithChild == null)
|
||||
continue;
|
||||
|
@ -6,10 +6,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace WGneu
|
||||
{
|
||||
static class Validator
|
||||
{
|
||||
namespace WGneu {
|
||||
static class Validator {
|
||||
|
||||
private static readonly Dictionary<string, string[][]> PHONE_NRS = new() {
|
||||
{ "43", new string[][] {
|
||||
@ -35,17 +33,14 @@ namespace WGneu
|
||||
};
|
||||
|
||||
|
||||
public static ValidationResult CheckNumericInput(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckNumericInput(TextBox input) {
|
||||
return CheckNumericInput(input, -1);
|
||||
}
|
||||
|
||||
private static ValidationResult CheckNumericInput(TextBox input, int maxLen)
|
||||
{
|
||||
private static ValidationResult CheckNumericInput(TextBox input, int maxLen) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0; i < input.Text.Length; i++)
|
||||
{
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (Char.IsDigit(ch))
|
||||
text += ch;
|
||||
@ -55,8 +50,7 @@ namespace WGneu
|
||||
input.Text = text;
|
||||
input.CaretIndex = pos;
|
||||
|
||||
if (maxLen >= 0 && input.Text.Length > maxLen)
|
||||
{
|
||||
if (maxLen >= 0 && input.Text.Length > maxLen) {
|
||||
input.Text = input.Text.Substring(0, maxLen);
|
||||
input.CaretIndex = Math.Min(pos, maxLen);
|
||||
}
|
||||
@ -64,31 +58,23 @@ namespace WGneu
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckPhoneNumber(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckPhoneNumber(TextBox input) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0, v = 0; i < input.Text.Length; i++)
|
||||
{
|
||||
for (int i = 0, v = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (v == 0 && input.Text.Length - i >= 2 && ch == '0' && input.Text[i + 1] == '0') {
|
||||
v++; i++;
|
||||
text += "+";
|
||||
} else if (ch == '(' && input.Text.Length - i >= 3 && input.Text[i + 1] == '0' && input.Text[i + 2] == ')') {
|
||||
i += 2;
|
||||
}
|
||||
else if (v == 0 && ch == '0')
|
||||
{
|
||||
} else if (v == 0 && ch == '0') {
|
||||
v += 3;
|
||||
text += "+43";
|
||||
}
|
||||
else if (v == 0 && ch == '+')
|
||||
{
|
||||
} else if (v == 0 && ch == '+') {
|
||||
v++;
|
||||
text += ch;
|
||||
}
|
||||
else if (v > 0 && char.IsDigit(ch))
|
||||
{
|
||||
} else if (v > 0 && char.IsDigit(ch)) {
|
||||
if (PHONE_NRS.Any(kv => text == "+" + kv.Key))
|
||||
text += " ";
|
||||
if (text.StartsWith("+43 ")) {
|
||||
@ -118,24 +104,18 @@ namespace WGneu
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckEmailAddress(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckEmailAddress(TextBox input) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
bool domain = false;
|
||||
for (int i = 0; i < input.Text.Length; i++)
|
||||
{
|
||||
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 (domain) {
|
||||
if ((char.IsAscii(ch) && char.IsLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch)) {
|
||||
if (!(text.Last() == '.' && ch == '.'))
|
||||
text += char.ToLower(ch);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (ch == '@') domain = true;
|
||||
if (!char.IsControl(ch) && !char.IsWhiteSpace(ch))
|
||||
text += ch;
|
||||
@ -158,8 +138,7 @@ namespace WGneu
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckLfbisNr(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckLfbisNr(TextBox input) {
|
||||
var res = CheckNumericInput(input, 7);
|
||||
if (!res.IsValid)
|
||||
return res;
|
||||
@ -173,18 +152,15 @@ namespace WGneu
|
||||
return new(true, "Not implemented yet");
|
||||
}
|
||||
|
||||
public static ValidationResult CheckUstIdInput(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckUstIdInput(TextBox input) {
|
||||
return new(false, "Not implemented yet");
|
||||
}
|
||||
|
||||
public static void SetInputInvalid(TextBox input)
|
||||
{
|
||||
public static void SetInputInvalid(TextBox input) {
|
||||
input.BorderBrush = System.Windows.Media.Brushes.Red;
|
||||
}
|
||||
|
||||
public static void SetInputValid(TextBox input)
|
||||
{
|
||||
public static void SetInputValid(TextBox input) {
|
||||
input.ClearValue(TextBox.BorderBrushProperty);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WGneu.Models;
|
||||
|
||||
namespace WGneu
|
||||
{
|
||||
public class WgContext : DbContext
|
||||
{
|
||||
namespace WGneu {
|
||||
public class WgContext : DbContext {
|
||||
public DbSet<Country> Countries { get; set; }
|
||||
public DbSet<Member> Members { get; set; }
|
||||
public DbSet<AT_Gem> Gemeinden { get; set; }
|
||||
@ -20,8 +18,7 @@ namespace WGneu
|
||||
public DbSet<Branch> Branches { get; set; }
|
||||
public DbSet<WbKg> WbKgs { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
|
||||
optionsBuilder.UseSqlite("Data Source=\"C:\\Users\\lorenz\\Desktop\\wgtest.sqlite3\"; foreign keys=true");
|
||||
optionsBuilder.UseLazyLoadingProxies();
|
||||
}
|
||||
|
@ -14,27 +14,21 @@ using System.Windows.Shapes;
|
||||
using WGneu.Models;
|
||||
|
||||
|
||||
namespace WGneu.Windows
|
||||
{
|
||||
namespace WGneu.Windows {
|
||||
/// <summary>
|
||||
/// Interaktionslogik für BankDetailsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class BankDetailsWindow : Window
|
||||
{
|
||||
public BankDetailsWindow()
|
||||
{
|
||||
public partial class BankDetailsWindow : Window {
|
||||
public BankDetailsWindow() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Iban_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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 (Char.IsLetterOrDigit(ch) && Char.IsAscii(ch)) {
|
||||
if (v != 0 && v % 4 == 0)
|
||||
iban += ' ';
|
||||
v++;
|
||||
@ -52,25 +46,20 @@ namespace WGneu.Windows
|
||||
GenerateBankDetails();
|
||||
}
|
||||
|
||||
private void Iban_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
private void Iban_LostFocus(object sender, EventArgs e) {
|
||||
// TODO vaildate checksum
|
||||
}
|
||||
|
||||
private void BankCode_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
private void BankCode_TextChanged(object sender, TextChangedEventArgs e) {
|
||||
string cc = "AT";
|
||||
string code = "";
|
||||
int pos = BankCode.CaretIndex;
|
||||
|
||||
if (cc == "AT")
|
||||
{
|
||||
if (cc == "AT") {
|
||||
|
||||
for (int i = 0, v = 0; i < BankCode.Text.Length && v < 5; i++)
|
||||
{
|
||||
for (int i = 0, v = 0; i < BankCode.Text.Length && v < 5; i++) {
|
||||
char ch = BankCode.Text[i];
|
||||
if (Char.IsDigit(ch))
|
||||
{
|
||||
if (Char.IsDigit(ch)) {
|
||||
v++;
|
||||
code += ch;
|
||||
}
|
||||
@ -86,19 +75,15 @@ namespace WGneu.Windows
|
||||
GenerateIban();
|
||||
}
|
||||
|
||||
private void AccountNumber_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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))
|
||||
{
|
||||
if (Char.IsLetterOrDigit(ch) && Char.IsAscii(ch)) {
|
||||
v++;
|
||||
num += ch;
|
||||
}
|
||||
@ -114,13 +99,11 @@ namespace WGneu.Windows
|
||||
GenerateIban();
|
||||
}
|
||||
|
||||
private void GenerateIban()
|
||||
{
|
||||
private void GenerateIban() {
|
||||
string cc = "AT";
|
||||
string iban = cc + "00";
|
||||
|
||||
if (cc == "AT")
|
||||
{
|
||||
if (cc == "AT") {
|
||||
iban += BankCode.Text.PadLeft(5, '0') + AccountNumber.Text.PadLeft(11, '0');
|
||||
}
|
||||
|
||||
@ -130,8 +113,7 @@ namespace WGneu.Windows
|
||||
Iban.CaretIndex = iban.Length;
|
||||
}
|
||||
|
||||
private void GenerateBankDetails()
|
||||
{
|
||||
private void GenerateBankDetails() {
|
||||
BankCode.Text = "";
|
||||
AccountNumber.Text = "";
|
||||
|
||||
@ -140,26 +122,19 @@ namespace WGneu.Windows
|
||||
return;
|
||||
|
||||
string cc = iban.Substring(0, 2);
|
||||
if (cc == "AT")
|
||||
{
|
||||
if (iban.Length > 4)
|
||||
{
|
||||
if (cc == "AT") {
|
||||
if (iban.Length > 4) {
|
||||
string bankCodeStr = iban.Substring(4, Math.Min(5, iban.Length - 4));
|
||||
if (bankCodeStr.All(Char.IsDigit))
|
||||
{
|
||||
if (bankCodeStr.All(Char.IsDigit)) {
|
||||
int bankCode = int.Parse(bankCodeStr);
|
||||
BankCode.Text = bankCode.ToString();
|
||||
}
|
||||
if (iban.Length > 9)
|
||||
{
|
||||
if (iban.Length > 9) {
|
||||
string accNumStr = iban.Substring(9, Math.Min(11, iban.Length - 9));
|
||||
if (accNumStr.All(Char.IsDigit))
|
||||
{
|
||||
if (accNumStr.All(Char.IsDigit)) {
|
||||
int accNum = int.Parse(accNumStr);
|
||||
AccountNumber.Text = (accNum != 0) ? accNum.ToString() : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
AccountNumber.Text = accNumStr;
|
||||
}
|
||||
}
|
||||
|
@ -18,52 +18,43 @@ using System.Windows.Shapes;
|
||||
using WGneu.Models;
|
||||
|
||||
|
||||
namespace WGneu.Windows
|
||||
{
|
||||
namespace WGneu.Windows {
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public partial class MainWindow : Window {
|
||||
private readonly WgContext _context = new WgContext();
|
||||
private CollectionViewSource countryViewSource;
|
||||
public MainWindow()
|
||||
{
|
||||
public MainWindow() {
|
||||
InitializeComponent();
|
||||
countryViewSource = (CollectionViewSource) FindResource("countryViewSource");
|
||||
countryViewSource = (CollectionViewSource)FindResource("countryViewSource");
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
_context.Countries.Load();
|
||||
countryViewSource.Source = _context.Countries.Local.ToObservableCollection();
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
protected override void OnClosing(CancelEventArgs e) {
|
||||
_context.Dispose();
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
private void Button1_Click(object sender, EventArgs e) {
|
||||
BankDetailsWindow w = new BankDetailsWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void Button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
private void Button2_Click(object sender, EventArgs e) {
|
||||
MemberListWindow w = new MemberListWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void Button_Click(object sender, RoutedEventArgs e) {
|
||||
|
||||
}
|
||||
|
||||
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,8 @@ using System.Windows.Shapes;
|
||||
using WGneu.Models;
|
||||
|
||||
|
||||
namespace WGneu.Windows
|
||||
{
|
||||
public partial class MemberListWindow : Window
|
||||
{
|
||||
namespace WGneu.Windows {
|
||||
public partial class MemberListWindow : Window {
|
||||
private bool IsEditing = false;
|
||||
private bool IsCreating = false;
|
||||
private List<string> TextFilter = new();
|
||||
@ -30,8 +28,7 @@ namespace WGneu.Windows
|
||||
private static readonly RoutedCommand CtrlF = new();
|
||||
private readonly WgContext Context = new();
|
||||
|
||||
public MemberListWindow()
|
||||
{
|
||||
public MemberListWindow() {
|
||||
InitializeComponent();
|
||||
CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
|
||||
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
|
||||
@ -39,26 +36,22 @@ namespace WGneu.Windows
|
||||
if (tb.Name != "SearchInput") Valid[tb] = true;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
RefreshMemberList();
|
||||
BranchInput.ItemsSource = Context.Branches.OrderBy(b => b.Name).ToList();
|
||||
DefaultKgInput.ItemsSource = Context.WbKgs.Select(k => k.Kg).OrderBy(k => k.Name).ToList();
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
protected override void OnClosing(CancelEventArgs e) {
|
||||
Context.Dispose();
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private int CountMatchesInMember(Member m)
|
||||
{
|
||||
private int CountMatchesInMember(Member m) {
|
||||
if (TextFilter.Count == 0) return 0;
|
||||
string[] check = new string[] { m.MgNr.ToString(), m.FamilyName.ToLower(), m.GivenName.ToLower(), m.DefaultKg.Name.ToLower() };
|
||||
int i = 0;
|
||||
foreach (string c in check)
|
||||
{
|
||||
foreach (string c in check) {
|
||||
if (TextFilter.Any(f => c == f))
|
||||
i += 10;
|
||||
else if (TextFilter.Any(f => c.Contains(f)))
|
||||
@ -67,13 +60,11 @@ namespace WGneu.Windows
|
||||
return i;
|
||||
}
|
||||
|
||||
private void RefreshMemberList()
|
||||
{
|
||||
private void RefreshMemberList() {
|
||||
Context.Members.Load();
|
||||
List<Member> members = Context.Members.OrderBy(m => m.FamilyName + " " + m.GivenName).ToList();
|
||||
|
||||
if (TextFilter.Count > 0)
|
||||
{
|
||||
if (TextFilter.Count > 0) {
|
||||
members = members
|
||||
.ToDictionary(m => m, m => CountMatchesInMember(m))
|
||||
.OrderByDescending(a => a.Value)
|
||||
@ -88,38 +79,30 @@ namespace WGneu.Windows
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
private void RefreshInputs()
|
||||
{
|
||||
private void RefreshInputs() {
|
||||
Member m = (Member)MemberList.SelectedItem;
|
||||
if (m != null)
|
||||
{
|
||||
if (m != null) {
|
||||
EditMemberButton.IsEnabled = true;
|
||||
DeleteMemberButton.IsEnabled = true;
|
||||
FillInputs(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EditMemberButton.IsEnabled = false;
|
||||
DeleteMemberButton.IsEnabled = false;
|
||||
ClearInputs();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitInputs()
|
||||
{
|
||||
private void InitInputs() {
|
||||
ClearInputs();
|
||||
MgNrInput.Text = NextMgNr().ToString();
|
||||
}
|
||||
|
||||
private void MemberList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
private void MemberList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
private void PlzInput_TextChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit))
|
||||
{
|
||||
private void PlzInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit)) {
|
||||
int plz = int.Parse(PlzInput.Text);
|
||||
var o = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
||||
OrtInput.ItemsSource = o;
|
||||
@ -127,8 +110,7 @@ namespace WGneu.Windows
|
||||
}
|
||||
}
|
||||
|
||||
private void NewMemberButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void NewMemberButton_Click(object sender, RoutedEventArgs e) {
|
||||
IsCreating = true;
|
||||
MemberList.IsEnabled = false;
|
||||
InitInputs();
|
||||
@ -137,8 +119,7 @@ namespace WGneu.Windows
|
||||
UnlockInputs();
|
||||
}
|
||||
|
||||
private void EditMemberButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void EditMemberButton_Click(object sender, RoutedEventArgs e) {
|
||||
if (MemberList.SelectedItem == null)
|
||||
return;
|
||||
|
||||
@ -150,24 +131,21 @@ namespace WGneu.Windows
|
||||
UnlockInputs();
|
||||
}
|
||||
|
||||
private void DeleteMemberButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void DeleteMemberButton_Click(object sender, RoutedEventArgs e) {
|
||||
Member m = (Member)MemberList.SelectedItem;
|
||||
if (m == null) return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll das Mitglied \"{m.FamilyName} {m.GivenName}\" (MgNr. {m.MgNr}) wirklich unwiderruflich gelöscht werden?",
|
||||
"Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r == MessageBoxResult.Yes)
|
||||
{
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
Context.Remove(m);
|
||||
Context.SaveChanges();
|
||||
RefreshMemberList();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||
// TODO only allow to click button, if values were checked
|
||||
|
||||
Member? m = new();
|
||||
@ -214,8 +192,7 @@ namespace WGneu.Windows
|
||||
if (ContactEmailInput.IsChecked ?? false) m.DefaultContact = "email";
|
||||
// TODO Buchhaltungskonto
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
if (IsEditing)
|
||||
Context.Update(m);
|
||||
else if (IsCreating)
|
||||
@ -224,9 +201,7 @@ namespace WGneu.Windows
|
||||
|
||||
if (newMgNr != m.MgNr)
|
||||
Context.Database.ExecuteSql($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
@ -241,16 +216,14 @@ namespace WGneu.Windows
|
||||
RefreshMemberList();
|
||||
}
|
||||
|
||||
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void ResetButton_Click(object sender, RoutedEventArgs e) {
|
||||
if (IsEditing)
|
||||
RefreshInputs();
|
||||
else if (IsCreating)
|
||||
InitInputs();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e) {
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
MemberList.IsEnabled = true;
|
||||
@ -260,30 +233,25 @@ namespace WGneu.Windows
|
||||
LockInputs();
|
||||
}
|
||||
|
||||
private void SearchInput_TextChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void SearchInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||
TextFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(s => s != "");
|
||||
RefreshMemberList();
|
||||
}
|
||||
|
||||
private void FocusSearchInput(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!IsEditing && !IsCreating)
|
||||
{
|
||||
private void FocusSearchInput(object sender, RoutedEventArgs e) {
|
||||
if (!IsEditing && !IsCreating) {
|
||||
SearchInput.Focus();
|
||||
SearchInput.SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
private int NextMgNr()
|
||||
{
|
||||
private int NextMgNr() {
|
||||
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; });
|
||||
return c + 1;
|
||||
}
|
||||
|
||||
private void ShowSaveResetCancelButtons()
|
||||
{
|
||||
private void ShowSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = true;
|
||||
ResetButton.IsEnabled = false;
|
||||
CancelButton.IsEnabled = true;
|
||||
@ -292,8 +260,7 @@ namespace WGneu.Windows
|
||||
CancelButton.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void HideSaveResetCancelButtons()
|
||||
{
|
||||
private void HideSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
CancelButton.IsEnabled = false;
|
||||
@ -302,8 +269,7 @@ namespace WGneu.Windows
|
||||
CancelButton.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void ShowNewEditDeleteButtons()
|
||||
{
|
||||
private void ShowNewEditDeleteButtons() {
|
||||
NewMemberButton.IsEnabled = true;
|
||||
EditMemberButton.IsEnabled = MemberList.SelectedItem != null;
|
||||
DeleteMemberButton.IsEnabled = MemberList.SelectedItem != null;
|
||||
@ -312,8 +278,7 @@ namespace WGneu.Windows
|
||||
DeleteMemberButton.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void HideNewEditDeleteButtons()
|
||||
{
|
||||
private void HideNewEditDeleteButtons() {
|
||||
NewMemberButton.IsEnabled = false;
|
||||
EditMemberButton.IsEnabled = false;
|
||||
DeleteMemberButton.IsEnabled = false;
|
||||
@ -322,8 +287,7 @@ namespace WGneu.Windows
|
||||
DeleteMemberButton.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void LockInputs()
|
||||
{
|
||||
private void LockInputs() {
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||
if (tb.Name != "SearchInput") tb.IsReadOnly = true;
|
||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||
@ -334,8 +298,7 @@ namespace WGneu.Windows
|
||||
rb.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void UnlockInputs()
|
||||
{
|
||||
private void UnlockInputs() {
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||
if (tb.Name != "SearchInput") tb.IsReadOnly = false;
|
||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||
@ -346,8 +309,7 @@ namespace WGneu.Windows
|
||||
rb.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void FillInputs(Member m)
|
||||
{
|
||||
private void FillInputs(Member m) {
|
||||
MgNrInput.Text = m.MgNr.ToString();
|
||||
PredecessorMgNrInput.Text = m.PredecessorMgNr.ToString();
|
||||
PrefixInput.Text = m.Prefix;
|
||||
@ -357,14 +319,11 @@ namespace WGneu.Windows
|
||||
BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null;
|
||||
AddressInput.Text = m.Address;
|
||||
AT_Plz? p = m.PostalDest.Plz(Context);
|
||||
if (p != null)
|
||||
{
|
||||
if (p != null) {
|
||||
PlzInput.Text = p.Plz.ToString();
|
||||
OrtInput.ItemsSource = p.Orte(Context);
|
||||
OrtInput.SelectedItem = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
PlzInput.Text = null;
|
||||
OrtInput.ItemsSource = null;
|
||||
OrtInput.SelectedItem = null;
|
||||
@ -393,15 +352,13 @@ namespace WGneu.Windows
|
||||
ActiveInput.IsChecked = m.Active;
|
||||
VollLieferantInput.IsChecked = m.VollLieferant;
|
||||
FunkionärInput.IsChecked = m.Funktionär;
|
||||
switch (m.DefaultContact)
|
||||
{
|
||||
switch (m.DefaultContact) {
|
||||
case "post": ContactPostInput.IsChecked = true; break;
|
||||
case "email": ContactEmailInput.IsChecked = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearInputs()
|
||||
{
|
||||
private void ClearInputs() {
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||
if (tb.Name != "SearchInput") tb.Text = "";
|
||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||
@ -412,27 +369,23 @@ namespace WGneu.Windows
|
||||
rb.IsChecked = false;
|
||||
}
|
||||
|
||||
private bool IsValid()
|
||||
{
|
||||
private bool IsValid() {
|
||||
return Valid.All(kv => kv.Value) &&
|
||||
Utils.FindVisualChilds<ComboBox>(this).All(cb => cb.ItemsSource == null || cb.SelectedItem != null);
|
||||
}
|
||||
|
||||
private void UpdateButtons()
|
||||
{
|
||||
private void UpdateButtons() {
|
||||
if (!IsEditing && !IsCreating) return;
|
||||
bool ch = HasChanged(), v = IsValid();
|
||||
ResetButton.IsEnabled = (ch);
|
||||
SaveButton.IsEnabled = (v && ch);
|
||||
}
|
||||
|
||||
private bool HasChanged()
|
||||
{
|
||||
private bool HasChanged() {
|
||||
return true; // TODO
|
||||
}
|
||||
|
||||
private void InputTextChanged(TextBox input, Func<TextBox, ValidationResult> checker)
|
||||
{
|
||||
private void InputTextChanged(TextBox input, Func<TextBox, ValidationResult> checker) {
|
||||
var res = checker(input);
|
||||
Valid[input] = res.IsValid;
|
||||
if (res.IsValid)
|
||||
@ -442,45 +395,37 @@ namespace WGneu.Windows
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void InputLostFocus(TextBox input, Func<TextBox, ValidationResult> checker, string? msg)
|
||||
{
|
||||
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)
|
||||
{
|
||||
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs e) {
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||
InputTextChanged((TextBox)sender, Validator.CheckPhoneNumber);
|
||||
}
|
||||
|
||||
private void PhoneNrInput_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void PhoneNrInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||
InputLostFocus((TextBox)sender, Validator.CheckPhoneNumber, null);
|
||||
}
|
||||
|
||||
private void EmailInput_TextChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void EmailInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||
InputTextChanged((TextBox)sender, Validator.CheckEmailAddress);
|
||||
}
|
||||
|
||||
private void EmailInput_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
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) {
|
||||
InputTextChanged((TextBox)sender, Validator.CheckLfbisNr);
|
||||
}
|
||||
|
||||
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||
InputLostFocus((TextBox)sender, Validator.CheckLfbisNr, "Betriebsnummer ungültig");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user