Ejemplo n.º 1
0
        public AlquileresView()
        {
            InitializeComponent();

            alquileresViewModel = (AlquileresViewModel)this.DataContext;

            panel.IsEnabled = false;
            alquileresViewModel.PanelLoading = true;

            Thread t = new Thread(new ThreadStart(() =>
            {
                ServerServiceAlquiler serverServiceAlquiler   = new ServerServiceAlquiler();
                ServerResponseAlquiler serverResponseAlquiler = serverServiceAlquiler.GetAll();

                if (200 == serverResponseAlquiler.error.code)
                {
                    foreach (var item in serverResponseAlquiler.listaAlquiler)
                    {
                        Dispatcher.Invoke(new Action(() => { observableCollectionAlquiler.Add(item); }));
                    }
                }
                else
                {
                    Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlquiler.error.message); }));
                }

                Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; }));
                Dispatcher.Invoke(new Action(() => { alquileresViewModel.PanelLoading = false; }));
                Dispatcher.Invoke(new Action(() => { lstAlq.ItemsSource = observableCollectionAlquiler; }));
            }));

            t.Start();
        }
Ejemplo n.º 2
0
        private void btnBuscar_Click(object sender, RoutedEventArgs e)
        {
            panel.IsEnabled = false;
            alquileresViewModel.PanelLoading = true;

            string cliente   = "null";
            string matricula = "null";

            if (!txtCliente.Text.Equals(""))
            {
                cliente = txtCliente.Text.ToString();
            }

            if (!txtMatricula.Text.Equals(""))
            {
                matricula = txtMatricula.Text.ToString();
            }

            Thread t = new Thread(new ThreadStart(() =>
            {
                ServerServiceAlquiler serverServiceAlquiler   = new ServerServiceAlquiler();
                ServerResponseAlquiler serverResponseAlquiler = serverServiceAlquiler.GetAllFilter(cliente, matricula, "null");

                if (200 == serverResponseAlquiler.error.code)
                {
                    //Limpiar la lista para recuperar la informacion de la busqueda
                    Dispatcher.Invoke(new Action(() => { observableCollectionAlquiler.Clear(); }));

                    foreach (var item in serverResponseAlquiler.listaAlquiler)
                    {
                        Dispatcher.Invoke(new Action(() => { observableCollectionAlquiler.Add(item); }));
                    }
                }
                else
                {
                    Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlquiler.error.message); }));
                }

                Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; }));
                Dispatcher.Invoke(new Action(() => { alquileresViewModel.PanelLoading = false; }));
            }));

            t.Start();
        }
        private void btnAceptarAlquileres_Click(object sender, RoutedEventArgs e)
        {
            if (modo == 1)
            {
                var dialog = new CustomMessageBox
                {
                    Caption            = "Nuevo",
                    InstructionHeading = "¿Está seguro que quiere guardar el alquiler?",
                    InstructionText    = "Esta acción guardará la información del alquiler",
                };
                dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel);

                var result = dialog.ShowDialog();
                if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1)
                {
                    if (cambiosAlquiler())
                    {
                        //TODO REVISAR
                        alquilerModif.tipoImporte = "Pendiente";

                        txtError.Text = "";

                        panel.IsEnabled = false;
                        gestionAlquileresViewModel.PanelLoading = true;

                        Thread t = new Thread(new ThreadStart(() =>
                        {
                            ServerServiceAlquiler serverServiceAlquiler   = new ServerServiceAlquiler();
                            ServerResponseAlquiler serverResponseAlquiler = serverServiceAlquiler.Save(alquilerModif, "null");

                            if (200 == serverResponseAlquiler.error.code)
                            {
                                Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Nuevo", "Se ha guardado el alquiler correctamente."); }));

                                Dispatcher.Invoke(new Action(() => { gestionAlquileresViewModel.alquiler = alquilerModif; }));
                                Dispatcher.Invoke(new Action(() => { volver(); }));
                            }
                            else
                            {
                                Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlquiler.error.message); }));
                            }

                            Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; }));
                            Dispatcher.Invoke(new Action(() => { gestionAlquileresViewModel.PanelLoading = false; }));
                        }));

                        t.Start();
                    }
                }
            }
            else
            {
                var dialog = new CustomMessageBox
                {
                    Caption            = "Modificar",
                    InstructionHeading = "¿Está seguro que quiere modificar el alquiler?",
                    InstructionText    = "Esta acción modificará la información del alquiler",
                };
                dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel);

                var result = dialog.ShowDialog();
                if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1)
                {
                    if (cambiosAlquiler())
                    {
                        txtError.Text = "";

                        panel.IsEnabled = false;
                        gestionAlquileresViewModel.PanelLoading = true;

                        Thread t = new Thread(new ThreadStart(() =>
                        {
                            ServerServiceAlquiler serverServiceAlquiler   = new ServerServiceAlquiler();
                            ServerResponseAlquiler serverResponseAlquiler = serverServiceAlquiler.Save(alquilerModif, alquilerModif.id);

                            if (200 == serverResponseAlquiler.error.code)
                            {
                                Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Modificar", "Se ha modificado el alquiler correctamente."); }));

                                Dispatcher.Invoke(new Action(() => { gestionAlquileresViewModel.alquiler = alquilerModif; }));
                                Dispatcher.Invoke(new Action(() => { volver(); }));
                            }
                            else
                            {
                                Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlquiler.error.message); }));
                            }

                            Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; }));
                            Dispatcher.Invoke(new Action(() => { gestionAlquileresViewModel.PanelLoading = false; }));
                        }));

                        t.Start();
                    }
                }
            }
        }