Exemple #1
0
        //Event-Handler when add button is clicked
        //New Vehicle
        private void addCarBtn_Click(object sender, EventArgs e)
        {
            //Execute Add button
            if (!makeTextBox.ReadOnly)
            {
                try
                {
                    //Parse the data from textboxes/////
                    //Car Textboxes
                    string make  = makeTextBox.Text;
                    string model = modelTextBox.Text;
                    int    year  = Int32.Parse(yearTextBox.Text);

                    Vehicle carObj = new Vehicle(make, model, year);

                    //Oil Textboxes
                    string w      = weightTextBox.Text;
                    string b      = brandTextBox.Text;
                    double qty    = Double.Parse(qtyTextBox.Text);
                    double oprice = Double.Parse(oPriceTextBox.Text);
                    string fb     = fBrandTextBox.Text;
                    double fp     = Double.Parse(fPriceTextBox.Text);

                    Oil oilObj = new Oil(w, b, qty, oprice, fb, fp);

                    //Service info
                    double   labor    = Double.Parse(laborHourTextBox.Text);
                    DateTime sDate    = DateTime.Parse(dateTimePicker1.Text);
                    int      sMileage = Int32.Parse(sMileageTxtbox.Text);
                    DateTime ns       = dateTimePicker2.Value;
                    int      nm       = Int32.Parse(nextSMileageTxtbox.Text);

                    //Add new vehicle to the file
                    fileData.AddVehicleService(carObj, oilObj, labor, sDate, sMileage, ns, nm);


                    //Read the file
                    eLines = File.ReadLines(fileTarget);

                    //Update main source
                    updateCarList(ParseFile(eLines));

                    //Display the added data in a message box//
                    string msg = carObj.ToString() + oilObj.ToString();

                    MessageBox.Show("Car has been successfully added: \n" + msg);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                gridCarSelect.ClearSelection();

                ToggleReadOnly(makeTextBox, modelTextBox, yearTextBox, weightTextBox, brandTextBox, qtyTextBox, oPriceTextBox, fBrandTextBox, fPriceTextBox, laborHourTextBox, sMileageTxtbox, nextSMileageTxtbox);
                dateTimePicker1.Enabled = false;
                dateTimePicker2.Enabled = false;
                gridCarSelect.Enabled   = true;
                return;
            }


            //Unlock textboxes for user input
            ToggleReadOnly(makeTextBox, modelTextBox, yearTextBox, weightTextBox, brandTextBox, qtyTextBox, oPriceTextBox, fBrandTextBox, fPriceTextBox, laborHourTextBox, sMileageTxtbox, nextSMileageTxtbox);
            dateTimePicker1.Enabled = true;
            dateTimePicker2.Enabled = true;

            //Clears out everything
            newForm();
        }