public void GenerateCSVLocation(LocationSingleton newLocation)
        {
            // Method for creating the Data.csv file if it does not exist already and adding any new location data to the file.
            string prefix = "Location:";

            if (!File.Exists(path))
            {
                using (StreamWriter writer = File.CreateText(path))
                {
                    var newLine = string.Format("{0},{1}", prefix, newLocation.LocationName);
                    writer.Write(newLine);
                    writer.Write(Environment.NewLine);
                }
            }
            else
            {
                using (StreamWriter writer = File.AppendText(path))
                {
                    var newLine = string.Format("{0},{1}", prefix, newLocation.LocationName);
                    writer.Write(newLine);
                    writer.Write(Environment.NewLine);
                }
            }
            writer.Close();
        }
 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 newLocationBtn_Click(object sender, RoutedEventArgs e)
        {
            LocationSingleton     newLocation = LocationSingleton.Instance;
            DataHandlingSingleton export      = DataHandlingSingleton.Instance;

            // Invoking NewLocation method
            newLocation.NewLocation(locationTxt.Text);
            // Adding locations to location combo boxes, unless they already exist
            foreach (LocationSingleton aLocation in newLocation.Locations)
            {
                if (!locationList.Items.Contains(aLocation.LocationName))
                {
                    locationList.Items.Add(aLocation.LocationName);
                }
            }
            // Reset Text Field
            locationTxt.Text = "";
            // Output data to CSV
            export.GenerateCSVLocation(newLocation.CurrentLocation);
        }
        public MainWindow()
        {
            InitializeComponent();
            // Importing all data contained within Data.csv file
            UserSingleton         user     = UserSingleton.Instance;
            LocationSingleton     location = LocationSingleton.Instance;
            VisitSingleton        visit    = VisitSingleton.Instance;
            ContactSingleton      contact  = ContactSingleton.Instance;
            DataHandlingSingleton data     = DataHandlingSingleton.Instance;

            // Invoke method to import all data from file
            data.ImportData();
            foreach (UserSingleton aUser in user.Users)
            {
                // Iterate through all user objects and populate user lists
                // Input validation to prevent duplicates
                if (!userList.Items.Contains(aUser.UserId))
                {
                    userList.Items.Add(aUser.UserId);
                }
                if (!individualList1.Items.Contains(aUser.UserId))
                {
                    individualList1.Items.Add(aUser.UserId);
                }
                if (!individualList2.Items.Contains(aUser.UserId))
                {
                    individualList2.Items.Add(aUser.UserId);
                }
                if (!chooseIndividualList.Items.Contains(aUser.UserId))
                {
                    chooseIndividualList.Items.Add(aUser.UserId);
                }
            }
            foreach (LocationSingleton aLocation in location.Locations)
            {
                // Iterate through all location objects and populate location lists
                // Input validation to prevent duplicates
                if (!locationList.Items.Contains(aLocation.LocationName))
                {
                    locationList.Items.Add(aLocation.LocationName);
                }
                if (!chooseVisitLocationList.Items.Contains(aLocation.LocationName))
                {
                    chooseVisitLocationList.Items.Add(aLocation.LocationName);
                }
            }
            foreach (VisitSingleton aVisit in visit.Visits)
            {
                // Iterate through all visit objects and populate visit lists
                // Input validation to prevent duplicates
                if (!chooseVisitDateList.Items.Contains(aVisit.Date))
                {
                    chooseVisitDateList.Items.Add(aVisit.Date);
                }
                if (!chooseVisitDate2List.Items.Contains(aVisit.Date))
                {
                    chooseVisitDate2List.Items.Add(aVisit.Date);
                }
                if (!chooseVisitTimeList.Items.Contains(aVisit.Time))
                {
                    chooseVisitTimeList.Items.Add(aVisit.Time);
                }
                if (!chooseVisitTime2List.Items.Contains(aVisit.Time))
                {
                    chooseVisitTime2List.Items.Add(aVisit.Time);
                }
            }
            foreach (ContactSingleton aContact in contact.Contacts)
            {
                // Iterate through all contact objects and populate contact lists
                // Input validation to prevent duplicates
                if (!chooseIndividualList.Items.Contains(aContact.Individual1))
                {
                    chooseIndividualList.Items.Add(aContact.Individual1);
                }
                if (!chooseDateList.Items.Contains(aContact.Date))
                {
                    chooseDateList.Items.Add(aContact.Date);
                }
                if (!chooseTimeList.Items.Contains(aContact.Time))
                {
                    chooseTimeList.Items.Add(aContact.Time);
                }
            }
        }