Vezba 04 visual studio
description
Transcript of Vezba 04 visual studio
![Page 1: Vezba 04 visual studio](https://reader035.fdocuments.in/reader035/viewer/2022081806/55cf969f550346d0338cbfbd/html5/thumbnails/1.jpg)
Kreirati formu sa sledećim izgledom:
Imena komponenti su:
txtIme
txtPrezime
txtBrojIndeksa
txtProsek
btnDodaj
dgStudenti
U okviru aplikacije dodati sledeće klase:
Student.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Studenti { class Student { private string ime; private string prezime; private string brIndeksa; private float prosek; public Student() { } public string Ime {
![Page 2: Vezba 04 visual studio](https://reader035.fdocuments.in/reader035/viewer/2022081806/55cf969f550346d0338cbfbd/html5/thumbnails/2.jpg)
get { return ime; } set { ime = value; if (ime == "") { throw new Exception("Morate uneti ime studenta!!!"); } } } public string Prezime { get { return prezime; } set { prezime = value; if (prezime == "") { throw new Exception("Morate uneti prezime studenta!!!"); } } } public string BrIndeksa { get { return brIndeksa; } set { brIndeksa = value; if (brIndeksa == "") { throw new Exception("Morate uneti broj indeksa za studenta!!!"); } } } public float Prosek { get { return prosek; } set { if (value < 5 || value > 10) { throw new Exception("Prosek mora biti između 5 i 10!!!"); } prosek = value; } } } }
Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
![Page 3: Vezba 04 visual studio](https://reader035.fdocuments.in/reader035/viewer/2022081806/55cf969f550346d0338cbfbd/html5/thumbnails/3.jpg)
using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Studenti { public partial class Form1 : Form { List<Student> studenti = new List<Student>(); public Form1() { InitializeComponent(); dgStudenti.Columns.Add("imeStudenta", "Ime"); dgStudenti.Columns.Add("prezimeStudenta", "Prezime"); dgStudenti.Columns.Add("brojIndeksa", "Br. Indeksa"); dgStudenti.Columns.Add("prosek", "Prosek"); dgStudenti.AllowUserToAddRows = false; dgStudenti.AllowUserToDeleteRows = false; dgStudenti.ReadOnly = true; } private void popuniTabelu() { dgStudenti.Rows.Clear(); if (studenti.Count > 0) { foreach (Student stud in studenti) { dgStudenti.Rows.Add(stud.Ime, stud.Prezime, stud.BrIndeksa, stud.Prosek); } } } private void ponistiUnos() { txtIme.Text = ""; txtPrezime.Text = ""; txtBrojIndeksa.Text = ""; txtProsek.Text = ""; } private void btnDodaj_Click(object sender, EventArgs e) { try { Student stud = new Student(); stud.Ime = txtIme.Text; stud.Prezime = txtPrezime.Text; stud.BrIndeksa = txtBrojIndeksa.Text; stud.Prosek = float.Parse(txtProsek.Text); studenti.Add(stud); popuniTabelu();
![Page 4: Vezba 04 visual studio](https://reader035.fdocuments.in/reader035/viewer/2022081806/55cf969f550346d0338cbfbd/html5/thumbnails/4.jpg)
ponistiUnos(); } catch (FormatException) { MessageBox.Show("Format proseka nije korektan!!!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
Domaći zadatak:
Uraditi aplikaciju za unošenje podataka o profesorima. Podaci se smeštaju u listu i prikazuju na
ekranu.