public ClientesView() { InitializeComponent(); clientesViewModel = (ClientesViewModel)this.DataContext; panel.IsEnabled = false; clientesViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceCliente serverServiceCliente = new ServerServiceCliente(); ServerResponseCliente serverResponseCliente = serverServiceCliente.GetAll(); if (200 == serverResponseCliente.error.code) { foreach (var item in serverResponseCliente.listaCliente) { Dispatcher.Invoke(new Action(() => { observableCollectionCliente.Add(item); })); } } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseCliente.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { clientesViewModel.PanelLoading = false; })); Dispatcher.Invoke(new Action(() => { lstCli.ItemsSource = observableCollectionCliente; })); })); t.Start(); }
public void cargaComboClientes() { panel.IsEnabled = false; gestionAlquileresViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceCliente serverServiceCliente = new ServerServiceCliente(); ServerResponseCliente serverResponseCliente = serverServiceCliente.GetAll(); if (200 == serverResponseCliente.error.code) { Dispatcher.Invoke(new Action(() => { listaClientes = serverResponseCliente.listaCliente; })); foreach (var item in serverResponseCliente.listaCliente) { if (null == gestionAlquileresViewModel.alquiler || !gestionAlquileresViewModel.alquiler.cliente.nif.Equals(item.nif)) { Dispatcher.Invoke(new Action(() => { observableCollectionClientes.Add(item.nombre); })); } } Dispatcher.Invoke(new Action(() => { cmbCliente.SelectedIndex = 0; })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionAlquileresViewModel.PanelLoading = false; })); })); t.Start(); }
/// <summary> /// Devuelve todos los datos /// </summary> /// <returns>ServerResponseCliente</returns> public ServerResponseCliente GetAll() { ServerResponseCliente serverResponseCliente; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + CLIENTE + "all"; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "GET"; httpRequest.Accept = "application/json"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseCliente = JsonSerializer.Deserialize <ServerResponseCliente>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseCliente = new ServerResponseCliente(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCliente.error = error; } } catch (System.Exception) { serverResponseCliente = new ServerResponseCliente(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCliente.error = error; } return(serverResponseCliente); }
private void btnBuscar_Click(object sender, RoutedEventArgs e) { panel.IsEnabled = false; clientesViewModel.PanelLoading = true; string nif = "null"; string cliente = "null"; if (!txtNif.Text.Equals("")) { nif = txtNif.Text.ToString(); } if (!txtCliente.Text.Equals("")) { cliente = txtCliente.Text.ToString(); } Thread t = new Thread(new ThreadStart(() => { ServerServiceCliente serverServiceCliente = new ServerServiceCliente(); ServerResponseCliente serverResponseCliente = serverServiceCliente.GetAllFilter(nif, cliente); if (200 == serverResponseCliente.error.code) { //Limpiar la lista para recuperar la informacion de la busqueda Dispatcher.Invoke(new Action(() => { observableCollectionCliente.Clear(); })); foreach (var item in serverResponseCliente.listaCliente) { Dispatcher.Invoke(new Action(() => { observableCollectionCliente.Add(item); })); } } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseCliente.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { clientesViewModel.PanelLoading = false; })); Dispatcher.Invoke(new Action(() => { lstCli.ItemsSource = observableCollectionCliente; })); })); t.Start(); }
private void btnBaja_Click(object sender, RoutedEventArgs e) { var dialog = new CustomMessageBox { Caption = "Baja", InstructionHeading = "¿Está seguro que quiere dar de baja el cliente?", InstructionText = "Esta acción dará de baja toda la información asociada a dicho cliente", }; dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel); var result = dialog.ShowDialog(); if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1) { panel.IsEnabled = false; gestionClientesViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceCliente serverServiceCliente = new ServerServiceCliente(); ServerResponseCliente serverResponseCliente = serverServiceCliente.Delete(gestionClientesViewModel.cliente.id); if (200 == serverResponseCliente.error.code) { Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Baja", "Se ha dado de baja el cliente correctamente."); })); Dispatcher.Invoke(new Action(() => { modo = Constantes.BAJA; })); Dispatcher.Invoke(new Action(() => { volver(); })); } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseCliente.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionClientesViewModel.PanelLoading = false; })); })); t.Start(); } }
/// <summary> /// Con el id "null" guarda un nuevo objeto y, en caso contrario, modifica el objeto de la BD /// </summary> /// <param name="clienteDTO">objeto de BD</param> /// <param name="id"></param> /// <returns>ServerResponseCliente</returns> public ServerResponseCliente Save(ClienteDTO clienteDTO, string id) { ServerResponseCliente serverResponseCliente; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + CLIENTE + "save/" + id; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; httpRequest.ContentType = "application/json"; Cliente cliente = transformClienteDTOToCliente(clienteDTO); if (null != cliente) { var data = JsonSerializer.Serialize <Cliente>(cliente); using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream())) { streamWriter.Write(data); } var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseCliente = JsonSerializer.Deserialize <ServerResponseCliente>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseCliente = new ServerResponseCliente(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCliente.error = error; } } else { serverResponseCliente = new ServerResponseCliente(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCliente.error = error; } } catch (System.Exception) { serverResponseCliente = new ServerResponseCliente(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCliente.error = error; } return(serverResponseCliente); }
private void btnAceptarClientes_Click(object sender, RoutedEventArgs e) { if (modo == Constantes.NUEVO) { var dialog = new CustomMessageBox { Caption = "Nuevo", InstructionHeading = "¿Está seguro que quiere guardar el cliente?", InstructionText = "Esta acción guardará la información del cliente", }; dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel); var result = dialog.ShowDialog(); if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1) { if (cambiosCliente()) { txtError.Text = ""; panel.IsEnabled = false; gestionClientesViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceCliente serverServiceCliente = new ServerServiceCliente(); ServerResponseCliente serverResponseCliente = serverServiceCliente.Save(clienteModif, "null"); if (200 == serverResponseCliente.error.code) { Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Nuevo", "Se ha guardado el cliente correctamente."); })); Dispatcher.Invoke(new Action(() => { gestionClientesViewModel.cliente = clienteModif; })); Dispatcher.Invoke(new Action(() => { volver(); })); } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseCliente.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionClientesViewModel.PanelLoading = false; })); })); t.Start(); } } } else { var dialog = new CustomMessageBox { Caption = "Modificar", InstructionHeading = "¿Está seguro que quiere modificar el cliente?", InstructionText = "Esta acción modificará la información del cliente", }; dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel); var result = dialog.ShowDialog(); if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1) { if (cambiosCliente()) { txtError.Text = ""; panel.IsEnabled = false; gestionClientesViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceCliente serverServiceCliente = new ServerServiceCliente(); ServerResponseCliente serverResponseCliente = serverServiceCliente.Save(clienteModif, clienteModif.id); if (200 == serverResponseCliente.error.code) { Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Modificar", "Se ha modificado el cliente correctamente."); })); Dispatcher.Invoke(new Action(() => { gestionClientesViewModel.cliente = clienteModif; })); Dispatcher.Invoke(new Action(() => { volver(); })); } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseCliente.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionClientesViewModel.PanelLoading = false; })); })); t.Start(); } } } }