//Save changes to text file. private void btnCreateAccountSave_Click(object sender, EventArgs e) { int accountId = int.Parse(txtbxAccountNumber.Text); string type = TypeOfAccount(); string status = "Open"; decimal balance = decimal.Parse(txtbxInitialBalance.Text); decimal rate; string maturitydate = txtBxMaturityDate.Text; Customer customer = new Customer(); customer.SSN = txtbxSSN.Text; customer.FName = txtbxFName.Text; customer.LName = txtbxLName.Text; customer.StAddr = txtbxAddress.Text; customer.City = txtCity.Text; customer.State = txtState.Text; customer.Zip = txtbxZip.Text; customer.Phone = txtPhoneNumber.Text; customer.Email = txtbxEmail.Text; //save depending on type of account. bool result = decimal.TryParse(txtbxRate.Text, out rate); if (result) { account = new Account() { AccountId = accountId, Type = type, Status = status, Balance = balance, Customer = customer, Rate = rate, Maturity = maturitydate }; } else { account = new Account() { AccountId = accountId, Type = type, Status = status, Balance = balance, Customer = customer, Rate = 0, Maturity = maturitydate }; } //remove account accounts.RemoveAll(x => x.AccountId == accountId); //readd acount. accounts.Add(account); //save the accounts list to a file ObjectToSerialize objectToSerialize = new ObjectToSerialize(); objectToSerialize.Accounts = accounts; Serializer serializer = new Serializer(); serializer.SerializeObject("outputFile.txt", objectToSerialize); this.Close(); }
private void btnCreateAccountSave_Click(object sender, EventArgs e) { try { int accountId = int.Parse(lblAccountNumber.Text); string type = TypeOfAccount(); string status = "Open"; decimal balance = decimal.Parse(txtbxInitialBalance.Text); decimal rate; string maturitydate = txtBxMaturityDate.Text; Customer customer = new Customer(); customer.SSN = txtbxSSN.Text; customer.FName = txtbxFName.Text; customer.LName = txtbxLName.Text; customer.StAddr = txtbxAddress.Text; customer.City = txtCity.Text; customer.State = txtState.Text; customer.Zip = txtbxZip.Text; customer.Phone = txtPhoneNumber.Text; customer.Email = txtbxEmail.Text; bool result = decimal.TryParse(txtbxRate.Text, out rate); if (result) { account = new Account() { AccountId = accountId, Type = type, Status = status, Balance = balance, Customer = customer, Rate = rate, Maturity = maturitydate }; } else { account = new Account() { AccountId = accountId, Type = type, Status = status, Balance = balance, Customer = customer, Rate = 0, Maturity = maturitydate }; } accounts.Add(account); //save the accounts list to a file ObjectToSerialize objectToSerialize = new ObjectToSerialize(); objectToSerialize.Accounts = accounts; Serializer serializer = new Serializer(); serializer.SerializeObject("outputFile.txt", objectToSerialize); this.Close(); } catch (Exception) { MessageBox.Show("All boxes should be filled out."); } }
/// <summary> /// Find a account within the list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFindAccount_Click(object sender, EventArgs e) { //Check for number to be entered. if (!string.IsNullOrEmpty(txtbxAccountNumber.Text)) { try { //find account within the list of accounts account = accounts.Single(s => s.AccountId == int.Parse(txtbxAccountNumber.Text)); //Enter account data into form FillinForm(account); } //Error Handling catch (Exception ex) { MessageBox.Show(ex.Message); txtbxAccountNumber.Clear(); txtbxAccountNumber.Focus(); } } //Handle Error if nothing entered. else { MessageBox.Show("Please, Enter a Account Number."); } }
/// <summary> /// Fill in the form with information from a single account. /// </summary> /// <param name="account"></param> private void FillinForm(Account account) { txtbxFName.Text = account.Customer.FName.ToString(); txtbxLName.Text = account.Customer.LName.ToString(); txtbxAddress.Text = account.Customer.StAddr.ToString(); txtCity.Text = account.Customer.City.ToString(); txtState.Text = account.Customer.State.ToString(); txtbxZip.Text = account.Customer.Zip.ToString(); txtPhoneNumber.Text = account.Customer.Phone.ToString(); txtbxEmail.Text = account.Customer.Email.ToString(); txtbxInitialBalance.Text = account.Balance.ToString(); txtbxSSN.Text = account.Customer.SSN.ToString(); //Format the form based on the type of account. if (account.Type == "Savings") { this.lblMaturityDate.Visible = false; this.lblRate.Visible = true; this.txtbxRate.Visible = true; this.txtBxMaturityDate.Visible = false; } else if (account.Type == "CD") { this.lblMaturityDate.Visible = false; this.lblRate.Visible = true; this.txtbxRate.Visible = true; this.txtBxMaturityDate.Visible = false; } else { this.lblMaturityDate.Visible = false; this.lblRate.Visible = false; this.txtbxRate.Visible = false; this.txtBxMaturityDate.Visible = false; } txtbxRate.Text = account.Rate.ToString(); txtBxMaturityDate.Text = account.Maturity.ToString(); }
//Format form and fill data account. private void FillinForm(Account account) { txtbxFName.Text = account.Customer.FName.ToString(); txtbxLName.Text = account.Customer.LName.ToString(); txtbxAddress.Text = account.Customer.StAddr.ToString(); txtCity.Text = account.Customer.City.ToString(); txtState.Text = account.Customer.State.ToString(); txtbxZip.Text = account.Customer.Zip.ToString(); txtPhoneNumber.Text = account.Customer.Phone.ToString(); txtbxEmail.Text = account.Customer.Email.ToString(); txtbxInitialBalance.Text = account.Balance.ToString(); txtbxSSN.Text = account.Customer.SSN.ToString(); txtbxRate.Text = account.Rate.ToString(); txtBxMaturityDate.Text = account.Maturity.ToString(); }
//Find Account within accounts. private void btnFindAccount_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtbxAccountNumber.Text)) { try { account = accounts.Single(s => s.AccountId == int.Parse(txtbxAccountNumber.Text)); switch (account.Type) { case "Checking": rdBtChecking.Checked = true; break; case "Savings": rdBtSavings.Checked = true; break; case "CD": rdBtCD.Checked = true; break; default: rdBtChecking.Checked = true; break; } FillinForm(account); } catch (Exception ex) { MessageBox.Show(ex.Message); txtbxAccountNumber.Clear(); txtbxAccountNumber.Focus(); } } else { MessageBox.Show("Please, Enter a Account Number."); } }
/// <summary> /// Handle the options for form. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmit_Click(object sender, EventArgs e) { ///Transfer option checked. if (rdbtnTransfer.Checked) { try { decimal transferAmount = decimal.Parse(txtbxTransferAmount.Text); //UPdate From Account account = accounts.Single(s => s.AccountId.ToString() == cmbxAccountFrom.SelectedValue.ToString()); if (account.Balance > transferAmount) { account.Balance -= transferAmount; accounts.RemoveAll(x => x.AccountId.ToString() == cmbxAccountFrom.SelectedValue.ToString()); accounts.Add(account); txtbxBalanceFromAccount.Text = account.Balance.ToString(); //Update To Account account = accounts.Single(s => s.AccountId.ToString() == cmbxToAccount.SelectedValue.ToString()); account.Balance += transferAmount; accounts.RemoveAll(x => x.AccountId.ToString() == cmbxToAccount.SelectedValue.ToString()); accounts.Add(account); txtbxToBalance.Text = account.Balance.ToString(); txtbxTransferAmount.Clear(); } else { MessageBox.Show("NSF"); } } catch (Exception ex) { MessageBox.Show(ex.Message); txtbxTransferAmount.Clear(); } } // Handle Deposits else if (rdbtnDeposit.Checked) { try { decimal deposit = decimal.Parse(txtbxDeposit.Text); account = accounts.Single(s => s.AccountId.ToString() == cmboxAccountNumbers.SelectedValue.ToString()); string intialAmount = account.Balance.ToString("c"); account.Balance += deposit; string newAmount = account.Balance.ToString("c"); accounts.RemoveAll(x => x.AccountId.ToString() == cmboxAccountNumbers.SelectedValue.ToString()); accounts.Add(account); MessageBox.Show("Deposited " + deposit.ToString("c") + " to your account raising your balance from " + intialAmount + " to " + newAmount + "."); this.txtbxDeposit.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //Handle Withdrawls. else if (rdbtnWithdrawl.Checked) { try { decimal withdrawl = decimal.Parse(txtbxWithdrawl.Text); account = accounts.Single(s => s.AccountId.ToString() == cmboxAccountNumbers.SelectedValue.ToString()); if (account.Balance > withdrawl) { string intialAmount = account.Balance.ToString("c"); account.Balance -= withdrawl; string newAmount = account.Balance.ToString("c"); accounts.RemoveAll(x => x.AccountId.ToString() == cmboxAccountNumbers.SelectedValue.ToString()); accounts.Add(account); MessageBox.Show("Withdrawled " + withdrawl.ToString("c") + " to your account raising your balance from " + intialAmount + " to " + newAmount + "."); this.txtbxWithdrawl.Clear(); } else { MessageBox.Show("NSF"); txtbxWithdrawl.Clear(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
//Enter combox calculate accounts private void cmbxToAccount_Leave(object sender, EventArgs e) { account = accounts.Single(s => s.AccountId.ToString() == cmbxToAccount.SelectedValue.ToString()); txtbxToBalance.Text = account.Balance.ToString(); }