Beispiel #1
0
        private void btnAddStock_Click(object sender, EventArgs e)
        {
            Boolean valid = Validation.ValidateAdd(txtStockName.Text);

            if (valid == false)
            {
                txtStockName.Focus();
                MessageBox.Show("Incorrect Name");
            }

            Boolean validDesc = Validation.ValidateAdd(txtDescription.Text);

            if (validDesc == false)
            {
                txtDescription.Focus();
                MessageBox.Show("Invalid characters used during description");
            }

            Boolean validSupplier = Validation.ValidateId(txtSupplier.Text);

            if (validSupplier == false)
            {
                txtSupplier.Focus();
            }

            if (valid && validDesc && validSupplier)
            {
                int    StockId     = Convert.ToInt16(Stock.getNextStockId());
                string name        = txtStockName.Text;
                string description = txtDescription.Text;
                int    amount      = Convert.ToInt16(txtAmount.Text);
                float  quantity    = float.Parse(txtPrice.Text);
                int    supplier    = Convert.ToInt16(txtSupplier.Text);
                string status      = "A";


                Stock newStock = new Stock(StockId, name, description, amount, quantity, supplier, status);
                newStock.AddStock();

                MessageBox.Show("You have added a new item of Stock");

                txtStockId.Clear();
                txtStockName.Clear();
                txtDescription.Clear();
                txtSupplier.Clear();
                txtAmount.Value = 0;
                txtPrice.Value  = 0;

                txtStockId.Text = Stock.getNextStockId().ToString("00000");
                txtStockName.Focus();
            }
        }
        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 btnUpdateStock_Click(object sender, EventArgs e)
        {
            Boolean valid = Validation.ValidateAdd(txtStockName.Text);

            if (valid == false)
            {
                txtStockName.Focus();
                MessageBox.Show("Incorrect Name");
            }

            Boolean validDesc = Validation.ValidateAdd(txtDescription.Text);

            if (validDesc == false)
            {
                txtDescription.Focus();
                MessageBox.Show("Invalid characters used during description");
            }

            Boolean validSupplier = Validation.ValidateId(txtSupplier.Text);

            if (validSupplier == false)
            {
                txtSupplier.Focus();
            }



            if (valid && validDesc && validSupplier)
            {
                int    StockId     = Convert.ToInt16(txtStockId.Text);
                string name        = txtStockName.Text;
                string description = txtDescription.Text;
                int    amount      = Convert.ToInt16(txtAmount.Text);
                float  price       = float.Parse(txtPrice.Text);
                int    supplier    = Convert.ToInt16(txtSupplier.Text);



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

                //define Sql Command
                String strSQL = "UPDATE Stock SET StockName = '" + name + "',Description = '" + description + "',Amount = " + amount + ", Price = " + price + ", SupplierId = " + supplier + ", Status = 'A' where StockId = " + StockId;


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



                connect.Open();


                cmd.ExecuteNonQuery();



                //Close Db
                connect.Close();

                MessageBox.Show("The Stock details have been updated and saved in the stock file");


                txtSearch.Clear();
                txtStockId.Clear();
                txtStockName.Clear();
                txtDescription.Clear();
                txtAmount.Clear();
                txtPrice.Clear();
                txtSupplier.Clear();

                grdData.DataSource = null;
            }
        }
        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;
            }
        }