}//end company method static void WriteToFileCompany(Contact contact, CompanyCon company) { string pathProfile = System.Environment.GetEnvironmentVariable("USERPROFILE"); string fileName = "ContactList.txt"; string filePath = pathProfile + "\\" + fileName; FileStream fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write); StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.WriteLine("Company entry: "); streamWriter.WriteLine(" "); streamWriter.WriteLine($"Name: {contact.firstName} {contact.lastName}"); streamWriter.WriteLine($"Address: {contact.address}"); streamWriter.WriteLine($"City: {contact.city}"); streamWriter.WriteLine($"State: {contact.state}"); streamWriter.WriteLine($"Zip code: {contact.zipCode}"); streamWriter.WriteLine($"Country: {contact.country}"); streamWriter.WriteLine($"Land line number: {contact.phoneLand}"); streamWriter.WriteLine($"Cell number: {contact.phoneCell}"); streamWriter.WriteLine(" "); streamWriter.WriteLine($"Company: {company.company}"); streamWriter.WriteLine($"Position: {company.position}"); streamWriter.WriteLine($"Email: {company.email}"); streamWriter.WriteLine("----------------------------------------------"); streamWriter.Close(); fileStream.Close(); }
static void ComapnyPrint(Contact contact, CompanyCon company) { Console.WriteLine("Company entry: "); Console.WriteLine(" "); Console.WriteLine($"Name: {contact.firstName} {contact.lastName}"); Console.WriteLine($"Address: {contact.address}"); Console.WriteLine($"City: {contact.city}"); Console.WriteLine($"State: {contact.state}"); Console.WriteLine($"Zip code: {contact.zipCode}"); Console.WriteLine($"Country: {contact.country}"); Console.WriteLine($"Land line number: {contact.phoneLand}"); Console.WriteLine($"Cell number: {contact.phoneCell}"); Console.WriteLine(" "); Console.WriteLine($"Company: {company.company}"); Console.WriteLine($"Position: {company.position}"); Console.WriteLine($"Email: {company.email}"); }
}//end friendFamily method static void Company() { Contact contact = new Contact(); CompanyCon company = new CompanyCon(); Console.Write("First name (req'd): "); contact.firstName = Console.ReadLine(); while (contact.firstName == "") { Console.Write("A name must me entered: "); contact.firstName = Console.ReadLine(); } Console.Write("Last name (req'd): "); contact.lastName = Console.ReadLine(); while (contact.lastName == "") { Console.Write("A name must me entered: "); contact.lastName = Console.ReadLine(); } Console.Write("Address (req'd): "); contact.address = Console.ReadLine(); while (contact.address == "") { Console.Write("An address must be entered: "); contact.address = Console.ReadLine(); } Console.Write("City (req'd): "); contact.city = Console.ReadLine(); while (contact.city == "") { Console.Write("A city must be entered: "); contact.city = Console.ReadLine(); } Console.Write("State (or enter if N/A): "); contact.state = Console.ReadLine(); if (contact.state == "") { contact.state = "N/A"; } Console.Write("Zip Code (or enter if no zipcode): "); contact.zipCode = Console.ReadLine(); if (contact.zipCode == "") { contact.zipCode = "N/A"; } if (contact.state == "N/A") { Console.Write("Country: "); contact.country = Console.ReadLine(); } else { contact.country = "USA"; } Console.Write("Phone Number - land line: "); contact.phoneLand = Console.ReadLine(); if (contact.phoneLand == "") { contact.phoneLand = "N/A"; } Console.Write("Phone number - cell phone: "); contact.phoneCell = Console.ReadLine(); if (contact.phoneCell == "") { contact.phoneCell = "N/A"; } Console.Write("Company name (or Enter for ACME TNT Manufacture): "); company.company = Console.ReadLine(); if (company.company == "") { company.company = "ACME TNT Manufacture"; } Console.Write("Position (or Enter if N/A): "); company.position = Console.ReadLine(); if (company.position == "") { company.position = "N/A"; } if (company.company == "ACME TNT Manufacture") { string email = contact.lastName + contact.firstName + "@acme.com"; company.email = email; } else { Console.Write("Email: "); company.email = Console.ReadLine(); } ComapnyPrint(contact, company); WriteToFileCompany(contact, company); }//end company method