Пример #1
0
        //add new transaction
        private void btnAddTransaction_Click(object sender, EventArgs e)
        {
            if (lvIbansTransaction.SelectedItems.Count > 0)
            {
                ListViewItem item = lvIbansTransaction.SelectedItems[0];
                string       iban = item.SubItems[0].Text.Trim();
                decimal      sum;
                bool         evalSum = decimal.TryParse(txtTransactionSum.Text.Trim(), out sum);

                string  currentBalanceStr = item.SubItems[3].Text.Trim();
                decimal currentBalance;
                bool    evalCurrentBalance = decimal.TryParse(currentBalanceStr, out currentBalance);

                //both negative and positive allowed, negative = draws out money from account, positive = deposits to account
                if (evalSum && evalCurrentBalance)
                {
                    if (sum < 0 && (currentBalance + sum) < 0)
                    {
                        MessageBox.Show("You are trying to draw out too much. The current balance is " + currentBalance, "Attempt to draw out too much", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        decimal updatedTotal            = currentBalance + sum;
                        Tuple <int, string, string> ret = customerUtility.MakeATransaction(iban, sum, updatedTotal);
                        if (ret.Item1 == 1)
                        {
                            customerUtility.ReplaceTransactionAccoutInList(lvIbansTransaction, iban, updatedTotal);
                            txtTransactionSum.Text = "";
                            lvCustomersTransactions.Items.Clear();
                            lvSearchCustomersTransactions.SelectedItems.Clear();
                            MessageBox.Show(ret.Item2, ret.Item3, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
                        }
                        else
                        {
                            txtTransactionSum.Focus();
                            MessageBox.Show(ret.Item2, ret.Item3, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Only non-empty and numeric decimal input for sum is allowed!", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    txtTransactionSum.Focus();
                }
            }
            else
            {
                MessageBox.Show("No iban was selected!", "No Iban selected", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
            }
        }