Beispiel #1
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);
            }
        }
Beispiel #2
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();
        }