private void btnWithdraw_Click(object sender, EventArgs e) { errorProvider1.Clear(); Transaction T = new Transaction(); T.amount = txtWithdrawAmount.Text; T.note = txtWithdrawNote.Text; T.account = cboAccount.SelectedValue.ToString(); T.type = "W"; Validation v = new Validation(); bool valid = true; if (!v.IsAmount(T.amount) || decimal.Parse(T.amount).Equals(0)) { errorProvider1.SetError(txtWithdrawAmount, "Amount must only be numbers and in the format 0.00 and greater then 0.01"); valid = false; } if ((!v.IsAccount(T.note)) && (!T.note.Equals(""))) { errorProvider1.SetError(txtWithdrawNote, "Note must not contain any special characters"); valid = false; } if (valid) { try { if (TransactionSQL.CheckBalance(ref T)) { try { TransactionSQL.Withdraw(ref T); MessageBox.Show("You just withdrew €" + T.amount); FrmDisplayAccounts Display = new FrmDisplayAccounts(); Display.Show(); this.Hide(); } catch { MessageBox.Show("Error 017: Could not connect to database. Your Withdrawal Has not been processed \nPlease contact an administratior"); } } else { MessageBox.Show("You do not have enough money in your account to process this Withdrawal"); } } catch { MessageBox.Show("Error 016: Could not connect to database. Please contact an administratior"); } } }
private void btnTransfer_Click(object sender, EventArgs e) { errorProvider1.Clear(); Validation v = new Validation(); Transaction T = new Transaction(); bool valid = true; T.account = cboCreditorAccount.SelectedValue.ToString(); T.amount = txtCreditorAmount.Text; T.note = txtCreditorNote.Text; T.debtor = txtDebtorAccount.Text; if (!v.IsAmount(T.amount)) { valid = false; errorProvider1.SetError(txtCreditorAmount, "Amount must only be numbers and in the format 0.00 and greater then 0.01"); } if (!v.IsEmpty(T.note) && !v.IsAccount(T.note)) { valid = false; errorProvider1.SetError(txtCreditorNote, "Note must not contain special characters"); } if (!v.isAccountNumber(T.debtor) && !v.isIBAN(T.debtor)) { valid = false; errorProvider1.SetError(txtDebtorAccount, "Please enter a valid account number or IBAN"); } else if (T.debtor == T.account) { valid = false; errorProvider1.SetError(txtDebtorAccount, "Please select a different account"); } if (valid) { if (TransactionSQL.CheckBalance(ref T)) { if (v.isIBAN(T.debtor)) { try { if (MessageBox.Show("Are you sure?", "Pay", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { T.type = "P"; TransactionSQL.Pay(ref T); MessageBox.Show("You just made a payment too " + T.debtor); FrmDisplayAccounts Display = new FrmDisplayAccounts(); Display.Show(); this.Hide(); } } catch { MessageBox.Show("Error 007: Could not connect to database. Please contact an administratior"); } } else if (v.isAccountNumber(T.debtor) && AccountSQL.AccountExists(T.debtor)) { if (MessageBox.Show("Are you sure?", "Transfer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { T.type = "T"; TransactionSQL.Transfer(ref T); MessageBox.Show("You transfered money too " + T.debtor); FrmDisplayAccounts Display = new FrmDisplayAccounts(); Display.Show(); this.Hide(); } catch { MessageBox.Show("Error 007: Could not connect to database. Please contact an administratior"); } } } else { errorProvider1.SetError(txtDebtorAccount, "That Account doesn't exist or has been closed"); } } else { errorProvider1.SetError(txtCreditorAmount, "You do not currently have enough money in your account to make that transaction"); } } }