void ReleaseDesignerOutlets() { if (AccountNameLabel != null) { AccountNameLabel.Dispose(); AccountNameLabel = null; } if (AmountLabel != null) { AmountLabel.Dispose(); AmountLabel = null; } if (AmountTextField != null) { AmountTextField.Dispose(); AmountTextField = null; } if (SubmitButton != null) { SubmitButton.Dispose(); SubmitButton = null; } if (TransactionNameLabel != null) { TransactionNameLabel.Dispose(); TransactionNameLabel = null; } if (TransactionNameTextField != null) { TransactionNameTextField.Dispose(); TransactionNameTextField = null; } if (TransactionTypeLabel != null) { TransactionTypeLabel.Dispose(); TransactionTypeLabel = null; } }
public override void ViewDidLoad() { var db = BankRepository.Connection(); base.ViewDidLoad(); AccountNameLabel.Text = account.Name; TransactionTypeLabel.Text = TransactionType; var g = new UITapGestureRecognizer(() => View.EndEditing(true)); View.AddGestureRecognizer(g); //Setting up fields AmountTextField.KeyboardType = UIKeyboardType.DecimalPad; TransactionNameTextField.AutocapitalizationType = UITextAutocapitalizationType.Sentences; TransactionNameTextField.ShouldReturn = (textField) => { TransactionNameTextField.EndEditing(true); return(true); }; AmountTextField.ShouldChangeCharacters = (textfield, range, replacementString) => { var newLength = textfield.Text.Length + replacementString.Length - range.Length; return(newLength <= 10); }; TransactionNameTextField.ShouldChangeCharacters = (textfield, range, replacementString) => { var newLength = textfield.Text.Length + replacementString.Length - range.Length; return(newLength <= 28); }; //button actions SubmitButton.TouchUpInside += (object sender, EventArgs e) => { if (TransactionNameTextField.Text != "" && AmountTextField.Text != "") { Transaction newTransaction = new Transaction(); newTransaction.TransactionID = Guid.NewGuid(); newTransaction.Account = account.Id; newTransaction.Date = DateTime.Now; newTransaction.Name = TransactionNameTextField.Text; newTransaction.TransAmount = double.Parse(AmountTextField.Text); string confirmationString; if (TransactionType == "Deposit") { confirmationString = "Confirm you are depositing $" + newTransaction.TransAmount + " into account: " + account.Name + "."; } else { confirmationString = "Confirm you are withdrawing $" + newTransaction.TransAmount + " from account: " + account.Name + "."; } var ConfirmationAlertController = UIAlertController.Create("Confirmation", confirmationString, UIAlertControllerStyle.Alert); ConfirmationAlertController.AddAction(UIAlertAction.Create("Confirm", UIAlertActionStyle.Default, Action => { if (TransactionType == "Withdrawal") { newTransaction.TransAmount = newTransaction.TransAmount - (newTransaction.TransAmount * 2); } var completed = db.Insert(newTransaction); if (completed > 0) { //updated balance in account table account.Balance = AccountCalculations.CalculateBalance(account); db.InsertOrReplace(account); NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadPage", null); //confirmation dialog var CompletionAlertController = UIAlertController.Create("Transaction Complete", "The transaction has been completed", UIAlertControllerStyle.Alert); CompletionAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, action => { DismissModalViewController(true); })); PresentViewController(CompletionAlertController, true, null); } })); ConfirmationAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(ConfirmationAlertController, true, null); } }; }