public void ImportData() { // Method for Importing all the data from the Data.csv file if it exists. if (File.Exists(path)) { string currentLine = ""; UserSingleton user = UserSingleton.Instance; LocationSingleton location = LocationSingleton.Instance; VisitSingleton visit = VisitSingleton.Instance; ContactSingleton contact = ContactSingleton.Instance; using (StreamReader reader = new StreamReader(path)) { while ((currentLine = reader.ReadLine()) != null) { var values = currentLine.Split(','); if (values[0] == "User:"******"Location:") { string locationNameTemp = values[1]; location.NewLocation(locationNameTemp); } else if (values[0] == "Visit:") { string userIdTemp = values[1]; string dateTemp = values[2]; string timeTemp = values[3]; string locationTemp = values[4]; visit.RecordVisit(userIdTemp, dateTemp, timeTemp, locationTemp); } else if (values[0] == "Contact:") { string individual1Temp = values[1]; string individual2Temp = values[2]; string individual2Number = values[3]; string dateTemp = values[4]; string timeTemp = values[5]; contact.RecordContact(individual1Temp, individual2Temp, individual2Number, dateTemp, timeTemp); } } } } }
private void recordContactBtn_Click(object sender, RoutedEventArgs e) { ContactSingleton newContact = ContactSingleton.Instance; UserSingleton user = UserSingleton.Instance; DataHandlingSingleton export = DataHandlingSingleton.Instance; string individual1UserId = ""; string individual2UserId = ""; string individual2PhoneNumber = ""; chooseIndividualList.Items.Add(individualList1.Text); // Separate date and time used for generating file string date = Convert.ToString(System.DateTime.Now.ToString("dd/MM/yyyy")); // Adding date of contact to date combo box, unless the date already exists to avoid duplicates if (!chooseDateList.Items.Contains(date)) { chooseDateList.Items.Add(date); } string time = System.DateTime.Now.ToShortTimeString(); // Adding time of contact to time combo box, unless the time already exists to avoid duplicates if (!chooseDateList.Items.Contains(time)) { chooseTimeList.Items.Add(time); } foreach (UserSingleton aUser in user.Users) { if (aUser.UserId.Equals(individualList1.Text)) { individual1UserId = aUser.UserId; } else if (aUser.UserId.Equals(individualList2.Text)) { individual2UserId = aUser.UserId; individual2PhoneNumber = aUser.PhoneNumber; } } newContact.RecordContact(individual1UserId, individual2UserId, individual2PhoneNumber, date, time); // Reset displayed text individualList1.Text = ""; individualList2.Text = ""; // Output data to CSV export.GenerateCSVContact(newContact.CurrentContact); }