public override void ViewDidLoad() { base.ViewDidLoad(); NSNotificationCenter.DefaultCenter.AddObserver((NSString)"ReloadPage", reloadPage); var db = BankRepository.Connection(); db.CreateTable <Account>(); db.CreateTable <Transaction>(); db.CreateTable <QuickDeposit>(); Accounts = db.CreateCommand("SELECT * FROM UserAccounts").ExecuteQuery <Account>(); SettingsButton.TouchUpInside += (object sender, EventArgs e) => { SettingsViewController settingsViewController = this.Storyboard.InstantiateViewController("SettingsViewController") as SettingsViewController; settingsViewController.ModalPresentationStyle = UIModalPresentationStyle.Automatic; settingsViewController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical; PresentViewController(settingsViewController, true, null); }; TableView.Source = new AccountListTableDataSource(this); }
void QuickDepositTransaction(string QuickDepositType) { var db = BankRepository.Connection(); QuickDeposit quickDeposit = db.Get <QuickDeposit>(QuickDepositType); Transaction transaction = new Transaction(); transaction.Account = Account.Id; transaction.TransactionID = Guid.NewGuid(); transaction.Name = QuickDepositType; transaction.TransAmount = quickDeposit.Amount; transaction.Date = DateTime.Now; db.Insert(transaction); Account.Balance = AccountCalculations.CalculateBalance(Account); db.InsertOrReplace(Account); NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadPage", null); var CompletionAlertController = UIAlertController.Create("Transaction Complete", "The transaction has been completed", UIAlertControllerStyle.Alert); CompletionAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(CompletionAlertController, true, null); }
public void NewAccount() { Account NewAccount = new Account(); NewAccount.Balance = 0; NewAccount.Id = Guid.NewGuid(); var NewAccountAlertController = UIAlertController.Create("New Piggybank", "What is the name of the new piggybank?", UIAlertControllerStyle.Alert); NewAccountAlertController.AddTextField(field => { }); NewAccountAlertController.TextFields[0].AutocapitalizationType = UITextAutocapitalizationType.Sentences; NewAccountAlertController.AddAction(UIAlertAction.Create("Add", UIAlertActionStyle.Default, action => { if (NewAccountAlertController.TextFields[0].Text != "") { NewAccount.Name = NewAccountAlertController.TextFields[0].Text; var db = BankRepository.Connection(); db.Insert(NewAccount); reloadPage(null); } else { var ErrorAlertController = UIAlertController.Create("Error", "You must enter a name in order to save a new piggybank", UIAlertControllerStyle.Alert); ErrorAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(ErrorAlertController, true, null); } })); NewAccountAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(NewAccountAlertController, true, null); reloadPage(null); }
public QuickDepositTableDataSource(SettingsViewController CallingController) { callingController = CallingController; var db = BankRepository.Connection(); quickDepositTypes = db.CreateCommand("SELECT * FROM QuickDepositTypes").ExecuteQuery <QuickDeposit>(); }
void reloadPage(NSNotification notification) { var db = BankRepository.Connection(); Accounts = db.CreateCommand("SELECT * FROM UserAccounts").ExecuteQuery <Account>(); TableView.Source = new AccountListTableDataSource(this); TableView.ReloadData(); }
void reloadPage(NSNotification notification) { var db = BankRepository.Connection(); Account = db.Get <Account>(Account.Id); BalanceLabel.Text = "$" + Account.Balance.ToString(); TransactionTableView.Source = new AccountTransactionTableDataSource(this); TransactionTableView.ReloadData(); }
public AccountTransactionTableDataSource(AccountViewController CallingController) { var db = BankRepository.Connection(); callingController = CallingController; string selectStatement = "SELECT * FROM Transactions WHERE Account = " + "'" + callingController.Account.Id.ToString() + "'"; Transactions = db.CreateCommand(selectStatement).ExecuteQuery <Transaction>(); CompileSections(); }
internal void NewQuickDeposit() { QuickDeposit newQuickDeposit = new QuickDeposit(); var QuickDepositNameAlert = UIAlertController.Create("Quick Deposit Name", "What is the name of the new Quick Deposit type?", UIAlertControllerStyle.Alert); QuickDepositNameAlert.AddTextField(field => { }); QuickDepositNameAlert.TextFields[0].AutocapitalizationType = UITextAutocapitalizationType.Sentences; QuickDepositNameAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, action => { if (QuickDepositNameAlert.TextFields[0].Text != "") { newQuickDeposit.QuickDepositType = QuickDepositNameAlert.TextFields[0].Text; var QuickDepositAmountAlert = UIAlertController.Create("Quick Deposit Amount", "What is the amount paid for " + newQuickDeposit.QuickDepositType + "?", UIAlertControllerStyle.Alert); QuickDepositAmountAlert.AddTextField(field => { }); QuickDepositAmountAlert.TextFields[0].KeyboardType = UIKeyboardType.DecimalPad; QuickDepositAmountAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, Action => { if (QuickDepositAmountAlert.TextFields[0].Text != "") { newQuickDeposit.Amount = Double.Parse(QuickDepositAmountAlert.TextFields[0].Text); var db = BankRepository.Connection(); db.Insert(newQuickDeposit); QuickDepositTableView.Source = new QuickDepositTableDataSource(this); QuickDepositTableView.ReloadData(); } else { var ErrorAlertController = UIAlertController.Create("Error", "Amount can not be blank", UIAlertControllerStyle.Alert); ErrorAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(ErrorAlertController, true, null); } })); QuickDepositAmountAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(QuickDepositAmountAlert, true, null); } else { var ErrorAlertController = UIAlertController.Create("Error", "Name can not be blank", UIAlertControllerStyle.Alert); ErrorAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(ErrorAlertController, true, null); } })); QuickDepositNameAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(QuickDepositNameAlert, true, null); QuickDepositTableView.ReloadData(); }
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) { switch (editingStyle) { case UITableViewCellEditingStyle.Delete: QuickDeposit deletedQuickDeposit = quickDepositTypes[indexPath.Row]; quickDepositTypes.Remove(deletedQuickDeposit); var db = BankRepository.Connection(); if (db.Delete(deletedQuickDeposit) == 1) { tableView.ReloadData(); } break; } }
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) { switch (editingStyle) { case UITableViewCellEditingStyle.Delete: Account account = Accounts[indexPath.Row]; Accounts.Remove(account); var db = BankRepository.Connection(); if (db.Delete(account) == 1) { tableView.ReloadData(); } break; } }
public static double CalculateBalance(Account account) { var db = BankRepository.Connection(); string selectStatement = "SELECT * FROM Transactions WHERE Account = " + "'" + account.Id.ToString() + "'"; List <Transaction> Transactions = db.CreateCommand(selectStatement).ExecuteQuery <Transaction>(); double runningTotal = 0; foreach (Transaction transaction in Transactions) { runningTotal += transaction.TransAmount; } return(runningTotal); }
public override void ViewDidLoad() { base.ViewDidLoad(); NSNotificationCenter.DefaultCenter.AddObserver((NSString)"ReloadPage", reloadPage); var db = BankRepository.Connection(); AccountNameLabel.Text = Account.Name; BalanceLabel.Text = "$" + Account.Balance.ToString(); TransactionTableView.Source = new AccountTransactionTableDataSource(this); BackButton.TouchUpInside += (object sender, EventArgs e) => { DismissModalViewController(true); }; DepositButton.TouchUpInside += (object sender, EventArgs e) => { TransactionViewController transactionViewController = this.Storyboard.InstantiateViewController("TransactionViewController") as TransactionViewController; if (transactionViewController != null) { transactionViewController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical; transactionViewController.ModalPresentationStyle = UIModalPresentationStyle.Automatic; transactionViewController.account = Account; transactionViewController.TransactionType = "Deposit"; PresentViewController(transactionViewController, true, null); } }; WithdrawlButton.TouchUpInside += (object sender, EventArgs e) => { TransactionViewController transactionViewController = this.Storyboard.InstantiateViewController("TransactionViewController") as TransactionViewController; if (transactionViewController != null) { transactionViewController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical; transactionViewController.ModalPresentationStyle = UIModalPresentationStyle.Automatic; transactionViewController.account = Account; transactionViewController.TransactionType = "Withdrawal"; PresentViewController(transactionViewController, true, null); } }; QuickDepositButton.TouchUpInside += (object sender, EventArgs e) => { List <QuickDeposit> quickDeposits = db.CreateCommand("SELECT * FROM QuickDepositTypes").ExecuteQuery <QuickDeposit>(); string MenuString; if (quickDeposits.Count == 0) { MenuString = "There are no Quick Deposit choices available. Add them by clicking on the wrench from the piggy bank list screen and selecting 'New Quick Deposit Choice'."; } else { MenuString = "Select quick deposit option"; } UIAlertController QuickDepositAlertController = UIAlertController.Create("Quick Deposit", MenuString, UIAlertControllerStyle.Alert); foreach (QuickDeposit quickDeposit in quickDeposits) { string buttonText = quickDeposit.QuickDepositType + " $" + quickDeposit.Amount; QuickDepositAlertController.AddAction(UIAlertAction.Create(buttonText, UIAlertActionStyle.Default, Action => { QuickDepositTransaction(quickDeposit.QuickDepositType); })); } QuickDepositAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(QuickDepositAlertController, true, 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); } }; }