Example #1
0
        private void AddCustomerButton_Click(object sender, EventArgs e)
        {
            try
            {
                // If any of the fields is empty
                if (main.isEmpty(CustomerIDBox.Text) || main.isEmpty(DriversLicenseBox.Text) || main.isEmpty(NameBox.Text) ||
                    main.isEmpty(PhoneNumberBox.Text) || main.isEmpty(AddressBox.Text) || main.isEmpty(CityBox.Text) ||
                    main.isEmpty(ProvinceBox.Text) || main.isEmpty(PostalCodeBox.Text))
                {
                    MessageBox.Show("Please fill in all fields");
                    return;
                }

                string command = "INSERT INTO Customer VALUES('" + CustomerIDBox.Text + "','" + DriversLicenseBox.Text.ToUpper() + "','" + text.ToTitleCase(NameBox.Text) + "','" +
                                 PhoneNumberBox.Text + "','" + text.ToTitleCase(AddressBox.Text) + "','" + text.ToTitleCase(CityBox.Text) + "','" +
                                 text.ToTitleCase(ProvinceBox.Text) + "','" + PostalCodeBox.Text.ToUpper() + "')";

                datab.insert(command);

                main.CustomersDGV_LoadAll(datab);
                this.Close();
            }
            catch (Exception e2)
            {
                //  MessageBox.Show("VIN already exists in the system", "VIN Error");
                MessageBox.Show(e2.ToString(), "Error");
            }
        }
Example #2
0
        private void SubmitChangesButton_Click(object sender, EventArgs e)
        {
            /* 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 (CustomerIDBox.Text != this.getCustomerIDValue() && !main.isEmpty(CustomerIDBox.Text))
                {
                    string updatecID = "UPDATE Customer SET cID = '" + CustomerIDBox.Text + "' WHERE cID = '" + this.getCustomerIDValue() + "'";
                    datab.insert(updatecID);
                }


                if (DriversLicenseBox.Text != this.getDriverLicenseValue() && !main.isEmpty(DriversLicenseBox.Text))
                {
                    string updateDriversLicense = "UPDATE Customer SET driverLicense = '" + DriversLicenseBox.Text + "' WHERE driverLicense = '" + this.getDriverLicenseValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updateDriversLicense);
                }


                if (NameBox.Text != this.getNameValue() && !main.isEmpty(NameBox.Text))
                {
                    string updateName = "UPDATE Customer SET name = '" + NameBox.Text + "' WHERE name = '" + this.getNameValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updateName);
                }

                if (PhoneNumberBox.Text != this.getPhoneNumberValue() && !main.isEmpty(PhoneNumberBox.Text))
                {
                    string updatePhoneNumber = "UPDATE Customer SET phoneNumber = '" + PhoneNumberBox.Text + "' WHERE phoneNumber = '" + this.getPhoneNumberValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updatePhoneNumber);
                }

                if (AddressBox.Text != this.getAddressValue() && !main.isEmpty(AddressBox.Text))
                {
                    string updateAddress = "UPDATE Customer SET address1 = '" + AddressBox.Text + "' WHERE address1 = '" + this.getAddressValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updateAddress);
                }
                if (CityBox.Text != this.getCityValue() && !main.isEmpty(CityBox.Text))
                {
                    string updateCity = "UPDATE Customer SET city = '" + CityBox.Text + "' WHERE city = '" + this.getCityValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updateCity);
                }

                if (ProvinceBox.Text != this.getProvinceValue() && !main.isEmpty(ProvinceBox.Text))
                {
                    string updateProvince = "UPDATE Customer SET province = '" + ProvinceBox.Text + "' WHERE province = '" + this.getProvinceValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updateProvince);
                }
                if (PostalCodeBox.Text != this.getPostalCodeValue() && !main.isEmpty(PostalCodeBox.Text))
                {
                    string updatePostalCode = "UPDATE Customer SET postCode = '" + PostalCodeBox.Text + "' WHERE postCode = '" + this.getPostalCodeValue() + "' AND cID ='" + getCustomerIDValue() + "'";
                    datab.insert(updatePostalCode);
                }

                main.CustomersDGV_LoadAll(datab);
                this.Close();
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.ToString(), "Error");
            }
        }