Example #1
0
        private static void ReturnCar(ClientClass client)
        {
            Console.Clear();
            List <RentClass> rentsOfClient = RentService.GetRentsOfClient(client);

            if (rentsOfClient.Count == 0)
            {
                Console.Clear();
                Console.WriteLine("You have no rents");
                return;
            }

            foreach (var i in RentService.GetRentsOfClient(client))
            {
                Console.WriteLine("\nCar id: " + i.CurrentCar.CarId);
                Console.WriteLine("Car type: " + i.CurrentCar.Bodywork.Type);
                Console.WriteLine("Car color: " + i.CurrentCar.Bodywork.Color);
            }
            Console.Write("\nChoose car's id you want to return: ");
            if (UserInputInt(out int chosenCarId))
            {
                Console.Clear();
                CarClass tempCar = AutoParkService.SearchCarById(chosenCarId);
                if (tempCar != null && tempCar.CurrentClient == client)
                {
                    RentService.RemoveRent(RentService.GetRentByCarId(chosenCarId));
                    Console.WriteLine($"Car with id '{chosenCarId}' was successfully returned");
                    return;
                }
            }
            Console.Clear();
            Console.WriteLine("Id not found!");
        }
        public ShowCarsListForm()
        {
            InitializeComponent();
            int formHeight = AutoParkService.GetAllCars().Count * 13 + 10;

            listBox1.DataSource = AutoParkService.GetAllCars();
            button1.Location    = new Point(button1.Location.X, button1.Location.Y - (listBox1.Height - formHeight));
            listBox1.Height     = formHeight;
            Height = formHeight + 130;
        }
        public RentCarForm(ClientClass client)
        {
            this.client = client;
            InitializeComponent();
            int lHeight = AutoParkService.GetAvailableCars().Count * 13 + 10;

            listBox1.DataSource = AutoParkService.GetAvailableCars();
            button1.Location    = new Point(button1.Location.X, button1.Location.Y - (listBox1.Height - lHeight));
            listBox1.Height     = lHeight;
            Height = lHeight + 150;
        }
Example #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (AutoParkService.GetAvailableCars().Count == 0)
     {
         MessageBox.Show("No cars are available for renting now", "Autopark");
         return;
     }
     else
     {
         this.Hide();
         RentCarForm rc = new RentCarForm(client);
         rc.Closed += (s, args) => this.Show();
         rc.Show();
     }
 }
Example #5
0
        private static void RentCar(ClientClass client)
        {
            Console.Clear();
            //AutoParkService.PrintAvailableCars();
            CarClass chosenCar = AutoParkService.ChooseCar();

            Console.Clear();
            if (chosenCar != null)
            {
                RentService.AddNewRent(new RentClass(client, chosenCar));
                Console.WriteLine("Car with id '{0}' was successfully rented.", chosenCar.CarId);
            }
            else
            {
                Console.WriteLine("Id not found!");
            }
        }
Example #6
0
        public static void LaunchMenu(ClientClass client)
        {
            bool stopflag = false;

            Console.WriteLine($"Welcome, {client.FirstName}!");
            while (true)
            {
                if (client.Status == 0)
                {
                    Console.WriteLine("\nChoose option:\n1 - exit\n2 - rent a car\n3 - return rented car");
                }
                else
                {
                    Console.WriteLine("\nChoose option:\n1 - exit\n2 - rent a car\n3 - return rented car\n4 - print all cars\n5 - print all rents\n6 - print transactions history");
                }
                ConsoleKeyInfo UserInput = Console.ReadKey();
                Console.Clear();
                Console.WriteLine();
                if (char.IsDigit(UserInput.KeyChar))
                {
                    switch (int.Parse(UserInput.KeyChar.ToString()))
                    {
                    case 1:
                    {
                        stopflag = true;
                        break;
                    }

                    case 2:
                    {
                        RentCar(client);
                        break;
                    }

                    case 3:
                    {
                        ReturnCar(client);
                        break;
                    }

                    case 4:
                    {
                        if (client.Status != 1)
                        {
                            goto default;
                        }
                        Console.WriteLine("All cars in autopark:\n");
                        AutoParkService.PrintAllCars();
                        EndCase();
                        break;
                    }

                    case 5:
                    {
                        if (client.Status != 1)
                        {
                            goto default;
                        }
                        Console.WriteLine("All current rents:\n");
                        RentService.PrintAllRents();
                        EndCase();
                        break;
                    }

                    case 6:
                    {
                        if (client.Status != 1)
                        {
                            goto default;
                        }
                        Console.WriteLine($"Current income: {TransactionService.TotalAmount}\n");
                        Console.WriteLine("Transactions history:\n");
                        //TransactionService.PrintTransactionsHistory();
                        EndCase();
                        break;
                    }

                    default:
                    {
                        Console.Clear();
                        Console.WriteLine("Wrong input!");
                        break;
                    }
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Wrong input!");
                }
                if (stopflag)
                {
                    break;
                }
            }
            Console.Clear();
            Console.WriteLine("All rents:\n");
            RentService.PrintAllRents();
            Console.WriteLine("\n\nAll transactions:\n");
            //TransactionService.PrintAllTransactions();
            Console.ReadKey();
            return;
        }
Example #7
0
        public RentClass Search(string rentId)
        {
            string          query  = "SELECT * FROM rents WHERE rentId='" + rentId + "'";
            RentClass       rent   = null;
            MySqlDataReader reader = GetReader(query);

            try
            {
                reader.Read();
                rent = new RentClass(int.Parse(reader[0].ToString()), ClientService.SearchClientById(int.Parse(reader[1].ToString())), AutoParkService.SearchCarById(int.Parse(reader[2].ToString())), DateTime.Parse(reader[3].ToString()), DateTime.Parse(reader[4].ToString()));
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { reader.Close(); }
            return(rent);

            throw new NotImplementedException();
        }
Example #8
0
        public IEnumerable <RentClass> GetList()
        {
            string          query  = "SELECT * FROM rents";
            MySqlDataReader reader = GetReader(query);

            while (reader.Read())
            {
                yield return(new RentClass(int.Parse(reader[0].ToString()), ClientService.SearchClientById(int.Parse(reader[1].ToString())), AutoParkService.SearchCarById(int.Parse(reader[2].ToString())), DateTime.Parse(reader[3].ToString()), DateTime.Parse(reader[4].ToString())));
            }
            reader.Close();
        }