示例#1
0
        private void createObjectButton_Click(object sender, EventArgs e)
        {
            // Create a CDAccount object
            CDAccounts myAccount = new CDAccounts();

            // Get the CD account data
            GetCDData(myAccount);

            // Display the CD account data
            accountNumberLabel.Text = myAccount.AccountNumber;
            interestRateLabel.Text  = myAccount.InterestRate.ToString("n2");
            balanceLabel.Text       = myAccount.Balance.ToString("c");
            maturityDateLabel.Text  = myAccount.MaturityDate;
        }
示例#2
0
        // The GetCDData method accepts a CDAccount object
        // as an argument. It assigns the data entered by
        // the user to the object's properties

        private void GetCDData(CDAccounts account)
        {
            // Temporary variables to hold interest rate
            // and balance
            decimal interestRate;
            decimal balance;

            // Get the account number
            account.AccountNumber = accountNumberTextBox.Text;

            // Get the maturity date
            account.MaturityDate = maturityDateTextBox.Text;

            // Get the interest rate
            if (decimal.TryParse(interestRateTextBox.Text, out interestRate))
            {
                account.InterestRate = interestRate;

                // Get the balance
                if (decimal.TryParse(balanceTextBox.Text, out balance))
                {
                    account.Balance = balance;
                }
                else
                {
                    // Display an error message
                    MessageBox.Show("Invalid balance");
                }
            }

            else
            {
                // Display an error message
                MessageBox.Show("Invalid interest rate");
            }
        }