Ejemplo n.º 1
0
        static void DisplayListAvailableCars(DataTable dt, string startDate, string endDate, SqlConnection con)
        {
            Console.Clear();

            int width = Console.WindowWidth;

            width = width / 6;
            Write.WriteProgress("CarID", 1, 1);
            Write.WriteProgress("Plate", width, 1);
            Write.WriteProgress("Manufacturer", 2 * width, 1);
            Write.WriteProgress("Model", 3 * width, 1);
            Write.WriteProgress("Price Per Day", 4 * width, 1);
            Write.WriteProgress("Location", 5 * width, 1);
            int r = 3;

            foreach (DataRow row in dt.Rows)
            {
                int carId = int.Parse(row["CarID"].ToString());
                if (Register_New_Rent.CarAvailable(con, carId.ToString(), DateTime.Parse(startDate), DateTime.Parse(endDate)))
                {
                    Write.WriteProgress(row["CarID"].ToString(), 1, r);
                    Write.WriteProgress(row["Plate"].ToString(), width, r);
                    Write.WriteProgress(row["Manufacturer"].ToString(), 2 * width, r);
                    Write.WriteProgress(row["Model"].ToString(), 3 * width, r);
                    Write.WriteProgress(row["PricePerDay"].ToString(), 4 * width, r);
                    Write.WriteProgress(row["Location"].ToString(), 5 * width, r);
                    r++;
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Sort by:");
            Console.WriteLine("1 - CarID");
            Console.WriteLine("2 - Plate");
            Console.WriteLine("3 - Manufacturer");
            Console.WriteLine("4 - Model");
            Console.WriteLine("5 - Price Per Day");
            Console.WriteLine("6 - Location");
        }
Ejemplo n.º 2
0
        public static void ListAvailableCars()
        {
            Console.Clear();
            string        conString = "Data Source=DESKTOP-MJA5A7T;Initial Catalog=Car Rent;Integrated Security=True";
            SqlConnection con       = new SqlConnection(conString);

            con.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter("select Cars.CarID,Plate, Model, Manufacturer, PricePerDay, Reservations.Location  from Cars join Reservations on Cars.CarID=Reservations.CarID", con);
            DataTable      dt          = new DataTable();

            dataAdapter.Fill(dt);
            Console.WriteLine("Start date:");
            string startDate = "";

            while (startDate == "")
            {
                startDate = Console.ReadLine();
                if (!(Register_New_Rent.DataValidation(startDate)))
                {
                    Console.WriteLine("Invalid data");
                }
            }
            Console.WriteLine("End Date:");
            string endDate = "";

            while (endDate == "")
            {
                endDate = Console.ReadLine();
                if (!(Register_New_Rent.DataValidation(endDate)))
                {
                    Console.WriteLine("Invalid data");
                }
            }
            DisplayListAvailableCars(dt, startDate, endDate, con);
            int column     = 0;
            int prevColumn = 0;

            while (true)
            {
                column = int.Parse(Console.ReadLine());
                if (column == prevColumn)
                {
                    switch (column)
                    {
                    case 1:
                        dt = OrderBy.OrderByCarIDDesc(dt);
                        break;

                    case 2:
                        dt = OrderBy.OrderByPlateDesc(dt);
                        break;

                    case 3:
                        dt = OrderBy.OrderByManufacturerDesc(dt);
                        break;

                    case 4:
                        dt = OrderBy.OrderByModelDesc(dt);
                        break;

                    case 5:
                        dt = OrderBy.OrderByPricePerDayDesc(dt);
                        break;

                    case 6:
                        dt = OrderBy.OrderByLocationDesc(dt);
                        break;
                    }
                }
                else
                {
                    switch (column)
                    {
                    case 1:
                        dt = OrderBy.OrderByCarID(dt);
                        break;

                    case 2:
                        dt = OrderBy.OrderByPlate(dt);
                        break;

                    case 3:
                        dt = OrderBy.OrderByManufacturer(dt);
                        break;

                    case 4:
                        dt = OrderBy.OrderByModel(dt);
                        break;

                    case 5:
                        dt = OrderBy.OrderByPricePerDay(dt);
                        break;

                    case 6:
                        dt = OrderBy.OrderByLocation(dt);
                        break;

                    default:
                        dt = OrderBy.OrderByCarID(dt);
                        break;
                    }
                }
                prevColumn = column;
                DisplayListAvailableCars(dt, startDate, endDate, con);
            }
        }
Ejemplo n.º 3
0
        public static void UpdateCarRent()
        {
            Console.Clear();

            Console.WriteLine("Cart Plate:");
            string plate = "";

            while (plate == "")
            {
                plate = Console.ReadLine();
            }
            Console.WriteLine("Client ID:");
            string clientId = "";

            while (clientId == "")
            {
                clientId = Console.ReadLine();
                if (!(Register_New_Rent.IntValidation(clientId)))
                {
                    Console.WriteLine("Invalid data");
                }
            }
            Console.WriteLine("Start Date:");
            string startDate = "";

            while (startDate == "")
            {
                startDate = Console.ReadLine();
                if (!(Register_New_Rent.DataValidation(startDate)))
                {
                    Console.WriteLine("Invalid data");
                }
            }
            Console.WriteLine("End Date:");
            string endDate = "";

            while (endDate == "")
            {
                endDate = Console.ReadLine();
                if (!(Register_New_Rent.DataValidation(endDate)))
                {
                    Console.WriteLine("Invalid data");
                }
            }
            Console.WriteLine("City:");
            string city = Console.ReadLine();

            while (city == "")
            {
                city = Console.ReadLine();
            }

            string        conString = "Data Source=DESKTOP-MJA5A7T;Initial Catalog=Car Rent;Integrated Security=True";
            SqlConnection con       = new SqlConnection(conString);

            con.Open();


            SqlCommand carID = new SqlCommand("select CarID from Cars where Plate = @CarPlate", con);

            carID.Parameters.AddWithValue("@CarPlate", plate);
            SqlDataReader rCarID = carID.ExecuteReader();
            string        carId  = "";

            while (rCarID.Read())
            {
                carId = rCarID.GetValue(0).ToString();
                Console.WriteLine(carId);
            }
            rCarID.Close();
            if (Register_New_Rent.CarAvailable(con, carId, DateTime.Parse(startDate), DateTime.Parse(endDate)) && Register_New_Rent.ClientExist(con, int.Parse(clientId)) && Register_New_Rent.CityAvailable(con, int.Parse(clientId), plate) && Register_New_Rent.CheckDate(DateTime.Parse(startDate), DateTime.Parse(endDate)))
            {
                string     register        = "update Reservations set StartDate=@StartDate, EndDate=@EndDate, Location=@Location  where CarID=@carID and CostumerID=@customerID";
                SqlCommand registerNewRent = new SqlCommand(register, con);
                registerNewRent.Parameters.AddWithValue("@carID", int.Parse(carId));
                registerNewRent.Parameters.AddWithValue("@customerId", int.Parse(clientId));
                registerNewRent.Parameters.AddWithValue("@StartDate", DateTime.Parse(startDate));
                registerNewRent.Parameters.AddWithValue("@EndDate", DateTime.Parse(endDate));
                registerNewRent.Parameters.AddWithValue("@Location", city);
                SqlDataReader reader = registerNewRent.ExecuteReader();
                Program.MenuScreen();
            }
            else
            {
                Console.WriteLine("Invalid data");
            }
            con.Close();
        }
Ejemplo n.º 4
0
        public static void MenuScreen()
        {
            Console.Clear();
            Console.WriteLine("Menu Screen");
            Console.WriteLine();
            Console.WriteLine("1. Register new Car Rent");
            Console.WriteLine("2. Update Car Rent");
            Console.WriteLine("3. List Rents");
            Console.WriteLine("4. List Available Cars");
            Console.WriteLine("5. Register new Customer");
            Console.WriteLine("6. Update Customer");
            Console.WriteLine("7. List Customers");
            Console.WriteLine("8. Gold/Silver Customers");
            Console.WriteLine("9. Most Recent Rented Cars");
            Console.WriteLine("10. Most Rented Cars");
            Console.WriteLine("11. Less rented Cars");
            Console.WriteLine("12. Quit");
            Console.WriteLine();
            Console.WriteLine("Please, type the number associated with the option you want and the press ENTER");
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new MenuScreen());
            int number;

            //ConsoleKeyInfo cki= Console.ReadKey()
            try
            {
                number = int.Parse(Console.ReadLine());

                if (number < 1 || number > 12)
                {
                    Console.WriteLine("This is not a valid option");
                }
                switch (number)
                {
                case 1:
                    Register_New_Rent.RegisterNewCarRent();
                    break;

                case 2:
                    Update_Rent.UpdateCarRent();
                    break;

                case 3:
                    List_Rents.ListRents();
                    break;

                case 4:
                    List_Available_Cars.ListAvailableCars();
                    break;

                case 5:
                    Register_New_Customer.RegisterNewCustomer();
                    break;

                case 6:
                    Update_Customer.UpdateCustomer();
                    break;

                case 7:
                    List_Customers.ListCustomers();
                    break;

                case 8:
                    Golden_Silver_Customers.GoldSilverCostumers();
                    break;

                case 9:
                    Most_Recent_Rented_Cars.MostRecentRentedCars();
                    break;

                case 10:
                    Most_Less_Rented_Cars.MostRentedCars();
                    break;

                case 11:
                    Most_Less_Rented_Cars.LessRentedCars();
                    break;

                case 12:
                    Environment.Exit(0);
                    break;
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("This is not a valid option");
            }
        }