Hi!
i want to write a program that handles commands like:
add: Asks for the name of person, age
list: displays a list of names/surnames in a directory
remove <planet name=""> removes the given person from the list
detail <planet name="">: display person data (given by add)
open <filename> loads the person directory from a file
save <filename> saves the persons list to a file.
reading / writing to a file can be in the selected format - JSON or XML
i want to write a program that handles commands like:
add: Asks for the name of person, age
list: displays a list of names/surnames in a directory
remove <planet name=""> removes the given person from the list
detail <planet name="">: display person data (given by add)
open <filename> loads the person directory from a file
save <filename> saves the persons list to a file.
reading / writing to a file can be in the selected format - JSON or XML
C#:
class Person
{
public string Name { get; set; }
public string Surname { get; set; }
public override string ToString()
{
return "Imie: " + Name + "Nazwisko: " + Surname;
}
public static void Main()
{
Console.WriteLine("Dokonaj wyboru");
string choice = Console.ReadLine();
string a = Console.ReadLine();
string b = Console.ReadLine();
Person person = new Person { Name = " " + a, Surname = " " + b };
Console.WriteLine(person);
while (true)
{
switch (choice)
{
case "Add":
using (StreamWriter sw = File.AppendText(@"logowanie64.txt"))
{
sw.WriteLine(person);
}
return;
case "Detail":
Detail();
return;
case "List":
List();
return;
case "Remove":
removeArtist();
return;
case "Save":
string json = JsonSerializer.Serialize(person);
File.WriteAllText(@"path.json", json);
return;
}
}
}
public static void removeArtist()
{
Console.Write("Please enter name you want to delete: ");
string name = Console.ReadLine();
List<string> lst = File.ReadAllLines(@"logowanie64.txt").Where(arg => !string.IsNullOrWhiteSpace(arg)).ToList();
lst.RemoveAll(x => x.Split('.')[0].Equals(name));
File.WriteAllLines(@"logowanie64.txt", lst);
}
public static void Detail()
{
string[] lines = File.ReadAllLines(@"logowanie64.txt");
Console.WriteLine("Contents of WriteLines2.txt = ");
foreach (string line in lines)
{
Console.WriteLine("\t" + line);
}
}
public static void List()
{
string[] s = File.ReadAllLines(@"logowanie64.txt");
foreach (string line in s)
Console.WriteLine(line);
}
}