Exemplo n.º 1
0
        public void CheckStatusInfo(CartRent rent)
        {
            DataManager data  = new DataManager();
            Tools       tools = new Tools();

            string query1 = "(SELECT ReservStatsID FROM Reservations WHERE NOT((StartDate > convert(date,'" + rent.endDate + "',104)) or" +
                            " (EndDate < convert(date, '" + rent.startDate + "', 104))))";
            string query = "SELECT DISTINCT ReservStatsID FROM Reservations WHERE CarID = '" + rent.car.carID + "' and ReservStatsID IN ";

            try
            {
                using (data.databaseConnection = new SqlConnection())
                {
                    data.setDatabaseConection();
                    data.databaseConnection.Open();

                    SqlCommand    getStatusInfo = new SqlCommand(query + query1, data.databaseConnection);
                    SqlDataReader reader        = getStatusInfo.ExecuteReader();

                    while (reader.Read())
                    {
                        string sID = reader[0].ToString();
                        this.ID = Int32.Parse(sID);
                    }
                }
            }catch (SqlException e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Exemplo n.º 2
0
        public void readCarData(CartRent rent)
        {
            Console.Clear();

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

            Console.WriteLine("Car Model:");
            this.model = Console.ReadLine();

            Console.WriteLine("Start Date:");
            rent.startDate = Console.ReadLine();

            Console.WriteLine("End Date:");
            rent.endDate = Console.ReadLine();

            Console.WriteLine("City:");
            this.location = Console.ReadLine();
        }
Exemplo n.º 3
0
        public void availableCarList(CartRent rent) ////Need Modifications
        {
            DataManager data  = new DataManager();
            Tools       tools = new Tools();

            string query1 = "SELECT * FROM Cars WHERE Location = '" + location + "' and Plate = '" + plate + "' and Model = '" + model + "' and carID NOT IN";
            string query2 = "(SELECT carID FROM Reservations WHERE NOT((StartDate > '" + tools.convertStringDate(rent.endDate).ToString("yyyy-MM-dd") +
                            "') OR (EndDate < '" + tools.convertStringDate(rent.startDate).ToString("yyyy-MM-dd") + "')))";

            using (data.databaseConnection = new SqlConnection())
            {
                using (SqlCommand getAvailableCars = new SqlCommand())
                {
                    data.setDatabaseConection();

                    getAvailableCars.Connection  = data.databaseConnection;
                    getAvailableCars.CommandText = query1 + query2;

                    Console.WriteLine(string.Format("{0}\t {1}\t {2}\t {3}\t {4}\t {5}", "Car ID", "Cart Plate", "Manufacturer", "Model", "PricePerDay", "City"));
                    try
                    {
                        data.databaseConnection.Open();
                        SqlDataReader dataReader = getAvailableCars.ExecuteReader();

                        while (dataReader.Read())
                        {
                            Console.WriteLine(string.Format("{0}\t |{1}\t\t |{2}\t |{3}\t |{4}\t |{5}",
                                                            dataReader[0], dataReader[1], dataReader[2], dataReader[3], dataReader[4], dataReader[5]));
                        }
                    }
                    catch (SqlException e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }