Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public void ZapiszBaze()
  2. {
  3. try
  4. {
  5. System.IO.StreamWriter file = new System.IO.StreamWriter("baza_danych.txt");
  6. foreach (Produkt data in produkty)
  7. {
  8. file.WriteLine(data.Id);
  9. file.WriteLine(data.Nazwa);
  10. file.WriteLine(data.Cena);
  11. file.WriteLine(data.Opis);
  12. }
  13. file.Close();
  14. }
  15. catch (Exception e)
  16. {
  17. Console.WriteLine(e.Message);
  18.  
  19. }
  20. }
  21.  
  22. public void WczytajBaze()
  23. {
  24. int _id;
  25. string _nazwa, _opis, _ID, _CENA;
  26. float _cena;
  27.  
  28. try
  29. {
  30. System.IO.StreamReader file = new System.IO.StreamReader("baza_danych.txt");
  31. while (!file.EndOfStream)
  32. {
  33. _ID = file.ReadLine();
  34. _nazwa = file.ReadLine();
  35. _CENA = file.ReadLine();
  36. _opis = file.ReadLine();
  37.  
  38. _id = Convert.ToInt32(_ID);
  39. _cena = Convert.ToSingle(_CENA);
  40.  
  41.  
  42. produkty.Add(new Produkt(_id, _nazwa, _cena, _opis));
  43.  
  44. }
  45. file.Close();
  46. }
  47.  
  48. catch (Exception e)
  49. {
  50. Console.WriteLine(e.Message);
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement