Advertisement
Guest User

OOP vj

a guest
Apr 19th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace OOPvjezbanje
  9. {
  10. public class Repozitorij
  11. {
  12. public static List<Korisnik> lista = new List<Korisnik>();
  13. public delegate void JMBGcheck(Korisnik k);
  14. public static event JMBGcheck JMBGHandler;
  15.  
  16. static bool DodajKorisnika(Korisnik k)
  17. {
  18. try
  19. {
  20. lista.Add(k);
  21. return true;
  22. }
  23. catch (Exception e)
  24. {
  25. Console.WriteLine(e.Message);
  26. return false;
  27. }
  28. }
  29.  
  30. static bool ObrisiKorisnika(Korisnik k)
  31. {
  32. try
  33. {
  34. lista.Remove(k);
  35. return true;
  36. }
  37. catch (Exception e)
  38. {
  39. Console.WriteLine(e.Message);
  40. return false;
  41. }
  42. }
  43.  
  44. internal static void UnesiNovog()
  45. {
  46. try
  47. {
  48. Console.WriteLine("Unesite ime korisnika: ");
  49. string ime = Console.ReadLine();
  50. Console.WriteLine("Unesite prezime korisnika: ");
  51. string prezime = Console.ReadLine();
  52. Console.WriteLine("Unesite JMBG korisnika: ");
  53. string jmbg = Console.ReadLine();
  54.  
  55. if (!ProvjeriDalPostojiJMBG(jmbg))
  56. {
  57. throw new MojException("Vec postoji JMBG!");
  58. }
  59. Console.WriteLine("Unesite status korisnika: ");
  60. string status = Console.ReadLine();
  61. while (!ProvjeriStatus(status))
  62. {
  63. Console.WriteLine("Krivi status! \nUnesite status korisnika: ");
  64. status = Console.ReadLine();
  65. }
  66.  
  67. Korisnik k = new Korisnik(ime, prezime, jmbg, status);
  68.  
  69. if (!ProvjeriJMBG(jmbg))
  70. {
  71. if (JMBGHandler != null)
  72. {
  73. JMBGHandler(k);
  74. }
  75. }
  76. else
  77. {
  78. //Ako je punoljetan, dodaj u listu
  79. lista.Add(k);
  80. ListaUTekstFile();
  81. }
  82. }
  83. catch (MojException me)
  84. {
  85. Console.WriteLine(me.Message);
  86. }
  87. }
  88.  
  89. private static bool ProvjeriDalPostojiJMBG(string jmbg)
  90. {
  91. foreach (Korisnik k in lista)
  92. {
  93. if (k.JMBG == jmbg)
  94. {
  95. return false;
  96. }
  97. }
  98. return true;
  99. }
  100.  
  101. public static bool ProvjeriStatus(string status)
  102. {
  103. if (status == "Zlatni" || status == "Platinasti" || status == "Srebrni")
  104. {
  105. return true;
  106. }
  107.  
  108. return false;
  109. }
  110.  
  111. public static void TraziPoStatusu()
  112. {
  113. Console.WriteLine("Unesite status: ");
  114. string status = Console.ReadLine();
  115.  
  116. if (status == "Zlatni" || status == "Platinasti" || status == "Srebrni")
  117. {
  118. foreach (Korisnik k in lista)
  119. {
  120. if (k.Status == status)
  121. {
  122. Console.WriteLine(k);
  123. }
  124. }
  125. }
  126. }
  127.  
  128. public static void TraziPoJMBG()
  129. {
  130. Console.WriteLine("Unesite JMBG: ");
  131. string jmbg = Console.ReadLine();
  132. foreach (Korisnik k in lista)
  133. {
  134. if (k.JMBG == jmbg)
  135. {
  136. Console.WriteLine(k);
  137. }
  138. }
  139. }
  140.  
  141. public static void ObrisiKorisnika()
  142. {
  143. Console.WriteLine("Unesite ime: ");
  144. string ime = Console.ReadLine();
  145. Console.WriteLine("Unesite prezime: ");
  146. string prezime = Console.ReadLine();
  147.  
  148. foreach(Korisnik k in lista)
  149. {
  150. if (k.Ime == ime && k.Prezime == prezime)
  151. {
  152. lista.Remove(k);
  153. }
  154. }
  155. }
  156.  
  157. public static void IspisiSve()
  158. {
  159. foreach (Korisnik k in lista)
  160. {
  161. Console.WriteLine(k);
  162. }
  163. }
  164.  
  165. public static bool ProvjeriJMBG (string jmbg)
  166. {
  167. int parsano = int.Parse(jmbg.Substring(4, 3));
  168.  
  169. if ( parsano > 900)
  170. {
  171. return true;
  172. }
  173. else
  174. {
  175. return false;
  176. }
  177. }
  178.  
  179. internal static void ListaUTekstFile()
  180. {
  181. using (StreamWriter sw = new StreamWriter(@"C:\Users\Dubstep\Desktop\OOPvj\OOPvjezbanje\OOPvjezbanje\Korisnici.txt"))
  182. {
  183. foreach (Korisnik k in lista)
  184. {
  185. sw.WriteLine(k.ToString());
  186. }
  187. }
  188. }
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement