Exemple #1
0
        public static void MostRecentRentedCars()
        {
            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 * from Reservations", con);
            DataTable      dt          = new DataTable();

            dataAdapter.Fill(dt);
            DataTable newTable = new DataTable();

            newTable.Columns.Add("CarID");
            newTable.Columns.Add("StartDate");
            newTable.Columns.Add("EndDate");
            newTable.Columns.Add("Location");
            //order by endDate
            dt = OrderBy.OrderByEndDateDesc(dt);
            //add into the tabel just the days from the past
            foreach (DataRow row in dt.Rows)
            {
                if (DateTime.Parse(row["EndDate"].ToString()) < DateTime.Now)
                {
                    newTable.ImportRow(row);
                }
            }

            int width = Console.WindowWidth;

            width = width / 4;
            Write.WriteProgress("CarID", 1, 1);
            Write.WriteProgress("StartDate", width, 1);
            Write.WriteProgress("EndDate", 2 * width, 1);
            Write.WriteProgress("Location", 3 * width, 1);
            int r = 3;

            foreach (DataRow row in newTable.Rows)
            {
                Write.WriteProgress(row["CarID"].ToString(), 1, r);
                Write.WriteProgress(row["StartDate"].ToString(), width, r);
                Write.WriteProgress(row["EndDate"].ToString(), 2 * width, r);
                Write.WriteProgress(row["Location"].ToString(), 3 * width, r);
                r++;
                //display just the first cars(20) from the table
                if (r == 23)
                {
                    break;
                }
            }
        }
Exemple #2
0
        public static void ListRents()
        {
            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 Plate, CostumerID, StartDate, EndDate, Reservations.Location from Reservations join Cars on Reservations.CarID = Cars.CarID", con);
            DataTable      dt          = new DataTable();

            dataAdapter.Fill(dt);
            DisplayListRents(dt);
            int column     = 0;
            int prevColumn = 0;

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

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

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

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

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

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

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

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

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

                    default:
                        dt = OrderBy.OrderByCustomerId(dt);
                        break;
                    }
                }
                prevColumn = column;
                DisplayListRents(dt);
            }
        }