Compare commits
	
		
			2 Commits
		
	
	
		
			7468af3970
			...
			fb077bc557
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| fb077bc557 | |||
| 9229f27cf7 | 
| @@ -32,13 +32,13 @@ namespace Elwig { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         protected override void OnStartup(StartupEventArgs evt) { |         protected override void OnStartup(StartupEventArgs evt) { | ||||||
|             IEnumerable<string> branches = Array.Empty<string>(); |             Dictionary<string, string> branches = new(); | ||||||
|             using (var ctx = new AppDbContext()) { |             using (var ctx = new AppDbContext()) { | ||||||
|                 if (!ctx.Database.CanConnect()) { |                 if (!ctx.Database.CanConnect()) { | ||||||
|                     MessageBox.Show($"Invalid Database:\n\n{Config.DatabaseFile}", "Invalid Database", MessageBoxButton.OK, MessageBoxImage.Error); |                     MessageBox.Show($"Invalid Database:\n\n{Config.DatabaseFile}", "Invalid Database", MessageBoxButton.OK, MessageBoxImage.Error); | ||||||
|                     Shutdown(); |                     Shutdown(); | ||||||
|                 } else { |                 } else { | ||||||
|                     branches = ctx.Branches.Select(b => b.ZwstId).ToList(); |                     branches = ctx.Branches.ToDictionary(b => b.Name.ToLower(), b => b.ZwstId); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             Utils.RunBackground("HTML Initialization", () => Documents.Html.Init(PrintingReadyChanged)); |             Utils.RunBackground("HTML Initialization", () => Documents.Html.Init(PrintingReadyChanged)); | ||||||
| @@ -67,15 +67,15 @@ namespace Elwig { | |||||||
|             } |             } | ||||||
|             Scales = list; |             Scales = list; | ||||||
|  |  | ||||||
|             if (Config.ZwstId != null) { |             if (Config.Branch != null) { | ||||||
|                 if (!branches.Contains(Config.ZwstId)) { |                 if (!branches.ContainsKey(Config.Branch.ToLower())) { | ||||||
|                     MessageBox.Show("Invalid branch id in config!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error); |                     MessageBox.Show("Invalid branch name in config!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error); | ||||||
|                     Shutdown(); |                     Shutdown(); | ||||||
|                 } else { |                 } else { | ||||||
|                     ZwstId = Config.ZwstId; |                     ZwstId = branches[Config.Branch.ToLower()]; | ||||||
|                 } |                 } | ||||||
|             } else if (branches.Count() == 1) { |             } else if (branches.Count == 1) { | ||||||
|                 ZwstId = branches.First(); |                 ZwstId = branches.First().Value; | ||||||
|             } else { |             } else { | ||||||
|                 MessageBox.Show("Unable to determine local branch!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error); |                 MessageBox.Show("Unable to determine local branch!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error); | ||||||
|                 Shutdown(); |                 Shutdown(); | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ namespace Elwig.Helpers { | |||||||
|         private readonly string FileName; |         private readonly string FileName; | ||||||
|         public string DatabaseFile = App.DataPath + "database.sqlite3"; |         public string DatabaseFile = App.DataPath + "database.sqlite3"; | ||||||
|         public string? DatabaseLog = null; |         public string? DatabaseLog = null; | ||||||
|         public string? ZwstId = null; |         public string? Branch = null; | ||||||
|         public IEnumerable<string[]> Scales; |         public IEnumerable<string[]> Scales; | ||||||
|         private readonly LinkedList<string[]> ScaleList = new(); |         private readonly LinkedList<string[]> ScaleList = new(); | ||||||
|  |  | ||||||
| @@ -45,9 +45,9 @@ namespace Elwig.Helpers { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (ini == null || !ini.TryGetKey("general.branch", out string branch)) { |             if (ini == null || !ini.TryGetKey("general.branch", out string branch)) { | ||||||
|                 ZwstId = null; |                 Branch = null; | ||||||
|             } else { |             } else { | ||||||
|                 ZwstId = branch; |                 Branch = branch; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             ScaleList.Clear(); |             ScaleList.Clear(); | ||||||
|   | |||||||
| @@ -201,6 +201,7 @@ namespace Elwig.Windows { | |||||||
|             Utils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id); |             Utils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id); | ||||||
|             if (list != null && ortInput.SelectedItem == null && list.Count == 1) |             if (list != null && ortInput.SelectedItem == null && list.Count == 1) | ||||||
|                 ortInput.SelectedItem = list[0]; |                 ortInput.SelectedItem = list[0]; | ||||||
|  |             UpdateComboBox(ortInput); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) { |         protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) { | ||||||
| @@ -280,22 +281,31 @@ namespace Elwig.Windows { | |||||||
|             UpdateButtons(); |             UpdateButtons(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         protected void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) { |         private void UpdateComboBox(Control input) { | ||||||
|             var input = (ComboBox)sender; |             bool valid = false; | ||||||
|             if (input.ItemsSource != null && input.SelectedItem == null && RequiredInputs.Contains(input)) { |             if (input is ComboBox cb) { | ||||||
|                 ValidateInput(input, false); |                 valid = cb.ItemsSource == null || cb.SelectedItem != null || !RequiredInputs.Contains(input); | ||||||
|                 Utils.SetInputInvalid(input); |             } else if (input is CheckComboBox ccb) { | ||||||
|             } else { |                 valid = ccb.ItemsSource == null || ccb.SelectedItem != null || !RequiredInputs.Contains(input); | ||||||
|  |             } | ||||||
|  |             if (valid) { | ||||||
|                 ValidateInput(input, true); |                 ValidateInput(input, true); | ||||||
|                 if (InputHasChanged(input)) { |                 if (InputHasChanged(input)) { | ||||||
|                     Utils.SetInputChanged(input); |                     Utils.SetInputChanged(input); | ||||||
|                 } else { |                 } else { | ||||||
|                     Utils.ClearInputState(input); |                     Utils.ClearInputState(input); | ||||||
|                 } |                 } | ||||||
|  |             } else { | ||||||
|  |                 ValidateInput(input, false); | ||||||
|  |                 Utils.SetInputInvalid(input); | ||||||
|             } |             } | ||||||
|             UpdateButtons(); |             UpdateButtons(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         protected void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) { | ||||||
|  |             UpdateComboBox((Control)sender); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         protected void IntegerInput_TextChanged(object sender, RoutedEventArgs evt) { |         protected void IntegerInput_TextChanged(object sender, RoutedEventArgs evt) { | ||||||
|             InputTextChanged((TextBox)sender, Validator.CheckInteger); |             InputTextChanged((TextBox)sender, Validator.CheckInteger); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user