private void btnSave_Click(object sender, EventArgs e) { //MyCar car = (MyCar)this.cmbBoxCars.SelectedItem; if (this.cmbBoxCars.SelectedItem is Truck) { vehicle = (Truck)this.cmbBoxCars.SelectedItem; //vehicle.bedSize = ""; } else if (this.cmbBoxCars.SelectedItem is Suv) { vehicle = (Suv)this.cmbBoxCars.SelectedItem; } else if (this.cmbBoxCars.SelectedItem is Sedan) { vehicle = (Sedan)this.cmbBoxCars.SelectedItem; } else { //MessageBox.Show(invalidObject); } vehicle.make = viewMake.Text.ToString(); vehicle.model = viewModel.Text.ToString(); vehicle.color = viewColor.Text.ToString(); int cy = 0, d = 0; if (int.TryParse(viewCylinders.Text.ToString(), out cy)) { vehicle.cylinders = cy; } if (int.TryParse(viewDoors.Text.ToString(), out d)) { vehicle.doors = d; } double p = 0.0; if (double.TryParse(viewPrice.Text.ToString(), out p)) { vehicle.price = p; } //vehicle.option = viewOption.Text.ToString(); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { String[] info = null; if (this.cmbBoxCars.SelectedItem is Truck) { MessageBox.Show(truck); vehicle = (Truck)this.cmbBoxCars.SelectedItem; lblOption.Text = "Bed Size"; } else if (this.cmbBoxCars.SelectedItem is Suv) { MessageBox.Show(suv); vehicle = (Suv)this.cmbBoxCars.SelectedItem; lblOption.Text = "Drivetrain"; } else if (this.cmbBoxCars.SelectedItem is Sedan) { MessageBox.Show(sedan); vehicle = (Sedan)this.cmbBoxCars.SelectedItem; lblOption.Text = "Transmission"; } else { MessageBox.Show(invalidObject); } info = vehicle.print(); viewMake.Text = vehicle.print()[0]; viewModel.Text = info[1]; viewColor.Text = info[2]; viewCylinders.Text = info[3]; viewDoors.Text = info[4]; viewPrice.Text = info[5]; viewOption.Text = info[6]; }
private void btnCreate_Click(object sender, EventArgs e) { MyCar car = null; make = txtMake.Text.ToString(); model = txtModel.Text.ToString(); color = txtColor.Text.ToString(); cylinder = txtCylinders.Text.ToString(); doors = txtDoors.Text.ToString(); price = txtPrice.Text.ToString(); truck = rbtnTruck.Checked; suv = rbtnSuv.Checked; sedan = rbtnSedan.Checked; if (make.Equals("") || model.Equals("") || color.Equals("") || cylinder.Equals("") || doors.Equals("") || price.Equals("") /* || groupBox1.Controls.OfType<RadioButton>().Any(x => x.Checked) */) { MessageBox.Show("There is an empty field."); } else { if (rbtnTruck.Checked) { car = new Truck(txtOption.Text.ToString()); } else if (rbtnSedan.Checked) { car = new Sedan(txtOption.Text.ToString()); } else if (rbtnSuv.Checked) { car = new Suv(txtOption.Text.ToString()); } else { } car.make = make; car.model = model; car.color = color; if (int.TryParse(cylinder, out cy)) { car.cylinders = cy; } else { MessageBox.Show("Cylinders must be a number"); } if (int.TryParse(doors, out d)) { car.doors = d; } if (double.TryParse(price, out p)) { car.price = p; } carList.add(car); var alert = MessageBox.Show("CAR CREATED\n\n" + car.make + "\n" + car.model + "\n" + car.color + "\n" + car.cylinders.ToString() + "\n" + car.doors.ToString() + "\n" + car.price.ToString() + "\n" ); txtMake.Text = ""; txtModel.Text = ""; txtColor.Text = ""; txtCylinders.Text = ""; txtDoors.Text = ""; txtPrice.Text = ""; txtOption.Text = ""; rbtnSedan.Checked = false; rbtnSuv.Checked = false; rbtnTruck.Checked = false; lblOption.Text = ""; } }
public void add(MyCar car) { carList.Add(car); }