예제 #1
0
 static void Main(string[] args)
 {
     Console.OutputEncoding = Encoding.Unicode; //Behöver ändra typsnitt i konsolenfönstret för att tyda ovanliga tecken.
     Console.InputEncoding  = Encoding.Unicode;
     // Connectionstringen ligger högst upp i klassen SQLMethods
     MenuClass.MainMenu();
 }
예제 #2
0
        /// <summary>
        /// Ta bort fordon ur parkeringsplatsen, (hämtar ut)
        /// </summary>
        public static void RemoveVehicle(bool payForParking)
        {
            Console.Clear();
            Console.WriteLine("Type your registrationnumber to remove your vehicle");
            string userReg = Console.ReadLine();

            connection.ConnectionString = connectionString;

            bool vehicleRemoved = false;

            using (connection)
            {
                SqlCommand command = new SqlCommand();
                command.Connection = connection;
                //Här testar vi ifall användaren ska betala eller ej för parkering. Detta är för att undvika dublicering av kod.
                if (payForParking == true)
                {
                    command.CommandText = "dbo.DeleteParkedVehicle";
                }
                else if (payForParking != true)
                {
                    command.CommandText = "dbo.RemoveVehicleForFree";
                }
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@registrationNumber", userReg);
                try
                {
                    connection.Open();
                    int affectedRows = command.ExecuteNonQuery();
                    if (affectedRows != 0)
                    {
                        Console.WriteLine("You have now removed your vehicle");
                        vehicleRemoved = true;
                    }
                    else
                    {
                        Console.WriteLine("Couldnt find your vehicle, try search again.");
                        MenuClass.MainMenu();
                    }
                }
                catch
                {
                }
            }
            if (vehicleRemoved)
            {
                PrintRemovedVehicle(userReg);
            }
        }
예제 #3
0
        /// <summary>
        /// Konverterar till giltiligt datum att skicka in för jämförelser i databasen.
        /// </summary>
        /// <param name="userDate">datumet att converetera till datetime.</param>
        /// <returns></returns>
        public static DateTime ConvertToDateTime(string userDate)
        {
            string   date = userDate;
            DateTime time = new DateTime();

            try
            {
                time = DateTime.Parse(date);
            }
            catch
            {
                Console.WriteLine("Invalid date, try again.");
                Console.ReadKey();
                MenuClass.MainMenu();
            }
            return(time);
        }
예제 #4
0
        /// <summary>
        /// Flyttar fordon till önskad plats.
        /// </summary>
        public static void MoveVehicle()
        {
            Console.Clear();
            Console.Write("Type your RegistrationNumber to move your vehicle: ");
            string userReg = Console.ReadLine();

            Console.Write("To which spot would you like to move the vehicle to?:");
            int userSpot = MenuClass.InputChecker();

            connection.ConnectionString = connectionString;
            using (connection)
            {
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandText = "dbo.MoveVehicleToSpecificSpot";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@registrationNumber", userReg);
                command.Parameters.AddWithValue("@parkingSpot", userSpot);

                try
                {
                    connection.Open();
                    int affectedRows = command.ExecuteNonQuery();
                    if (affectedRows != 0)
                    {
                        Console.WriteLine("You have now moved your vehicle");
                        PrintWorkOrder();
                    }
                    else
                    {
                        Console.WriteLine("Couldnt find your vehicle, try search again.");
                        Console.ReadKey();
                        MenuClass.MainMenu();
                    }
                }
                catch
                {
                    Console.WriteLine("Couldnt fit your vehicle to desired spot, or spot was not in parkinglot. 1-100");
                }
            }
        }