Join us on theapp
Kako uraditi maturske zadatke
Neki tvrde da se to ne moze, ja vam tvrdim da se to moze
Search…
A1
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 a1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection konekcija = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=C:UsersNemanjaDesktopa1Database1.mdf;Integrated Security=True");
SqlCommand komanda = new SqlCommand();
SqlDataReader dr;
string upit;
private void Form1_Load(object sender, EventArgs e)
{
prikazi();
}
void prikazi()
{
listView1.Items.Clear();
upit = "Select * from Citalac";
komanda = new SqlCommand(upit, konekcija);
try
{
konekcija.Open();
dr = komanda.ExecuteReader();
while (dr.Read())
{
ListViewItem a = new ListViewItem(dr[0].ToString());
a.SubItems.Add(dr[1].ToString());
a.SubItems.Add(dr[2].ToString());
a.SubItems.Add(dr[3].ToString());
a.SubItems.Add(dr[4].ToString());
listView1.Items.Add(a);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
konekcija.Close();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "" || Convert.ToInt32(textBox1.Text)>listView1.Items.Count)
{
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
}
else
foreach(ListViewItem a in listView1.Items)
{
if (textBox1.Text == a.SubItems[0].Text)
{
textBox2.Text = a.SubItems[1].Text;
textBox3.Text = a.SubItems[2].Text;
textBox4.Text = a.SubItems[3].Text;
textBox5.Text = a.SubItems[4].Text;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
upit = string.Format(@"Insert into Citalac(MaticniBroj, Ime, Prezime, Adresa) values('{0}','{1}','{2}','{3}')", textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text);
komanda = new SqlCommand(upit, konekcija);
try
{
konekcija.Open();
komanda.ExecuteNonQuery();
MessageBox.Show("Upisan.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
konekcija.Close();
}
prikazi();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void oAplikacijiToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Aplikacija a1");
}
private void pregledIznajmljivanjaToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
}
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 a1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection konekcija = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=C:UsersNemanjaDesktopa1Database1.mdf;Integrated Security=True");
SqlCommand Komanda = new SqlCommand();
SqlDataReader Dr;
DataTable Dt;
SqlDataAdapter Da=new SqlDataAdapter();
string upit;
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == -1)
return;
if (numericUpDown1.Value < numericUpDown2.Value)
{
chart1.Series.Clear();
chart1.Titles.Clear();
Komanda = new SqlCommand();
Komanda.Connection = konekcija;
int pc = comboBox1.SelectedItem.ToString().IndexOf('-');
string s = comboBox1.SelectedItem.ToString().Substring(0, pc);
int rb = Convert.ToInt32(s);
Komanda.CommandText = string.Format("Select Ime+' '+Prezime As Citalac, Year(DatumUzimanja) As Godina, Count(*) As [Broj iznajmljivanja], Count(*)-Count(DatumVracanja) As [Nije vraceno] From Citalac, Na_Citanju Where Citalac.CitalacID=Na_Citanju.CitalacID And Year(DatumUzimanja)>={0} And Year(DatumUzimanja)<={1} And Na_Citanju.CitalacID={2} Group By Year(DatumUzimanja),Ime,Prezime,Citalac.CitalacID Order By Ime,Prezime", (int)numericUpDown1.Value, (int)numericUpDown2.Value, rb);
Da = new SqlDataAdapter();
Da.SelectCommand = Komanda;
Dt = new DataTable();
Da.Fill(Dt);
dataGridView1.DataSource = Dt;
chart1.Series.Add("G1");
chart1.DataSource = Dt;
chart1.Series["G1"].XValueMember = "Godina";
chart1.Series["G1"].YValueMembers = "Broj iznajmljivanja";
chart1.Series.Add("G2");
chart1.DataSource = Dt;
chart1.Series["G2"].XValueMember = "Godina";
chart1.Series["G2"].YValueMembers = "Nije vraceno";
}
else if (numericUpDown1.Value == 0 && numericUpDown2.Value == 0)
{
chart1.Series.Clear();
chart1.Titles.Clear();
Komanda = new SqlCommand();
Komanda.Connection = konekcija;
int pc = comboBox1.SelectedItem.ToString().IndexOf('-');
string s = comboBox1.SelectedItem.ToString().Substring(0, pc);
int rb = Convert.ToInt32(s);
Komanda.CommandText = string.Format("Select Ime+' '+Prezime As Citalac, Year(DatumUzimanja) As Godina, Count(*) As [Broj iznajmljivanja], Count(*)-Count(DatumVracanja) As [Nije vraceno] From Citalac, Na_Citanju Where Citalac.CitalacID=Na_Citanju.CitalacID And Year(DatumUzimanja)>=2014 And Year(DatumUzimanja)<=2024 And Na_Citanju.CitalacID={0} Group By Year(DatumUzimanja),Ime,Prezime,Citalac.CitalacID Order By Ime,Prezime", rb);
Da = new SqlDataAdapter();
Da.SelectCommand = Komanda;
Dt = new DataTable();
Da.Fill(Dt);
dataGridView1.DataSource = Dt;
chart1.Series.Add("G1");
chart1.DataSource = Dt;
chart1.Series["G1"].XValueMember = "Godina";
chart1.Series["G1"].YValueMembers = "Broj iznajmljivanja";
chart1.Series.Add("G2");
chart1.DataSource = Dt;
chart1.Series["G2"].XValueMember = "Godina";
chart1.Series["G2"].YValueMembers = "Nije vraceno";
}
else MessageBox.Show("Godine nisu dobro unete!");
}
private void Form2_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
upit = "Select CitalacID, Ime+' '+Prezime from Citalac";
Komanda = new SqlCommand(upit, konekcija);
try
{
konekcija.Open();
Dr = Komanda.ExecuteReader();
while (Dr.Read())
{
comboBox1.Items.Add(Dr[0].ToString() + "-" + Dr[1].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
konekcija.Close();
}
}
}
}
A2
Form1:
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 A2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection konekcija = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=C:UsersUcenik7DesktopA2A2Database1.mdf;Integrated Security=True");
SqlCommand komanda;
string upit;
SqlDataReader dr;
bool prvi = true;
public void prikazi()
{
listView1.Items.Clear();
upit = "Select AutorID, Ime, Prezime, DatumRodjenja from Autor";
komanda = new SqlCommand(upit, konekcija);
try
{
konekcija.Open();
dr = komanda.ExecuteReader();
while (dr.Read())
{
if (prvi)
{
textBox1.Text = dr[0].ToString();
textBox2.Text = dr[1].ToString();
textBox3.Text = dr[2].ToString();
textBox4.Text = Convert.ToDateTime(dr[3]).ToString("dd/MM/yyyy");
prvi = false;
}
ListViewItem a = new ListViewItem(dr[0].ToString());
a.SubItems.Add(dr[1].ToString());
a.SubItems.Add(dr[2].ToString());
a.SubItems.Add(Convert.ToDateTime(dr[3]).ToString("dd/MM/yyyy"));
listView1.Items.Add(a);
}
dr.Close();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
finally
{
konekcija.Close();
}
}
private void brisanjeToolStripMenuItem_Click(object sender, EventArgs e)
{
upit = "Delete from Autor where AutorID=" + listView1.SelectedItems[0].SubItems[0].Text.ToString();
komanda = new SqlCommand(upit, konekcija);
try
{
konekcija.Open();
dr = komanda.ExecuteReader();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
finally
{
konekcija.Close();
}
prikazi();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 1)
{
textBox1.Text = listView1.SelectedItems[0].SubItems[0].Text.ToString();
textBox2.Text = listView1.SelectedItems[0].SubItems[1].Text.ToString();
textBox3.Text = listView1.SelectedItems[0].SubItems[2].Text.ToString();
textBox4.Text = listView1.SelectedItems[0].SubItems[3].Text.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
prikazi();
listView1.Items[0].Selected = true;
}
private void analizaToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 a = new Form2();
a.ShowDialog();
}
}
}
Form2:
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.Windows.Forms.DataVisualization.Charting;
using System.Data.SqlClient;
namespace A2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection konekcija = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=C:UsersUcenik7DesktopA2A2Database1.mdf;Integrated Security=True");
SqlCommand komanda;
string upit;
SqlDataReader dr;
List<string> a = new List<string>();
private void label1_Click(object sender, EventArgs e)
{
}
private void Form2_Load(object sender, EventArgs e)
{
upit = "Select Ime +' ' + Prezime from Autor";
komanda = new SqlCommand(upit, konekcija);
try
{
konekcija.Open();
dr = komanda.ExecuteReader();
while (dr.Read())
{
if(!a.Contains(dr[0].ToString()))a.Add(dr[0].ToString());
}
dr.Close();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
finally
{
konekcija.Close();
}
foreach (string x in a) comboBox1.Items.Add(x);
comboBox1.Text = a[0].ToString();
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
upit =string.Format("Select year(DatumUzimanja), Count(autor.AutorID) From autor, napisali, na_Citanju where autor.AutorID=napisali.AutorID and na_Citanju.KnjigaID=napisali.KnjigaID and Ime +' '+ Prezime = '{0}' and (year(DatumUzimanja) between year(getdate())-{1} and year(getdate())) group by year(DatumUzimanja)", comboBox1.Text, Convert.ToUInt32(numericUpDown1.Value));
komanda = new SqlCommand(upit, konekcija);
chart1.Series.Clear();
chart1.Series.Add("Broj");
try
{
konekcija.Open();
dr = komanda.ExecuteReader();
while (dr.Read())
{
dataGridView1.Rows.Add(dr[0].ToString(), dr[1].ToString());
chart1.Series["Broj"].Points.AddXY(dr[0].ToString(), dr[1].ToString());
}
dr.Close();
chart1.Series["Broj"].ChartType = SeriesChartType.FastLine;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
finally
{
konekcija.Close();
}
}
}
}
Da prepisem na maturskom
Luka Nikolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1