Mam do napisania program w któym możemy dodawać do bazy dane osoby, a potem je przeglądać, kasować i wyszukiwać. Pierwsze dwa mam ;p. Zostało wyszukiwanie i kasowanie. Oto co na razie mam:
class Person
{
private string pesel;
private string surname;
private string tel;
private string but;
public Person(string pesel, string sname, string tele, string rozm)
{
this.pesel = pesel;
this.surname = sname;
this.tel = tele;
this.but = rozm;
}
public string Pesel
{
get
{
return pesel;
}
}
public string Surname
{
get
{
return surname;
}
}
public string Telefon
{
get
{
return tel;
}
}
public string But
{
get
{
return but;
}
}
}
interface Cmd
{
string Desc();
void Exec(List<Person> db);
}
class AddCmd : Cmd
{
public string Desc()
{
return "Dodaj dane";
}
public void Exec(List<Person> db)
{
Console.Write("Podaj PESEL: ");
string p = Console.ReadLine();
Console.Write("Podaj nazwisko: ");
string n = Console.ReadLine();
Console.Write("Podaj numer telefonu: ");
string s = Console.ReadLine();
Console.Write("Podaj numer buta: ");
string d = Console.ReadLine();
db.Add(new Person(p, n, s, d));
}
}
class ListCmd : Cmd
{
public string Desc()
{
return "Wyświetl";
}
public void Exec(List<Person> db)
{
foreach (Person p in db)
{
Console.WriteLine("{0}, {1}, {2}, {3}", p.Pesel, p.Surname, p.Telefon, p.But);
}
}
}
class ExitCmd : Cmd
{
public string Desc()
{
return "Zakończ";
}
public void Exec(List<Person> db)
{
System.Environment.Exit(-1);
}
}
class PersonDB
{
private List<Person> persons = new List<Person>();
private List<Cmd> cmds = new List<Cmd>();
void showMenu()
{
int i = 1;
foreach (Cmd p in cmds)
{
Console.WriteLine("{0}: {1}", i++, p.Desc());
}
}
void execCmd(int i)
{
if (i >= 0 && i < cmds.Count)
{
cmds[i].Exec(persons);
}
}
public void RunApp()
{
//Rejestracja polecen
cmds.Add(new AddCmd());
cmds.Add(new ListCmd());
cmds.Add(new ExitCmd());
//Main loop
while (true)
{
showMenu();
Console.WriteLine("Twój wybór: ");
try
{
int i = Int32.Parse(Console.ReadLine()) - 1;
execCmd(i);
}
catch (FormatException e)
{
//skip
}
}
}
}
class Program
{
static void Main(string[] args)
{
new PersonDB().RunApp();
}
}
}
Pomoże ktoś w napisaniu funkcji kasowania i wyszukiwania po numerze PESEL?