private void tbAmount_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(tbAmount.Text)) { _checkInput = new CheckValidUserInput(_currentClient); if (_checkInput.validInput(tbAmount.Text, true)) { addItemsToDropDown(Convert.ToInt32(tbAmount.Text)); } } }
private void tbAmount_TextChanged(object sender, EventArgs e) { // checks if the user only entered numbers CheckValidUserInput check = new CheckValidUserInput(); if (!string.IsNullOrEmpty(tbAmount.Text)) { if (check.validInput(tbAmount.Text, true)) { try { addItemsToDropDown(Convert.ToInt32(tbAmount.Text)); } catch (OverflowException ex) { updateMessage("Te groot getal... niet doen aub :)"); Thread.Sleep(2000); } } } }
//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); } }
private async void btnOk_Click(object sender, EventArgs e) { Boolean validInput = false; checkInput = new CheckValidUserInput(_currentClient); if (!string.IsNullOrWhiteSpace(tbUserName.Text) && !string.IsNullOrWhiteSpace(tbUserPassword.Text)) { if (tbUserPassword.Text.Length == 4) { validInput = true; } } else { validInput = false; } validInput = checkInput.validInput(tbUserPassword.Text, validInput); if (validInput && checkInput.validUserInput) { HttpRequest httpRequest; username = tbUserName.Text; password = new string(checkInput.checkInput); password = password.Replace("\n", ""); password = password.Replace("\r", ""); //create a new usertag _newUserId.Password = password; httpRequest = new HttpRequest("UserTagItems"); Object response = await HttpRequest.CreateAsync(_newUserId, httpRequest.createUrl()); //get the new usertag httpRequest = new HttpRequest("UserTagItems", _newUserId.PassId); ReturnObject returnedObject = await HttpRequest.GetUserTagAsync(httpRequest.createUrl()); UserTagViewModel createdUser = returnedObject.ReturnUserTag; //create a new user, and link the user and the usertag with the usertagId _currentClient.Name = username; _currentClient.UserTagId = createdUser.UserTagId; httpRequest = new HttpRequest("ClientItems"); response = await HttpRequest.CreateAsync(_currentClient, httpRequest.createUrl()); Helper.showMessage("U bent succesvol toegevoegd."); this.DialogResult = DialogResult.OK; this.Close(); } else { if (!validInput) { if (!checkInput.validUserInput && checkInput.inputLength == 4) { Helper.showMessage("Uw wachtwoord mag alleen bestaan uit: '0, 1, 2, 3, 4, 5, 6, 7, 8, 9' ", MessageBoxIcon.Error); } else if (checkInput.inputLength < 4 || checkInput.inputLength > 4) { Helper.showMessage("Uw wachtwoord moet bestaan uit 4 karakters. U hebt er nu: " + checkInput.inputLength, MessageBoxIcon.Error); } else { Helper.showMessage("Gelieve AL de velden invullen.", MessageBoxIcon.Error); } } } }