Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OOPvjezbanje
- {
- public class Repozitorij
- {
- public static List<Korisnik> lista = new List<Korisnik>();
- public delegate void JMBGcheck(Korisnik k);
- public static event JMBGcheck JMBGHandler;
- static bool DodajKorisnika(Korisnik k)
- {
- try
- {
- lista.Add(k);
- return true;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- return false;
- }
- }
- static bool ObrisiKorisnika(Korisnik k)
- {
- try
- {
- lista.Remove(k);
- return true;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- return false;
- }
- }
- internal static void UnesiNovog()
- {
- try
- {
- Console.WriteLine("Unesite ime korisnika: ");
- string ime = Console.ReadLine();
- Console.WriteLine("Unesite prezime korisnika: ");
- string prezime = Console.ReadLine();
- Console.WriteLine("Unesite JMBG korisnika: ");
- string jmbg = Console.ReadLine();
- if (!ProvjeriDalPostojiJMBG(jmbg))
- {
- throw new MojException("Vec postoji JMBG!");
- }
- Console.WriteLine("Unesite status korisnika: ");
- string status = Console.ReadLine();
- while (!ProvjeriStatus(status))
- {
- Console.WriteLine("Krivi status! \nUnesite status korisnika: ");
- status = Console.ReadLine();
- }
- Korisnik k = new Korisnik(ime, prezime, jmbg, status);
- if (!ProvjeriJMBG(jmbg))
- {
- if (JMBGHandler != null)
- {
- JMBGHandler(k);
- }
- }
- else
- {
- //Ako je punoljetan, dodaj u listu
- lista.Add(k);
- ListaUTekstFile();
- }
- }
- catch (MojException me)
- {
- Console.WriteLine(me.Message);
- }
- }
- private static bool ProvjeriDalPostojiJMBG(string jmbg)
- {
- foreach (Korisnik k in lista)
- {
- if (k.JMBG == jmbg)
- {
- return false;
- }
- }
- return true;
- }
- public static bool ProvjeriStatus(string status)
- {
- if (status == "Zlatni" || status == "Platinasti" || status == "Srebrni")
- {
- return true;
- }
- return false;
- }
- public static void TraziPoStatusu()
- {
- Console.WriteLine("Unesite status: ");
- string status = Console.ReadLine();
- if (status == "Zlatni" || status == "Platinasti" || status == "Srebrni")
- {
- foreach (Korisnik k in lista)
- {
- if (k.Status == status)
- {
- Console.WriteLine(k);
- }
- }
- }
- }
- public static void TraziPoJMBG()
- {
- Console.WriteLine("Unesite JMBG: ");
- string jmbg = Console.ReadLine();
- foreach (Korisnik k in lista)
- {
- if (k.JMBG == jmbg)
- {
- Console.WriteLine(k);
- }
- }
- }
- public static void ObrisiKorisnika()
- {
- Console.WriteLine("Unesite ime: ");
- string ime = Console.ReadLine();
- Console.WriteLine("Unesite prezime: ");
- string prezime = Console.ReadLine();
- foreach(Korisnik k in lista)
- {
- if (k.Ime == ime && k.Prezime == prezime)
- {
- lista.Remove(k);
- }
- }
- }
- public static void IspisiSve()
- {
- foreach (Korisnik k in lista)
- {
- Console.WriteLine(k);
- }
- }
- public static bool ProvjeriJMBG (string jmbg)
- {
- int parsano = int.Parse(jmbg.Substring(4, 3));
- if ( parsano > 900)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- internal static void ListaUTekstFile()
- {
- using (StreamWriter sw = new StreamWriter(@"C:\Users\Dubstep\Desktop\OOPvj\OOPvjezbanje\OOPvjezbanje\Korisnici.txt"))
- {
- foreach (Korisnik k in lista)
- {
- sw.WriteLine(k.ToString());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement