private void button_latvany_modos_Click(object sender, EventArgs e) { if (listBox_latvany.SelectedItem == null) { MessageBox.Show("Kérem válaszon egyet a látványoságok közul"); } else { Latvanyossagok varok = (Latvanyossagok)listBox_latvany.SelectedItem; int id = varok.Id; string update = @"UPDATE latvanyossagok SET nev= @nev , ar = @ar, leiras = @leiras WHERE latvanyossagok.id = @id"; var updatecomm = conn.CreateCommand(); updatecomm.CommandText = update; updatecomm.Parameters.AddWithValue("@id", id); updatecomm.Parameters.AddWithValue("@nev", textBox_latvany.Text); updatecomm.Parameters.AddWithValue("@leiras", textBox_lerias.Text); updatecomm.Parameters.AddWithValue("@ar", numericUpDown_ar.Value); int sork = updatecomm.ExecuteNonQuery(); listBox1.Items.Clear(); listBox_latvany.Items.Clear(); AdatBetoltes(); } }
private void listBox_latvany_SelectedIndexChanged(object sender, EventArgs e) { Latvanyossagok latvany = (Latvanyossagok)listBox_latvany.SelectedItem; if (listBox_latvany.SelectedItem == null) { } else { /* * label_lat_ar_m.Visible = true; * numericUpDown_lat_ar_m.Visible = true; * textBox_lat_ler_m.Visible = true; * label_lat_ler_m.Visible = true; * * label_lat_nev.Visible = true; * textBox_lat_nev.Visible = true;*/ button_torlos_lat.Visible = true; button_latvany_modos.Visible = true; textBox_latvany.Text = latvany.Nev; textBox_lerias.Text = latvany.Leiras; numericUpDown_ar.Value = latvany.Ar; } }
private void button_torlos_lat_Click(object sender, EventArgs e) { if (listBox_latvany.SelectedItem == null) { MessageBox.Show("Kérem válaszon egyet a látványoságok közul"); } else { Latvanyossagok p = (Latvanyossagok)listBox_latvany.SelectedItem; int id = p.Id; string torvaros = @"DELETE FROM `latvanyossagok` WHERE `latvanyossagok`.`id` = @id"; var commDeletVar = this.conn.CreateCommand(); commDeletVar.CommandText = torvaros; commDeletVar.Parameters.AddWithValue("@id", id); int erinV = commDeletVar.ExecuteNonQuery(); listBox_latvany.Items.RemoveAt(listBox_latvany.SelectedIndex); } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { Varosok varos = (Varosok)listBox1.SelectedItem; if (listBox1.SelectedItem == null) { } else { listBox_latvany.Items.Clear(); button_modositasi.Visible = true; textBox_nev.Text = varos.Nev; numericUpDown_lakos.Value = varos.Lakossag; Varosok p = (Varosok)listBox1.SelectedItem; int id = p.Id; string sql = @" SELECT nev,ar,leiras,varos_id,id FROM latvanyossagok WHERE latvanyossagok.varos_id = @id"; /*MessageBox.Show("" + id);*/ var comm = this.conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@id", id); int ae = comm.ExecuteNonQuery(); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int idv = reader.GetInt32("id"); string nev = reader.GetString("nev"); string leiras = reader.GetString("leiras"); int ar = reader.GetInt32("ar"); int varos_id = reader.GetInt32("varos_id"); var latvanyok = new Latvanyossagok(idv, varos_id, nev, leiras, ar); listBox_latvany.Items.Add(latvanyok); } } } }
private void button1_Click(object sender, EventArgs e) { int id = 0; for (int i = 0; i < listBox_latvany.Items.Count; i++) { Latvanyossagok l = (Latvanyossagok)listBox_latvany.Items[i]; id = l.Id; id++; } string nev = textBox_latvany.Text; var ar = (int)numericUpDown_ar.Value; string leiras = textBox_lerias.Text; if (textBox_latvany.Text == "") { MessageBox.Show("Kérem adjon meg a látványoság nevét"); } if (leiras.Length == 0) { MessageBox.Show("Kérem adjon meg a látványoság leirását"); } bool ll = false; List <string> lnevek = new List <string>(); List <string> lleiras = new List <string>(); for (int i = 0; i < listBox_latvany.Items.Count; i++) { Latvanyossagok v = (Latvanyossagok)listBox_latvany.Items[i]; lnevek.Add(v.Nev); lleiras.Add(v.Leiras); } if (lnevek.Contains(textBox_latvany.Text) && lleiras.Contains(textBox_lerias.Text)) { MessageBox.Show("Van már ilyen látványoság fel véve."); ll = true; } if (ll == false && leiras.Length != 0 && nev.Length != 0) { Varosok l = (Varosok)listBox1.SelectedItem; int vid = l.Id; var latvany = new Latvanyossagok(id, vid, nev, leiras, ar); var iVaros = conn.CreateCommand(); iVaros.CommandText = @" INSERT INTO latvanyossagok (id,nev,leiras,ar,varos_id) VALUES (@id,@nev,@leiras,@ar,@vid)"; iVaros.Parameters.AddWithValue("@id", null); iVaros.Parameters.AddWithValue("@vid", vid); iVaros.Parameters.AddWithValue("@nev", nev); iVaros.Parameters.AddWithValue("@leiras", leiras); iVaros.Parameters.AddWithValue("@ar", ar); int sor = iVaros.ExecuteNonQuery(); listBox_latvany.Items.Add(latvany); listBox1_SelectedIndexChanged(sender, e); } }