A12
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            PopuniListView();
            PopuniCB();

        }
        public void PopuniCB()
        {
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A12;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select grad from grad ", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                comboBox1.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }

        public void PopuniListView()
        {
            listView1.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A12;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select stadion.stadionid , stadion.naziv, grad.grad, stadion.kapacitet, stadion.adresa,stadion.brojulaza from stadion inner join grad on stadion.gradid=grad.gradid ", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                ListViewItem item = new ListViewItem(reader[0].ToString());
                item.SubItems.Add(reader[1].ToString());
                item.SubItems.Add(reader[2].ToString());
                item.SubItems.Add(reader[3].ToString());
                item.SubItems.Add(reader[4].ToString());
                item.SubItems.Add(reader[5].ToString());
                listView1.Items.Add(item);
            }
            connection.Close();      
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                textBox1.Text = listView1.SelectedItems[0].SubItems[0].Text;
                textBox2.Text = listView1.SelectedItems[0].SubItems[1].Text;
                textBox3.Text = listView1.SelectedItems[0].SubItems[4].Text;
                numericUpDown1.Text = listView1.SelectedItems[0].SubItems[3].Text;
                numericUpDown2.Text = listView1.SelectedItems[0].SubItems[5].Text;
                comboBox1.Text= listView1.SelectedItems[0].SubItems[2].Text;
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            try
            {
                if (listView1.SelectedItems.Count == 0)
                {
                    throw new Exception("Nije selektovan ni jedan red");
                }
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A12;Integrated Security=True");
                connection.Open();
                SqlCommand komandica1 = new SqlCommand("select gradid from grad where grad = @naziv", connection);
                SqlCommand komandica2 = new SqlCommand("update stadion set naziv=@p1,adresa=@p2,kapacitet=@p3,brojulaza=@p4,gradid=@p5 where stadionid=@p6", connection);
                komandica1.Parameters.AddWithValue("@naziv", comboBox1.Text);
                komandica2.Parameters.AddWithValue("@p1", textBox2.Text);
                komandica2.Parameters.AddWithValue("@p2", textBox3.Text);
                komandica2.Parameters.AddWithValue("@p3", numericUpDown1.Value);
                komandica2.Parameters.AddWithValue("@p4", numericUpDown2.Value);
                komandica2.Parameters.AddWithValue("@p5", komandica1.ExecuteScalar());
                komandica2.Parameters.AddWithValue("@p6", textBox1.Text);
                komandica2.ExecuteNonQuery();
                MessageBox.Show("uspeo si majmune");
                PopuniListView();
                connection.Close();
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                numericUpDown1.Value = 0;
                numericUpDown2.Value = 0;
                comboBox1.Text = "";

            }
            catch (Exception eks)
            {
                MessageBox.Show("greskica: " + eks.Message);
            }
        }
        public void Pretraga(string nazivDrzave)
        {
            listView1.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A12;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select stadion.stadionid, stadion.naziv, grad.grad, stadion.kapacitet,stadion.adresa,stadion.brojulaza from stadion inner join grad on stadion.gradid=grad.gradid inner join drzava on grad.drzavaid=drzava.drzavaid where drzava.naziv=@nesto", connection);
            komanda.Parameters.AddWithValue("@nesto", nazivDrzave);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                ListViewItem item = new ListViewItem(reader[0].ToString());
                item.SubItems.Add(reader[1].ToString());
                item.SubItems.Add(reader[2].ToString());
                item.SubItems.Add(reader[3].ToString());
                item.SubItems.Add(reader[4].ToString());
                item.SubItems.Add(reader[5].ToString());
                listView1.Items.Add(item);
            }
            connection.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Form2 forma = new Form2(this);
            this.Show();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            Form3 forma = new Form3();
            forma.Show();
            this.Hide();
        }
    }
}
---------------druga
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 WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        Form1 formica2;
        public Form2(Form1 formica1)
        {
            InitializeComponent();
            formica2 = formica1;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            formica2.Pretraga(textBox1.Text);
            this.Close();
        }
    }
}
------------------------------treca
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A12;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand(@" SELECT Stadion.Naziv AS Stadion, COUNT(utakmica.UtakmicaID) AS BrojUtakmica 
            FROM Utakmica JOIN Klub  ON utakmica.DomacinID = klub.KlubID JOIN Stadion ON klub.StadionID = stadion.StadionID where YEAR(Utakmica.DatumIgranja)=2022 GROUP BY stadion.Naziv  ", connection);
            SqlDataAdapter adapter = new SqlDataAdapter(komanda);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            chart1.DataSource = dt;
            chart1.Series[0].XValueMember = "Stadion";
            chart1.Series[0].YValueMembers= "BrojUtakmica";
            chart1.DataBind();
        }
    }
}

A12

A13
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            PopuniLB();
            listBox1.SelectedIndex = 0;
            
        }
        public void PopuniLB()
        {
            listBox1.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A13;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select producentid,ime,email from producent", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                listBox1.Items.Add(reader[0].ToString() + "\t\t\t\t" + reader[1].ToString() + "\t\t\t\t" + reader[2].ToString());
            }
            connection.Close();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Form2 forma = new Form2();
            this.Hide();
            forma.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count > 0)
            {
                textBox1.Text = listBox1.SelectedItem.ToString().Split('\t')[0].Trim();
                textBox2.Text = listBox1.SelectedItem.ToString().Split('\t')[4].Trim();
                textBox3.Text = listBox1.SelectedItem.ToString().Split('\t')[8].Trim();
       
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
                {
                    throw new Exception("Nisi sve popunio");
                }
                if (!textBox3.Text.Contains('@') || !textBox3.Text.Contains('.'))
                {
                    throw new Exception("nisi uneo u obliku maila");
                }
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A13;Integrated Security=True");
                connection.Open();
                SqlCommand komanda = new SqlCommand("update producent set ime=@p2, email=@p3 where producentid=@p1", connection);
                komanda.Parameters.AddWithValue("p1", textBox1.Text);
                komanda.Parameters.AddWithValue("p2", textBox2.Text);
                komanda.Parameters.AddWithValue("p3", textBox3.Text);
                komanda.ExecuteNonQuery();
                MessageBox.Show("Uspesno odradili izmenu!");
                PopuniLB();
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                connection.Close();
            }
            catch(Exception eks)
            {
                MessageBox.Show("greska: " + eks.Message);
            }
        }
    }
}
--------------------druga
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

           
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A13;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select Producent.ime as'Producent', COUNT(Film.FilmID) as 'Broj filmova' from producent inner join producirao on producent.producentid=producirao.producentid inner join film on producirao.filmid=film.filmid group by producent.ime", connection);


            SqlDataAdapter adapter = new SqlDataAdapter(komanda);
            DataTable table = new DataTable();
            adapter.Fill(table);
            dataGridView1.DataSource = table;

            chart1.DataSource = table;
            chart1.Series[0].XValueMember = "Producent";
            chart1.Series[0].YValueMembers = "Broj filmova";
            chart1.DataBind();

            connection.Close();
        }
    }
}

A13

A14
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            PopuniDGV();
            textBox1.Text = dataGridView1.Rows[0].Cells[2].Value.ToString();
            textBox1.Text = dataGridView1.Rows[0].Cells[4].Value.ToString();
        }
        public void PopuniDGV()
        {
           
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A14;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select lekid as 'Sifra leka', proizvodjac.proizvodjacid as 'Sifra proizvodjaca',lek.nazivLeka as 'Naziv leka', lek.pro  as'Nezasticeno ime', proizvodjac.naziv from lek inner join proizvodjac on lek.proizvodjacid=proizvodjac.proizvodjacid order by lek.nazivleka", connection);
            SqlDataAdapter adapter = new SqlDataAdapter(komanda);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            dataGridView1.DataSource = dt;
            connection.Close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                textBox1.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                textBox2.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                    throw new Exception("mora biti popunjeno");

                }
                DialogResult odgovor = MessageBox.Show("Da li ste sigurni da zelite da obrisete ovaj lek", "", MessageBoxButtons.YesNo);
                if (odgovor == DialogResult.Yes && dataGridView1.SelectedRows.Count > 0)
                {
                    SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A14;Integrated Security=True");
                    connection.Open();
                    SqlCommand komanda1 = new SqlCommand("delete from Lek_Pakovenje where lekid=@p1", connection);
                    SqlCommand komanda2 = new SqlCommand("delete from lek_bolest where lekid=@p1", connection);
                    SqlCommand komanda3 = new SqlCommand("delete from Lek_Kontraindikcija where lekid=@p1", connection);
                    SqlCommand komanda4 = new SqlCommand("delete from lek_nezeljeni_efekat where lekid=@p1", connection);
                    SqlCommand komanda5 = new SqlCommand("delete from lek where lekid=@p1", connection);

                    komanda1.Parameters.AddWithValue("@p1", dataGridView1.SelectedRows[0].Cells[0].Value);
                    komanda2.Parameters.AddWithValue("@p1", dataGridView1.SelectedRows[0].Cells[0].Value);
                    komanda3.Parameters.AddWithValue("@p1", dataGridView1.SelectedRows[0].Cells[0].Value);
                    komanda4.Parameters.AddWithValue("@p1", dataGridView1.SelectedRows[0].Cells[0].Value);
                    komanda5.Parameters.AddWithValue("@p1", dataGridView1.SelectedRows[0].Cells[0].Value);

                    komanda1.ExecuteNonQuery();
                    komanda2.ExecuteNonQuery();
                    komanda3.ExecuteNonQuery();
                    komanda4.ExecuteNonQuery();
                    komanda5.ExecuteNonQuery();
                    MessageBox.Show("uspesno obrisan");
                    PopuniDGV();
                    connection.Close();
                }
                else
                {
                    textBox1.Clear();
                    textBox2.Clear();
                }
               
            }
            catch(Exception eks)
            {
                MessageBox.Show("greska: " + eks.Message);
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Form2 forma = new Form2();
            this.Hide();
            forma.Show();
        }
    }
}
----------------druga
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            PopuniCLB();
        }
        public void PopuniCLB()
        {
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A14;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select naziv from proizvodjac", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                checkedListBox1.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }
        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A14;Integrated Security=True");
                connection.Open();
                SqlCommand komanda1 = new SqlCommand("select proizvodjacid from proizvodjac where proizvodjac.naziv=@naziv", connection);
                SqlCommand komanda2 = new SqlCommand("select proizvodjac.naziv, COUNT(lekid) from proizvodjac inner join lek on proizvodjac.proizvodjacid=lek.proizvodjacid where proizvodjac.proizvodjacid=@id group by proizvodjac.naziv", connection);
                chart1.Series[0].Points.Clear();
                foreach (var item in checkedListBox1.CheckedItems)
                {
                    komanda1.Parameters.Clear();
                    komanda1.Parameters.AddWithValue("@naziv", item.ToString());
                    komanda2.Parameters.Clear();
                    komanda2.Parameters.AddWithValue("@id", komanda1.ExecuteScalar());

                    SqlDataReader reader = komanda2.ExecuteReader();
                    while (reader.Read())
                    {
                        chart1.Series[0].Points.AddXY(reader[0].ToString(), reader[1].ToString());
                    }
                    reader.Close();
                }
            }
            catch(Exception eks)
            {
                MessageBox.Show("greska:" + eks.Message);
            }
        }
    }
}

A14

A15
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            PopuniCB1();
            PopuniCB2();
            PopuniGV();
            comboBox1.Text = dataGridView1.Rows[0].Cells[0].Value.ToString();
            comboBox2.Text = dataGridView1.Rows[0].Cells[1].Value.ToString(); ;
        }
        public void PopuniCB1()
        {
            comboBox1.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select naziv from bolest", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                comboBox1.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }
        public void PopuniCB2()
        {
            comboBox2.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select nazivLeka from lek", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                comboBox2.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }
        public void PopuniGV()
        {
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select bolest.naziv as'Bolest', lek.nazivLeka as'Lek', proizvodjac.naziv as 'Proizvodjac'from bolest inner join lek_bolest on bolest.bolestid=lek_bolest.bolestid inner join lek on lek.lekid=lek_bolest.lekid inner join proizvodjac on lek.proizvodjacid=proizvodjac.proizvodjacid order by bolest.naziv ", connection);
            SqlDataAdapter adapter = new SqlDataAdapter(komanda);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            dataGridView1.DataSource = dt;
           
            connection.Close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "" || comboBox2.Text == "" || textBox1.Text == "")
                {
                    throw new Exception("sve mora biti popunjeno");
                }
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
                connection.Open();
                SqlCommand komanda1 = new SqlCommand("insert into lek_bolest values(@lekid,@bolestid,@napomena)", connection);
                SqlCommand komanda2 = new SqlCommand("select bolestid from bolest where bolest.naziv=@nazivbolesti", connection);
                SqlCommand komanda3 = new SqlCommand("select lekid from lek where nazivleka=@nazivleka", connection);

                komanda2.Parameters.AddWithValue("@nazivbolesti", comboBox1.Text);
                komanda3.Parameters.AddWithValue("@nazivleka", comboBox2.Text);

                komanda1.Parameters.AddWithValue("@lekid",komanda3.ExecuteScalar());
                komanda1.Parameters.AddWithValue("@bolestid",komanda2.ExecuteScalar());
                komanda1.Parameters.AddWithValue("@napomena", textBox1.Text);
                komanda1.ExecuteNonQuery();
                MessageBox.Show("uspesno uradjen insert");
                PopuniGV();
            }
            catch (Exception eks)
            {
                MessageBox.Show("Greska: " + eks.Message);
            }
            
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                comboBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                comboBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            }
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select napomena from lek_bolest inner join bolest on lek_bolest.bolestid=bolest.bolestid inner join lek on lek_bolest.lekid=lek.lekid where bolest.naziv=@nazivbolesti and lek.nazivleka=@nazivleka", connection);
            komanda.Parameters.AddWithValue("@nazivbolesti", comboBox1.Text);
            komanda.Parameters.AddWithValue("@nazivleka", comboBox2.Text);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                textBox1.Text = reader[0].ToString();
            }
            connection.Close();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Form2 forma = new Form2();
            this.Hide();
            forma.Show();
        }
    }
}
-----------------------druga
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            PopuniCheckListBox();
        }
        public void PopuniCheckListBox()
        {
            checkedListBox1.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select nazivGrupe from grupa_leka", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                checkedListBox1.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }
        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                chart1.Series[0].Points.Clear();
                if (checkedListBox1.CheckedItems.Count == 0)
                {
                    throw new Exception("NISI NISTA SELEKTOVAO");
                }
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A15;Integrated Security=True");
                connection.Open();
                foreach (var item in checkedListBox1.CheckedItems)
                {
                    SqlCommand komanda = new SqlCommand("select COUNT(Lek.Lekid),grupa_leka.nazivgrupe from lek inner join grupa_leka on grupa_leka.grupalekaid=lek.grupalekaid where grupa_leka.nazivgrupe=@naziv group by grupa_leka.nazivgrupe", connection);
                    komanda.Parameters.AddWithValue("@naziv", item.ToString());
                    chart1.Series[0].Points.AddXY(item.ToString(), komanda.ExecuteScalar());
                }
                connection.Close();
            }
            catch (Exception eks)
            {
                MessageBox.Show("greska: " + eks.Message);
            }
        }
    }
}

A15

A30
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            PopuniCB1();
            PopuniCB2();
            PopuniLB();
            comboBox1.Text = listBox1.Items[0].ToString().Split('\t')[0].Trim();
            textBox1.Text= listBox1.Items[0].ToString().Split('\t')[1].Trim();
            textBox2.Text= listBox1.Items[0].ToString().Split('\t')[2].Trim();
            comboBox2.Text= listBox1.Items[0].ToString().Split('\t')[4].Trim();
            textBox3.Text= listBox1.Items[0].ToString().Split('\t')[3].Trim();
        }
        public void PopuniCB1()
        {

            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A30;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select grad from grad", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                comboBox2.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }
        public void PopuniCB2()
        {

            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A30;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select terenid from teren order by terenid", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {
                comboBox1.Items.Add(reader[0].ToString());
            }
            connection.Close();
        }
        public void PopuniLB()
        {
            listBox1.Items.Clear();
            SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A30;Integrated Security=True");
            connection.Open();
            SqlCommand komanda = new SqlCommand("select teren.terenid, teren.teren,teren.adresa, teren.kontakttelefon,grad.grad from teren inner join grad on grad.gradid=teren.gradid", connection);
            SqlDataReader reader = komanda.ExecuteReader();
            while (reader.Read())
            {

                listBox1.Items.Add(reader[0].ToString() + "\t" + reader[1].ToString() + "\t" + reader[2].ToString() + "\t" + reader[3].ToString() + "\t" + reader[4].ToString());
            }
            connection.Close();
        }
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Form2 milica = new Form2();
            this.Hide();
            milica.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count > 0)
            {
                comboBox1.Text = listBox1.SelectedItem.ToString().Split('\t')[0].Trim();
                textBox1.Text = listBox1.SelectedItem.ToString().Split('\t')[1].Trim();
                textBox2.Text = listBox1.SelectedItem.ToString().Split('\t')[2].Trim();
                comboBox2.Text = listBox1.SelectedItem.ToString().Split('\t')[4].Trim();
                textBox3.Text = listBox1.SelectedItem.ToString().Split('\t')[3].Trim();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool found = false;
            if (comboBox1.Text == "")
            {

            }
            else
            {

                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (comboBox1.Text == listBox1.Items[i].ToString().Split('\t')[0])
                    {
                        listBox1.SelectedIndex = i;
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    MessageBox.Show("Nije pronadjen sa tim indexom");
                    listBox1.SelectedIndex = -1;
                }
            }

        }

        private void comboBox1_TextUpdate(object sender, EventArgs e)
        {
            bool found = false;
            if (comboBox1.Text == "")
            {

            }
            else
            {

                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (comboBox1.Text == listBox1.Items[i].ToString().Split('\t')[0])
                    {
                        listBox1.SelectedIndex = i;
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    MessageBox.Show("Nije pronadjen sa tim indexom");
                    listBox1.SelectedIndex = -1;
                }
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBox1.SelectedItems.Count == 0)
                {
                    throw new Exception("Nije selektovan ni jedan red");
                }
                
                DialogResult odgovor = MessageBox.Show("Da li zelite da obrisete ovaj teren", "", MessageBoxButtons.YesNo);
                if (odgovor == DialogResult.Yes && listBox1.SelectedItems.Count > 0)
                {
                    SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A30;Integrated Security=True");
                    connection.Open();
                    SqlCommand komanda1 = new SqlCommand("delete from teren where terenid=@id", connection);
                    SqlCommand komanda2 = new SqlCommand("delete from partija where terenid=@id", connection);
                    SqlCommand komanda3 = new SqlCommand("delete from rupa where terenid=@id", connection);
                    SqlCommand komanda4 = new SqlCommand("delete from rezultat where rupaid in(select rupa.rupaid from rupa where rupa.terenid=@id) or partijaid in (select partija.partijaid from partija where partija.terenid=@id)", connection);
                    SqlCommand komanda5 = new SqlCommand("delete from igraju where partijaid in (select partija.partijaid from partija where partija.terenid=@id)", connection);

                    komanda1.Parameters.AddWithValue("@id", listBox1.SelectedItems[0].ToString().Split()[0].Trim());
                    komanda2.Parameters.AddWithValue("@id", listBox1.SelectedItems[0].ToString().Split()[0].Trim());
                    komanda3.Parameters.AddWithValue("@id", listBox1.SelectedItems[0].ToString().Split()[0].Trim());
                    komanda4.Parameters.AddWithValue("@id", listBox1.SelectedItems[0].ToString().Split()[0].Trim());
                    komanda5.Parameters.AddWithValue("@id", listBox1.SelectedItems[0].ToString().Split()[0].Trim());

                    komanda5.ExecuteNonQuery();
                    komanda4.ExecuteNonQuery();
                    komanda3.ExecuteNonQuery();
                    komanda2.ExecuteNonQuery();
                    komanda1.ExecuteNonQuery();
                    connection.Close();
                    MessageBox.Show("Uspesno si izbrisao podatak");
                    PopuniLB();
                }
                else
                {
                    MessageBox.Show("Niste obrisali podatak");
                }
            }
            catch (Exception eks)
            {
                MessageBox.Show("greska: " + eks.Message);
            }
        }
    }
}
----------------------druga
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.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            PopuniCB1();
            
        }
        public void PopuniCB1()
        {
            for(int i = 0; i <= 24;i++)
            {
                comboBox2.Items.Add(i.ToString());
                comboBox1.Items.Add(i.ToString());
            }
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A30;Integrated Security=True");
                connection.Open();
                SqlCommand komanda = new SqlCommand("select partija.partijaid as 'PartijaID', teren.teren AS'Teren',partija.datum as'Datum',DATEDIFF(MINUTE,vremepocetka,vremezavrsetka) as'Trajanje' from partija inner join teren on partija.terenid=teren.terenid where DATEPART(HOUR,vremepocetka) between @p1 and @p2 and DATEPART(HOUR,vremezavrsetka) between @p1 and @p2 order by DATEDIFF(MINUTE,vremepocetka,vremezavrsetka)", connection);
                komanda.Parameters.AddWithValue("@p1",comboBox1.Text);
                komanda.Parameters.AddWithValue("@p2", comboBox2.Text);
                SqlDataAdapter adapter = new SqlDataAdapter(komanda);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                dataGridView1.DataSource = dt;
                chart1.DataSource = dt;
                chart1.Series[0].XValueMember = "Teren";
                chart1.Series[0].YValueMembers = "Trajanje";
                chart1.DataBind();
                connection.Close();
            }
            catch(Exception eks)
            {
                MessageBox.Show("greska: " + eks.Message);
            }
        }
    }
}

A30

A12-A30

By its4

A12-A30

  • 113