Пример #1
0
        //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();
                    }

                }
            }
        }