コード例 #1
0
        private void btn_devolver_Click(object sender, EventArgs e)
        {
            Entities.User user = service.userLogged();
            Rental        r    = user.lastRental();
            bool          err  = false;
            string        id   = "";

            try
            {
                if (txt_estacion.TextLength == 0)
                {
                    err = true;
                    MessageBox.Show("Por favor, indique una estación");
                }
                else
                {
                    if (r == null)
                    {
                        MessageBox.Show("No dispone de ningun alquiler");
                        throw new ServiceException("Ha-ha");
                    }
                    id = txt_estacion.Text;
                    if (btn_si.Checked == true)
                    {
                        Station st = service.findStationById(id);
                        service.returnScooter(r, st);
                        MessageBox.Show("Patinete devuelto, se procede a registrar incidente" + "\nPrecio del recorrido: " + r.Price);
                        registrarIncidente RegistrarIncidente = new registrarIncidente(service);
                        RegistrarIncidente.ShowDialog();
                        this.Hide();
                    }
                    else
                    {
                        if (btn_no.Checked == true)
                        {
                            Station st = service.findStationById(id);
                            service.returnScooter(r, st);
                            MessageBox.Show("Patinete devuelto sin incidentes" + "\nPrecio del recorrido: " + r.Price);
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("Por favor, seleccione si desea registrar un incidente");
                        }
                    }
                }
            }
            catch (ServiceException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ricardpons/ProyectoISW
        void returnScooters()
        {
            Console.WriteLine();
            Console.WriteLine("RETURN SCOOTERS...");

            try
            {
                service.login("user1", "user1");
                Station st    = service.findStationById("st2");
                User    us    = service.userLogged();
                Rental  r     = us.lastRental();
                decimal price = service.returnScooter(r, st);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            try
            {
                service.login("user1", "user1");
                Station st    = service.findStationById("st2");
                User    us    = service.userLogged();
                Rental  r     = us.lastRental();
                decimal price = service.returnScooter(r, st);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            try
            {
                service.login("user5", "user5");
                Station st    = service.findStationById("st3");
                User    us    = service.userLogged();
                Rental  r     = us.lastRental();
                decimal price = service.returnScooter(r, st);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            try
            {
                service.login("user6", "user6");
                Station  st = service.findStationById("st4");
                User     us = service.userLogged();
                Rental   r  = us.lastRental();
                Incident i  = new Incident("Crash with a mobile streetlamp", DateTime.Now);
                r.addIncident(i);
                decimal price = service.returnScooter(r, st);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            foreach (Rental r in service.getAllRentals())
            {
                Console.WriteLine(rentalToString(r));
                if (r.Incident != null)
                {
                    Console.WriteLine("      " + r.Incident.Description + " time: " + r.Incident.TimeStamp);
                }
            }
        }