Exemple #1
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);
            }
        }