コード例 #1
0
        void customer_BalanceChanged(object sender, EventArgs e)
        {
            CustomerAccountManager customer = (CustomerAccountManager)sender;
            int index = lbBankAccounts.SelectedIndex;

            if (index >= 0)
            {
                lbBankAccounts.Items[index] = customer;
            }

            if (customer.chequingBalance == null)
            {
                tbChequingBalance.Text = "N/A";
            }
            else
            {
                tbChequingBalance.Text = string.Format("{0:C2}", customer.chequingBalance);
            }
            if (customer.savingsBalance == null)
            {
                tbSavingsBalance.Text = "N/A";
            }
            else
            {
                tbSavingsBalance.Text = string.Format("{0:C2}", customer.savingsBalance);
            }

            CustomerAccountManagerDAO customerDAO = new CustomerAccountManagerDAO();

            customerDAO.SaveCustomer(customer);
            loadSummary();
        }
コード例 #2
0
        private void btnWithdraw_Click(object sender, EventArgs e)
        {
            CustomerAccountManager customer = (CustomerAccountManager)lbBankAccounts.SelectedItem;

            if (customer == null)
            {
                return;
            }
            decimal AmountDec;

            decimal.TryParse(tbAmount.Text, out AmountDec);
            if (rbChequing.Checked)
            {
                try
                {
                    customer.WithdrawChequing(AmountDec);
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(ex.Message, "Invalid Operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (rbSavings.Checked)
            {
                try
                {
                    customer.WithdrawSavings(AmountDec);
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(ex.Message, "Invalid Operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            tbAmount.Clear();
        }
コード例 #3
0
        private void btnCreateCustomer_Click(object sender, EventArgs e)
        {
            if (tbFirstName.TextLength == 0 || tbLastName.TextLength == 0)
            {
                MessageBox.Show("Enter First name and Last name of the customer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            CustomerAccountManagerDAO customerDAO = new CustomerAccountManagerDAO();
            CustomerAccountManager    customer    = customerDAO.CreateCustomer(tbFirstName.Text, tbLastName.Text);

            customer.BalanceChanged += customer_BalanceChanged;
            lbBankAccounts.Items.Add(customer);
            tbFirstName.Clear();
            tbLastName.Clear();
            loadSummary();
        }
コード例 #4
0
        private void btnDeposit_Click(object sender, EventArgs e)
        {
            CustomerAccountManager customer = (CustomerAccountManager)lbBankAccounts.SelectedItem;

            if (customer == null)
            {
                return;
            }
            decimal AmountDec;

            decimal.TryParse(tbAmount.Text, out AmountDec);

            if (rbChequing.Checked)
            {
                customer.DepositChequing(AmountDec);
            }
            if (rbSavings.Checked)
            {
                customer.DepositSavings(AmountDec);
            }
            tbAmount.Clear();
        }
コード例 #5
0
        private void lbBankAccounts_SelectedIndexChanged(object sender, EventArgs e)
        {
            CustomerAccountManager customer = (CustomerAccountManager)lbBankAccounts.SelectedItem;

            if (customer != null)
            {
                if (customer.chequingBalance == null)
                {
                    tbChequingBalance.Text = "N/A";
                }
                else
                {
                    tbChequingBalance.Text = string.Format("{0:C2}", customer.chequingBalance);
                }
                if (customer.savingsBalance == null)
                {
                    tbSavingsBalance.Text = "N/A";
                }
                else
                {
                    tbSavingsBalance.Text = string.Format("{0:C2}", customer.savingsBalance);
                }
            }
        }
コード例 #6
0
        internal void SaveCustomer(CustomerAccountManager CustomerAccount)
        {
            decimal?chequing = CustomerAccount.chequingBalance;
            decimal?saving   = CustomerAccount.savingsBalance;

            if (chequing != null)
            {
                SqlCommand        sqlcmdCustomer = new SqlCommand("SELECT CustomerNumber, AccountType, Balance FROM Account WHERE CustomerNumber = @pCustomerNumber AND AccountType='C'", Connection);
                SqlDataAdapter    sqldaCustomer  = new SqlDataAdapter(sqlcmdCustomer);
                SqlCommandBuilder cmdbldr        = new SqlCommandBuilder(sqldaCustomer);
                DataTable         dt             = new DataTable();

                sqlcmdCustomer.Parameters.AddWithValue("pCustomerNumber", CustomerAccount.customerNo);

                sqldaCustomer.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    dr["Balance"] = chequing;
                    sqldaCustomer.Update(dt);
                }
                else
                {
                    DataRow dr = dt.NewRow();
                    dr["CustomerNumber"] = CustomerAccount.customerNo;
                    dr["AccountType"]    = 'C';
                    dr["Balance"]        = chequing;
                    dt.Rows.Add(dr);
                    sqldaCustomer.Update(dt);
                }
            }

            if (saving != null)
            {
                SqlCommand        sqlcmdCustomer = new SqlCommand("SELECT CustomerNumber, AccountType, Balance FROM Account WHERE CustomerNumber = @pCustomerNumber AND AccountType='S'", Connection);
                SqlDataAdapter    sqldaCustomer  = new SqlDataAdapter(sqlcmdCustomer);
                SqlCommandBuilder cmdbldr        = new SqlCommandBuilder(sqldaCustomer);
                DataTable         dt             = new DataTable();

                sqlcmdCustomer.Parameters.AddWithValue("pCustomerNumber", CustomerAccount.customerNo);

                sqldaCustomer.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    dr["Balance"] = saving;
                    sqldaCustomer.Update(dt);
                }
                else
                {
                    DataRow dr = dt.NewRow();
                    dr["CustomerNumber"] = CustomerAccount.customerNo;
                    dr["AccountType"]    = 'S';
                    dr["Balance"]        = saving;
                    dt.Rows.Add(dr);
                    sqldaCustomer.Update(dt);
                }
            }
        }