예제 #1
0
        // This part here is called when we click on register button
        private void buttonRegVeh_Click(object sender, EventArgs e)
        {
            MotorVehicle mv = null;
            if(radioButtonTruck.Checked) // if radio button for truck is checked
            {
                // This calls for boxes, what to input if truck is selected

                mv = new Truck(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, dateTimePicker1.Value, Convert.ToDouble(textBox1.Text));
            }
            if(radioButtonBus.Checked)
            {

                // If bus is selected..
                mv = new Bus(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfSeats.Value, (int)NoOfWheels.Value, dateTimePicker1.Value, textBox1.Text);
            }
            if(radioButtonTaxi.Checked)
            {

                // Taxi selected
                mv = new Taxi(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfSeats.Value, (int)NoOfWheels.Value, dateTimePicker1.Value, textBox1.Text,true,Convert.ToInt32(textBox2.Text),radioButtonYes.Checked);
            }
            if(radioButtonCar.Checked)
            {
                mv = new Car(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfSeats.Value, (int)NoOfWheels.Value, dateTimePicker1.Value, textBox1.Text,radioButtonYes.Checked,Convert.ToInt32(textBox2.Text));
            }
            if(radioButtonMotorcycle.Checked)
            {
                MessageBox.Show("Not implemented to do");
                return;
            }

            // This checks if you have or haven't choose type of vehicle. If it's null, or not selected anything
            // it shows message box to choose one type of vehicle.
            if(mv==null)
            {

                MessageBox.Show("Please choose type of vehicle!");
                return;

            }
            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();

                // Checks if file exists

            if (!File.Exists("RegisteredVehicles.txt"))
            {
                File.Create("RegisteredVehicles.txt").Close();
            }

                // Checks if directory exists

            if (!Directory.Exists("C:\\DVM\\BACKUP"))
            {

                Directory.CreateDirectory("C:\\DVM\\BACKUP"); // If it doesn't exist, it creates it
            }

            // Moves file to backup Registered Vehicles
            File.Move("RegisteredVehicles.txt", "C:\\DVM\\Backup\\RegisteredVehicles.txt");

            // adding date to it's name
            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;
        }
예제 #2
0
        // This part here is called when we click on register button

        private void buttonRegVeh_Click(object sender, EventArgs e)
        {
            MotorVehicle mv = null;

            if (radioButtonTruck.Checked) // if radio button for truck is checked
            {
                // This calls for boxes, what to input if truck is selected

                mv = new Truck(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfWheels.Value, (int)NoOfSeats.Value, dateTimePicker1.Value, Convert.ToDouble(textBox1.Text));
            }
            if (radioButtonBus.Checked)
            {
                // If bus is selected..
                mv = new Bus(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfSeats.Value, (int)NoOfWheels.Value, dateTimePicker1.Value, textBox1.Text);
            }
            if (radioButtonTaxi.Checked)
            {
                // Taxi selected
                mv = new Taxi(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfSeats.Value, (int)NoOfWheels.Value, dateTimePicker1.Value, textBox1.Text, true, Convert.ToInt32(textBox2.Text), radioButtonYes.Checked);
            }
            if (radioButtonCar.Checked)
            {
                mv = new Car(textBoxVIN.Text, ComboBoxMake.Text, textBoxModel.Text, (int)NoOfSeats.Value, (int)NoOfWheels.Value, dateTimePicker1.Value, textBox1.Text, radioButtonYes.Checked, Convert.ToInt32(textBox2.Text));
            }
            if (radioButtonMotorcycle.Checked)
            {
                MessageBox.Show("Not implemented to do");
                return;
            }

            // This checks if you have or haven't choose type of vehicle. If it's null, or not selected anything
            // it shows message box to choose one type of vehicle.
            if (mv == null)
            {
                MessageBox.Show("Please choose type of vehicle!");
                return;
            }
            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();

            // Checks if file exists

            if (!File.Exists("RegisteredVehicles.txt"))
            {
                File.Create("RegisteredVehicles.txt").Close();
            }

            // Checks if directory exists

            if (!Directory.Exists("C:\\DVM\\BACKUP"))
            {
                Directory.CreateDirectory("C:\\DVM\\BACKUP"); // If it doesn't exist, it creates it
            }

            // Moves file to backup Registered Vehicles
            File.Move("RegisteredVehicles.txt", "C:\\DVM\\Backup\\RegisteredVehicles.txt");

            // adding date to it's name
            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;
        }