public ParkingSpot GetSpotForReserve(ParkingSpot spotToRecieve, int selectedPosition)
 {
     try
     {
         using (SqlCommand sqlCommand = new SqlCommand("Get_Spot", ManageDatabaseConnection("Open")))
         {
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.Parameters.AddWithValue("@ParkingId", spotToRecieve.IdParking);
             sqlCommand.Parameters.AddWithValue("@Position", selectedPosition);
             using (SqlDataReader sqlReader = sqlCommand.ExecuteReader())
             {
                 if (sqlReader.Read())
                 {
                     spotToRecieve.Id = (int)sqlReader["Id"];
                     spotToRecieve.SpotType = sqlReader["Spottype"].ToString().Trim();
                 }
             }
         }
         ManageDatabaseConnection("Close");
     }
     catch (SqlException sqlException)
     {
         throw sqlException;
     }
     return spotToRecieve;
 }
 public void BookSpot(ParkingSpot selectedSpot, DateTime entryTime, DateTime exitTime)
 {
     currentBooking.IdParkingSpot = selectedSpot;
         currentBooking.EntryTime = entryTime;
         currentBooking.ExitTime = exitTime;
         addUserDataToBook();
 }
Esempio n. 3
0
    public Flight(Gate _gate, ParkingSpot parking_spot, Runway _runway, 
		int delayBeforeExit, int seperation, int variation,
		int _minutesToBoarding, int _minutesBoarding, FlightController _flightController)
    {
        gate = _gate;
        parkingSpot = parking_spot;
        runway = _runway;

        secondsDelayBeforeExit = delayBeforeExit;
         		secondsSeparation = seperation;
         		secondsVariation = variation;

         		minutesToBoarding = _minutesToBoarding;
         		minutesBoarding = _minutesBoarding;

         		flightController = _flightController;

        origin = "Sydney"; // need to pull from some sort of database
        state = STATE_START;
    }
    public void btnNext_Click(object sender, EventArgs e)
    {
        ParkingBusiness pb = new ParkingBusiness();
        pl.ListOfSpots = new List<ParkingSpot>();
        ParkingSpot ps = new ParkingSpot();
        int validNameResult = 0;

        if (TextBoxNameOfNewParking.Text.Equals("") || TextBoxLocationOfNewParking.Text.Equals("") || TextBoxDimensionsOfParkingX.Text.Equals("") || TextBoxDimensionsOfParkingY.Text.Equals(""))
        {
            LabelError.Text = "Espacios vacíos";
        }
        else
        {
            pl.Name = TextBoxNameOfNewParking.Text;
            pl.Location = TextBoxLocationOfNewParking.Text;
            pl.DimensionX = Int32.Parse(TextBoxDimensionsOfParkingX.Text);
            pl.DimensionY = Int32.Parse(TextBoxDimensionsOfParkingY.Text);
            Session["PARKINGLOT"] = pl;
            validNameResult = pb.VerifyParking(pl);
            if (validNameResult == -1)
            {
                LabelError.Text = "Nombre del parqueo ya existe";
                TextBoxNormalSpot.Enabled = true;
                TextBoxNameOfNewParking.Enabled = true;
                TextBoxLocationOfNewParking.Enabled = true;
                TextBoxDimensionsOfParkingX.Enabled = true;
                TextBoxDimensionsOfParkingY.Enabled = true;
            }
            else
            {
                ButtonNext.Enabled = false;
                ButtonCancel.Enabled = false;
                TextBoxNormalSpot.Text = "" + pl.DimensionX * pl.DimensionY;
                Session["AddParking"] = 1;
            }
        }
    }
 public FutureFlight(Gate _gate, ParkingSpot parking_spot)
 {
     gate = _gate; parkingSpot = parking_spot;
 }
Esempio n. 6
0
 public boolean canFitinSpot(ParkingSpot spot)
 {
Esempio n. 7
0
 public void Unpark(ParkingSpot parkingSpot)
 {
     parkingSpot.Unpark();
 }
Esempio n. 8
0
 public void Add(ParkingSpot parkingSpot)
 {
     db.ParkingSpots.Add(parkingSpot);
     SaveChanges();
 }
        // Creates Rndf from an input FileStream
        public IRndf createRndf(FileStream fileStream)
        {
            numWps = 0;

            // File in Read Only mode, convert to stream
            StreamReader r = new StreamReader(fileStream, Encoding.UTF8);

            // Create new queue for input buffer
            Queue q = new Queue();
            string word = "";

            // Create the Rndf (with only segments for now, no zones)
            IRndf rndf = new IRndf();
            rndf.Segments = new List<SimpleSegment>();
            rndf.Zones = new List<SimpleZone>();

            // Loop until reach end of file marker
            while ((word.Length < 8) || (word.Substring(0, 8) != "end_file"))
            {
                // get the next word
                word = parseWord(r, q);

                if (word == "RNDF_name")
                {
                    word = parseWord(r, q);
                    rndf.Name = word;
                }
                else if (word == "num_segments")
                {
                    word = parseWord(r, q);
                    rndf.NumSegs = int.Parse(word);
                }
                else if (word == "num_zones")
                {
                    word = parseWord(r, q);
                    rndf.NumZones = int.Parse(word);
                }
                else if (word == "format_version")
                {
                    word = parseWord(r, q);
                    rndf.FormatVersion = word;
                }
                else if (word == "creation_date")
                {
                    word = parseWord(r, q);
                    rndf.CreationDate = word;
                }
                else if (word == "segment")
                {
                    // create new segment
                    SimpleSegment seg = new SimpleSegment();
                    seg.Lanes = new List<SimpleLane>();

                    word = parseWord(r, q);
                    seg.Id = word;

                    // run until reach end of segment marker
                    while (word != "end_segment")
                    {
                        // get next word
                        word = parseWord(r, q);

                        if (word == "segment_name")
                        {
                            word = parseWord(r, q);
                            seg.Name = word;
                        }
                        else if (word == "num_lanes")
                        {
                            word = parseWord(r, q);
                            seg.NumLanes = int.Parse(word);
                        }
                        else if (word == "end_segment")
                        {
                            // do nothing if at the end
                        }
                        else if (word == "lane")
                        {
                            // Create new lane
                            SimpleLane ln = new SimpleLane();
                            ln.Checkpoints = new List<SimpleCheckpoint>();
                            ln.Waypoints = new List<SimpleWaypoint>();
                            ln.Stops = new List<string>();
                            ln.ExitEntries = new List<SimpleExitEntry>();

                            word = parseWord(r, q);
                            ln.Id = word;

                            // run until reach end of lane
                            while (word != "end_lane")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "num_waypoints")
                                {
                                    word = parseWord(r, q);
                                    ln.NumWaypoints = int.Parse(word);
                                }
                                else if (word == "checkpoint")
                                {
                                    // create checkpoint
                                    SimpleCheckpoint cp = new SimpleCheckpoint();

                                    // get waypoint id
                                    string wp = parseWord(r, q);
                                    cp.WaypointId = wp;

                                    // get checkpoint id
                                    string id = parseWord(r, q);
                                    cp.CheckpointId = id;

                                    // add to collection of checkpoints within lane
                                    ln.Checkpoints.Add(cp);
                                }
                                else if (word == "lane_width")
                                {
                                    word = parseWord(r, q);
                                    ln.LaneWidth = double.Parse(word);
                                }
                                else if (word == "stop")
                                {
                                    word = parseWord(r, q);
                                    ln.Stops.Add(word);
                                }
                                else if (word == "left_boundary")
                                {
                                    word = parseWord(r, q);
                                    ln.LeftBound = word;
                                }
                                else if (word == "right_boundary")
                                {
                                    word = parseWord(r, q);
                                    ln.RightBound = word;
                                }
                                else if (word == "exit")
                                {
                                    // create exit-entry pair
                                    SimpleExitEntry exitEntry = new SimpleExitEntry();

                                    // get the exit id
                                    string exit = parseWord(r, q);
                                    exitEntry.ExitId = exit;

                                    // get the entry id
                                    string entry = parseWord(r, q);
                                    exitEntry.EntryId = entry;

                                    // add to collection of exit-entry pairs within lane
                                    ln.ExitEntries.Add(exitEntry);
                                }
                                else if (word == "end_lane")
                                {
                                    // do nothing
                                }
                                // Otherwise we probably have a waypoint
                                else
                                {
                                    // check to make sure a wp by matching lane id to lane identifier of waypoint
                                    int laneIdLength = ln.Id.Length;

                                    // if waypoint matches then create the waypoint
                                    if (word.Length >= laneIdLength + 2 && (word.Substring(0, laneIdLength)).CompareTo(ln.Id) == 0)
                                    {
                                        // create a new waypoint
                                        SimpleWaypoint wp = new SimpleWaypoint();
                                        wp.Position = new UrbanChallenge.Common.Coordinates();

                                        // set its id
                                        wp.ID = word;

                                        // get latitude or X
                                        string lat = parseWord(r, q);
                                        wp.Position.X = double.Parse(lat);

                                        // get longitude or y
                                        string lon = parseWord(r, q);
                                        wp.Position.Y = double.Parse(lon);

                                        // add to lane's collection of waypoints
                                        ln.Waypoints.Add(wp);

                                        numWps += 1;
                                    }
                                    else
                                    {
                                        Console.WriteLine("Unknown identifier: " + word);
                                    }
                                }
                            }
                            seg.Lanes.Add(ln);
                        }
                        else
                        {
                            Console.WriteLine("Unknown identifier: " + word);
                        }
                    }
                    rndf.Segments.Add(seg);
                }
                else if (word == "zone")
                {
                    // create new zone
                    SimpleZone zone = new SimpleZone();
                    zone.ParkingSpots = new List<ParkingSpot>();

                    // get ID
                    word = parseWord(r, q);
                    zone.ZoneID = word;

                    // run until reach end of segment marker
                    while (word != "end_zone")
                    {
                        // get next word
                        word = parseWord(r, q);

                        if (word == "num_spots")
                        {
                            // get next word
                            word = parseWord(r, q);

                            // set num of parking spots
                            zone.NumParkingSpots = int.Parse(word);
                        }
                        else if (word == "zone_name")
                        {
                            // get next word
                            word = parseWord(r, q);

                            // set zone name
                            zone.Name = word;
                        }
                        else if (word == "perimeter")
                        {
                            // create perimeter
                            zone.Perimeter = new ZonePerimeter();
                            zone.Perimeter.ExitEntries = new List<SimpleExitEntry>();
                            zone.Perimeter.PerimeterPoints = new List<PerimeterPoint>();

                            // set perimeter id
                            zone.Perimeter.PerimeterID = parseWord(r, q);

                            while (word != "end_perimeter")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "num_perimeterpoints")
                                {
                                    // set num of perimeter points
                                    zone.Perimeter.NumPerimeterPoints = int.Parse(parseWord(r, q));
                                }
                                else if (word == "exit")
                                {
                                    // create new exit,entry
                                    SimpleExitEntry ee = new SimpleExitEntry();

                                    // set exit
                                    ee.ExitId = parseWord(r, q);

                                    // set entry
                                    ee.EntryId = parseWord(r, q);

                                    // add to perimeter exit entries
                                    zone.Perimeter.ExitEntries.Add(ee);
                                }
                                else if (word == "end_perimeter")
                                {
                                    // Do Nothing
                                }
                                else
                                {
                                    // create new perimeter point
                                    PerimeterPoint p = new PerimeterPoint();

                                    // set id
                                    p.ID = word;

                                    // create new coordinate
                                    p.position = new UrbanChallenge.Common.Coordinates();

                                    // setX
                                    p.position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    p.position.Y = Double.Parse(parseWord(r, q));

                                    // add to perimeter points
                                    zone.Perimeter.PerimeterPoints.Add(p);
                                }
                            }
                        }
                        else if (word == "spot")
                        {
                            // create a new spot
                            ParkingSpot ps = new ParkingSpot();

                            // set spot id
                            ps.SpotID = parseWord(r, q);

                            while (word != "end_spot")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "spot_width")
                                {
                                    // set spot width
                                    ps.SpotWidth = parseWord(r, q);
                                }
                                else if (word == "checkpoint")
                                {
                                    // get waypoint id that corresponds with checkpoint
                                    ps.CheckpointWaypointID = parseWord(r, q);

                                    // get checkpoint id
                                    ps.CheckpointID = parseWord(r, q);
                                }
                                else if (word == "end_spot")
                                {
                                    // add spot to zone
                                    zone.ParkingSpots.Add(ps);
                                }
                                else
                                {
                                    // SimpleWaypoint 1
                                    #region

                                    // create new waypoint for waypoint1
                                    ps.Waypoint1 = new SimpleWaypoint();
                                    ps.Waypoint1.Position = new UrbanChallenge.Common.Coordinates();

                                    // set id
                                    ps.Waypoint1.ID = word;

                                    // check if id is checkpointWaypointID
                                    if (ps.Waypoint1.ID == ps.CheckpointWaypointID)
                                    {
                                        ps.Waypoint1.IsCheckpoint = true;
                                        ps.Waypoint1.CheckpointID = ps.CheckpointID;
                                    }

                                    // setX
                                    ps.Waypoint1.Position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    ps.Waypoint1.Position.Y = Double.Parse(parseWord(r, q));

                                    #endregion

                                    // SimpleWaypoint 2
                                    #region

                                    // create new waypoint for waypoint2
                                    ps.Waypoint2 = new SimpleWaypoint();
                                    ps.Waypoint2.Position = new UrbanChallenge.Common.Coordinates();

                                    // set id
                                    ps.Waypoint2.ID = parseWord(r, q);

                                    // check if id is checkpointWaypointID
                                    if (ps.Waypoint2.ID == ps.CheckpointWaypointID)
                                    {
                                        ps.Waypoint2.IsCheckpoint = true;
                                        ps.Waypoint2.CheckpointID = ps.CheckpointID;
                                    }

                                    // setX
                                    ps.Waypoint2.Position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    ps.Waypoint2.Position.Y = Double.Parse(parseWord(r, q));

                                    #endregion
                                }
                            }
                        }
                        else if (word == "end_zone")
                        {
                            // Do Nothing
                        }
                        else
                        {
                            Console.WriteLine("Unrecognized: " + word);
                        }
                    }

                    // Add zones to zone
                    rndf.Zones.Add(zone);
                }
                else
                {
                    if (word == "end_file")
                        Console.WriteLine("Rndf Parse :: Successful");
                    else
                        Console.WriteLine("Unknown identifier: " + word);
                }
            }
            return rndf;
        }
Esempio n. 10
0
 // 주차 공간이 주차하려는 차량을 수용할 수 있으며, 비어 있는지 확인.
 // 크기만 비교하며, 주차 장소가 충분히 있는지는 확인하지 않음
 public abstract bool CanFitInSpot(ParkingSpot spot);
Esempio n. 11
0
 public void AddParkingSpot(ParkingSpot parking_spot)
 {
     parkingSpot = parking_spot;
     // notify flight controller that this gate + parking spot is ready
     FlightController.FlightSpotAvailable(this, parkingSpot);
 }
Esempio n. 12
0
        /// <summary>
        /// This method reads from the parkinglist on startup - I know, this method is huge...
        /// </summary>
        // TODO - byt ut denna mot en som läser in från databasen
        public static void ReadParkingFile()
        {
            //string parkingPath = @"../../../Textfiles/Parkinglist.txt";
            //List<string> lines = File.ReadAllLines(parkingPath).ToList(); // Thank you Tim Corey!
            //string[] places;
            //if (lines.Count > 0)
            //{
            //    foreach (string line in lines)
            //    {
            //        places = line.Split("|");
            //        int spotNr = int.Parse(places[1]);
            //        int spot = spotNr - 1;
            //        ParkingSpots[spot] = new ParkingSpot();
            //        ParkingSpots[spot].SpotNumber = spotNr;
            //        ParkingSpots[spot].FreeSpace = int.Parse(places[2]);

            //        if (places[0] == "#") // One vehicle in the spot
            //        {
            //            if (places[3] == "Car") { AddFirstCar(places, spot); }
            //            else { AddFirstMC(places, spot); }
            //        }
            //        else if (places[0] == "§") // Two vehicles in the spot
            //        {
            //            if (places[3] == "Car") { AddFirstCar(places, spot); }
            //            else { AddFirstMC(places, spot); }

            //            if (places[6] == "Car") { AddSecondCar(places, spot); }
            //            else { AddSecondMC(places, spot); }
            //        }
            //        else if (places[0] == "&") // Three vehicles in the spot
            //        {
            //            if (places[3] == "Car") { AddFirstCar(places, spot); }
            //            else { AddFirstMC(places, spot); }

            //            if (places[6] == "Car") { AddSecondCar(places, spot); }
            //            else { AddSecondMC(places, spot); }

            //            if (places[9] == "Car") { AddThirdCar(places, spot); }
            //            else { AddThirdMC(places, spot); }
            //        }
            //        else if (places[0] == "£") // Four vehicles in the spot
            //        {
            //            if (places[3] == "Car") { AddFirstCar(places, spot); }
            //            else { AddFirstMC(places, spot); }

            //            if (places[6] == "Car") { AddSecondCar(places, spot); }
            //            else { AddSecondMC(places, spot); }

            //            if (places[9] == "Car") { AddThirdCar(places, spot); }
            //            else { AddThirdMC(places, spot); }

            //            if (places[12] == "Car") { AddFourthCar(places, spot); }
            //            else { AddFourthMC(places, spot); }
            //        }
            //    }
            //}
            //else
            //{ //This loop creates the ParkingSpots in the ParkingHouse if the parkinglistfile is empty.
            for (int i = 0; i < Initilizing.ParkValue; i++)
            {
                ParkingSpots[i]            = new ParkingSpot();
                ParkingSpots[i].SpotNumber = i + 1;
            }
            //}
        }
    protected void btnBookingSpot_Click(object sender, EventArgs e)
    {
        Booking newBooking = new Booking();
        BookingBusiness bookingBusiness = new BookingBusiness();
        ParkingBusiness parkingBusiness = new ParkingBusiness();
        User currentUser = (User)Session["USER"];
        Vehicle bookingVehicle = new Vehicle();
        ParkingSpot bookingSpot = new ParkingSpot();
        ParkingLot bookingParking = new ParkingLot();

        bookingSpot.IdParking = Int32.Parse(DropDownListParking.SelectedValue);
        bookingSpot = parkingBusiness.GetSpotForReserve(bookingSpot, (int)Session["Position"]);
        newBooking.IdVehicle = bookingVehicle;
        bookingParking.Name = DropDownListParking.SelectedItem.Text;
        newBooking.IdUser = currentUser;
        newBooking.IdParkingSpot = bookingSpot;
        newBooking.IdParkingLot = bookingParking;
        newBooking.EntryTime = DateTime.Parse(DropDownListInitialHour.SelectedValue);
        newBooking.ExitTime = DateTime.Parse(DropDownListFinalHour.SelectedValue);
        newBooking.IdVehicle.Id = DropDownListVehicleFormUser.SelectedValue.Trim();
        newBooking.Date = DateTime.Today;
        newBooking.IdParkingSpot.Id = bookingSpot.Id;
        newBooking.IdParkingLot.Id = Int32.Parse(DropDownListParking.SelectedValue);

        if (bookingSpot.Id == 0)
        {

        }
        else
        {
            bookingBusiness.InsertBooking(newBooking);
            Session["BOOKING"] = newBooking;
            bookingParking = parkingBusiness.GetDimensions(bookingParking);
            selectedPosition = -1;
            bookingParking = removeSelected(Int32.Parse(DropDownListParking.SelectedValue));
            Session["BOOKINGALERT"] = SendMail(newBooking);
            TableDesignOfNewParking = bookingBusiness.VerifySpots(bookingParking, TableDesignOfNewParking, DateTime.Parse(DropDownListInitialHour.SelectedValue), DateTime.Parse(DropDownListFinalHour.SelectedValue));
            Response.Redirect("bookingdone.aspx");

        }
    }
Esempio n. 14
0
        private void btn_GetByIDOrName_Click(object sender, EventArgs e)
        {
            var request = new RestRequest();

            request.Method = Method.GET;
            request.AddHeader("accept", "application/json");
            RestClient           client     = null;
            IRestResponse        response   = null;
            string               content    = null;
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            list_ByID.Items.Clear();
            string id   = text_ByID.Text.Trim();
            string name = text_ByName.Text.Trim();

            string type   = (string)comboBox_selectType.SelectedItem;
            string option = (string)comboBox_NameOrId.SelectedItem;
            string uri    = null;

            switch (type)
            {
            case "Park":
                switch (option)
                {
                case "Id":
                    if (id == "")
                    {
                        MessageBox.Show($"Error: Please define an id to search!");
                        return;
                    }
                    uri = $"{baseURI}/parks/{id}";
                    break;

                case "Name":
                    if (name == "")
                    {
                        MessageBox.Show($"Error: Please define a name to search!");
                        return;
                    }
                    if (!Regex.IsMatch(name, "^Campus_[1-5]_[A-Z]_Park[1-9]$"))
                    {
                        MessageBox.Show("Field 'name' format invalid! Example pattern: 'Campus_[1-5]_[A-Z]_Park[1-9]'");
                        return;
                    }
                    uri = $"{baseURI}/parks/{name}";
                    break;

                default:
                    MessageBox.Show($"Error: Please choose what kind of 'search by' you want. By 'name' or by 'id'?");
                    return;
                }
                client   = new RestClient(uri);
                response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    content = response.Content.ToString();
                    ParkInfo park = new ParkInfo();
                    park = serializer.Deserialize <List <ParkInfo> >(content).First();
                    list_ByID.Items.Add($"{park.Name}: # of Spots/Special Spots - {park.NumberOfSpots}/{park.NumberOfSpecialSpots} ({park.OperatingHours})");
                }
                else
                {
                    MessageBox.Show($"Error: Park does not exist! {response.StatusDescription}");
                }
                break;

            case "Parking Spot":

                switch (option)
                {
                case "Id":
                    if (id == "")
                    {
                        MessageBox.Show($"Error: Please define an id to search!");
                        return;
                    }
                    uri = $"{baseURI}/parkingSpots/{id}";
                    break;

                case "Name":
                    if (name == "")
                    {
                        MessageBox.Show($"Error: Please define a name to search!");
                        return;
                    }
                    if (!Regex.IsMatch(name, "^[A-Z]-[1-9][0-9]?$"))
                    {
                        MessageBox.Show("Field 'name' format invalid! Accepts: 'A-1' to 'Z-99' patterns.");
                        return;
                    }
                    uri = $"{baseURI}/parkingSpots?spotId={name}";
                    break;

                default:
                    MessageBox.Show($"Error: Please choose what kind of 'search by' you want. By 'name' or by 'id'?");
                    return;
                }

                client   = new RestClient(uri);
                response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    content = response.Content.ToString();
                    ParkingSpot parkingSpot = new ParkingSpot();
                    parkingSpot = serializer.Deserialize <List <ParkingSpot> >(content).First();

                    string isFree = parkingSpot.Status.Value ? "occupied" : "free";
                    list_ByID.Items.Add($"{parkingSpot.SpotId}: {parkingSpot.Type} is {isFree} (Park #{parkingSpot.ParkId})");
                }
                else
                {
                    MessageBox.Show($"Error: Parking Spot does not exist! {response.StatusDescription}");
                }
                break;

            default:
                MessageBox.Show($"Error: Please choose what type of search you want. A 'Park' or a 'Parking Spot'?");
                return;
            }
        }
Esempio n. 15
0
        private void btn_SpotPOST_Click(object sender, EventArgs e)
        {
            string parkId    = textBox_SpotParkID.Text.Trim();
            string timestamp = dateTimePicker_SpotDateTime.Text.Trim();
            string spotId    = text_SpotSpotID.Text.Trim();

            if (!Regex.IsMatch(spotId, "^[A-Z]-[1-9][0-9]?$"))
            {
                MessageBox.Show("Field 'Spot Id' format invalid! Accepts: 'A-1' to 'Z-99' patterns.");
                return;
            }
            var client  = new RestClient($"{baseURI}/parks/{parkId}/parkingSpots?spotId={spotId}&timestamp={timestamp}");
            var request = new RestRequest();

            request.Method = Method.GET;
            request.AddHeader("accept", "application/json");
            var         response    = client.Execute(request);
            ParkingSpot parkingSpot = null;

            //show response
            JavaScriptSerializer scriptSerializer = new JavaScriptSerializer();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                #region If the Parking Spot already exists
                string             str_response = response.Content.ToString();
                List <ParkingSpot> parkingSpots = scriptSerializer.Deserialize <List <ParkingSpot> >(str_response);
                if (parkingSpots.Count > 1)
                {
                    Console.WriteLine("ERROR: Parking Spot found duplicated on database. Press OK to resolve it...");
                    #region Delete duplicated rows on database
                    ParkingSpot[] @for = parkingSpots.ToArray();
                    int           i    = parkingSpots.Count;
                    while (--i > 0)
                    {
                        client         = new RestClient($"{baseURI}/parkingSpots/{@for[i].Id}");
                        request        = new RestRequest();
                        request.Method = Method.DELETE;
                        request.AddHeader("accept", "application/json");
                        response = client.Execute(request);

                        //show response
                        scriptSerializer = new JavaScriptSerializer();
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            MessageBox.Show($"OK: Parking Spot Deleted ID: {@for[i].Id}");
                        }
                        else
                        {
                            MessageBox.Show($"ERROR: {response.StatusDescription}");
                        }
                    }
                    #endregion
                    MessageBox.Show($"Info: Remaining Parking Spot ID: {@for[i].Id}");
                }
                else
                {
                    parkingSpot = parkingSpots.First();
                    MessageBox.Show($"OK: Parking Spot Found ID: {parkingSpot.Id}");
                }
                #endregion
            }
            else
            {
                #region Create Parking Spot Data Contact
                parkingSpot                  = new ParkingSpot();
                parkingSpot.ParkId           = Convert.ToInt32(textBox_SpotParkID.Text.Trim());
                parkingSpot.SpotId           = spotId;
                parkingSpot.Type             = comboBox_SpotType.Text;
                parkingSpot.Status           = new Status();
                parkingSpot.Status.Value     = Convert.ToBoolean(comboBox_SpotStatus.Text);
                parkingSpot.Status.Timestamp = DateTime.Parse(dateTimePicker_SpotDateTime.Text);
                parkingSpot.BatteryStatus    = Convert.ToBoolean(comboBox_SpotBatteryStatus.Text);
                parkingSpot.Location         = text_SpotLocation.Text.Trim();
                #endregion

                #region POST Parking Spot On Database
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string content = serializer.Serialize(parkingSpot);
                client         = new RestClient($"{baseURI}/parkingSpots");
                request        = new RestRequest();
                request.Method = Method.POST;
                request.AddHeader("accept", "application/json");
                request.AddParameter("application/json; charset=utf-8", content, ParameterType.RequestBody);
                request.RequestFormat = DataFormat.Json;

                response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    string str_response = response.Content.ToString();
                    parkingSpot = serializer.Deserialize <ParkingSpot>(str_response);
                    MessageBox.Show($"Success: Parking Spot Created Id: {parkingSpot.Id}");
                }
                else
                {
                    MessageBox.Show($"Error: Parking Spot not created! {response.ErrorMessage}");
                }
                #endregion
            }
        }
 public ParkingSpot GetSpotForReserve(ParkingSpot parkingSpot, int position)
 {
     ParkingSpotData parkingSpotData = new ParkingSpotData();
     parkingSpot = parkingSpotData.GetSpotForReserve(parkingSpot, position);
     return parkingSpot;
 }
    public Table GetSpot(ParkingLot parkingTable, Table bookingTable)
    {
        ParkingSpot parkingSpot = new ParkingSpot();
        parkingSpot.IdParking = parkingTable.Id;
        try
        {
            string statement = "SELECT Id, Spottype FROM ParkingLotSpots WHERE ParkingId = @ParkingId AND Position = @Position";
            using (SqlCommand sqlCommand = new SqlCommand(statement, ManageDatabaseConnection("Open")))
            {
                sqlCommand.Parameters.AddWithValue("@ParkingId", parkingSpot.IdParking);
                sqlCommand.Parameters.Add("@Position", SqlDbType.Int);
                int counter = 0;
                for (int counterRow = 0; counterRow < parkingTable.DimensionX; counterRow++)
                 {
                    TableRow tableRow = new TableRow();
                    for (int counterColumn = 0; counterColumn < parkingTable.DimensionY; counterColumn++)
                       {
                       TableCell tableCell = new TableCell();
                        tableCell.CssClass = "btn-error";
                        parkingSpot.Position = counter;
                       sqlCommand.Parameters["@Position"].Value = parkingSpot.Position;
                       sqlCommand.ExecuteNonQuery();
                       using (SqlDataReader reader = sqlCommand.ExecuteReader())
                       {
                           if (reader.Read())
                           {
                                parkingSpot.Id = (int)reader["Id"];
                                parkingSpot.SpotType = reader["Spottype"].ToString().Trim();
                           }
                       }
                         switch (parkingSpot.SpotType)
                         {
                             case "Normal Spot":
                                tableCell.BackColor = Color.Transparent;
                                 break;
                             case "Road Spot":
                                tableCell.BackColor = Color.DarkGray;
                                tableCell.Enabled = false;
                                  break;
                             case "Handicap Spot":
                                tableCell.BackColor = Color.Blue;
                                tableCell.Enabled = false;
                                 break;
                             case "Motorcycle Spot":
                                tableCell.BackColor = Color.Yellow;
                                 break;
                                  }
                        tableRow.Cells.Add(tableCell);
                          counter++;
                        }
                     bookingTable.Rows.Add(tableRow);
                  }

            }
            ManageDatabaseConnection("Close");
        }
        catch (SqlException sqlException)
        {
            throw sqlException;
        }
        return bookingTable;
    }
Esempio n. 18
0
 public override bool CanFitInSpot(ParkingSpot spot)
 {
     return(true);
 }
    protected void btnDeleteReserve_Click(object sender, EventArgs e)
    {
        Booking newBooking = new Booking();
        BookingBusiness bookingBusiness = new BookingBusiness();
        ParkingBusiness parkingBusiness = new ParkingBusiness();
        User currentUser = (User)Session["USER"];
        Vehicle bookingVehicle = new Vehicle();
        ParkingSpot bookingSpot = new ParkingSpot();
        ParkingLot bookingParking = new ParkingLot();

        bookingSpot.IdParking = Int32.Parse(DropDownListParking.SelectedValue);
        bookingSpot = parkingBusiness.GetSpotForReserve(bookingSpot, (int)Session["Position"]);
        newBooking.IdVehicle = bookingVehicle;
        newBooking.IdUser = currentUser;
        newBooking.IdParkingSpot = bookingSpot;
        newBooking.IdParkingLot = bookingParking;
        newBooking.EntryTime = DateTime.Parse(DropDownListInitialHour.SelectedValue);
        newBooking.ExitTime = DateTime.Parse(DropDownListFinalHour.SelectedValue);
        newBooking.IdVehicle.Id = DropDownListVehicleFormUser.SelectedValue.Trim();
        newBooking.Date = DateTime.Today;
        newBooking.IdParkingSpot.Id = bookingSpot.Id;
        newBooking.IdParkingLot.Id = Int32.Parse(DropDownListParking.SelectedValue);

        if (bookingSpot.Id == 0)
        {
            //Return error here
        }
        else
        {
            bookingBusiness.DenyBooking(newBooking, newBooking.EntryTime, newBooking.ExitTime);
            bookingParking = parkingBusiness.GetDimensions(bookingParking);
            selectedPosition = -1;
            bookingParking = removeSelected(Int32.Parse(DropDownListParking.SelectedValue));
            FillTableDesignOfNewParking(newBooking.IdParkingLot.Id);

        }
    }
Esempio n. 20
0
 // 주차 공간이 큰지 확인. 주차 공간 수는 검사하지 않음
 public override bool CanFitInSpot(ParkingSpot spot)
 {
     return(spot.SpotSize == VehicleSize.Large);
 }
 protected void btnAddNewParking_Click(object sender, EventArgs e)
 {
     ParkingSpot ps = new ParkingSpot();
     ParkingBusiness pb = new ParkingBusiness();
     ParkingLot currentParking = (ParkingLot)Session["PARKINGLOT"];
     ps.IdParking = pb.AddParking(currentParking);
     currentParking.Id = ps.IdParking;
     if (ps.IdParking == -1)
     {
         LabelError.Text = "El nombre del parqueo ya existe";
     }
     else
     {
         pb.AddParkingSpot(TableDesignOfNewParking, currentParking);
     }
 }
Esempio n. 22
0
        /// <summary>
        /// This method is for the menu Check out vehicle.
        /// </summary>
        public static void CheckOut()
        {
            Console.Clear();
            Mainmenu.MenuPrinter();
            Console.Write("Please enter the registration number or the bikedescription of the vehicle you would like to check out: ");
            string regNr = Console.ReadLine().ToUpper();

            (Vehicle foundVehicle, ParkingSpot spot) = ParkingHouse.FindVehicle(regNr);

            if (spot is not null)
            {
                TimeSpan parkedTime;
                if (foundVehicle.type is not "Bus")
                {
                    spot.RemoveVehicle(foundVehicle);
                    //ParkingHouse.BackUp();
                    foundVehicle.TimeOut = DateTime.Now;
                    parkedTime           = foundVehicle.TimeOut - foundVehicle.timeIn;
                }
                else
                {
                    int removeSpot = spot.SpotNumber;
                    ParkingSpot.RemoveBus(foundVehicle, removeSpot);
                    //ParkingHouse.BackUp();
                    foundVehicle.TimeOut = DateTime.Now;
                    parkedTime           = foundVehicle.TimeOut - foundVehicle.timeIn;
                }
                if (parkedTime.Hours < 1)
                {
                    if (parkedTime.Minutes <= Initilizing.FreeMinutes)
                    {
                        Console.WriteLine($"\nThe parking for { foundVehicle.RegNr } is less than { Initilizing.FreeMinutes } minutes and is therefore without cost. " +
                                          $"\nThis vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                    else
                    {
                        Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for more than { Initilizing.FreeMinutes } minutes but less than an hour. " +
                                          $"\nThe cost for this parking is { foundVehicle.cost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                }
                else
                {
                    if (parkedTime.Days < 30)
                    {
                        int parkedHours = parkedTime.Hours;
                        parkedHours += 1;
                        int startedDays  = parkedTime.Days;
                        int startedHours = parkedHours + (startedDays * 24);
                        int vehicleCost  = startedHours * foundVehicle.cost;

                        if (parkedTime.Days >= 1)
                        {
                            Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for { parkedTime.Days } day(s) and { parkedHours } started hours. " +
                                              $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                            Console.ReadKey();
                            Mainmenu.MainMenu();
                        }
                        else
                        {
                            Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for { startedHours } started hours. " +
                                              $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                            Console.ReadKey();
                            Mainmenu.MainMenu();
                        }
                    }
                    else
                    {
                        Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for more than a month. " +
                                          $"\nThe cost for this parking is on me :) This vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                }
            }
            else if (regNr == "EXIT")
            {
                Mainmenu.MainMenu();
            }
            else
            {
                Console.WriteLine("There is no vehicle with that registration number, try again");
                Console.ReadKey();
                CheckOut();
            }
        }
Esempio n. 23
0
 public void Edit(ParkingSpot parkingSpot)
 {
     db.Entry(parkingSpot).State = EntityState.Modified;
     SaveChanges();
 }
Esempio n. 24
0
 public String ShowParkingSpotsBatteryReplacement(ParkingSpot p)
 {
     return($"{p.Id}\nBattery Status: Critical!!\n---------------------------------------------------------");
 }
Esempio n. 25
0
 /* Park vehicle in this spot (among others,
  *      potentially) */
 public void parkinSpot(ParkingSpot s)
 {
     parkingSpots.add(s);
 }
Esempio n. 26
0
 public String ShowFullParkingSpot(ParkingSpot p)
 {
     return($"ID :{p.Id}\nValue: { turnValue(p.Value.ToString())} \nName: {p.Name}\nLocation: {p.Location}\nType: {p.Type}\nBattery Status: {p.BateryStatus}\nTime: {p.Timestamp}\n---------------------------------------------------------\n");
 }
Esempio n. 27
0
 public void AddParkingSpot(ParkingSpot parkingSpot)
 {
     ParkingSpots.Add(parkingSpot);
 }
Esempio n. 28
0
 public String ShowParkingSpotsAll(ParkingSpot p)
 {
     return($"ID: { p.Id}\nValue:" + turnValue(p.Value.ToString()) + "\n\n");
 }
Esempio n. 29
0
        public static void Initialize(ParkingAppContext context)
        {
            //context.Database.EnsureCreated();

            // Look for any students.
            if (context.Members.Any())
            {
                return;   // DB has been seeded
            }

            var members = new Member[]
            {
                new Member {
                    FirstName = "Carson", LastName = "Alexander", LicenseNo = "abc1234", Email = "*****@*****.**", CreditCard = "1234567891000000"
                },
                new Member {
                    FirstName = "Suhaib", LastName = "Shahaib", LicenseNo = "1234567", Email = "*****@*****.**", CreditCard = "1234567891000001"
                }
            };

            context.Members.AddRange(members);
            context.SaveChanges();

            var nonmembers = new NonMember[]
            {
                new NonMember {
                    FirstName = "Carson", LastName = "Alexander", LicenseNo = "abc1234", Email = "*****@*****.**",
                },
                new NonMember {
                    FirstName = "Suhaib", LastName = "Shahaib", LicenseNo = "1234567", Email = "*****@*****.**",
                }
            };

            context.Members.AddRange(members);
            context.SaveChanges();

            var parkingLots = new ParkingLot[]
            {
                new ParkingLot {
                    Name = "South 1", AvailableSpaces = 50, TotalSpaces = 150
                },
                new ParkingLot {
                    Name = "North 1", AvailableSpaces = 4, TotalSpaces = 50
                },
                new ParkingLot {
                    Name = "South 2", AvailableSpaces = 400, TotalSpaces = 500
                }
            };

            context.ParkingLots.AddRange(parkingLots);
            context.SaveChanges();

            var reservations = new Reservation[]
            {
                new Reservation {
                    MemberId = 1, ParkingLotId = 1
                },
                new Reservation {
                    MemberId = 1, ParkingLotId = 3
                },
                new Reservation {
                    MemberId = 2, ParkingLotId = 2
                }
            };

            context.Reservations.AddRange(reservations);
            context.SaveChanges();

            var parkingSpots = new ParkingSpot[]
            {
                new ParkingSpot {
                    isAvailable = true, ParkingLotId = 1, MemberId = 1
                },
                new ParkingSpot {
                    isAvailable = true, ParkingLotId = 3, MemberId = 1
                },
                new ParkingSpot {
                    isAvailable = true, ParkingLotId = 2, MemberId = 2
                }
            };

            context.ParkingSpots.AddRange(parkingSpots);
            context.SaveChanges();
        }
Esempio n. 30
0
        /// <summary>
        /// This method prints the layout of the parking house and fills the spots with vehicles.
        /// </summary>
        public static void MenuPrinter()
        {
            int spaces       = Initilizing.ParkValue;
            int first        = spaces / 4;
            int second       = first + first;
            int third        = second + first;
            int fourth       = third + (spaces - third);
            int moveCoursor1 = 0;
            int moveCoursor2 = 0;
            int moveCoursor3 = 0;
            int moveCoursor4 = 0;

            for (int i = 1; i <= first; i++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(i);
                int         counter       = 0;
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    counter += 1;
                    if (counter < 3)
                    {
                        parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                    }
                    else
                    {
                        parkingString = " More than 3 vehicles";
                    }
                }
                moveCoursor1++;
                Console.SetCursorPosition(0, moveCoursor1);
                Console.Write(i + parkingString + "\n");
            }
            for (int j = first + 1; j <= second; j++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(j);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor2++;
                Console.SetCursorPosition(35, moveCoursor2);
                Console.Write(j + parkingString + "\n");
            }
            for (int k = second + 1; k <= third; k++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(k);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor3++;
                Console.SetCursorPosition(70, moveCoursor3);
                Console.Write(k + parkingString + "\n");
            }
            for (int l = third + 1; l <= fourth; l++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(l);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor4++;
                Console.SetCursorPosition(105, moveCoursor4);
                Console.Write(l + parkingString + "\n");
            }
        }
 /* ----------------------------------- static methods -----------------------------------
 /*
  *	When a parking spot is build (connected to gate) this function will
  * 	add the flight to the futureFlightList so it can be tested for validity
  */
 public static void FlightSpotAvailable(Gate gate, ParkingSpot parking_spot)
 {
     FutureFlight futureFlight = new FutureFlight(gate, parking_spot);
     futureFlights.Add(futureFlight);
 }
Esempio n. 32
0
 public void AddParkingSpot(ParkingSpot parking_spot)
 {
     parkingSpot = parking_spot;
     // notify flight controller that this gate + parking spot is ready
     FlightController.FlightSpotAvailable(this, parkingSpot);
 }
 public void Insert(Table parkingToAddSpots, ParkingLot currentParking)
 {
     ParkingSpot parkingSpot = new ParkingSpot();
     parkingSpot.IdParking = currentParking.Id;
     try
     {
         string statement = "INSERT INTO dbo.ParkingLotSpots(ParkingId, Spottype, Position) VALUES(@IdParking, @Spottype, @Position)";
         SqlCommand sqlCommand = new SqlCommand(statement, ManageDatabaseConnection("Open"));
         {
             int counter = 0;
             sqlCommand.Parameters.Add("@Spottype", SqlDbType.NChar, 25);
             sqlCommand.Parameters.Add("@IdParking", SqlDbType.Int);
             sqlCommand.Parameters.Add("@Position", SqlDbType.Int);
             for (int counterRow = 0; counterRow < currentParking.DimensionY; counterRow++)
             {
                 for (int counterColumn = 0; counterColumn < currentParking.DimensionY; counterColumn++)
                 {
                     switch (parkingToAddSpots.Rows[counterRow].Cells[counterColumn].BackColor.Name)
                     {
                         case "Transparent":
                             parkingSpot.SpotType = "Normal Spot";
                             parkingSpot.Position = counter;
                             sqlCommand.Parameters["@Spottype"].Value= parkingSpot.SpotType;
                             sqlCommand.Parameters["@IdParking"].Value = parkingSpot.IdParking;
                             sqlCommand.Parameters["@Position"].Value = parkingSpot.Position;
                             break;
                         case "DarkGray":
                             parkingSpot.SpotType = "Road Spot";
                             parkingSpot.Position = counter;
                             sqlCommand.Parameters["@Spottype"].Value= parkingSpot.SpotType;
                             sqlCommand.Parameters["@IdParking"].Value = parkingSpot.IdParking;
                             sqlCommand.Parameters["@Position"].Value = parkingSpot.Position;
                             break;
                         case "Blue":
                             parkingSpot.SpotType = "Handicap Spot";
                             parkingSpot.Position = counter;
                             sqlCommand.Parameters["@Spottype"].Value= parkingSpot.SpotType;
                             sqlCommand.Parameters["@IdParking"].Value = parkingSpot.IdParking;
                             sqlCommand.Parameters["@Position"].Value = parkingSpot.Position;
                             break;
                         case "Yellow":
                             parkingSpot.SpotType = "Motorcycle Spot";
                             parkingSpot.Position = counter;
                             sqlCommand.Parameters["@Spottype"].Value= parkingSpot.SpotType;
                             sqlCommand.Parameters["@IdParking"].Value = parkingSpot.IdParking;
                             sqlCommand.Parameters["@Position"].Value = parkingSpot.Position;
                             break;
                         default:
                             parkingSpot.SpotType = "Normal Spot";
                             parkingSpot.Position = counter;
                             sqlCommand.Parameters["@Spottype"].Value= parkingSpot.SpotType;
                             sqlCommand.Parameters["@IdParking"].Value = parkingSpot.IdParking;
                             sqlCommand.Parameters["@Position"].Value = parkingSpot.Position;
                             break;
                     }
                     counter++;
                     sqlCommand.ExecuteNonQuery();
                 }
             }
         }
         ManageDatabaseConnection("Close");
     }
     catch (SqlException sqlException)
     {
         throw sqlException;
     }
 }
Esempio n. 34
0
		public void TakeOff () {
			this.parkingSpot = null;
			this.state = LightShipState.Flying;
			this.cRigidbody.isKinematic = false;
			if (this.motherShip != null) {
				this.cRigidbody.velocity = this.motherShip.GetVelocity ();
			}
			this.cTransform.parent = null;
			this.motherShip = null;
			this.currentGrav = null;
		}
Esempio n. 35
0
		public void OnTriggerEnter (Collider trigger) {
			ParkingSpot parkingSpot = trigger.GetComponent<ParkingSpot> ();
			if (parkingSpot != null) {
				if (this.parkingSpot == null) {
					this.parkingSpot = parkingSpot;
				}
			}
		}
Esempio n. 36
0
		public void OnTriggerExit (Collider trigger) {
			if (!(this.state == LightShipState.Parking)) {
				ParkingSpot parkingSpot = trigger.GetComponent<ParkingSpot> ();
				if (parkingSpot != null) {
					if (this.parkingSpot == parkingSpot) {
						this.parkingSpot = null;
					}
				}
			}
		}
    public void FillTableDesignOfNewParking(int parkingName)
    {
        TableDesignOfNewParking.Rows.Clear();
        ParkingBusiness parkingBusiness = new ParkingBusiness();
        BookingBusiness bookingBusiness = new BookingBusiness();
        ParkingLot parkingspotTable = new ParkingLot();
        ParkingSpot parking = new ParkingSpot();
        int counter = 0;
        parkingspotTable.Id = parkingName;
        parkingspotTable = parkingBusiness.GetDimensions(parkingspotTable);
        TableDesignOfNewParking = parkingBusiness.GetSpotData(parkingspotTable, TableDesignOfNewParking);

        for (int counterRow = 0; counterRow < parkingspotTable.DimensionX; counterRow++)
        {
            for (int counterColumn = 0; counterColumn < parkingspotTable.DimensionY; counterColumn++)
            {
                TableDesignOfNewParking.Rows[counterRow].Cells[counterColumn].Controls.Add(addButton(counter));
                counter++;
            }
        }
        TableDesignOfNewParking = bookingBusiness.VerifySpots(parkingspotTable, TableDesignOfNewParking, DateTime.Parse(DropDownListInitialHour.SelectedValue), DateTime.Parse(DropDownListFinalHour.SelectedValue));
        for (int counterRow = 0; counterRow < parkingspotTable.DimensionX; counterRow++)
        {
            for (int counterColumn = 0; counterColumn < parkingspotTable.DimensionY; counterColumn++)
            {
                if (TableDesignOfNewParking.Rows[counterRow].Cells[counterColumn].BackColor == Color.Red)
                {
                    TableDesignOfNewParking.Rows[counterRow].Cells[counterColumn].Enabled = true;
                }
                else
                {
                    TableDesignOfNewParking.Rows[counterRow].Cells[counterColumn].Enabled = false;
                }
            }
        }
    }
 public ParkingSpotViewModel(ParkingSpot parkingSpot)
 {
     this.ParkedCarLocation = new NotifyTaskCompletion <ParkingSpot>(parkingSpot);
 }
    public Table VerifyReserve(ParkingLot parkingTable, Table bookingTable, DateTime lowerLimit, DateTime upperLimit)
    {
        Booking bookingToVerify = new Booking();
        ParkingSpot parkingSpot = new ParkingSpot();
        parkingSpot.IdParking = parkingTable.Id;
        bookingToVerify.IdParkingLot = parkingTable;
        bookingToVerify.IdParkingSpot = parkingSpot;

        try
        {
            string statement = "SELECT * FROM Booking WHERE IdParking = @ParkingId AND Validated = @Validated";
            using (SqlCommand sqlCommand = new SqlCommand(statement, ManageDatabaseConnection("Open")))
            {
                sqlCommand.Parameters.AddWithValue("@ParkingId", bookingToVerify.IdParkingLot.Id);
                sqlCommand.Parameters.AddWithValue("@Validated", true);
                using (SqlDataReader reader = sqlCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        bookingToVerify.IdParkingSpot.Id = (int)reader["IdParkingSpot"];
                        bookingToVerify.EntryTime = (DateTime)reader["EntryTime"];
                        bookingToVerify.ExitTime = (DateTime)reader["ExitTime"];
                        if (bookingToVerify.EntryTime >= lowerLimit && bookingToVerify.EntryTime < upperLimit || bookingToVerify.ExitTime > lowerLimit && bookingToVerify.ExitTime <= upperLimit || bookingToVerify.EntryTime <= lowerLimit && bookingToVerify.ExitTime >= upperLimit)
                        {
                            string secondStatement = "SELECT * FROM ParkingLotSpots WHERE Id = @SpotId";
                            using (SqlCommand sqlCommandSecond = new SqlCommand(secondStatement, ManageDatabaseConnection("Open")))
                            {
                                sqlCommandSecond.Parameters.AddWithValue("@SpotId", bookingToVerify.IdParkingSpot.Id);
                                using (SqlDataReader secondReader = sqlCommandSecond.ExecuteReader())
                                {
                                    if (secondReader.Read())
                                    {
                                        bookingToVerify.IdParkingSpot.Position = (int)secondReader["Position"];
                                    }
                                }
                                int counter = 0;
                                for (int counterRow = 0; counterRow < parkingTable.DimensionX; counterRow++)
                                {
                                    for (int counterColumn = 0; counterColumn < parkingTable.DimensionY; counterColumn++)
                                    {
                                        if (bookingToVerify.IdParkingSpot.Position == counter)
                                        {
                                            bookingTable.Rows[counterRow].Cells[counterColumn].BackColor = Color.Red;
                                            bookingTable.Rows[counterRow].Cells[counterColumn].Enabled = false;
                                        }
                                        counter++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            string secondStatement = "SELECT * FROM ParkingLotSpots WHERE Id = @SpotId";
                            using (SqlCommand sqlCommandSecond = new SqlCommand(secondStatement, ManageDatabaseConnection("Open")))
                            {
                                sqlCommandSecond.Parameters.AddWithValue("@SpotId", bookingToVerify.IdParkingSpot.Id);
                                using (SqlDataReader secondReader = sqlCommandSecond.ExecuteReader())
                                {
                                    if (secondReader.Read())
                                    {
                                        bookingToVerify.IdParkingSpot.Position = (int)secondReader["Position"];
                                        bookingToVerify.IdParkingSpot.SpotType = secondReader["Spottype"].ToString().Trim();
                                    }
                                }
                                int counter = 0;
                                for (int counterRow = 0; counterRow < parkingTable.DimensionX; counterRow++)
                                {
                                    for (int counterColumn = 0; counterColumn < parkingTable.DimensionY; counterColumn++)
                                    {
                                        if (bookingToVerify.IdParkingSpot.Position == counter)
                                        {
                                            if (bookingTable.Rows[counterRow].Cells[counterColumn].BackColor == Color.Red)
                                            {
                                                switch (parkingSpot.SpotType)
                                                {
                                                    case "Normal Spot":
                                                        bookingTable.Rows[counterRow].Cells[counterColumn].Enabled = true;
                                                        bookingTable.Rows[counterRow].Cells[counterColumn].BackColor = Color.Transparent;
                                                        break;
                                                    case "Motorcycle Spot":
                                                        bookingTable.Rows[counterRow].Cells[counterColumn].Enabled = true;
                                                        bookingTable.Rows[counterRow].Cells[counterColumn].BackColor = Color.Yellow;
                                                        break;
                                                }

                                            }
                                        }
                                        counter++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ManageDatabaseConnection("Close");
        }
        catch (SqlException sqlException)
        {
            throw sqlException;
        }
        return bookingTable;
    }
 public ParkingSpotViewModel()
 {
     this.ParkedCarLocation = new NotifyTaskCompletion <ParkingSpot>(ParkingSpot.CreateAsync());
 }
 public ParkingLot()
 {
     ParkingSpotsMatrix = new ParkingSpot[10, 20];
 }
Esempio n. 42
0
        /// <summary>
        /// This metod is for the menu choice "Search for and move vehicle"
        /// </summary>
        public static void MoveVehicle()
        {
            Console.Clear();
            Mainmenu.MenuPrinter();
            Console.Write("Please enter the registration number of the vehicle you would like to search for: ");
            string regNr = Console.ReadLine().ToUpper();

            if (regNr is not "EXIT")
            {
                (Vehicle foundVehicle, ParkingSpot oldSpot) = ParkingHouse.FindVehicle(regNr);
                if (foundVehicle is not null || oldSpot is not null)
                {
                    if (foundVehicle.type is not "Bus")
                    {
                        Console.Write($"\nThis vehicle is parked in spot { oldSpot.SpotNumber }, would you like to move it?: ");
                        string answer = Console.ReadLine().ToUpper();

                        if (answer == "Y" || answer == "YES")
                        {
                            Console.Write("Ok! Where would you like to park it instead?: ");
                            string spotAnswer = Console.ReadLine();
                            bool   correct    = int.TryParse(spotAnswer, out int spotSuggest);

                            if (correct)
                            {
                                ParkingSpot newSpot = ParkingHouse.FreeSpotFinder(foundVehicle.value, spotSuggest);
                                if (newSpot is not null)
                                {
                                    oldSpot.RemoveVehicle(foundVehicle);
                                    newSpot.Vehicles.Add(foundVehicle);
                                    newSpot.FreeSpace -= foundVehicle.value;
                                    Console.WriteLine($"\nThe { foundVehicle.type } with the registration number { foundVehicle.RegNr } " +
                                                      $"\nthat was parked in { oldSpot.SpotNumber } has been moved to { newSpot.SpotNumber }.");
                                    //ParkingHouse.BackUp();
                                }
                                else
                                {
                                    Console.WriteLine("This spot is not available." +
                                                      "\nNo changes have been made, please start over");
                                    Console.ReadKey();
                                    MoveVehicle();
                                }
                            }
                            else
                            {
                                Console.WriteLine("Incorrect input, please start from the beginning");
                                Console.ReadKey();
                                MoveVehicle();
                            }
                        }
                        else
                        {
                            Mainmenu.MainMenu();
                        }
                    }
                    else
                    {
                        Console.Write($"\nThis bus is parked in spot { oldSpot.SpotNumber } - { oldSpot.SpotNumber + 3 }, would you like to move it?: ");
                        string answer = Console.ReadLine().ToUpper();

                        if (answer == "Y" || answer == "YES")
                        {
                            Console.Write("Ok! It can only be parked somewhere in the first 50 spots." +
                                          "\nplease inser the number of the first spot of the four you would like to park it in: ");
                            string spotAnswer = Console.ReadLine();
                            bool   correct    = int.TryParse(spotAnswer, out int spotSuggest);

                            if (correct)
                            {
                                int         busSpace = foundVehicle.value / 4;
                                ParkingSpot newSpot  = ParkingHouse.FreeBusSpotFinder(spotSuggest);
                                if (newSpot is not null && spotSuggest < 47)
                                {
                                    int removeSpot = oldSpot.SpotNumber;
                                    ParkingSpot.RemoveBus(foundVehicle, removeSpot);

                                    ParkingHouse.ParkingSpots[spotSuggest - 1].FreeSpace -= busSpace;
                                    ParkingHouse.ParkingSpots[spotSuggest].FreeSpace     -= busSpace;
                                    ParkingHouse.ParkingSpots[spotSuggest + 1].FreeSpace -= busSpace;
                                    ParkingHouse.ParkingSpots[spotSuggest + 2].FreeSpace -= busSpace;

                                    ParkingHouse.ParkingSpots[spotSuggest - 1].Vehicles.Add(foundVehicle);
                                    ParkingHouse.ParkingSpots[spotSuggest].Vehicles.Add(foundVehicle);
                                    ParkingHouse.ParkingSpots[spotSuggest + 1].Vehicles.Add(foundVehicle);
                                    ParkingHouse.ParkingSpots[spotSuggest + 2].Vehicles.Add(foundVehicle);
                                    Console.WriteLine($"\nThe bus with the registration number { foundVehicle.RegNr } " +
                                                      $"\nthat was parked in { oldSpot.SpotNumber } - { oldSpot.SpotNumber + 3 } has been moved to { newSpot.SpotNumber } - { newSpot.SpotNumber + 3 }.");
                                    //ParkingHouse.BackUp();
                                }
                                else if (spotSuggest > 47)
                                {
                                    Console.WriteLine("Sorry, all spots above 50 have a too low ceiling to fit a bus");
                                }
                                else
                                {
                                    Console.WriteLine("This spot and the three following ones are not available." +
                                                      "\nNo changes have been made, please start over");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Incorrect input, please start from the beginning");
                                Console.ReadKey();
                                MoveVehicle();
                            }
                        }
                        else
                        {
                            Mainmenu.MainMenu();
                        }
                    }