//checkingAccount dataCheckingAccount; //savingAccount dataSavingAccount; public Form1() { InitializeComponent(); //this code loads the existing accounts into the progran. FileStream inFile; string filename = @"C:\Users\Admin\Desktop\ADV-C#2017\Data.ser"; //path to the file contining the saved accounts. if (File.Exists(filename)) //chesk if the file exist alredy, if it does not, creates a new one. { inFile = new FileStream(filename, FileMode.Open, FileAccess.Read); } else { inFile = new FileStream(filename, FileMode.Create, FileAccess.Write); } while (inFile.Position < inFile.Length) //this loop reads the file. { inAccount = (serialData)bFormatter.Deserialize(inFile); //Deserialize the data from thr file and cast it into an serialData object. dArray[inAccount.accountNumber] = inAccount; if (inAccount.type.Equals("Checking")) //verifies whether the object belongs to a cheking or savings account. { checkingRButton.Checked = true; } else { savingsRButton.Checked = true; } seniorCheckBox.Checked = inAccount.senior; studentCheckBox.Checked = inAccount.student; createAccount(inAccount.accountNumber, inAccount.Balance, true); // a new Account object from the serialData. } inFile.Close(); //closes the file outputLabel.Text = String.Format("{0} accounts loaded", maxAccounts); // displays how many accounts were loaded. }
void addData(int accNumber, double balance, string type, bool senior, bool student)//adds or modifies data to the serial data array { serialData temp; if (dArray[accNumber] != null) { dArray[accNumber].accountNumber = accNumber; dArray[accNumber].Balance = balance; dArray[accNumber].type = type; dArray[accNumber].senior = senior; dArray[accNumber].student = student; } else { temp = new serialData(); temp.accountNumber = accNumber; temp.Balance = balance; temp.type = type; temp.senior = senior; temp.student = student; dArray[accNumber] = temp; } }