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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        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();
            }
        }
        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();
                    }
                }
            }
        }