Vous êtes sur la page 1sur 3

public partial class Form3 : Form

{
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=F:\SKOLA\Programiranje i baze\rezerva access fajla\ribara.mdb");
string starostanje;
string updatestanje;
string sifra, naziv;
double cijena;
double novacijena, standardnacijena;
double cijenaPecenje, cijenaCiscenjel;
double ukupnaCijena;
string datum = DateTime.Now.ToString("M/d/yyyy");
public Form3()
{
InitializeComponent();
prikazitabelu();
}

private void odbijkolicinu()


{

con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from PROIZVODI";
OleDbDataReader reader;
try
{
reader = cmd.ExecuteReader();
while (reader.Read())
{
string stanje = reader["KOLICINA"].ToString();
starostanje = stanje;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
int kg, kg1, kg2;
int.TryParse(starostanje, out kg1);
int.TryParse(textBox2.Text, out kg2);
kg = kg1 - kg2;
updatestanje = kg.ToString();
}
private void novaCijena()
{
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from PROIZVODI";
OleDbDataReader reader;
try
{
reader = cmd.ExecuteReader();
while (reader.Read())
{
string stanje = reader["CIJENA"].ToString();
standardnacijena = Convert.ToDouble(stanje);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
int kolicina;
Int32.TryParse(textBox2.Text, out kolicina);
novacijena = standardnacijena * kolicina + ((cijenaPecenje +
cijenaCiscenjel) * kolicina);

}
private void prikazitabelu()
{

con.Open();
OleDbCommand cmd10 = con.CreateCommand();
cmd10.CommandType = CommandType.Text;
cmd10.CommandText = "select * from POPIS WHERE DATUM LIKE '" + datum +
"'";
cmd10.ExecuteNonQuery();
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd10);
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();

}
private void label1_Click(object sender, EventArgs e)
{

private void checkBox2_CheckedChanged(object sender, EventArgs e)


{
if (checkBox2.Checked == true)
cijenaCiscenjel = 0.5;
else cijenaCiscenjel = 0;
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)


{
if (checkBox1.Checked == true)
cijenaPecenje = 1.5;
else cijenaPecenje = 0;
}

private void button1_Click(object sender, EventArgs e)


{

odbijkolicinu();
novaCijena();
con.Open();
OleDbCommand cmd5 = con.CreateCommand();
cmd5.CommandType = CommandType.Text;
cmd5.CommandText = "SELECT * FROM PROIZVODI WHERE SIFRA = '" +
textBox1.Text + "'";
OleDbDataReader reader = cmd5.ExecuteReader();
while (reader.Read())
{
sifra = reader["SIFRA"].ToString();
naziv = reader["NAZIV"].ToString();
string cijena1 = reader["CIJENA"].ToString();
cijena = Convert.ToDouble(cijena1);
}

OleDbCommand cmd = con.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO POPIS VALUES('" + sifra + "','" + naziv
+ "','" + novacijena + "','" + textBox2.Text + "', '" + datum + "')";
cmd.ExecuteNonQuery();
OleDbCommand cmd2 = con.CreateCommand();
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "UPDATE PROIZVODI SET KOLICINA = '" + updatestanje +
"' WHERE SIFRA = '" + textBox1.Text + "'";
cmd2.ExecuteNonQuery();
con.Close();
prikazitabelu();

private void button2_Click(object sender, EventArgs e)


{
con.Open();
string noviDatum = datum;
OleDbCommand cmd2 = con.CreateCommand();
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "SELECT SUM(CIJENA) FROM POPIS WHERE DATUM like '" +
noviDatum + "'";
object result = cmd2.ExecuteScalar();
label3.Text = Convert.ToString(result);
con.Close();
}

private void Form3_Load(object sender, EventArgs e)


{

}
}
}