コード例 #1
0
        private void btnPaySupplier_Click(object sender, EventArgs e)
        {
            Boolean valid = Validation.ValidateAmount(txtAmountToPay.Text);

            MessageBox.Show("" + valid);

            if (valid)
            {
                float pay     = float.Parse(txtAmountToPay.Text);
                float balance = float.Parse(txtBalance.Text);

                if (balance > 0)
                {
                    if (balance >= pay)
                    {
                        float remainder = balance - pay;
                        int   id        = Convert.ToInt16(txtSupplierId.Text);

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

                        //define Sql Command
                        String strSQL = "UPDATE Supplier SET Balance = " + remainder + " WHERE SupplierId =" + id;

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

                        connect.Open();

                        cmd.ExecuteNonQuery();

                        //Close Db
                        connect.Close();

                        MessageBox.Show(pay + " has been paid off the balance");


                        txtSupplierId.Clear();
                        txtSupplierName.Clear();
                        txtSearchSupplier.Clear();
                        txtBalance.Clear();
                        txtAmountToPay.Clear();

                        grdData.DataSource = null;
                    }
                    else
                    {
                        MessageBox.Show("The amount you want to pay exceeds the balance");
                    }
                }
                else
                {
                    MessageBox.Show("The balance is zero so Cannot be paid");
                }
            }

            else
            {
                MessageBox.Show("You have not entered a correct amount into the Amount to Pay Textbox");
            }
        }