Esempio n. 1
0
        private void SubmitChangesButton_Click(object sender, EventArgs e)
        {
            if (!main.isMakeValid(MakeBox.Text) && MakeBox.Text != "")
            {
                MessageBox.Show(MakeBox.Text + " is not a valid make", "Car Make Error");
                return;
            }

            /* Compare the corresponding input text to the value of the cell selected. If they are different update. If not, dont do anything*/
            try
            {
                // converts the string into something "System.Globalization" can manipulate?
                TextInfo text = CultureInfo.CurrentCulture.TextInfo;

                // Ensure the input text is not empty and different from the original value
                if (VINBox.Text != this.getVINValue() && !main.isEmpty(VINBox.Text))
                {
                    string updateVIN = "UPDATE Car SET VIN = '" + VINBox.Text.ToUpper() + "' WHERE VIN = '" + this.getVINValue() + "'";
                    datab.insert(updateVIN);
                }


                if (MakeBox.Text != this.getMakeValue() && !main.isEmpty(MakeBox.Text))
                {
                    string updateMake = "UPDATE Car SET make = '" + main.ProperMakeFormat(MakeBox) + "' WHERE make = '" + this.getMakeValue() + "' AND VIN ='" + VINBox.Text + "'";
                    datab.insert(updateMake);
                }


                if (ModelBox.Text != this.getModelValue() && !main.isEmpty(ModelBox.Text))
                {
                    string updateModel = "UPDATE Car SET model = '" + text.ToTitleCase(ModelBox.Text) + "' WHERE model = '" + this.getModelValue() + "' AND VIN ='" + VINBox.Text + "'";
                    datab.insert(updateModel);
                }

                if (ColorBox.Text != this.getColorValue() && !main.isEmpty(ColorBox.Text))
                {
                    string updateColor = "UPDATE Car SET color = '" + text.ToTitleCase(ColorBox.Text) + "' WHERE color = '" + this.getColorValue() + "' AND VIN ='" + VINBox.Text + "'";
                    datab.insert(updateColor);
                }

                if (CarTypeDropBox.Text != this.getcTypeValue() && !main.isEmpty(CarTypeDropBox.Text))
                {
                    string updatecType = "UPDATE Car SET cType = '" + main.ProperCarTypeFormat(CarTypeDropBox) + "' WHERE cType = '" + this.getcTypeValue() + "' AND VIN ='" + VINBox.Text + "'";
                    datab.insert(updatecType);
                }
                if (BranchIDDropBox.Text != this.getbIDValue() && !main.isEmpty(BranchIDDropBox.Text))
                {
                    string updatebID = "UPDATE Car SET branchID = '" + BranchIDDropBox.Text + "' WHERE branchID = '" + this.getbIDValue() + "' AND VIN ='" + VINBox.Text + "'";
                    datab.insert(updatebID);
                }

                main.CarsDGV_LoadAll(datab);
                this.Close();
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.ToString(), "Error");
            }
        }
Esempio n. 2
0
        private void AddCarButton_Click(object sender, EventArgs e)
        {
            // Error message if inputted text is not found in the ModelsList array
            if (!main.isMakeValid(MakeBox.Text) && MakeBox.Text != "")
            {
                MessageBox.Show(text.ToTitleCase(MakeBox.Text) + " is not a valid make", "Car Make Error");
                return;
            }

            try
            {
                // If any of the fields is empty
                if (main.isEmpty(VINBox.Text) || main.isEmpty(MakeBox.Text) || main.isEmpty(ModelBox.Text) ||
                    main.isEmpty(ColorBox.Text) || main.isEmpty(CarTypeDropBox.Text) || main.isEmpty(BranchIDDropBox.Text))
                {
                    MessageBox.Show("Please fill in all fields");
                    return;
                }

                // Proper make format variable
                string Make;

                // if 'bmw', 'gmc', or 'srt' is entered, make them all upper case
                if (MakeBox.Text.ToLower() == "bmw" || MakeBox.Text.ToLower() == "gmc" || MakeBox.Text.ToLower() == "srt")
                {
                    Make = MakeBox.Text.ToUpper();
                }

                else
                {
                    Make = text.ToTitleCase(MakeBox.Text);
                }



                string command = "INSERT INTO Car VALUES('" + VINBox.Text.ToUpper() + "','" + main.ProperMakeFormat(MakeBox) + "','" + text.ToTitleCase(ModelBox.Text) + "','" +
                                 text.ToTitleCase(ColorBox.Text) + "','" + main.ProperCarTypeFormat(CarTypeDropBox) + "'," + BranchIDDropBox.Text + ")";

                datab.insert(command);

                main.CarsDGV_LoadAll(datab);
                this.Close();
            }
            catch (Exception e2)
            {
                //  MessageBox.Show("VIN already exists in the system", "VIN Error");
                MessageBox.Show(e2.ToString(), "Error");
            }
        }