// Called when register button is clicked private void buttonRegVeh_Click(object sender, EventArgs e) { MotorVehicle mv = null; if(radioButtonTruck.Checked) { //cast //cast mv = new Truck(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, dateTimePicker1.Value, Convert.ToDouble(textBox1.Text)); } if (radioButtonBus.Checked) { //cast //cast mv = new Bus(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, dateTimePicker1.Value, textBox1.Text); } if (radioButtonCar.Checked) { //cast //cast mv = new Car(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, dateTimePicker1.Value, textBox1.Text, radioButtonYes.Checked, Convert.ToInt32(textBox2.Text)); } vehicles.Add(mv); richTextBox1.Clear(); foreach (MotorVehicle mV in vehicles) { if (mV != null) { richTextBox1.AppendText(mv.show() + "\n\n"); FileStream file = new FileStream(fileName, FileMode.Append, FileAccess.Write); StreamWriter writer = new StreamWriter(file); writer.WriteLine(mv.show()); writer.Close(); file.Close(); } } }
//Button Click method. Creates objects, puts them in our array, then displays them in log as well as stores them in out textfile private void RegisterVehicleClick(object sender, EventArgs e) { MotorVehicle mv = null; if (rbTruck.Checked) { mv = new Truck(tbVIN.Text, tbMake.Text, tbModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, datePicker.Value, Convert.ToDouble(customTb01.Text)); } else if (rbBus.Checked) { mv = new Bus(tbVIN.Text, tbMake.Text, tbModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, datePicker.Value, customTb01.Text); } else if (rbCar.Checked) { mv = new Car(tbVIN.Text, tbMake.Text, tbModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, datePicker.Value, customTb01.Text, rbYes.Checked, Convert.ToInt32(customTb02.Text)); } else if (rbTaxi.Checked) { mv = new Taxi(tbVIN.Text, tbMake.Text, tbModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, datePicker.Value, customTb01.Text, rbYes.Checked, Convert.ToInt32(customTb02.Text), rbYes2.Checked); } vehicleList.Add(mv); //Append newest object to array rtLog.Clear(); foreach(MotorVehicle m in vehicleList) //Display and store in textfile { if (m != null) { rtLog.AppendText(m.show() + "\n\n"); using (FileStream file = new FileStream(textFile, FileMode.Append, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(file)) { writer.WriteLine(m.show()); writer.Close(); } file.Close(); } } } }