using ETSStariGrad.Models;
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;

namespace ETSStariGrad
{
    public partial class frmStudent : Form
    {

        List<Student> studenti = new List<Student>();

        BindingSource _bsStudneti= new BindingSource();

        public frmStudent(BindingSource bsStudenti)
        {
            InitializeComponent();
            //this._bsStudneti = bsStudenti;
            STUDENTSKAEF baza=new STUDENTSKAEF();
            _bsStudneti.DataSource=baza.students
                .ToList();
            lstStudenti.DataSource = _bsStudneti;
            cbStudenti.DataSource = _bsStudneti;
        }

        private void btnUnesi_Click(object sender, EventArgs e)
        {

            Student s = new Student()
            {
                Id= studenti.Count + 1,
                Ime = txtIme.Text,
                Prezime = txtPrezime.Text,
                Indeks = txtIndeks.Text,
                Smer = txtSmer.Text
            };
            //studenti.Add(s);
            _bsStudneti.Add(s);
            //prikaziStudnete();
            isprazniPolja();
        }

        private void prikaziStudnete()
        {
            lstStudenti.Items.Clear();
            lstStudenti.Items.AddRange(studenti.ToArray());
        }

        private void btnUnesi_MouseEnter(object sender, EventArgs e)
        {
            btnUnesi.BackColor = Color.LightGreen;
        }


        private void btnOznaciDugme_MouseEnter(object sender, EventArgs e)
        {
            Button tmp = (Button)sender;
            //var tmp1 = (Button)sender;
            tmp.BackColor = Color.LightGreen;
        }

        private void btnVratiUControl_MouseLeave(object sender, EventArgs e)
        {
            Button tmp = (Button)sender;
            //var tmp1 = (Button)sender;
            tmp.BackColor = Color.Coral;
        }

        private void bsStudenti_CurrentChanged(object sender, EventArgs e)
        {
            if (bsStudenti.Current == null)
            {
                return;
            }
            Student student= (Student)bsStudenti.Current;
            txtIme.Text = student.Ime;
            txtPrezime.Text = student.Prezime;
            txtIndeks.Text = student.Indeks;
            txtSmer.Text = student.Smer;
        }

        private void btnNovi_Click(object sender, EventArgs e)
        {
            isprazniPolja();
        }

        private void isprazniPolja()
        {
            txtIme.Text = "";
            txtPrezime.Clear();
            txtIndeks.Text = String.Empty;
            txtSmer.Text = "";
        }
    }
}
