Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace Studenti
  13. {
  14. public partial class Form1 : Form
  15. {
  16.  
  17. List<Student> studenti;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. studenti = nactiStudenty("studenti.csv");
  22. listBox1.DisplayMember = "Text";
  23. listBox1.DataSource = studenti;
  24. }
  25.  
  26.  
  27. private List<Student> nactiStudenty(string soubor)
  28. {
  29. List<Student> s = new List<Student>();
  30. // čtení z textového souboru
  31. StreamReader st = new StreamReader(soubor, Encoding.GetEncoding(1250));
  32. string radek;
  33. string[] hodnoty;
  34. int oborId;
  35. while (!st.EndOfStream)
  36. {
  37. radek = st.ReadLine();
  38. hodnoty = radek.Split(';');
  39. oborId = Convert.ToInt32(hodnoty[3]);
  40. s.Add(new Student(hodnoty[0],
  41. hodnoty[1],
  42. Convert.ToInt32(hodnoty[2]),
  43. oborId));
  44. if (oborId == 1) pocetIT++;
  45. else pocetE++;
  46. }
  47. textBox1.Text = pocetE.ToString();
  48. textBox2.Text = pocetIT.ToString();
  49. st.Close();
  50. return s;
  51. }
  52. }
  53. }
  54.  
  55.  
  56.  
  57. using System;
  58. using System.Collections.Generic;
  59. using System.Linq;
  60. using System.Text;
  61. using System.Threading.Tasks;
  62.  
  63. namespace Studenti
  64. {
  65. /*
  66. * ENTITNÍ TŘÍDA pro záznam Student
  67. */
  68. class Student
  69. {
  70. // Vnitřní objektové proměnné jsou zpřístupněné pouze pro čtení prostřednictvím automaticky vytvořených vlastností
  71. // Velká písmena v názvu se zavádí z důvodu konvencí označení veřejných (public) členů
  72. public string Prijmeni { get; }
  73. public string Krestni { get; }
  74. public int Rocnik { get; }
  75. public int OborId { get; }
  76.  
  77. public int it=0;
  78. public int e=0;
  79.  
  80.  
  81. public string OborNazev
  82. {
  83. get
  84. {
  85. if (this.OborId == 1) { it++; return "Informační technologie"; }
  86. else { e++; return "Elektrotechnika"; }
  87. }
  88. }
  89.  
  90.  
  91. public string Text
  92. {
  93. get
  94. {
  95. return String.Format("{0} {1}, {2}", this.Prijmeni, this.Krestni, this.OborNazev);
  96. }
  97. }
  98.  
  99. // Konstruktor zajistí prvotní naplnění hodnot do objektových proměnných
  100. public Student(string krestni, string prijmeni, int rocnik, int obor)
  101. {
  102. this.Prijmeni = prijmeni;
  103. this.Krestni = krestni;
  104. this.Rocnik = rocnik;
  105. this.OborId = obor;
  106. }
  107.  
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement