Example #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Live date and Time
            timer1.Start();
            Time_Label.Text = DateTime.Now.ToLongTimeString();

            Date_Label.Text = DateTime.Now.ToLongDateString();
            try
            {
                //create the list object for car and truck
                Vehicle_SZ.Car_List_SZ   = new List <Car_SZ>();                // Car List Object
                Vehicle_SZ.Truck_List_SZ = new List <Truck_SZ>();              // Truck List Object

                StreamReader Car_Reader_SZ   = new StreamReader("Cars.txt");   // car file
                StreamReader Truck_Reader_SZ = new StreamReader("Trucks.txt"); // truck file

                string   Each_Object_SZ  = "";
                string[] Spilt_Object_SZ = new string[7]; // 7 spaces for my 7 values

                while (!Car_Reader_SZ.EndOfStream)        // loop puts every value in order
                {
                    Car_SZ carVehicle = new Car_SZ();     //declare
                    Each_Object_SZ             = Car_Reader_SZ.ReadLine();
                    Spilt_Object_SZ            = Each_Object_SZ.Split(',');
                    carVehicle.VIN_SZ          = Spilt_Object_SZ[0];
                    carVehicle.Make_SZ         = Spilt_Object_SZ[1];
                    carVehicle.Model_SZ        = Spilt_Object_SZ[2];
                    carVehicle.Year_SZ         = int.Parse(Spilt_Object_SZ[3]);
                    carVehicle.Invoice_SZ      = int.Parse(Spilt_Object_SZ[4]);
                    carVehicle.Mileage_SZ      = int.Parse(Spilt_Object_SZ[5]);
                    carVehicle.PurchaseDate_SZ = Spilt_Object_SZ[6];
                    Vehicle_SZ.Car_List_SZ.Add(carVehicle);
                }
                //close car reader
                Car_Reader_SZ.Close();

                while (!Truck_Reader_SZ.EndOfStream)        // same loop for truck
                {
                    Truck_SZ truckVehicle = new Truck_SZ(); //declare
                    Each_Object_SZ               = Truck_Reader_SZ.ReadLine();
                    Spilt_Object_SZ              = Each_Object_SZ.Split(',');
                    truckVehicle.VIN_SZ          = Spilt_Object_SZ[0];
                    truckVehicle.Make_SZ         = Spilt_Object_SZ[1];
                    truckVehicle.Model_SZ        = Spilt_Object_SZ[2];
                    truckVehicle.Year_SZ         = int.Parse(Spilt_Object_SZ[3]);
                    truckVehicle.Invoice_SZ      = int.Parse(Spilt_Object_SZ[4]);
                    truckVehicle.Mileage_SZ      = int.Parse(Spilt_Object_SZ[5]);
                    truckVehicle.PurchaseDate_SZ = Spilt_Object_SZ[6];
                    Vehicle_SZ.Truck_List_SZ.Add(truckVehicle);
                }
                //close truck reader
                Truck_Reader_SZ.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message); // Exception
            }
        }
Example #2
0
        private void Create_Vehicle_BTN_Click(object sender, EventArgs e)
        {
            try
            {
                if (Car_Radio_Button.Checked)
                {
                    // variable for textboxes
                    int Year_SZ, Invoice_SZ, Mileage_SZ;
                    int.TryParse(Vehicle_Year_SZ_M_TexTBox.Text, out Year_SZ);
                    int.TryParse(Invoice_SZ_Price_M_TexTBox.Text, out Invoice_SZ);
                    int.TryParse(Mileage_SZ_M_TexTBox.Text, out Mileage_SZ);
                    // date variable
                    DateTime PurchaseDate_SZ;
                    DateTime.TryParse(Date_Purchased_M_TexTBox.Text, out PurchaseDate_SZ);

                    //Calling my data Valdation
                    bool Validation_M_SZ;
                    Validation_M_SZ = CheckValid(Year_SZ, Invoice_SZ, Mileage_SZ, PurchaseDate_SZ);

                    if (Validation_M_SZ)
                    {
                        //If everything passeses create the car and set its properties

                        Car_SZ My_Car_SZ = new Car_SZ();
                        My_Car_SZ.VIN_SZ          = WinNum_M_TexTBox.Text;
                        My_Car_SZ.Make_SZ         = Make_SZ_M_TexTBox.Text;
                        My_Car_SZ.Model_SZ        = Model_SZ_M_TexTBox.Text;
                        My_Car_SZ.Year_SZ         = Year_SZ;
                        My_Car_SZ.Invoice_SZ      = Invoice_SZ;
                        My_Car_SZ.Mileage_SZ      = Mileage_SZ;
                        My_Car_SZ.PurchaseDate_SZ = PurchaseDate_SZ.ToString();
                        //adding car to my list
                        Vehicle_SZ.Car_List_SZ.Add(My_Car_SZ);
                        MessageBox.Show("Congratulations" + Environment.NewLine + " New Car Added.");

                        //clear text boxes for next vehicle
                        WinNum_M_TexTBox.Text           = "";
                        Make_SZ_M_TexTBox.Text          = "";
                        Model_SZ_M_TexTBox.Text         = "";
                        Vehicle_Year_SZ_M_TexTBox.Text  = "";
                        Invoice_SZ_Price_M_TexTBox.Text = "";
                        Mileage_SZ_M_TexTBox.Text       = "";
                        Date_Purchased_M_TexTBox.Text   = "MM/DD/YYYY";
                    }
                }
                else if (Truck_Radio_BTN.Checked)
                {
                    // variable for textboxes
                    int Year_SZ, Invoice_SZ, Mileage_SZ;
                    int.TryParse(Vehicle_Year_SZ_M_TexTBox.Text, out Year_SZ);
                    int.TryParse(Invoice_SZ_Price_M_TexTBox.Text, out Invoice_SZ);
                    int.TryParse(Mileage_SZ_M_TexTBox.Text, out Mileage_SZ);
                    // date variable
                    DateTime PurchaseDate_SZ;
                    DateTime.TryParse(Date_Purchased_M_TexTBox.Text, out PurchaseDate_SZ);

                    //Calling my data Valdation
                    bool Validation_M_SZ;
                    Validation_M_SZ = CheckValid(Year_SZ, Invoice_SZ, Mileage_SZ, PurchaseDate_SZ);

                    if (Validation_M_SZ)
                    {
                        //If everything passeses create the car and set its properties
                        Truck_SZ My_Truck_SZ = new Truck_SZ();
                        My_Truck_SZ.VIN_SZ          = WinNum_M_TexTBox.Text;
                        My_Truck_SZ.Make_SZ         = Make_SZ_M_TexTBox.Text;
                        My_Truck_SZ.Model_SZ        = Model_SZ_M_TexTBox.Text;
                        My_Truck_SZ.Year_SZ         = Year_SZ;
                        My_Truck_SZ.Invoice_SZ      = Invoice_SZ;
                        My_Truck_SZ.Mileage_SZ      = Mileage_SZ;
                        My_Truck_SZ.PurchaseDate_SZ = PurchaseDate_SZ.ToString();
                        //Adding truck to my list
                        Vehicle_SZ.Truck_List_SZ.Add(My_Truck_SZ);
                        MessageBox.Show("Congratulations" + Environment.NewLine + " New Truck Added.");

                        //clear text boxes for next vehicle
                        WinNum_M_TexTBox.Text           = "";
                        Make_SZ_M_TexTBox.Text          = "";
                        Model_SZ_M_TexTBox.Text         = "";
                        Vehicle_Year_SZ_M_TexTBox.Text  = "";
                        Invoice_SZ_Price_M_TexTBox.Text = "";
                        Mileage_SZ_M_TexTBox.Text       = "";
                        Date_Purchased_M_TexTBox.Text   = "MM/DD/YYYY";
                    }
                    else
                    {
                        // if none vehicle type is selected show this message
                        MessageBox.Show("Error" + Environment.NewLine + "Select a vehicle Type.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message); // Exception
            }
        }