private void button1_Click(object sender, EventArgs e) { string location = textBox5.Text; string plate = textBox1.Text; if (context1.Cars.Where(c => c.Plate == plate && c.Location == location).FirstOrDefault() != null) { MyCar = context1.Cars.Where(c => c.Plate == plate && c.Location == location).FirstOrDefault(); MyReservation.CarID = MyCar.CarID; MyReservation.Plate = MyCar.Plate; MyReservation.Location = MyCar.Location; } else { MessageBox.Show("Invalid car plate or location!"); this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } int customerID = Convert.ToInt32(textBox2.Text); if (context1.Customers.Where(c => c.CustomerID == customerID).FirstOrDefault() != null) { MyCustomer = context1.Customers.Where(c => c.CustomerID == customerID).FirstOrDefault(); MyReservation.CustomerID = MyCustomer.CustomerID; } else { MessageBox.Show("Please insert a valid Customer Id"); this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } MyReservation.StartDate = Convert.ToDateTime(textBox3.Text); MyReservation.EndDate = Convert.ToDateTime(textBox4.Text); using (var MyDbEntities = new ReservationModel()) { if ((MyReservation.StartDate <= MyReservation.EndDate) && (MyReservation.StartDate >= DateTime.Now)) { if (context1.Reservations.Where(c => (c.StartDate > MyReservation.EndDate || c.EndDate < MyReservation.StartDate) && c.Plate == MyReservation.Plate).Any()) { MyDbEntities.Reservations.Add(MyReservation); MyDbEntities.SaveChanges(); } else if (context1.Reservations.Where(c => c.Plate == MyReservation.Plate).Any() == false) { MyDbEntities.Reservations.Add(MyReservation); MyDbEntities.SaveChanges(); } else { MessageBox.Show("Please insert other dates for your reservation"); this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } } else { MessageBox.Show("Please insert valid dates"); this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } } this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); }
private void Menu_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Back) { this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D1) { this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D2) { this.Hide(); UpdateCarRental updateCarRental = new UpdateCarRental(); updateCarRental.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D3) { this.Hide(); ListRents listRents = new ListRents(); listRents.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D4) { this.Hide(); AvailableCars availableCars = new AvailableCars(); availableCars.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D5) { this.Hide(); RegisterNewCustomer registerNewCustomer = new RegisterNewCustomer(); registerNewCustomer.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D6) { this.Hide(); UpdateCustomer updateCustomer = new UpdateCustomer(); updateCustomer.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D7) { this.Hide(); ListCustomers listCustomers = new ListCustomers(); listCustomers.ShowDialog(); this.Close(); } else if (e.KeyChar == (char)Keys.D8) { this.Close(); } else { MessageBox.Show("Please insert a valid number"); this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); } }