//lookup for the vehicle, if in garage, release it. public static bool ReleaseVehicle(Vehicle v) { bool res = false; for (int i = 0; i < levels.Count; i++) { int ind = Convert.ToInt32(ParkingMain.findVehicle(v).Split('/')[1]); if (ind != -1) { res = levels[i].ReleaseVehicle(v, ind); if (res) { return(true); } } } return(false); }
private void button1_Click(object sender, EventArgs e) { string licNum = textBoxLicNum.Text.Trim(); if (licNum.Length > 0) { Vehicle v = new Vehicle(licNum, comboBox1.SelectedItem.ToString()); string res = ParkingMain.findVehicle(v); if (res.Split('/')[1] != "-1") { string level = res.Split('/')[0]; string slotNum = res.Split('/')[1]; MessageBox.Show(String.Format("The vehicle is parked at Level : {0} and spot number {1} ", level, slotNum)); } else { MessageBox.Show("This vehicle is not parked here...!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static int parkVehicle(Vehicle v) { int res = -1; //res used to identify response of this method (1 : parked, 0 : already in garage, -1: not enough space) if (Convert.ToInt32(ParkingMain.findVehicle(v).Split('/')[1]) == -1) //the term returns -1 when it cannot find the vehicle in any of the parking spot at any levels // meaning the park is not in garage so can be parked. { res = -1; for (int i = 0; i < levels.Count; i++) { if (levels[i].availableCapacity > 0) { levels[i].parkVehicle(v); res = 1; } } } else { res = 0; } return(res); }