Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace Studenti
- {
- public partial class Form1 : Form
- {
- List<Student> studenti;
- public Form1()
- {
- InitializeComponent();
- studenti = nactiStudenty("studenti.csv");
- listBox1.DisplayMember = "Text";
- listBox1.DataSource = studenti;
- }
- private List<Student> nactiStudenty(string soubor)
- {
- List<Student> s = new List<Student>();
- // čtení z textového souboru
- StreamReader st = new StreamReader(soubor, Encoding.GetEncoding(1250));
- string radek;
- string[] hodnoty;
- int oborId;
- while (!st.EndOfStream)
- {
- radek = st.ReadLine();
- hodnoty = radek.Split(';');
- oborId = Convert.ToInt32(hodnoty[3]);
- s.Add(new Student(hodnoty[0],
- hodnoty[1],
- Convert.ToInt32(hodnoty[2]),
- oborId));
- if (oborId == 1) pocetIT++;
- else pocetE++;
- }
- textBox1.Text = pocetE.ToString();
- textBox2.Text = pocetIT.ToString();
- st.Close();
- return s;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Studenti
- {
- /*
- * ENTITNÍ TŘÍDA pro záznam Student
- */
- class Student
- {
- // Vnitřní objektové proměnné jsou zpřístupněné pouze pro čtení prostřednictvím automaticky vytvořených vlastností
- // Velká písmena v názvu se zavádí z důvodu konvencí označení veřejných (public) členů
- public string Prijmeni { get; }
- public string Krestni { get; }
- public int Rocnik { get; }
- public int OborId { get; }
- public int it=0;
- public int e=0;
- public string OborNazev
- {
- get
- {
- if (this.OborId == 1) { it++; return "Informační technologie"; }
- else { e++; return "Elektrotechnika"; }
- }
- }
- public string Text
- {
- get
- {
- return String.Format("{0} {1}, {2}", this.Prijmeni, this.Krestni, this.OborNazev);
- }
- }
- // Konstruktor zajistí prvotní naplnění hodnot do objektových proměnných
- public Student(string krestni, string prijmeni, int rocnik, int obor)
- {
- this.Prijmeni = prijmeni;
- this.Krestni = krestni;
- this.Rocnik = rocnik;
- this.OborId = obor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement