private void ArtikalJedan_Load(object sender, EventArgs e) { try { baza.OtvoriKonekciju(); OleDbCommand cmd = new OleDbCommand(); /* * dodao zbog zatvaranja formi * */ cmd.Connection = baza.Connection; cmd.CommandText = "select * from artikal"; OleDbDataReader reader = cmd.ExecuteReader(); artikal.Clear(); while (reader.Read()) { Artikal a = new Artikal(); a.Id_artikla = int.Parse(reader["id_artikla"].ToString()); a.Naziv = reader["naziv"].ToString(); a.Cena = int.Parse(reader["cena"].ToString()); a.Popust = int.Parse(reader["popust"].ToString()); a.Id_grupa = int.Parse(reader["id_grupa"].ToString()); artikal.Add(a); } //ovaj deo sam morao jer mi upit baca problem kada pretrazujem prozivode // koji imaju to ime sa naziv like ime, ili naziv in ime....... foreach (Artikal a in artikal) { if (a.Naziv == ime) { nasArtikal = a; } } textBox1.Text = nasArtikal.Naziv; textBox2.Text = nasArtikal.Cena.ToString(); textBox3.Text = nasArtikal.Popust.ToString(); } catch (Exception ex) { MessageBox.Show("Greska je " + ex); } finally { baza.ZatvoriKonekciju(); } }
private void FormaArtikli_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'prodavnicaDataSet.racun' table. You can move, or remove it, as needed. this.racunTableAdapter.Fill(this.prodavnicaDataSet.racun); // TODO: This line of code loads data into the 'prodavnicaDataSet.grupa' table. You can move, or remove it, as needed. this.grupaTableAdapter.Fill(this.prodavnicaDataSet.grupa); try { racun(); baza.OtvoriKonekciju(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = baza.Connection; cmd.CommandText = "select * from artikal where id_grupa=" + grupa; OleDbDataReader reader = cmd.ExecuteReader(); artikli.Clear(); while (reader.Read()) { Artikal a = new Artikal(); a.Id_artikla = int.Parse(reader["id_artikla"].ToString()); a.Naziv = reader["naziv"].ToString(); a.Cena = int.Parse(reader["cena"].ToString()); a.Popust = int.Parse(reader["popust"].ToString()); a.Id_grupa = int.Parse(reader["id_grupa"].ToString()); artikli.Add(a); } } catch (Exception ex) { MessageBox.Show("Greska je " + ex); } finally { baza.ZatvoriKonekciju(); } for (int i = 0; i < artikli.Count(); i++) { Button button = new Button(); button.Width = 92; button.Height = 62; button.Text = artikli[i].Naziv; button.Name = artikli[i].Id_grupa.ToString(); button.Click += new EventHandler(otvoriArtikal); flowLayoutPanel1.Controls.Add(button); } }