Small fixes
This commit is contained in:
		@@ -14,7 +14,7 @@ namespace WGneu.Print {
 | 
				
			|||||||
        private static readonly string CHROMIUM = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
 | 
					        private static readonly string CHROMIUM = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
 | 
				
			||||||
        private static IBrowser? Browser = null;
 | 
					        private static IBrowser? Browser = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public static async void Init() {
 | 
					        public static async Task Init() {
 | 
				
			||||||
            Browser = await Puppeteer.LaunchAsync(new LaunchOptions {
 | 
					            Browser = await Puppeteer.LaunchAsync(new LaunchOptions {
 | 
				
			||||||
                Headless = true,
 | 
					                Headless = true,
 | 
				
			||||||
                ExecutablePath = CHROMIUM,
 | 
					                ExecutablePath = CHROMIUM,
 | 
				
			||||||
@@ -23,7 +23,7 @@ namespace WGneu.Print {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public static async Task Convert(string path_html, string path_pdf) {
 | 
					        public static async Task Convert(string path_html, string path_pdf) {
 | 
				
			||||||
            if (Browser == null)
 | 
					            if (Browser == null)
 | 
				
			||||||
                Init();
 | 
					                await Init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using var page = await Browser?.NewPageAsync();
 | 
					            using var page = await Browser?.NewPageAsync();
 | 
				
			||||||
            await page.GoToAsync("file://" + path_html);
 | 
					            await page.GoToAsync("file://" + path_html);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,10 @@ namespace WGneu {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj, IEnumerable<DependencyObject> exempt) where T : DependencyObject {
 | 
				
			||||||
 | 
					            return FindVisualChilds<T>(depObj).Where(c => !exempt.Contains(c));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public static int Modulo(string a, int b) {
 | 
					        public static int Modulo(string a, int b) {
 | 
				
			||||||
            if (!a.All(char.IsDigit))
 | 
					            if (!a.All(char.IsDigit))
 | 
				
			||||||
                throw new ArgumentException("First argument has to be a decimal string");
 | 
					                throw new ArgumentException("First argument has to be a decimal string");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,17 +24,23 @@ namespace WGneu.Windows {
 | 
				
			|||||||
        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 readonly Control[] ExemptInputs;
 | 
				
			||||||
        private readonly Dictionary<Control, bool> Valid = new();
 | 
					        private readonly Dictionary<Control, bool> Valid = new();
 | 
				
			||||||
        private readonly Dictionary<Control, object?> OriginalValues = new();
 | 
					        private readonly Dictionary<Control, object?> OriginalValues = new();
 | 
				
			||||||
        private static readonly RoutedCommand CtrlF = new();
 | 
					        private readonly RoutedCommand CtrlF = new();
 | 
				
			||||||
        private readonly WgContext Context = new();
 | 
					        private readonly WgContext Context = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public MemberListWindow() {
 | 
					        public MemberListWindow() {
 | 
				
			||||||
            InitializeComponent();
 | 
					            InitializeComponent();
 | 
				
			||||||
            CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
 | 
					            CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
 | 
				
			||||||
            CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
 | 
					            CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
 | 
				
			||||||
            foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
 | 
					            ExemptInputs = new Control[] {
 | 
				
			||||||
                if (tb.Name != "SearchInput") Valid[tb] = true;
 | 
					                SearchInput, ActiveMemberInput, MemberList,
 | 
				
			||||||
 | 
					                NewMemberButton, EditMemberButton, DeleteMemberButton,
 | 
				
			||||||
 | 
					                ResetButton, SaveButton, CancelButton
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					            foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
 | 
				
			||||||
 | 
					                Valid[tb] = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Window_Loaded(object sender, RoutedEventArgs e) {
 | 
					        private void Window_Loaded(object sender, RoutedEventArgs e) {
 | 
				
			||||||
@@ -86,13 +92,13 @@ namespace WGneu.Windows {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void ClearInputStates() {
 | 
					        private void ClearInputStates() {
 | 
				
			||||||
            foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
 | 
					            foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
 | 
				
			||||||
                if (tb.Name != "SearchInput") Utils.ClearInputState(tb);
 | 
					                Utils.ClearInputState(tb);
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
 | 
				
			||||||
                Utils.ClearInputState(cb);
 | 
					                Utils.ClearInputState(cb);
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
 | 
				
			||||||
                if (cb.Name != "ActiveMemberInput") Utils.ClearInputState(cb);
 | 
					                Utils.ClearInputState(cb);
 | 
				
			||||||
            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
 | 
					            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
 | 
				
			||||||
                Utils.ClearInputState(rb);
 | 
					                Utils.ClearInputState(rb);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -305,24 +311,24 @@ namespace WGneu.Windows {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void LockInputs() {
 | 
					        private void LockInputs() {
 | 
				
			||||||
            foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
 | 
					            foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
 | 
				
			||||||
                if (tb.Name != "SearchInput") tb.IsReadOnly = true;
 | 
					                tb.IsReadOnly = true;
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
 | 
				
			||||||
                cb.IsEnabled = false;
 | 
					                cb.IsEnabled = false;
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
 | 
				
			||||||
                if (cb.Name != "ActiveMemberInput") cb.IsEnabled = false;
 | 
					                cb.IsEnabled = false;
 | 
				
			||||||
            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
 | 
					            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
 | 
				
			||||||
                rb.IsEnabled = false;
 | 
					                rb.IsEnabled = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void UnlockInputs() {
 | 
					        private void UnlockInputs() {
 | 
				
			||||||
            foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
 | 
					            foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
 | 
				
			||||||
                if (tb.Name != "SearchInput") tb.IsReadOnly = false;
 | 
					                tb.IsReadOnly = false;
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
 | 
				
			||||||
                cb.IsEnabled = true;
 | 
					                cb.IsEnabled = true;
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
 | 
				
			||||||
                if (cb.Name != "ActiveMemberInput") cb.IsEnabled = true;
 | 
					                cb.IsEnabled = true;
 | 
				
			||||||
            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
 | 
					            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
 | 
				
			||||||
                rb.IsEnabled = true;
 | 
					                rb.IsEnabled = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -387,31 +393,31 @@ namespace WGneu.Windows {
 | 
				
			|||||||
                case "email": ContactEmailInput.IsChecked = true; break;
 | 
					                case "email": ContactEmailInput.IsChecked = true; break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
 | 
					            foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
 | 
				
			||||||
                if (tb.Name != "SearchInput") OriginalValues[tb] = tb.Text;
 | 
					                OriginalValues[tb] = tb.Text;
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
 | 
				
			||||||
                OriginalValues[cb] = cb.SelectedItem;
 | 
					                OriginalValues[cb] = cb.SelectedItem;
 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
 | 
					            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
 | 
				
			||||||
                if (cb.Name != "ActiveMemberInput") OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null;
 | 
					                OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null;
 | 
				
			||||||
            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
 | 
					            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
 | 
				
			||||||
                OriginalValues[rb] = (rb.IsChecked ?? false) ? bool.TrueString : null;
 | 
					                OriginalValues[rb] = (rb.IsChecked ?? false) ? bool.TrueString : null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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))
 | 
					 | 
				
			||||||
                cb.SelectedItem = null;
 | 
					 | 
				
			||||||
            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
 | 
					 | 
				
			||||||
                if (cb.Name != "ActiveMemberInput") cb.IsChecked = false;
 | 
					 | 
				
			||||||
            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
 | 
					 | 
				
			||||||
                rb.IsChecked = false;
 | 
					 | 
				
			||||||
            OriginalValues.Clear();
 | 
					            OriginalValues.Clear();
 | 
				
			||||||
 | 
					            foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
 | 
				
			||||||
 | 
					                tb.Text = "";
 | 
				
			||||||
 | 
					            foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
 | 
				
			||||||
 | 
					                cb.SelectedItem = null;
 | 
				
			||||||
 | 
					            foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
 | 
				
			||||||
 | 
					                cb.IsChecked = false;
 | 
				
			||||||
 | 
					            foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
 | 
				
			||||||
 | 
					                rb.IsChecked = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private bool IsValid() {
 | 
					        private bool IsValid() {
 | 
				
			||||||
            return Valid.All(kv => kv.Value) &&
 | 
					            return Valid.All(kv => kv.Value) &&
 | 
				
			||||||
                Utils.FindVisualChilds<ComboBox>(this).All(cb => cb.ItemsSource == null || cb.SelectedItem != null);
 | 
					                Utils.FindVisualChilds<ComboBox>(this, ExemptInputs).All(cb => cb.ItemsSource == null || cb.SelectedItem != null);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void UpdateButtons() {
 | 
					        private void UpdateButtons() {
 | 
				
			||||||
@@ -439,10 +445,10 @@ namespace WGneu.Windows {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        private bool HasChanged() {
 | 
					        private bool HasChanged() {
 | 
				
			||||||
            return !IsValid() ||
 | 
					            return !IsValid() ||
 | 
				
			||||||
                Utils.FindVisualChilds<TextBox>(this).Any(InputHasChanged) ||
 | 
					                Utils.FindVisualChilds<TextBox>(this, ExemptInputs).Any(InputHasChanged) ||
 | 
				
			||||||
                Utils.FindVisualChilds<ComboBox>(this).Any(InputHasChanged) ||
 | 
					                Utils.FindVisualChilds<ComboBox>(this, ExemptInputs).Any(InputHasChanged) ||
 | 
				
			||||||
                Utils.FindVisualChilds<CheckBox>(this).Any(InputHasChanged) ||
 | 
					                Utils.FindVisualChilds<CheckBox>(this, ExemptInputs).Any(InputHasChanged) ||
 | 
				
			||||||
                Utils.FindVisualChilds<RadioButton>(this).Any(InputHasChanged);
 | 
					                Utils.FindVisualChilds<RadioButton>(this, ExemptInputs).Any(InputHasChanged);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void UpdatePlz(TextBox plzInput, ComboBox ortInput) {
 | 
					        private void UpdatePlz(TextBox plzInput, ComboBox ortInput) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user