private void button1_Click(object sender, EventArgs e) { string vehicleNumber = textBox1.Text.Trim(); string type = comboBox1.SelectedItem.ToString(); if (vehicleNumber.Length > 0 && type != "") { Vehicle v = new Vehicle(vehicleNumber, type); int k = ParkingMain.parkVehicle(v); switch (k) { case 0: MessageBox.Show("Vehicle already parked in the Garage...!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; case 1: MessageBox.Show("Vehicle parked successfully in the Garage...!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case -1: MessageBox.Show("WARNING : Not enough space in the garage, vehicle cannot be parked!", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); break; } } }
//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 vehicleNumber = textBox1.Text.Trim(); string type = comboBox1.SelectedItem.ToString(); if (vehicleNumber.Length > 0 && type != "") { Vehicle v = new Vehicle(vehicleNumber, type); bool k = ParkingMain.ReleaseVehicle(v); if (k) { MessageBox.Show("Vehicle succeffuly Released...!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("WARNING : Vehicle not in the Garage...!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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); }