private void button1_Click(object sender, EventArgs e) { MyCustomer.CustomerID = Convert.ToInt32(textBox2.Text); MyCustomer.Name = textBox3.Text; DateTime dt; string[] formats = { "yyyy-MM-dd" }; if (!DateTime.TryParseExact(textBox4.Text, formats, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { MyCustomer.BirthDate = Convert.ToDateTime(textBox3.Text); } else { MessageBox.Show("Please insert a valid birthday"); this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } MyCustomer.Location = textBox5.Text; using (var MyDbEntities = new CustomerModel()) { MyDbEntities.Entry(MyCustomer).State = System.Data.Entity.EntityState.Modified; MyDbEntities.SaveChanges(); } this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); }
private void button1_Click(object sender, EventArgs e) { int customerID = Convert.ToInt32(textBox2.Text); if (context1.Customers.Where(c => c.CustomerID == customerID).FirstOrDefault() == null) { MyCustomer.CustomerID = customerID; } else { MessageBox.Show("This ID already exists!"); this.Hide(); RegisterNewCustomer registerNewCustomer = new RegisterNewCustomer(); registerNewCustomer.ShowDialog(); this.Close(); } MyCustomer.Name = textBox3.Text; DateTime dt; string[] formats = { "yyyy-MM-dd" }; if (!DateTime.TryParseExact(textBox4.Text, formats, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { MyCustomer.BirthDate = Convert.ToDateTime(textBox3.Text); } else { MessageBox.Show("Please insert a valid birthday"); this.Hide(); RegisterNewCar registerNewCar = new RegisterNewCar(); registerNewCar.ShowDialog(); this.Close(); } MyCustomer.Location = textBox5.Text; using (var MyDbEntities = new CustomerModel()) { MyDbEntities.Customers.Add(MyCustomer); MyDbEntities.SaveChanges(); } this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); }
private void button1_Click(object sender, EventArgs e) { string location = textBox6.Text; string plate = textBox2.Text; MyReservation.ReservationId = Convert.ToInt32(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(textBox3.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(); UpdateCarRental updateCarRental = new UpdateCarRental(); updateCarRental.ShowDialog(); this.Close(); } MyReservation.StartDate = Convert.ToDateTime(textBox4.Text); MyReservation.EndDate = Convert.ToDateTime(textBox5.Text); using (var MyDbEntities = new ReservationModel()) { if ((MyReservation.StartDate <= MyReservation.EndDate) && (MyReservation.StartDate >= DateTime.Now)) { if ((context1.Reservations.Where(c => !((c.EndDate < MyReservation.StartDate) || (c.StartDate > MyReservation.EndDate)) && (c.ReservationId != MyReservation.ReservationId) && (c.Plate == MyReservation.Plate)).Any()) == false) { MyDbEntities.Entry(MyReservation).State = System.Data.Entity.EntityState.Modified; MyDbEntities.SaveChanges(); this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); } else if (context1.Reservations.Where(c => c.Plate == MyReservation.Plate).Count() == 1) { MyDbEntities.Entry(MyReservation).State = System.Data.Entity.EntityState.Modified; MyDbEntities.SaveChanges(); this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); } else { MessageBox.Show("Please insert another dates"); this.Hide(); UpdateCarRental updateCarRental = new UpdateCarRental(); updateCarRental.ShowDialog(); this.Close(); } } else { MessageBox.Show("Please insert valid dates"); this.Hide(); Menu menu = new Menu(); menu.ShowDialog(); this.Close(); } } }