public void Insert(CarSimulation car) { try { connectionobject = new SqlConnection(connectionstring); connectionobject.Open(); int user = car.User; string TimeIn = car.Timein; string TimeOut = car.TimeOUT; string insertCommandQuery = @"INSERT INTO ParkingData (TimeIN,TimeOut) Values ('" + TimeIn + "','" + TimeOut + "')"; sqlCommandobject = new SqlCommand(insertCommandQuery, connectionobject); sqlCommandobject.ExecuteNonQuery(); } catch (Exception e) { MessageBox.Show(e.Message); } finally { if (reader != null) { reader.Close(); } if (connectionobject != null) { connectionobject.Close(); } } }
public void Update(CarSimulation Car) { try { connectionobject = new SqlConnection(connectionstring); connectionobject.Open(); int User = Car.User; string timeOut = Car.TimeOUT; string updateCommandQuery = @"Update ParkingData SET TimeOut='" + timeOut + "' where User ='******'"; sqlCommandobject = new SqlCommand(updateCommandQuery, connectionobject); sqlCommandobject.ExecuteNonQuery(); } catch (Exception e) { MessageBox.Show("Update " + e.Message); } finally { if (reader != null) { reader.Close(); } if (connectionobject != null) { connectionobject.Close(); } } }
private void MyTimer_Tick(object sender, EventArgs e) { pEntrance.BackColor = Color.DarkRed; if (Parkingspaces[0] == 1 && Parkingspaces[1] == 1 && Parkingspaces[2] == 1 && Parkingspaces[3] == 1 && Parkingspaces[4] == 1 && Parkingspaces[5] == 1 && Parkingspaces[6] == 1 && Parkingspaces[7] == 1 && Parkingspaces[8] == 1 && Parkingspaces[9] == 1) { MessageBox.Show("Parking lot is full!!!"); MyTimer.Stop(); } else { if (temp < 10) { //MessageBox.Show((temp + 1).ToString()); switch (temp) { case 0: pSpace1.BackColor = Color.DarkRed; break; case 1: pSpace2.BackColor = Color.DarkRed; break; case 2: pSpace3.BackColor = Color.DarkRed; break; case 3: pSpace4.BackColor = Color.DarkRed; break; case 4: pSpace5.BackColor = Color.DarkRed; break; case 5: pSpace6.BackColor = Color.DarkRed; break; case 6: pSpace7.BackColor = Color.DarkRed; break; case 7: pSpace8.BackColor = Color.DarkRed; break; case 8: pSpace9.BackColor = Color.DarkRed; break; case 9: pSpace10.BackColor = Color.DarkRed; break; default: break; } temp++; btnRemove.Enabled = true; Random random = new Random(); TimeSpan duration = new TimeSpan(random.Next(0, 12), 0, 0); string timeIN = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"); string TimeOUT = DateTime.Now.Add(duration).ToString("MM/dd/yyyy hh:mm tt"); CarSimulation newCar = new CarSimulation(0, timeIN, TimeOUT); datahandler.Insert(newCar); lblParkingleft.Text = "Parking Spaces Left: " + (10 - temp); MyTimer.Stop(); } else { MyTimer.Stop(); MessageBox.Show("Parking is full"); } } }