Exemple #1
0
        //update customer's account
        private void btnUpdateCustAccount_Click(object sender, EventArgs e)
        {
            string custId = ""; string iban = "";

            if (lvCustomerData.SelectedItems.Count > 0 && lvCustomerAccounts.SelectedItems.Count > 0)
            {
                //where clauses data, current state of the user
                ListViewItem custItem = lvCustomerData.SelectedItems[0];
                custId = custItem.SubItems[0].Text.Trim();
                int          cId;
                bool         evalCust    = int.TryParse(custId, out cId);
                ListViewItem accountItem = lvCustomerAccounts.SelectedItems[0];
                iban = accountItem.SubItems[0].Text.Trim();

                string  strBalance = txtCustomerDataBalance.Text.Trim();
                decimal balance;
                bool    evalBalance = decimal.TryParse(strBalance, out balance);
                if (txtCustomerDataAccountName.Text.Trim().Length > 2 &&
                    lbBank.SelectedIndex >= 0 && evalBalance && balance > 0)
                {
                    Tuple <int, string, string> ret = customerUtility.UpdateAccount(cId, iban, txtCustomerDataAccountName.Text.Trim(), balance);
                    if (ret.Item1 == 1)
                    {
                        customerUtility.ReplaceAccountInList(lvCustomerAccounts, iban, txtCustomerDataAccountName.Text.Trim(), balance);
                        MessageBox.Show(ret.Item2, ret.Item3, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        MessageBox.Show(ret.Item2, ret.Item3, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    }
                }
                else
                {
                    MessageBox.Show("Please provide valid input for account name, bank and positive, decimal input for balance!", "Invalid input fields", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                MessageBox.Show("No customer and account was selected!", "No Customer & Account selected", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
            }
        }