private void btn_alquilar_Click(object sender, EventArgs e)
 {
     try
     {
         if (txt_idEstacion.TextLength == 0)
         {
             MessageBox.Show("Introduce el id de la estaciĆ³n!");
         }
         else
         {
             Station st = service.findStationById(txt_idEstacion.Text);
             Scooter sc = st.chooseScooterToRent();
             User    u  = service.userLogged();
             Rental  r  = new Rental(DateTime.Now, st, sc, u);
             service.rentScooter(r);
         }
     }
     catch (ServiceException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #2
0
        void rentScooters()
        {
            Console.WriteLine();
            Console.WriteLine("RENTING SCOOTERS...");

            try
            {
                service.login("user1", "user1");
                Station st = service.findStationById("st1");
                Scooter sc = st.chooseScooterToRent();
                User    us = service.userLogged();
                // public Rental(DateTime startDate, Station originStation, Scooter scooter, User user)
                Rental rental = new Rental(DateTime.Now.AddMinutes(-800), st, sc, us);
                service.rentScooter(rental);
                service.logout();
            }
            catch (Exception e)
            {
                printError(e);
            }

            try
            {
                service.login("user1", "user1");
                Station st = service.findStationById("st1");
                Scooter sc = st.chooseScooterToRent();
                User    us = service.userLogged();
                // public Rental(DateTime startDate, Station originStation, Scooter scooter, User user)
                Rental rental = new Rental(DateTime.Now.AddMinutes(-800), st, sc, us);
                service.rentScooter(rental);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            try
            {
                service.login("user5", "user5");
                Station st = service.findStationById("st1");
                Scooter sc = st.chooseScooterToRent();
                User    us = service.userLogged();
                // public Rental(DateTime startDate, Station originStation, Scooter scooter, User user)
                Rental rental = new Rental(DateTime.Now.AddMinutes(-400), st, sc, us);
                service.rentScooter(rental);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            try
            {
                service.login("user6", "user6");
                Station st = service.findStationById("st1");
                Scooter sc = st.chooseScooterToRent();
                User    us = service.userLogged();
                // public Rental(DateTime startDate, Station originStation, Scooter scooter, User user)
                Rental rental = new Rental(DateTime.Now.AddMinutes(-200), st, sc, us);
                service.rentScooter(rental);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            try
            {
                service.login("user7", "user7");
                Station st = service.findStationById("st1");
                Scooter sc = st.chooseScooterToRent();
                User    us = service.userLogged();
                // public Rental(DateTime startDate, Station originStation, Scooter scooter, User user)
                Rental rental = new Rental(DateTime.Now.AddMinutes(-200), st, sc, us);
                service.rentScooter(rental);
            }
            catch (Exception e)
            {
                printError(e);
            }
            service.logout();

            foreach (Scooter s in service.getAllScooters())
            {
                Console.WriteLine(scooterToString(s));
            }
        }