Inheritance: MotorVehicle
        // 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();
                }
            }
        }
示例#2
0
        // 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));
            }

            richTextBox1.Text = mv.show();
            FileStream file = new FileStream(fileName, FileMode.Append, FileAccess.Write);
            StreamWriter writer = new StreamWriter(file);
            writer.WriteLine(mv.show());
            writer.Close();
            file.Close();

            if (!File.Exists("RegisteredVehicles.txt"))
            {
                File.Create("RegisteredVehicles.txt").Close();
            }
            if (!Directory.Exists("C:\\DVM\\BACKUP"))
            {
                Directory.CreateDirectory("C:\\DVM\\BACKUP");
            }
            File.Move("RegisteredVehicles.txt", "C:\\DVM\\Backup\\RegisteredVehicles.txt");
            String name = "C:\\DVM\\Backup\\RegisteredVehicles" + DateTime.Now.ToString("HH-mm-ss dd-MM-yyyy") + ".txt";
            File.Move("C:\\DVM\\Backup\\RegisteredVehicles.txt", name);
            file = new FileStream(name, FileMode.Append, FileAccess.Write);
            writer = new StreamWriter(file);
            StringBuilder sb = new StringBuilder();
            writer.WriteLine(mv.show());
            writer.Close();
            file.Close();
            lastUsedFileName = name;
        }
示例#3
0
        private void buttonRegVeh_Click(object sender, EventArgs e)
        {
            MotorVehicle mv = null;
            if(radioButtonTruck.Checked)
            {                                                                         //cast                    //cast
                mv = new Truck(textBoxVIN.Text, textBoxMake.Text, textBoxModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, dateTimePicker1.Value, Convert.ToDouble(textBox1.Text));
            }

            vehicles[count++] = mv;

            richTextBox1.Clear();

            foreach(MotorVehicle m in vehicles)
            {
                if (m != null) richTextBox1.AppendText(m.show() + '\n');
            }
        }
        //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();
                    }

                }
            }
        }
示例#5
0
        private void RegisterVehicleClick(object sender, EventArgs e) //Button Click method. Creates objects, puts them in our array, then displays them in log as well as stores them in out textfile
        {
            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);
            }

            vehicleArray[mvArrayCounter++] = mv; //Append newest object to array

            rtLog.Clear();



            foreach (MotorVehicle m in vehicleArray) //Display and store in textfile
            {
                if (m != null)
                {
                    rtLog.AppendText(m.show() + "\n\n");
                    FileStream file = new FileStream(textFile, FileMode.Append, FileAccess.Write);
                    try
                    {
                        StreamWriter writer = new StreamWriter(file);
                        try
                        {
                            writer.WriteLine(m.show());
                            writer.Close();
                        }
                        catch (Exception exc)
                        {
                            throw exc;
                        }
                        finally
                        {
                            writer.Dispose();
                        }
                    }
                    catch (Exception exc)
                    {
                        throw exc;
                    }
                    finally
                    {
                        file.Close();
                        file.Dispose();
                    }
                }
            }
        }