Elina has started developing the application. She needs to ensure that the application meets the
following requirements:
When the application executes for the first time, it should perform the following tasks:
Display a message to the user to specify the path of the file in which the customer details are to
be stored.
Create the customer details file at the user-defined location.
Create a configuration file and store the path of the customer details file in the configuration file.
This configuration file needs to be used by the application to retrieve the location of the customer
details file.
The user should be able to save data to the customer details file. Write the code that Elina
should use to save data to the customer details file.
The user should be able to view the data stored in the customer details file. Write the code that
Elina should use to read the data stored in the customer details file and display it to the user.
[10 Marks]
1
Expert's answer
2014-03-24T10:46:07-0400
using System; using System.IO; using System.Text;
namespace Elina_Conf { class Program { static void Main(string[] args) {
do { Console.Clear(); Console.WriteLine("Choose appropriate line (ESC-EXIT):"); switch (MyPatterns.Singleton.CreateMenu.ShowMenu("Settings", "Show Content", "Add data")) { case 0:
Console.WriteLine("Please enter the path to the folder with Cus_detail.txt:"); string path = Console.ReadLine(); if (!Directory.Exists(path)) { Console.WriteLine("The folder doesn't exist! Press any key to continue..."); Console.ReadKey(); continue; }
StreamWriter swtr = new StreamWriter(Directory.GetCurrentDirectory() + @"\conf_file.txt", false, Encoding.GetEncoding(1251));
if (!File.Exists(path + @"\Cus_detail.txt")) { FileStream fs = new FileStream(path + @"\Cus_detail.txt", FileMode.Create); fs.Close(); // Console.WriteLine(path + @"\Cus_detail.txt" + " was successfully created");
Console.WriteLine("Please enter the path to the folder with Cus_detail.txt:"); path = Console.ReadLine(); if (!Directory.Exists(path)) { Console.WriteLine("The folder doesn't exist! Press any key to continue..."); Console.ReadKey(); continue; }
Console.ReadKey(); continue; }
Console.WriteLine("Saved! Press any key to continue..."); Console.ReadKey(); break;
case 1:
if (!File.Exists(Directory.GetCurrentDirectory() + @"\conf_file.txt")) {
StreamWriter strw = new StreamWriter(Directory.GetCurrentDirectory() + @"\conf_file.txt", false); strw.Close(); Console.WriteLine("Configuration file is empty! Press any key..."); Console.ReadKey(); continue; }
StreamReader strd = new StreamReader(Directory.GetCurrentDirectory() + @"\conf_file.txt");
string file_path = strd.ReadToEnd(); strd.Close(); if (File.Exists(file_path)) { strd = new StreamReader(file_path); Console.WriteLine("The content from file:"); Console.WriteLine("/////////////////////////////////////////////////////////"); Console.WriteLine(strd.ReadToEnd()); Console.WriteLine("/////////////////////////////////////////////////////////"); strd.Close(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { Console.WriteLine(file_path + "Doesn's exists. Press any key..."); Console.ReadKey(); continue; } break;
case 2: if (!File.Exists(Directory.GetCurrentDirectory() + @"\conf_file.txt")) { File.Create(Directory.GetCurrentDirectory() + @"\conf_file.txt"); Console.WriteLine("Configuration file is empty! Press any key..."); Console.ReadKey(); continue; }
StreamReader strd1 = new StreamReader(Directory.GetCurrentDirectory() + @"\conf_file.txt");
string file_path1 = strd1.ReadToEnd(); strd1.Close(); if (File.Exists(file_path1)) { StreamWriter swr = new StreamWriter(file_path1, true, Encoding.GetEncoding(1251)); Console.WriteLine("Please enter the data to add:"); swr.Write(Console.ReadLine()); swr.Close(); Console.WriteLine("Successfully saved. Press any key to continue..."); Console.ReadKey(); }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment