public InicioView() { InitializeComponent(); inicioViewModel = (InicioViewModel)this.DataContext; panel.IsEnabled = false; inicioViewModel.PanelLoading = true; cmbTipo.ItemsSource = inicioViewModel.observableCollectionTipoAlerta; Thread t = new Thread(new ThreadStart(() => { Dispatcher.Invoke(new Action(() => { inicioViewModel.cargaCombo(); })); ServerServiceAlerta serverServiceAlerta = new ServerServiceAlerta(); ServerResponseAlerta serverResponseAlerta = serverServiceAlerta.GetAll(); if (200 == serverResponseAlerta.error.code) { foreach (var item in serverResponseAlerta.listaAlerta) { if (7 >= item.vencimiento) { item.urlImage = "/Images/ico_rojo.png"; } else { item.urlImage = "/Images/ico_amarillo.png"; } Dispatcher.Invoke(new Action(() => { observableCollectionAlerta.Add(item); })); } } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlerta.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { inicioViewModel.PanelLoading = false; })); Dispatcher.Invoke(new Action(() => { lstAle.ItemsSource = observableCollectionAlerta; })); })); t.Start(); }
/** *------------------------------------------------------------------------------ * Metodos para controlar los botones *------------------------------------------------------------------------------ **/ private void btnBuscar_Click(object sender, RoutedEventArgs e) { panel.IsEnabled = false; inicioViewModel.PanelLoading = true; Object selectedTipo = cmbTipo.SelectedItem; string tipo = "null"; string cliente = "null"; string matricula = "null"; if (null != selectedTipo && 0 < cmbTipo.SelectedIndex) { tipo = selectedTipo.ToString(); foreach (var item in inicioViewModel.ListaTipoAlerta) { if (item.nombre.Equals(tipo)) { tipo = item.id; } } } if (!txtCliente.Text.Equals("")) { cliente = txtCliente.Text.ToString(); } if (!txtMatricula.Text.Equals("")) { matricula = txtMatricula.Text.ToString(); } Thread t = new Thread(new ThreadStart(() => { ServerServiceAlerta serverServiceAlerta = new ServerServiceAlerta(); ServerResponseAlerta serverResponseAlerta = serverServiceAlerta.GetAllFilter(tipo, cliente, matricula); if (200 == serverResponseAlerta.error.code) { //Limpiar la lista para recuperar la informacion de la busqueda Dispatcher.Invoke(new Action(() => { observableCollectionAlerta.Clear(); })); foreach (var item in serverResponseAlerta.listaAlerta) { if (7 >= item.vencimiento) { item.urlImage = "/Images/ico_rojo.png"; } else { item.urlImage = "/Images/ico_amarillo.png"; } Dispatcher.Invoke(new Action(() => { observableCollectionAlerta.Add(item); })); } } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlerta.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { inicioViewModel.PanelLoading = false; })); Dispatcher.Invoke(new Action(() => { lstAle.ItemsSource = observableCollectionAlerta; })); })); t.Start(); }