Exemplo n.º 1
0
        private void btnAddSupplier_Click(object sender, EventArgs e)
        {
            Boolean validName = Validation.ValidateName(txtSupplierName.Text);

            if (validName == false)
            {
                txtSupplierName.Clear();
                txtSupplierName.Focus();
                MessageBox.Show("Incorrect Name format");
            }

            Boolean validAdd1 = Validation.ValidateAdd(txtAddressLine1.Text);

            if (validAdd1 == false)
            {
                txtAddressLine1.Clear();
                txtAddressLine1.Focus();
                MessageBox.Show("Incorrect Address Line 1");
            }

            Boolean validAdd2 = Validation.ValidateAdd(txtAddressLine2.Text);

            if (validAdd2 == false)
            {
                txtAddressLine2.Clear();
                txtAddressLine2.Focus();
                MessageBox.Show("Incorrect Address Line 2");
            }

            Boolean validTown = Validation.ValidateTown(txtTown.Text);

            if (validTown == false)
            {
                txtTown.Focus();
                MessageBox.Show("Incorrect Town");
            }

            Boolean validCounty = Validation.ValidateCounty(txtCounty.Text);

            if (validCounty == false)
            {
                txtCounty.Focus();
                MessageBox.Show("Incorrect County");
            }

            Boolean validPhone = Validation.ValidatePhone(txtPhone.Text);

            if (validPhone == false)
            {
                txtPhone.Clear();
                txtPhone.Focus();
                MessageBox.Show("Incorrect Phone format");
            }

            Boolean validEmail = Validation.ValidateEmail(txtEmail.Text);

            if (validEmail == false)
            {
                txtEmail.Focus();
                MessageBox.Show("Incorrect Email address");
            }

            if (validName && validAdd1 && validAdd2 && validTown && validCounty && validPhone && validEmail)
            {
                int    supplierId = Convert.ToInt16(Supplier.getNextSupplierId());
                string name       = txtSupplierName.Text.ToUpper();
                string add1       = txtAddressLine1.Text;
                string add2       = txtAddressLine2.Text;
                string town       = txtTown.Text;
                string county     = txtCounty.Text;
                string email      = txtEmail.Text;
                string phone      = txtPhone.Text;
                string status     = "A";
                float  balance    = 0;

                Supplier newSupplier = new Supplier(supplierId, name, add1, add2, town, county, email, phone, status, balance);
                newSupplier.AddSupplier();

                MessageBox.Show("You have added a new Supplier");

                txtSupplierName.Clear();
                txtAddressLine1.Clear();
                txtAddressLine2.Clear();
                txtTown.Clear();
                txtCounty.Clear();
                txtEmail.Clear();
                txtPhone.Clear();

                txtSupplierId.Text = Supplier.getNextSupplierId().ToString("00000");
                txtSupplierName.Focus();
            }
        }
        private void btnUpdateSupplier_Click(object sender, EventArgs e)
        {
            Boolean validName = Validation.ValidateName(txtSupplierName.Text);

            if (validName == false)
            {
                txtSupplierName.Clear();
                txtSupplierName.Focus();
                MessageBox.Show("Incorrect Name format");
            }

            Boolean validAdd1 = Validation.ValidateAdd(txtAddressLine1.Text);

            if (validAdd1 == false)
            {
                txtAddressLine1.Clear();
                txtAddressLine1.Focus();
                MessageBox.Show("Incorrect Address Line 1");
            }

            Boolean validAdd2 = Validation.ValidateAdd(txtAddressLine2.Text);

            if (validAdd2 == false)
            {
                txtAddressLine2.Clear();
                txtAddressLine2.Focus();
                MessageBox.Show("Incorrect Address Line 2");
            }

            Boolean validTown = Validation.ValidateTown(txtTown.Text);

            if (validTown == false)
            {
                txtTown.Focus();
                MessageBox.Show("Incorrect Town");
            }

            Boolean validCounty = Validation.ValidateCounty(txtCounty.Text);

            if (validCounty == false)
            {
                txtCounty.Focus();
                MessageBox.Show("Incorrect County");
            }

            Boolean validPhone = Validation.ValidatePhone(txtPhone.Text);

            if (validPhone == false)
            {
                txtPhone.Clear();
                txtPhone.Focus();
                MessageBox.Show("Incorrect Phone format");
            }

            Boolean validEmail = Validation.ValidateEmail(txtEmail.Text);

            if (validEmail == false)
            {
                txtEmail.Focus();
                MessageBox.Show("Incorrect Email address");
            }

            if (validName && validAdd1 && validAdd2 && validTown && validCounty && validPhone && validEmail)
            {
                int    supplierId = Convert.ToInt16(txtSupplierId.Text);
                string name       = txtSupplierName.Text;
                string add1       = txtAddressLine1.Text;
                string add2       = txtAddressLine2.Text;
                string town       = txtTown.Text;
                string county     = txtCounty.Text;
                string email      = txtEmail.Text;
                string phone      = txtPhone.Text;



                //connect to the db
                OracleConnection connect = new OracleConnection(DBConnect.oradb);

                //define Sql Command
                String strSQL = "UPDATE Supplier SET SupplierName = '" + name + "',AddressLine1 = '" + add1 + "',AddressLine2 = '" + add2 + "', Town = '" + town + "', County = +'" + county + "', Email = '" + email + "', Phone = '" + phone + "', Status = 'A' where SupplierId = " + supplierId;

                //Execute Query
                OracleCommand cmd = new OracleCommand(strSQL, connect);

                connect.Open();

                cmd.ExecuteNonQuery();


                //Close Db
                connect.Close();

                MessageBox.Show(name + " has been updated");

                txtSearch.Clear();
                txtSupplierId.Clear();
                txtSupplierName.Clear();
                txtAddressLine1.Clear();
                txtAddressLine2.Clear();
                txtTown.Clear();
                txtCounty.Clear();
                txtEmail.Clear();
                txtPhone.Clear();


                txtSearch.Focus();

                grdData.DataSource = null;
            }
        }