/// <summary> /// Initializes combo boxes from data on database /// </summary> private void InitOther() { List <int> years = Enumerable.Range(2000, DateTime.Today.Year - 1999).ToList(); this.YearsBox.ItemsSource = years; List <String> months = new List <string> { "TODOS", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; this.Meses.ItemsSource = months; new Thread(() => { Thread.CurrentThread.IsBackground = true; Dictionary <string, List <string> > data = null; try { data = BDManager.GetDistinct(new string[] { "Nodo" }); } catch (MySqlException e) { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.setErrorCodeMessage(e.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } if (data != null) { List <String> nodos; bool valueWasRetrieved = data.TryGetValue("Nodo", out nodos); if (valueWasRetrieved) { foreach (var nodo in nodos) { this.Nodos.Dispatcher.Invoke(() => this.Nodos.Items.Add(nodo)); } this.Nodos.Dispatcher.Invoke(() => this.Nodos.Items.Add("TODOS")); } else { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.NotNodosKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } } else { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.ConnectionFailed, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } }).Start(); }
/// <summary> /// Sets the values of different combo boxes /// </summary> private void InitOtherComponents() { new Thread(() => { Thread.CurrentThread.IsBackground = true; Dictionary <string, List <string> > data = null; try { data = BDManager.GetDistinct(new string[] { "Barrio", "Nodo", "Megas" }); } catch (MySqlException e) { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.setErrorCodeMessage(e.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } if (data != null) { List <string> barrios; bool valueWasRetrieved = data.TryGetValue("Barrio", out barrios); if (valueWasRetrieved) { foreach (var barrio in barrios) { this.BarrioBox.Dispatcher.Invoke(() => this.BarrioBox.Items.Add(barrio)); } } else { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.NotBarriosKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } List <String> nodos; valueWasRetrieved = data.TryGetValue("Nodo", out nodos); if (valueWasRetrieved) { foreach (var nodo in nodos) { this.NodoBox.Dispatcher.Invoke(() => this.NodoBox.Items.Add(nodo)); } } else { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.NotNodosKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } List <String> megas; valueWasRetrieved = data.TryGetValue("Megas", out megas); if (valueWasRetrieved) { foreach (var _megas in megas) { this.MegasBox.Dispatcher.Invoke(() => this.MegasBox.Items.Add(_megas)); } } else { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.NotMegasKeyFound, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); } return; } else { this.Dispatcher.Invoke(delegate { SystemSounds.Beep.Play(); MessageBox.Show(Messages.Errors.ConnectionFailed, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error); }); return; } }).Start(); }