public void InitializeAddCar() { CarRentalManagementEntities context = new CarRentalManagementEntities(); var carMakes = context.CarMakes.OrderBy(x => x.MakeId).Select(x => x.Make); comboBoxCarMake.DataSource = carMakes.ToList(); }
public void LoadReseverdCars() { CarRentalManagementEntities context = new CarRentalManagementEntities(); List <Reservation> reservations = Controller <CarRentalManagementEntities, Reservation> .GetEntities(r => !r.IsReturend).ToList(); List <int> carIds = reservations.Where(r => !r.IsReturend).Select(r => r.CarId).ToList(); List <Car> cars = Controller <CarRentalManagementEntities, Car> .GetEntities(c => carIds.Contains(c.CarId)).ToList(); List <int> typeIds = cars.Select(r => r.TypeId).ToList(); List <int> makeIds = cars.Select(r => r.MakeId).ToList(); var rentedCars = (from s in cars join cs in context.CarTypes on s.TypeId equals cs.TypeId join os in context.CarMakes on s.MakeId equals os.MakeId select new { CarMake = os.Make, CarType = cs.Type, Model = s.Model, Year = s.Year, Price = s.Price }).ToList(); dataGridViewRentedCars.DataSource = rentedCars; }
public void AddNewCar() { context = new CarRentalManagementEntities(); var type = comboBoxCarType.Text; var typeId = context.CarTypes.Where(x => x.Type == type).Select(x => x.TypeId).Distinct(); var make = comboBoxCarType.Text; var makeId = context.CarMakes.Where(x => x.Make == make).Select(x => x.MakeId).Distinct(); MessageBox.Show("" + makeId.First()); /*Car newCar = new Car() * { * TypeId = typeId.First(), * MakeId = makeId.First(), * Color = textBoxCarColor.Text, * Model = textBoxCarModel.Text, * Year = Int32.Parse(textBoxCarYear.Text), * Price = Decimal.Parse(textBoxCarPrice.Text), * }; * * try * { * context.Cars.Add(newCar); * context.SaveChanges(); * } * catch (Exception ex) * { * MessageBox.Show("Cannot add car to database" + ex.InnerException.InnerException.Message + "\n Make " + makeId.First()); * return; * }*/ }
public void AddNewCar() { context = new CarRentalManagementEntities(); var type = comboBoxCarType.Text; var typeId = context.CarTypes.Where(x => x.Type == type).Select(x => x.TypeId).Distinct(); var make = comboBoxCarMake.Text; var makeId = context.CarMakes.Where(x => x.Make == make).Select(x => x.MakeId).Distinct(); Car newCar = new Car() { TypeId = typeId.First(), MakeId = makeId.First(), Color = textBoxCarColor.Text, Model = textBoxCarModel.Text, Year = Int32.Parse(textBoxCarYear.Text), Price = Decimal.Parse(textBoxCarPrice.Text), }; try { context.Cars.Add(newCar); context.SaveChanges(); MessageBox.Show("Car added successfully"); } catch (Exception ex) { MessageBox.Show("Cannot add car to database" + ex.InnerException.InnerException.Message + "\n Make " + makeId.First()); return; } }
private void InitializeStudentRegistrationFormsAppMainForm() { CarRentalManagementEntities context = new CarRentalManagementEntities(); //context.SeedDatabase(); //Calling method that initializes all of the datagrids. //InitializeDataGridView<Reservation>(dataGridViewRentedCars); }
public AddCar() { context = new CarRentalManagementEntities(); InitializeComponent(); InitializeAddCar(); buttonAddCar.Click += ButtonAddCar_Click; buttonCarMake.Click += ButtonCarMake_Click; buttonAddCarType.Click += ButtonAddCarType_Click; }
private void InitializeStudentRegistrationFormsAppMainForm() { CarRentalManagementEntities context = new CarRentalManagementEntities(); //context.SeedDatabase(); //Calling method that initializes all of the datagrids. InitializeDataGridView <Student>(dataGridViewStudents, "Department", "Courses"); InitializeDataGridView <Department>(dataGridViewDepartments, "Courses", "Students"); }
public void MoveToAvailable() { CarRentalManagementEntities context = new CarRentalManagementEntities(); int selectedrowindexCarId = dataGridViewRentedCars.SelectedCells[0].RowIndex; DataGridViewRow selectedRowCarId = dataGridViewRentedCars.Rows[selectedrowindexCarId]; string carId = Convert.ToString(selectedRowCarId.Cells["CarId"].Value); Reservation res = Controller <CarRentalManagementEntities, Reservation> .GetEntities(r => r.CarId == Int32.Parse(carId)).First(); res.IsReturend = true; Controller <CarRentalManagementEntities, Reservation> .UpdateEntity(res); }
public void MoveToAvailable() { CarRentalManagementEntities context = new CarRentalManagementEntities(); int selectedrowindexCarId = dataGridViewAvailableCars.SelectedCells[0].RowIndex; DataGridViewRow selectedRowCarId = dataGridViewAvailableCars.Rows[selectedrowindexCarId]; string carId = Convert.ToString(selectedRowCarId.Cells["CarId"].Value); var isReserved = (from reserved in context.Reservations where reserved.CarId == Int32.Parse(carId) select new { isReserved = reserved.IsReturend }); }
public AdminForm() { rentalDataSet = new DataSet() { DataSetName = "rentalDataSet", }; context = new CarRentalManagementEntities(); InitializeComponent(); InitializeAdminForm(); buttonAddNewCar.Click += ButtonAddNewCar_Click; buttonViewReports.Click += ButtonViewReports_Click; buttonMoveToAvailable.Click += ButtonMoveToAvailable_Click; buttonBackupDatabase.Click += ButtonBackupDatabase_Click; }
public void MoveToAvailable() { CarRentalManagementEntities context = new CarRentalManagementEntities(); int selectedrowindexCarId = dataGridViewAvailableCars.SelectedCells[0].RowIndex; DataGridViewRow selectedRowCarId = dataGridViewAvailableCars.Rows[selectedrowindexCarId]; string carId = Convert.ToString(selectedRowCarId.Cells["CarId"].Value); Reservation isReturned = new Reservation() { IsReturend = false, }; context.Reservations.Find(carId); }
public void AddNewCar() { context = new CarRentalManagementEntities(); Car newCar = new Car() { Color = textBoxCarColor.Text, Model = textBoxCarModel.Text, Year = Int32.Parse(textBoxCarYear.Text), Price = Int32.Parse(textBoxCarPrice.Text), }; try { context.Cars.Add(newCar); context.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot add car to databse" + ex.InnerException.InnerException.Message); return; } }
/// <summary> /// Method to add new type in car types. /// </summary> public void AddNewType() { CarRentalManagementEntities entities = new CarRentalManagementEntities(); CarType carType = new CarType() { Type = textBoxCarType.Text }; try { entities.CarTypes.Add(carType); entities.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot add Car Type to database" + ex.InnerException.InnerException.Message); return; } this.DialogResult = DialogResult.OK; entities.Dispose(); Close(); }
private void ButtonAddCarMake_Click(object sender, EventArgs e) { CarRentalManagementEntities entities = new CarRentalManagementEntities(); CarMake carMake = new CarMake() { Make = textBoxAddCarMake.Text }; try { entities.CarMakes.Add(carMake); entities.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot add Car Make to database" + ex.InnerException.InnerException.Message); return; } this.DialogResult = DialogResult.OK; entities.Dispose(); Close(); }