/// <summary> /// Remove the Account from List of accounts. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCreateAccountSave_Click(object sender, EventArgs e) { //Check for Number entered. if (!string.IsNullOrEmpty(txtbxAccountNumber.Text)) { try { int accountId = int.Parse(txtbxAccountNumber.Text); //Remove account. accounts.RemoveAll(x => x.AccountId == accountId); // Save list of accounts to Text file. ObjectToSerialize objectToSerialize = new ObjectToSerialize(); objectToSerialize.Accounts = accounts; Serializer serializer = new Serializer(); serializer.SerializeObject("outputFile.txt", objectToSerialize); //Close Form. this.Close(); } //Error Handling catch (Exception ex) { MessageBox.Show(ex.Message); txtbxAccountNumber.Clear(); txtbxAccountNumber.Focus(); ClearFrom(); } } else //Error Handling { MessageBox.Show("Please, Enter a Account Number."); } }
//Serialize public void SerializeObject(string filename, ObjectToSerialize objectToSerialize) { Stream stream = File.Open(filename, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream, objectToSerialize); stream.Close(); }
// Pull data. private void ManageAccount_Load(object sender, EventArgs e) { //Pull data from txt file. ObjectToSerialize objectToSerialize = new ObjectToSerialize(); Serializer serializer = new Serializer(); objectToSerialize = serializer.DeSerializeObject("outputFile.txt"); accounts = objectToSerialize.Accounts; }
/// <summary> /// When closing form save data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnClose_Click(object sender, EventArgs e) { ObjectToSerialize objectToSerialize = new ObjectToSerialize(); objectToSerialize.Accounts = accounts; Serializer serializer = new Serializer(); serializer.SerializeObject("outputFile.txt", objectToSerialize); //Close Form this.Close(); }
/// <summary> /// Pull data from text file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConductTransaction_Load(object sender, EventArgs e) { this.pnlTransferDepositWithdrawl.Visible = false; //Pull data from txt file. ObjectToSerialize objectToSerialize = new ObjectToSerialize(); Serializer serializer = new Serializer(); objectToSerialize = serializer.DeSerializeObject("outputFile.txt"); accounts = objectToSerialize.Accounts; }
//Load Accounts into Form private void CreateAccount_Load(object sender, EventArgs e) { //Calculate the next Account number lblAccountNumber.Text = NextAccountNumber(); //Pull data from txt file. ObjectToSerialize objectToSerialize = new ObjectToSerialize(); Serializer serializer = new Serializer(); objectToSerialize = serializer.DeSerializeObject("outputFile.txt"); accounts = objectToSerialize.Accounts; //Calculate the next Account number lblAccountNumber.Text = NextAccountNumber(); }
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."); } }
//Load Accounts into Form private void CloseAccount_Load(object sender, EventArgs e) { //Pull data from txt file. ObjectToSerialize objectToSerialize = new ObjectToSerialize(); Serializer serializer = new Serializer(); objectToSerialize = serializer.DeSerializeObject("outputFile.txt"); accounts = objectToSerialize.Accounts; }
//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(); }