public void LatvanyossagokListaz() { lib_latvanyossagok.Items.Clear(); var command = conn.CreateCommand(); var selectedVaros = (Varosok)lib_varosok.SelectedItem; command.CommandText = @"SELECT id,nev,leiras,ar,varos_id FROM latvanyossagok WHERE varos_id = " + selectedVaros.Id + @" ORDER BY nev"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var id = reader.GetInt32("id"); var nev = reader.GetString("nev"); var leiras = reader.GetString("leiras"); var ar = reader.GetInt32("ar"); var varos_id = reader.GetInt32("varos_id"); var latvanyossagok = new Latvanyossagok(id, nev, leiras, ar, varos_id); lib_latvanyossagok.Items.Add(latvanyossagok); } } }
private void btn_latvany_delete_Click(object sender, EventArgs e) { var deleteComm = conn.CreateCommand(); deleteComm.CommandText = @" DELETE FROM latvanyossagok WHERE latvanyossagok.id = @id; "; var foreigncheckonComm = conn.CreateCommand(); foreigncheckonComm.CommandText = @"SET FOREIGN_KEY_CHECKS=0;"; foreigncheckonComm.ExecuteNonQuery(); Latvanyossagok l = (Latvanyossagok)lbox_varos_latvanyossagok.SelectedItem; int id = l.Id; deleteComm.Parameters.AddWithValue("@id", id); int erintettSorok = deleteComm.ExecuteNonQuery(); lbox_varos_latvanyossagok.Items.RemoveAt(lbox_varos_latvanyossagok.SelectedIndex); var foreigncheckoffComm = @"SET FOREIGN_KEY_CHECKS=0;"; foreigncheckonComm.ExecuteNonQuery(); btn_latvany_edit.Visible = false; btn_latvany_delete.Visible = false; }
internal LatvanyossagModositas(Latvanyossagok l) { selectedLatvanyossag = l; conn = new MySqlConnection("Server=localhost;Port=3307;Database=latvanyossagokdb;Uid=root;"); conn.Open(); InitializeComponent(); }
private void latvanyossagujratolt() { lbox_varos_latvanyossagok.Items.Clear(); Varosok v = (Varosok)lbox_varosok.SelectedItem; string sql = @" SELECT `id`, `nev`, `leiras`, `ar`, `varos_id` FROM `latvanyossagok` WHERE varos_id = @kivalasztott_varosid"; int vid = lbox_varosok.SelectedIndex + 1; var comm = this.conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@kivalasztott_varosid", vid); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int id = 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"); v.Latvanyossagok.Add(new Latvanyossagok(id, nev, leiras, ar, varos_id)); var latvany = new Latvanyossagok(id, nev, leiras, ar, varos_id); lbox_varos_latvanyossagok.Items.Add(latvany); } } }
private void btn_latvanyossag_Click(object sender, System.EventArgs e) { int id = 0; for (int i = 0; i < lbox_varos_latvanyossagok.Items.Count; i++) { Latvanyossagok l = (Latvanyossagok)lbox_varos_latvanyossagok.Items[i]; id = l.Id; id++; } string nev = txt_lnev.Text; string leiras = txt_leiras.Text; int ar = Convert.ToInt32(nud_ar.Value); int varos_id = Convert.ToInt32(cbox_varos.SelectedIndex) + 1; var latvanyossag = new Latvanyossagok(id, nev, leiras, ar, varos_id); //Ellenőrzések if (nev.Length == 0) { MessageBox.Show("nem lehet üres a név mező"); } if (leiras.Length == 0) { MessageBox.Show("nem lehet üres a leírás"); } if (ar == 0) { MessageBox.Show("Az ár nem lehet nulla"); } if (varos_id == -1) { MessageBox.Show("A város id-t ki kell választani!"); } if (nev.Length != 0 && leiras.Length != 0 && ar != 0 && varos_id != -1) { var insertComm = conn.CreateCommand(); insertComm.CommandText = @" INSERT INTO latvanyossagok (id, nev, leiras, ar, varos_id) VALUES(@id, @nev, @leiras, @ar, @varos_id); "; insertComm.Parameters.AddWithValue("@id", null); insertComm.Parameters.AddWithValue("@nev", nev); insertComm.Parameters.AddWithValue("@leiras", leiras); insertComm.Parameters.AddWithValue("@ar", ar); insertComm.Parameters.AddWithValue("@varos_id", varos_id); int erintettSorok = insertComm.ExecuteNonQuery(); } latvanyossagujratolt(); }
private void lbox_varosok_SelectedIndexChanged(object sender, EventArgs e) { btn_varos_delete.Visible = true; btn_varos_edit.Visible = true; lbox_varos_latvanyossagok.Items.Clear(); Varosok v = (Varosok)lbox_varosok.SelectedItem; if (lbox_varosok.SelectedItem == null) { text_nev.Text = " "; numeric_lakossag.Value = 0; } else { //nup_test.Value = v.Id; text_nev.Text = v.Nev; numeric_lakossag.Value = v.Lakossag; } //nup_test.Value = lbox_varosok.SelectedIndex+1; string sql = @" SELECT `id`, `nev`, `leiras`, `ar`, `varos_id` FROM `latvanyossagok` WHERE varos_id = @kivalasztott_varosid"; int vid = lbox_varosok.SelectedIndex + 1; var comm = this.conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@kivalasztott_varosid", vid); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int id = 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"); v.Latvanyossagok.Add(new Latvanyossagok(id, nev, leiras, ar, varos_id)); var latvany = new Latvanyossagok(id, nev, leiras, ar, varos_id); lbox_varos_latvanyossagok.Items.Add(latvany); } } }
private void btn_latvany_edit_Click(object sender, EventArgs e) { Latvanyossagok l = (Latvanyossagok)lbox_varos_latvanyossagok.SelectedItem; int id = l.Id; int ar = Convert.ToInt32(nud_ar.Value); Latvanyossagok l2 = new Latvanyossagok(id, txt_lnev.Text, txt_leiras.Text, ar, cbox_varos.SelectedIndex); lbox_varos_latvanyossagok.Items[lbox_varos_latvanyossagok.SelectedIndex] = l2; var editComm = conn.CreateCommand(); editComm.CommandText = @" UPDATE latvanyossagok SET nev = @nev, leiras = @leiras, ar = @ar, varos_id = @varos_id WHERE latvanyossagok.id = @id; "; editComm.Parameters.AddWithValue("@id", id); editComm.Parameters.AddWithValue("@nev", txt_lnev.Text); editComm.Parameters.AddWithValue("@leiras", txt_leiras.Text); editComm.Parameters.AddWithValue("@ar", ar); editComm.Parameters.AddWithValue("@varos_id", cbox_varos.SelectedIndex + 1); int erintettSorok = editComm.ExecuteNonQuery(); }
private void LatvanyossagokListazas() { latvanyossagokListBox.Items.Clear(); var cmdS = conn.CreateCommand(); cmdS.CommandText = @"SELECT id, nev, leiras, ar, varos_id FROM latvanyossagok ORDER BY nev"; using (var reader = cmdS.ExecuteReader()) { while (reader.Read()) { var id = reader.GetInt32("id"); var nev = reader.GetString("nev"); var leiras = reader.GetString("leiras"); var ar = reader.GetInt32("ar"); var varos_id = reader.GetInt32("varos_id"); var latvanyossagok = new Latvanyossagok(id, nev, leiras, ar, varos_id); latvanyossagokListBox.Items.Add(latvanyossagok); } } }
private void lbox_varos_latvanyossagok_SelectedIndexChanged(object sender, EventArgs e) { Latvanyossagok l = (Latvanyossagok)lbox_varos_latvanyossagok.SelectedItem; if (lbox_varos_latvanyossagok.SelectedItem == null) { txt_lnev.Text = ""; txt_leiras.Text = ""; nud_ar.Value = 0; cbox_varos.SelectedIndex = -1; btn_latvany_edit.Visible = false; btn_latvany_delete.Visible = false; } else { txt_lnev.Text = l.Nev; txt_leiras.Text = l.Leiras; nud_ar.Value = l.Ar; cbox_varos.SelectedIndex = l.Varos_id - 1; btn_latvany_edit.Visible = true; btn_latvany_delete.Visible = true; } }
void latvanyossagokBetoltes() { string sql = @" SELECT id, nev, leiras, ar, varos_id FROM latvanyossagok order by id; "; var comm = this.conn.CreateCommand(); comm.CommandText = sql; using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int id = 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"); //string uzlet; //try //{ // uzlet = reader.GetString("uzlet"); //} //catch (SqlNullValueException ex) //{ // uzlet = null; //} var latvanyossag = new Latvanyossagok(id, nev, leiras, ar, varos_id); } } comboboxfeltoltes(); }