A6
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();
PopuniListBox();
PopuniComboBox();
numericUpDown2.Minimum = numericUpDown1.Value;
}
public void PopuniListBox()
{
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A6;Integrated Security=True");
connection.Open();
listBox1.Items.Clear();
SqlCommand komanda = new SqlCommand("select model.modelid, model.naziv,proizvodjac.naziv from model inner join proizvodjac on model.proizvodjacid=proizvodjac.proizvodjacid ", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add(reader[0].ToString() + "\t" + reader[1].ToString() + ", " + reader[2].ToString());
}
connection.Close();
}
public void PopuniComboBox()
{
comboBox1.Items.Clear();
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A6;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select naziv from proizvodjac", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader[0].ToString());
}
connection.Close();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
numericUpDown2.Minimum = numericUpDown1.Value;
}
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', ',')[2].Trim();
textBox1.Text = listBox1.SelectedItem.ToString().Split('\t', ',')[1].Trim();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (listBox1.SelectedItems.Count == 0)
{
throw new Exception("Nije selektovan ni jedan red");
}
if (comboBox1.Text == "" || textBox1.Text == "")
{
throw new Exception("Nije popunjeno sve");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A6;Integrated Security=True");
connection.Open();
string modelid = listBox1.SelectedItem.ToString().Split()[0].Trim();
SqlCommand komanda = new SqlCommand("update model set Naziv=@naziv, ProizvodjacID=(select ProizvodjacID from Proizvodjac where Naziv = @proizvodjac) where ModelID = @modelid", connection);
komanda.Parameters.AddWithValue("@naziv",textBox1.Text);
komanda.Parameters.AddWithValue("@proizvodjac",comboBox1.Text);
komanda.Parameters.AddWithValue("@modelid", modelid);
komanda.ExecuteNonQuery();
PopuniListBox();
MessageBox.Show("uspesna izmena");
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (listBox1.Items[i].ToString().Split()[0] == modelid)
{
listBox1.SelectedIndex = i;
break;
}
}
connection.Close();
}
catch(Exception eks)
{
MessageBox.Show("greska: " + eks.Message);
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
bool found = false;
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (textBox2.Text == listBox1.Items[i].ToString().Split()[0])
{
listBox1.SelectedIndex = i;
found = true;
break;
}
}
if (!found)
{
listBox1.SelectedIndex = -1;
comboBox1.SelectedIndex = -1;
textBox1.Text = "";
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button3_Click(object sender, EventArgs e)
{
try
{
if (Convert.ToInt32(textBox3.Text) < 0)
{
throw new Exception("ne moze biti kilometraza negativna");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A6;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select proizvodjac.naziv as 'Proizvodjac', COUNT(Vozilo.voziloid) as'Broj' from proizvodjac inner join model on proizvodjac.proizvodjacid=model.proizvodjacid inner join vozilo on model.modelid=vozilo.modelid where vozilo.predjenoKM<=@p1 and YEAR(Vozilo.GodinaProzivodnje) between @od and @do group by Proizvodjac.naziv", connection);
komanda.Parameters.AddWithValue("@p1",Convert.ToInt32(textBox3.Text));
komanda.Parameters.AddWithValue("@od",numericUpDown1.Value);
komanda.Parameters.AddWithValue("@do",numericUpDown2.Value);
SqlDataAdapter adapter = new SqlDataAdapter(komanda);
DataTable dt = new DataTable();
adapter.Fill(dt);
chart1.DataSource = dt;
chart1.Series[0].XValueMember = "Proizvodjac";
chart1.Series[0].YValueMembers = "Broj";
chart1.DataBind();
listView1.Items.Clear();
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
ListViewItem item = new ListViewItem(reader[0].ToString());
item.SubItems.Add(reader[1].ToString());
listView1.Items.Add(item);
}
connection.Close();
}
catch (Exception eks){
MessageBox.Show("greska: " + eks.Message);
}
}
private void tabPage2_Click(object sender, EventArgs e)
{
}
}
}A6
A7
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();
PopuniDGV();
}
public void PopuniDGV()
{
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A7;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select * from predmet", connection);
SqlDataAdapter adapter = new SqlDataAdapter(komanda);
DataTable dt = new DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
connection.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
textBox4.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
textBox5.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (dataGridView1.SelectedRows.Count == 0)
{
throw new Exception("nije selektovan red");
}
if(textBox1.Text=="" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
{
throw new Exception("nije popunjeno sve");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A7;Integrated Security=True");
connection.Open();
SqlCommand komanda1 = new SqlCommand("delete from izabranipredmet where predmetid=@id", connection);
SqlCommand komanda2 = new SqlCommand("delete from predmet where predmetid=@id", connection);
komanda1.Parameters.AddWithValue("@id", textBox1.Text);
komanda2.Parameters.AddWithValue("@id", textBox1.Text);
komanda1.ExecuteNonQuery();
komanda2.ExecuteNonQuery();
MessageBox.Show("bravo majmune");
PopuniDGV();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
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 Form3 : Form
{
public Form3()
{
InitializeComponent();
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=DESKTOP-8O361E7;Initial Catalog=A7;Integrated Security=True";
SqlCommand command = new SqlCommand("select predmet from predmet", connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
checkedListBox1.Items.Add(reader[0].ToString());
}
connection.Close();
//GRIDVIEW
dataGridView1.Columns[1].HeaderText = (2022).ToString();
dataGridView1.Columns[2].HeaderText = (2023).ToString();
dataGridView1.Columns[3].HeaderText = (2024).ToString();
//CHART
chart1.Series[0].LegendText = (2022).ToString();
chart1.Series[1].LegendText = (2023).ToString();
chart1.Series[2].LegendText = (2024).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (checkedListBox1.CheckedItems.Count > 5)
{
throw new Exception("Ne moze vise od 5");
}
dataGridView1.Rows.Clear();
chart1.Series[0].Points.Clear();
chart1.Series[1].Points.Clear();
chart1.Series[2].Points.Clear();
foreach (var item in checkedListBox1.CheckedItems)
{
DataGridViewRow row = new DataGridViewRow();
DataGridViewCell predmet = new DataGridViewTextBoxCell();
DataGridViewCell godina_1 = new DataGridViewTextBoxCell();
DataGridViewCell godina_2 = new DataGridViewTextBoxCell();
DataGridViewCell godina_3 = new DataGridViewTextBoxCell();
godina_1.Value = "0";
godina_2.Value = "0";
godina_3.Value = "0";
predmet.Value = item.ToString();
row.Cells.Add(predmet);
row.Cells.Add(godina_1);
row.Cells.Add(godina_2);
row.Cells.Add(godina_3);
int j = 0;
for (int i = 2022; i <= 2024; i++)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=DESKTOP-8O361E7;Initial Catalog=A7;Integrated Security=True";
SqlCommand command = new SqlCommand(@"select predmet.predmet,COUNT(Student.studentid) from student inner join izabranipredmet on student.studentid=izabranipredmet.studentid inner join predmet on predmet.predmetid=izabranipredmet.predmetid where predmet=@predmet and izabranipredmet.odslusao='da' and YEAR(izabranipredmet.GodinaSlusanja)=@godina group by predmet.predmet ", connection);
command.Parameters.AddWithValue("@godina", i);
command.Parameters.AddWithValue("@predmet", item.ToString());
connection.Open();
SqlDataReader reader = command.ExecuteReader();
bool read = false;
while (reader.Read())
{
row.Cells[j+1].Value = reader[1].ToString();
chart1.Series[j].Points.AddXY(item.ToString(), reader[1]);
chart1.Series[j].Points[chart1.Series[j].Points.Count-1].Label = reader[1].ToString();
read = true;
}
if (read == false)
{
chart1.Series[j].Points.AddXY(item.ToString(), 0);
}
connection.Close();
j++;
}
dataGridView1.Rows.Add(row);
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
}A7
A9
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();
comboBox1.SelectedIndex = 0;
}
public void PopuniCB1()
{
comboBox1.Items.Clear();
comboBox1.Items.Add("Svi drzave");
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A9;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select naziv from drzava", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader[0].ToString());
}
connection.Close();
}
public void PopuniCB2()
{
comboBox2.Items.Clear();
comboBox2.Items.Add("Sve gradovi");
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A9;Integrated Security=True");
connection.Open();
SqlCommand komanda1 = new SqlCommand("select grad.grad from drzava inner join grad on drzava.drzavaid=grad.drzavaid where drzava.naziv=@naziv", connection);
komanda1.Parameters.AddWithValue("@naziv", comboBox1.Text);
SqlDataReader reader = komanda1.ExecuteReader();
while (reader.Read())
{
comboBox2.Items.Add(reader[0].ToString());
}
connection.Close();
}
public void PopuniCB3()
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Sve klubovi");
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A9;Integrated Security=True");
connection.Open();
SqlCommand komanda1 = new SqlCommand("select klub.nazivkluba from klub inner join stadion on klub.stadionid=stadion.stadionid inner join grad on stadion.gradid=grad.gradid where grad.grad=@naziv", connection);
komanda1.Parameters.AddWithValue("@naziv", comboBox2.Text);
SqlDataReader reader = komanda1.ExecuteReader();
while (reader.Read())
{
comboBox3.Items.Add(reader[0].ToString());
}
connection.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
pictureBox1.Image = Image.FromFile(@"C:\Users\Nidzo\Desktop\MATURA SANJA GLAVNO\1 VEZBANJE ZA MATURU ZADACI SVI\PROGRAMIRANJE\A9 - Fudbalski klubovi\WindowsFormsApp1\WindowsFormsApp1\slike\Fifa1.png");
comboBox2.Enabled = false;
comboBox3.Enabled = false;
comboBox2.Text = "";
comboBox3.Text = "";
label5.Text = "";
label6.Text = "";
linkLabel1.Text = "";
}
else
{
comboBox2.Enabled = true;
PopuniCB2();
comboBox2.SelectedIndex = 0;
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex == 0)
{
pictureBox1.Image = Image.FromFile(@"C:\Users\Nidzo\Desktop\MATURA SANJA GLAVNO\1 VEZBANJE ZA MATURU ZADACI SVI\PROGRAMIRANJE\A9 - Fudbalski klubovi\WindowsFormsApp1\WindowsFormsApp1\slike\Fifa1.png");
comboBox3.Enabled = false;
comboBox3.Text = "";
label5.Text = "";
label6.Text = "";
linkLabel1.Text = "";
}
else
{
comboBox3.Enabled = true;
PopuniCB3();
comboBox3.SelectedIndex = 0;
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox3.SelectedIndex == 0)
{
pictureBox1.Image = Image.FromFile(@"C:\Users\Nidzo\Desktop\MATURA SANJA GLAVNO\1 VEZBANJE ZA MATURU ZADACI SVI\PROGRAMIRANJE\A9 - Fudbalski klubovi\WindowsFormsApp1\WindowsFormsApp1\slike\Fifa1.png");
label5.Text = "";
label6.Text = "";
linkLabel1.Text = "";
}
else
{
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A9;Integrated Security=True");
connection.Open();
SqlCommand komanda1 = new SqlCommand("select grad.grad,stadion.naziv,klub.sajt,klub.amblem from grad inner join stadion on grad.gradid=stadion.gradid inner join klub on klub.stadionid=stadion.stadionid where klub.nazivkluba=@p1 and grad.grad=@p2", connection);
komanda1.Parameters.AddWithValue("@p1", comboBox3.Text);
komanda1.Parameters.AddWithValue("@p2", comboBox2.Text);
SqlDataReader reader = komanda1.ExecuteReader();
while (reader.Read())
{
label5.Text = reader[0].ToString();
label6.Text = reader[1].ToString();
linkLabel1.Text = reader[2].ToString();
pictureBox1.Image = Image.FromFile(@"C:\Users\Nidzo\Desktop\MATURA SANJA GLAVNO\1 VEZBANJE ZA MATURU ZADACI SVI\PROGRAMIRANJE\A9 - Fudbalski klubovi\WindowsFormsApp1\WindowsFormsApp1\slike\" + reader[3].ToString());
}
}
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
label5.Text = "";
label6.Text = "";
linkLabel1.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
try
{
if (dateTimePicker1.Text == "")
{
throw new Exception("nisi izabrao datum");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A9;Integrated Security=True");
connection.Open();
SqlCommand n = new SqlCommand(@"select stadion.naziv, k1.nazivkluba,golovadomacin,golovagost,k2.nazivkluba from utakmica inner join Klub k1 on k1.klubid = utakmica.domacinid inner join Klub k2 on k2.klubid = utakmica.gostid inner join stadion on stadion.stadionid = k1.stadionid where utakmica.datumigranja = @p1", connection);
n.Parameters.AddWithValue("@p1", dateTimePicker1.Value);
SqlDataReader dr = n.ExecuteReader();
while (dr.Read())
{
ListViewItem item = new ListViewItem(dr[0].ToString());
item.SubItems.Add(dr[1].ToString());
item.SubItems.Add(dr[2].ToString());
item.SubItems.Add(dr[3].ToString());
item.SubItems.Add(dr[4].ToString());
listView1.Items.Add(item);
}
connection.Close();
}
catch (Exception eks)
{
MessageBox.Show("greska:" + eks.Message);
}
}
}
}A9
A10
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();
PopuniListBox();
PopuniCB();
textBox1.Text = listBox1.Items[0].ToString().Split('\t')[0].Trim();
textBox2.Text = listBox1.Items[0].ToString().Split('\t')[1].Trim();
textBox3.Text = listBox1.Items[0].ToString().Split('\t')[2].Trim();
textBox4.Text = listBox1.Items[0].ToString().Split('\t')[3].Trim();
comboBox1.Text = listBox1.Items[0].ToString().Split('\t')[4].Trim();
textBox5.Text = listBox1.Items[0].ToString().Split('\t')[5].Trim();
}
public void PopuniCB()
{
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A10;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select grad from grad order by grad", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader[0].ToString());
}
connection.Close();
}
public void PopuniListBox()
{
listBox1.Items.Clear();
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A10;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select pecaros.pecarosid, pecaros.ime,pecaros.prezime,pecaros.adresa,grad.grad,pecaros.telefon from pecaros inner join grad on pecaros.gradid=grad.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() + "\t" + reader[5].ToString());
}
connection.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox3_Click(object sender, EventArgs e)
{
Form2 forma = new Form2();
this.Hide();
forma.Show();
}
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')[1].Trim();
textBox3.Text = listBox1.SelectedItem.ToString().Split('\t')[2].Trim();
textBox4.Text = listBox1.SelectedItem.ToString().Split('\t')[3].Trim();
comboBox1.Text = listBox1.SelectedItem.ToString().Split('\t')[4].Trim();
textBox5.Text = listBox1.SelectedItem.ToString().Split('\t')[5].Trim();
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
try
{
if (listBox1.SelectedItems.Count == 0)
{
throw new Exception("nije selektovan ni jedan red");
}
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || comboBox1.Text == "" || textBox5.Text == "")
{
throw new Exception("Nije sve popunjeno");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A10;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("update pecaros set ime=@p2,prezime=@p3,adresa=@p4,gradid=@p5,telefon=@p6 where pecarosid=@p1 ", connection);
SqlCommand komanda1 = new SqlCommand("select gradid from grad where grad=@kurac", connection);
komanda1.Parameters.AddWithValue("@kurac", comboBox1.Text);
komanda.Parameters.AddWithValue("@p1",textBox1.Text);
komanda.Parameters.AddWithValue("@p2",textBox2.Text);
komanda.Parameters.AddWithValue("@p3",textBox3.Text);
komanda.Parameters.AddWithValue("@p4",textBox4.Text);
komanda.Parameters.AddWithValue("@p5",komanda1.ExecuteScalar());
komanda.Parameters.AddWithValue("@p6", textBox5.Text);
komanda.ExecuteNonQuery();
MessageBox.Show("uspesna izmena");
PopuniListBox();
connection.Close();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
comboBox1.Text="";
textBox5.Clear();
}
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();
PopuniCB();
comboBox1.SelectedIndex = 0;
}
public void PopuniCB()
{
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A10;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select pecarosid,ime,prezime from pecaros order by pecarosid", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader[0].ToString()+" - "+reader[1].ToString()+" " +reader[2].ToString());
}
connection.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (comboBox1.SelectedIndex == 0)
{
throw new Exception("niste izabrali pecarosa");
}
if (dateTimePicker1.Value > dateTimePicker2.Value)
{
throw new Exception("ne more");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A10;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select VrstaRibe.naziv as 'Vrsta', COUNT(ulov.rbrulova) as'broj' from VrstaRibe inner join ulov on VrstaRibe.vrstaid=ulov.vrstaid inner join pecaros on pecaros.pecarosid=ulov.pecarosid where pecaros.pecarosid=@id and ulov.datum between @od and @do group by VrstaRibe.naziv", connection);
komanda.Parameters.AddWithValue("@id", comboBox1.Text.Split()[0]);
komanda.Parameters.AddWithValue("@od",dateTimePicker1.Value);
komanda.Parameters.AddWithValue("@do", dateTimePicker2.Value);
SqlDataAdapter adapter = new SqlDataAdapter(komanda);
DataTable dt = new DataTable();
adapter.Fill(dt);
chart1.DataSource = dt;
chart1.Series[0].XValueMember = "Vrsta";
chart1.Series[0].YValueMembers = "broj";
dataGridView1.DataSource = dt;
chart1.DataBind();
connection.Close();
}
catch(Exception eks)
{
MessageBox.Show("greska: " + eks.Message);
}
}
}
}A10
A11
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();
PopuniListBox();
button2.Enabled = false;
button3.Enabled = false;
textBox1.Text = listBox1.Items[0].ToString().Split('\t')[0].Trim();
textBox2.Text = listBox1.Items[0].ToString().Split('\t')[2].Trim();
textBox3.Text = listBox1.Items[0].ToString().Split('\t')[4].Trim();
dateTimePicker1.Text = listBox1.Items[0].ToString().Split('\t')[6].Trim();
}
public void PopuniListBox()
{
listBox1.Items.Clear();
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A11_V2;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select * from autor", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add(reader[0].ToString().Trim() + "\t\t" + reader[1].ToString().Trim() + "\t\t" + reader[2].ToString().Trim() + "\t\t" + reader[3].ToString().Split()[0]);
}
connection.Close();
}
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')[2].Trim();
textBox3.Text = listBox1.SelectedItem.ToString().Split('\t')[4].Trim();
dateTimePicker1.Text = listBox1.SelectedItem.ToString().Split('\t')[6].Trim();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
textBox2.Text = "";
textBox3.Text = "";
dateTimePicker1.Text = "";
}
else
{
listBox1.SelectedItems.Clear();
bool found = false;
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (textBox1.Text == listBox1.Items[i].ToString().Split('\t')[0])
{
listBox1.SelectedIndex = i;
found = true;
break;
}
else
{
textBox2.Text = "";
textBox3.Text = "";
dateTimePicker1.Text = "";
}
}
if (!found)
{
textBox2.Text = "";
textBox3.Text = "";
dateTimePicker1.Text = "";
MessageBox.Show("nema sa tim indexom");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
textBox1.ReadOnly = true;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
dateTimePicker1.Text = "";
button2.Enabled = true;
button3.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
try
{
if (listBox1.SelectedItems.Count == 0)
{
throw new Exception("nije selektovan red");
}
if (textBox2.Text == "" || textBox3.Text == "" || dateTimePicker1.Text == "")
{
throw new Exception("nisi sve popunio");
}
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A11_V2;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("insert into autor values(@p1,@p2,@p3,@p4)", connection);
komanda.Parameters.AddWithValue("@p1", listBox1.Items.Count + 1);
komanda.Parameters.AddWithValue("@p2", textBox2.Text);
komanda.Parameters.AddWithValue("@p3", textBox3.Text);
komanda.Parameters.AddWithValue("@p4", dateTimePicker1.Value);
komanda.ExecuteNonQuery();
MessageBox.Show("uspeo si majmune");
PopuniListBox();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
dateTimePicker1.Text = "";
button2.Enabled = false;
button3.Enabled = false;
button1.Enabled = true;
}
catch(Exception eks)
{
MessageBox.Show("greska: " + eks.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.ReadOnly = false;
button2.Enabled = false;
button3.Enabled = false;
button1.Enabled = true;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
dateTimePicker1.Text = "";
}
private void pictureBox3_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();
PopuniCBL();
}
public void PopuniCBL()
{
checkedListBox1.Items.Clear();
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A11_V2;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select ime, prezime from autor", connection);
SqlDataReader reader = komanda.ExecuteReader();
while (reader.Read())
{
checkedListBox1.Items.Add(reader[0].ToString() + " " + reader[1].ToString());
}
connection.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
PopuniCBL();
chart1.Series[0].Points.Clear();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (checkedListBox1.CheckedItems.Count == 0)
{
throw new Exception("nisi selektovao nista");
}
chart1.Series[0].Points.Clear();
foreach( var item in checkedListBox1.CheckedItems)
{
SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-8O361E7;Initial Catalog=A11_V2;Integrated Security=True");
connection.Open();
SqlCommand komanda = new SqlCommand("select COUNT(knjiga.knjigaid) as'Broj knjiga', (autor.ime+ ' '+autor.prezime) as 'Autor' from knjiga inner join autor_izdanje on knjiga.knjigaid=autor_izdanje.knjigaid inner join autor on autor_izdanje.autorid=autor.autorid where (autor.ime+' '+autor.prezime)=@ime group by (autor.ime+ ' '+autor.prezime)", connection);
komanda.Parameters.AddWithValue("@ime", item.ToString());
chart1.Series[0].Points.AddXY(item.ToString(),komanda.ExecuteScalar());
chart1.DataBind();
}
}
catch(Exception eks)
{
MessageBox.Show("greska: " + eks.Message);
}
}
}
}A11
A6-A11
By its4
A6-A11
- 102