//prints the receipt on screen private void printReceipt() { if (rbtnWithdrawel.Checked) { _print = new PrintReceipt(_transaction, _currentClient, cmbChooseBill.Text, Convert.ToInt32(Convert.ToInt16(tbAmount.Text) / _billValue)); } else { _print = new PrintReceipt(_transaction, _currentClient); } rtbReceipt.Text = _print.print(); }
//perform the transaction private void transaction(String pMode) { _checkInput = new CheckValidUserInput(_currentClient); bool validBillFormat = false; bool input = false; bool validInput = false; double oldSaldo = _currentClient.Saldo; bool tSuccesfull = false;//transaction succesfull //checks if the user entered the input fields if (!string.IsNullOrWhiteSpace(tbAmount.Text)) { double amount = 0; try { input = true; validInput = _checkInput.validInput(tbAmount.Text, input); if (validInput) { amount = Convert.ToDouble(tbAmount.Text); } } catch (OverflowException) { Helper.showMessage("Uw hebt een te groot getal ingevoerd.", MessageBoxIcon.Error); } if (validInput) { if (pMode.Equals("Deposit")) { //deposit Deposit deposit = new Deposit(_currentClient, amount); tSuccesfull = deposit.deposit(); } else { if (!string.IsNullOrEmpty(cmbChooseBill.Text)) { _chosenBill = cmbChooseBill.Text.Replace("€", ""); _billValue = Convert.ToInt32(_chosenBill); //withdraw if ((amount / _billValue) % 1 == 0) { Withdraw withDrawel = new Withdraw(_currentClient, _userTagId, amount); tSuccesfull = withDrawel.withdrawMoney(); validBillFormat = true; } } } if (tSuccesfull) { //creates and prints the receipt createReceipt(oldSaldo, _currentClient.Saldo, pMode); if (rbtnWithdrawel.Checked) { _print = new PrintReceipt(_transaction, _currentClient, cmbChooseBill.Text, Convert.ToInt32(amount / _billValue)); } else { _print = new PrintReceipt(_transaction, _currentClient); } btnPrintReceipt.Visible = true; rtbReceipt.Text = _print.print(); Helper.showMessage("Transactie geslaagd"); } else { if (amount > _currentClient.Saldo && pMode == "Withdrawel") { Helper.showMessage("Transactie mislukt. U hebt niet genoeg saldo.", MessageBoxIcon.Error); } else if (!validBillFormat) { Helper.showMessage($"Uw biljet keuze is niet geschikt '{cmbChooseBill.Text}'. Kies alstublieft een andere.", MessageBoxIcon.Error); } else { Helper.showMessage("Transactie mislukt. Controleer of u alleen getallen hebt ingevoerd.", MessageBoxIcon.Error); } rtbReceipt.Text = ""; } } else { inputErrorMsg(validInput); } } else { Helper.showMessage("Graag al de velden invullen.", MessageBoxIcon.Error); } }