// Loads the state of the CRM from file public void LoadFromFile() { string inValue; StreamReader inFile; if (File.Exists(crmFile)) { inFile = new StreamReader(crmFile); while ((inValue = inFile.ReadLine()) != null) { string[] listInValue = inValue.Split(','); if (listInValue[0] != "CustomerID") // to remove the headers { int customerID = int.Parse(listInValue[0]); string title = listInValue[1]; string firstNames = listInValue[2]; string lastName = listInValue[3]; Customer.Gender gender = (Customer.Gender)Enum.Parse(typeof(Customer.Gender), listInValue[4]); string dateOfBirth = listInValue[5]; Customer newCustomer = new Customer(customerID, title, firstNames, lastName, gender, dateOfBirth); customers.Add(newCustomer); Console.WriteLine(newCustomer); } } inFile.Close(); } }
} // end method /// <summary> /// load data to the local variable from the CSV file /// </summary> public void LoadFromFile() { // flush the customer list Customers = new List <Customer>(); // same algorithm for loadfromFIle in fleet class using (StreamReader sr = new StreamReader(CustomerFile)) { sr.ReadLine(); while (sr.Peek() != -1) { string line = sr.ReadLine(); List <string> lineValues = line.Split(',').ToList(); int customerID = int.Parse(lineValues[0]); string title = lineValues[1]; string firstName = lineValues[2]; string lastName = lineValues[3]; Customer.Gender gender = (Customer.Gender)Enum.Parse(typeof(Customer.Gender), lineValues[4]); string dateOfBirth = lineValues[5]; Customer current_customer = new Customer(customerID, title, firstName, lastName, gender, dateOfBirth); Customers.Add(current_customer); } // end while } // end using } //end method