private void lBVarosLista_SelectedIndexChanged(object sender, EventArgs e) { if (lBVarosLista.SelectedIndex > -1) { lBLatvanyosagLista.Items.Clear(); gBVarosModosit.Visible = true; bVarosTorol.Visible = true; Varos varos = (Varos)lBVarosLista.SelectedItem; string sql = @" SELECT id, nev, leiras, ar, varos_id FROM latvanyossagok WHERE varos_id = @varos_id "; var comm = this.conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@varos_id", varos.getId()); 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 varosId = reader.GetInt32("varos_id"); Latvanyossag latvanyosag = new Latvanyossag(id, nev, leiras, ar, varosId); lBLatvanyosagLista.Items.Add(latvanyosag); } } } }
void LatvanyossagListazas() { if (listBoxVaros.SelectedIndex == -1) { return; } else { listBoxLatvanyossag.Items.Clear(); var varos = (Varos)listBoxVaros.SelectedItem; var varosId = varos.Id; var cmd = conn.CreateCommand(); cmd.CommandText = @"SELECT id, nev, leiras, ar, varos_id FROM latvanyossagok WHERE varos_id = @id"; cmd.Parameters.AddWithValue("@id", varosId); using (var reader = cmd.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 latvanyossag = new Latvanyossag(id, nev, leiras, ar, varos_id); listBoxLatvanyossag.Items.Add(latvanyossag); } } } }
private void LatvListaFrissites() { latvBox.Items.Clear(); try { var command = conn.CreateCommand(); command.CommandText = @"SELECT id, nev, leiras, ar, varos_id FROM latvanyossagok WHERE varos_id = @id"; var varos = (Varos)varosBox.SelectedItem; command.Parameters.AddWithValue("@id", varos.Id); using (var reader = command.ExecuteReader()) { latvBox.Items.Clear(); 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 latv = new Latvanyossag(id, nev, leiras, ar, varos_id); latvBox.Items.Add(latv); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void bLModosit_Click(object sender, EventArgs e) { if (lBVarosLista.SelectedIndex > -1) { string sql = @" UPDATE `latvanyossagok` SET nev`= @id, `leiras`= @leiras, `ar`= @ar, `varos_id`= @varosId WHERE id`= @id, "; Latvanyossag lavanyosag = (Latvanyossag)lBLatvanyosagLista.SelectedItem; var comm = this.conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@id", lavanyosag.getId()); comm.Parameters.AddWithValue("@nev", tBVarosNevModosit.Text); comm.Parameters.AddWithValue("@leiras", tBLatvanyosagLeirasModosit); comm.Parameters.AddWithValue("@ar", nUDLatvanyosagArModosit); comm.Parameters.AddWithValue("@varosId", cBVaroshozKotesModosit.SelectedItem); comm.ExecuteNonQuery(); } else { MessageBox.Show("nem választotad ki mit akarsz modositani."); } lBVarosLista.SelectedIndex = -1; gBLatvanyosagModositas.Visible = true; bLatvanyosagTorol.Visible = true; }
private void LatvanyossagKilistazas(int id) { { listBoxLatvanyossag.Items.Clear(); groupBox2.Enabled = false; textBoxLatvanyossagMod.Text = ""; VarosLeirasModTxtB.Text = ""; NumUppDArMod.Value = 0; if (listBoxVaros.SelectedIndex != -1) { var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT id, nev, leiras,ar,id FROM latvanyossagok WHERE varos_id=@varos_id ORDER BY nev"; var varos = (Varos)listBoxVaros.SelectedItem; cmd.Parameters.AddWithValue("id", varos.Id); using (var reader = cmd.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 latvanyossag = new Latvanyossag(id, nev, leiras, ar, varos_id); listBoxLatvanyossag.Items.Add(latvanyossag); } } } } }
private void LatvanyossagList_SelectedIndexChanged(object sender, EventArgs e) { if (LatvanyossagList.SelectedIndex > -1) { Latvanyossag lv = (Latvanyossag)LatvanyossagList.SelectedItem; btnModositL.Visible = true; LatNevText.Text = lv.Nev; LeirasText.Text = lv.Leiras; numAr.Value = lv.Ar; } }
public void latvanyossagokFrissites() { //1 //lista törlődik //2 régi //lista feltöltődik az adatb alapján //2 új //lista feltöltődik a kiválasztott város alapján //1 latvanyossagok = new List <Latvanyossag>(); listBoxLatvanyossagok.Items.Clear(); string sql = @" SELECT `id`, `nev`, `leiras`, `ar`, `varos_id` FROM `latvanyossagok` "; 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 varosId = reader.GetInt32("varos_id"); Latvanyossag latv = new Latvanyossag(id, nev, leiras, ar, varosId); //2 régi //listBoxLatvanyossagok.Items.Add(latv.ToString()); latvanyossagok.Add(latv); } } //2 új if (listBoxVarosok.SelectedIndex >= 0) { listBoxLatvanyossagok.Items.Clear(); int seged = varosok[listBoxVarosok.SelectedIndex].Id; for (int i = 0; i < latvanyossagok.Count; i++) { if (latvanyossagok[i].VarosId == seged) { listBoxLatvanyossagok.Items.Add(latvanyossagok[i].ToString()); } } } }
void adatbetoltes() { string query = "SELECT * FROM varosok"; this.da = new MySqlDataAdapter(query, this.conn); this.ds = new DataSet(); da.Fill(ds); cmbBx_nev.DataSource = ds.Tables[0]; cmbBx_nev.DisplayMember = "nev"; cmbBx_nev.ValueMember = "id"; varosok = new List <Varos>(); latvanyossagok = new List <Latvanyossag>(); foreach (DataRow item in ds.Tables[0].Rows) { var varos = new Varos { Id = (int)item[0], Nev = item[1].ToString(), Lakossag = (int)item[2], Latvanyossagok = new List <Latvanyossag>() }; varosok.Add(varos); } lstBx_varosok.DataSource = varosok; string sql = "SELECT * FROM latvanyossagok"; this.da2 = new MySqlDataAdapter(sql, this.conn); this.ds2 = new DataSet(); da2.Fill(ds2); foreach (DataRow item in ds2.Tables[0].Rows) { var latv = new Latvanyossag { Id = (int)item[0], VarosId = (int)item[1], Nev = item[2].ToString(), Leiras = item[3].ToString(), Ar = (int)item[4] }; latvanyossagok.Add(latv); } foreach (var item in latvanyossagok) { varosok.Find((x) => x.Id == item.VarosId).Latvanyossagok.Add(item); } }
private void listBox_Latvanyossagok_SelectedIndexChanged(object sender, EventArgs e) { if (listBox_Latvanyossagok.SelectedIndex >= 0) { KivalasztottLatvanyossag = (Latvanyossag)listBox_Latvanyossagok.SelectedItem; textBox_nevezetesseg.Text = KivalasztottLatvanyossag.Nev; textBox_Nevezetesseg_leiras.Text = KivalasztottLatvanyossag.Leiras; } else { KivalasztottLatvanyossag = null; textBox_nevezetesseg.Text = ""; textBox_Nevezetesseg_leiras.Text = ""; } Gombok(); }
private void latvTorles() { Latvanyossag lv = (Latvanyossag)LatvanyossagList.SelectedItem; if (LatvanyossagList.SelectedIndex > -1) { string sql = @"DELETE FROM latvanyossagok WHERE id=@id"; var comm = conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@id", lv.Id); comm.ExecuteNonQuery(); LatvanyossagList.Items.RemoveAt(LatvanyossagList.SelectedIndex); LatvanyossagList.SelectedIndex = -1; } }
private void latvanyossagHozzaadAdatbazishoz(string nev, string leiras, int ar, int varos_id) { string sql = @"INSERT INTO latvanyossagok (nev,leiras, ar,varos_id) VALUES ('" + nev + "','" + leiras + "'," + ar + ",'" + varos_id + "');"; var comm = conn.CreateCommand(); comm.CommandText = sql; using (var mentes = comm.ExecuteReader()); string value = varosokLstBx.SelectedItem.ToString(); string[] adatok = value.Split(' '); string nev1 = adatok[0]; if (GetID(nev1) == varos_id) { Latvanyossag l1 = new Latvanyossag(nev, leiras, ar, varos_id); latvanyossagokLstBx.Items.Add(l1.ToString()); } }
private void bLatvanyosagTorol_Click(object sender, EventArgs e) { if (lBLatvanyosagLista.SelectedIndex > -1) { string sql3 = @" SELECT id FROM latvanyossagok WHERE nev LIKE @nev "; int id = 0; var comm3 = this.conn.CreateCommand(); comm3.CommandText = sql3; Latvanyossag latvanyosag = (Latvanyossag)lBVarosLista.SelectedItem; comm3.Parameters.AddWithValue("@nev", latvanyosag.getNev()); using (var reader = comm3.ExecuteReader()) { while (reader.Read()) { id = reader.GetInt32("id"); } } if (!(id >= 0)) { string sql2 = @" DELETE FROM `latvanyossagok` WHERE id = @id "; var comm2 = this.conn.CreateCommand(); comm2.CommandText = sql2; comm2.Parameters.AddWithValue("@id", id); comm2.ExecuteNonQuery(); int adotElem = lBVarosLista.SelectedIndex; lBVarosLista.Items.RemoveAt(adotElem); } } else { MessageBox.Show("nem választotad ki mit akarsz törölni."); } lBVarosLista.SelectedIndex = -1; gBLatvanyosagModositas.Visible = true; bLatvanyosagTorol.Visible = true; }
private void latvanyossagMentesBtn_Click(object sender, EventArgs e) { string nev; string leiras; int ar; string varos; bool mehet = true; if (latvanyossagNevTB.Text == "") { mehet = false; MessageBox.Show("Nem adott meg nevet!"); } if (leirasTB.Text == "") { mehet = false; MessageBox.Show("Nem adott meg leírást!"); } if (arNUD == null) { mehet = false; MessageBox.Show("Nem adott meg árat!"); } if (varosokCOB.SelectedItem == null) { mehet = false; MessageBox.Show("Nem választott várost!"); } if (mehet) { nev = latvanyossagNevTB.Text; leiras = leirasTB.Text; ar = Convert.ToInt32(arNUD.Value); varos = varosokCOB.SelectedItem.ToString(); int varos_id = GetID(varos); Latvanyossag l1 = new Latvanyossag(nev, leiras, ar, varos_id); latvanyossagHozzaadAdatbazishoz(nev, leiras, ar, varos_id); latvanyossagNevTB.Text = ""; leirasTB.Text = ""; arNUD.Value = 0; varosokCOB.SelectedItem = default; } }
private void latvanyossagokKiiratas() { latvanyossagokLstBx.Items.Clear(); string value = varosokLstBx.SelectedItem.ToString(); string[] adatok = value.Split(' '); string nev = adatok[0]; string sql = @"SELECT nev, leiras, ar, varos_id FROM latvanyossagok WHERE varos_id =" + GetID(nev) + ";"; var comm = conn.CreateCommand(); comm.CommandText = sql; using (var mentes = comm.ExecuteReader()) { while (mentes.Read()) { Latvanyossag l1 = new Latvanyossag(mentes.GetString("nev"), mentes.GetString("leiras"), mentes.GetInt32("ar"), mentes.GetInt32("varos_id")); latvanyossagokLstBx.Items.Add(l1.ToString()); } } }
private void LatvanyossagLista(int varos_id) { latvanyossagok_lista.Items.Clear(); var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM latvanyossagok WHERE varos_id=@varos_id ORDER BY nev;"; cmd.Parameters.AddWithValue("@varos_id", varos_id); using (var reader = cmd.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 latvanyossag = new Latvanyossag(id, nev, leiras, ar, varos_id); latvanyossagok_lista.Items.Add(latvanyossag); } } latvanyossag_torol.Enabled = false; }
private void LatvanyossagSubmit_Click(object sender, EventArgs e) { string nev = LatNevText.Text; string leiras = LeirasText.Text; int ar = Convert.ToInt32(numAr.Value); Varosok v = (Varosok)VarosokListBox.SelectedItem; if (nev == "" && leiras == "" && VarosokListBox.SelectedIndex < 0) { MessageBox.Show("Hiányzó adat"); } else { string sql = @"INSERT INTO latvanyossagok(nev,leiras,ar,varos_id) VALUES (@nev,@leiras,@ar,@varos_id)"; var comm = conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@nev", nev); comm.Parameters.AddWithValue("@leiras", leiras); comm.Parameters.AddWithValue("@ar", ar); comm.Parameters.AddWithValue("@varos_id", v.Id); comm.ExecuteNonQuery(); sql = @"SELECT id FROM latvanyossagok WHERE nev=@nev"; comm.CommandText = sql; int id = 0; using (var reader = comm.ExecuteReader()) { while (reader.Read()) { id = Convert.ToInt32(reader.GetString(0)); } } Latvanyossag lv = new Latvanyossag(id, nev, leiras, ar, v.Id); LatvanyossagList.Items.Add(lv); } }
private void adatbetoltes() { LatvanyossagList.Items.Clear(); string sql = @"SELECT `id`, `nev`, `lakossag` FROM `varosok`"; var comm = conn.CreateCommand(); comm.CommandText = sql; using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int id = Convert.ToInt32(reader.GetString(0)); string nev = reader.GetString(1); int lakossag = Convert.ToInt32(reader.GetString(2)); Varosok v = new Varosok(id, nev, lakossag); VarosokListBox.Items.Add(v); } } sql = @"SELECT * FROM latvanyossagok"; comm = conn.CreateCommand(); comm.CommandText = sql; using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int id = Convert.ToInt32(reader.GetString(0)); string nev = reader.GetString(1); string leiras = reader.GetString(2); int ar = Convert.ToInt32(reader.GetString(3)); int varos_id = Convert.ToInt32(reader.GetString(4)); Latvanyossag lv = new Latvanyossag(id, nev, leiras, ar, varos_id); LatvanyossagList.Items.Add(lv); } } }
private void bLHozzaAd_Click(object sender, EventArgs e) { if (!tBLatvanyosagNev.Text.Equals("") && !tBLatvanyosagLeiras.Text.Equals("") && !(cBVaroshozKotes.SelectedIndex == 0)) { string sql = @" SELECT COUNT(nev) as latvanyossagKerese FROM latvanyossagok WHERE nev LIKE @nev "; int nevEgyezes; var comm = this.conn.CreateCommand(); comm.CommandText = sql; comm.Parameters.AddWithValue("@nev", tBVarosNev.Text); using (var sherch = comm.ExecuteReader()) { sherch.Read(); nevEgyezes = sherch.GetInt32("latvanyossagKerese"); } if (!(nevEgyezes >= 1)) { string sql2 = @" INSERT INTO `latvanyossagok`(`nev`, `leiras`, `ar`, `varos_id`) VALUES (@nev, @leiras, @ar, @varos_id) "; var comm2 = this.conn.CreateCommand(); comm2.CommandText = sql2; comm2.Parameters.AddWithValue("@nev", tBLatvanyosagNev.Text); comm2.Parameters.AddWithValue("@leiras", tBLatvanyosagLeiras.Text); comm2.Parameters.AddWithValue("@ar", nUDLatvanyosagAr.Value); comm2.Parameters.AddWithValue("@varos_id", cBVaroshozKotes.SelectedItem); comm2.ExecuteNonQuery(); } else { MessageBox.Show("ez a város már ben van az adattábázisabn."); } string sql3 = @" SELECT id, nev, leiras, ar, varos_id FROM latvanyossagok WHERE nev`= @nev, "; var comm3 = this.conn.CreateCommand(); comm3.CommandText = sql3; comm3.Parameters.AddWithValue("@nev", tBLatvanyosagNev.Text); using (var reader = comm3.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 varosId = reader.GetInt32("varos_id"); var latvanyosag = new Latvanyossag(id, nev, leiras, ar, varosId); latvanosagLista.Add(latvanyosag); } } } else if (tBLatvanyosagNev.Text.Equals("") && tBLatvanyosagLeiras.Text.Equals("") && (cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoság nevet, leirását, ne adta meg és nem köttöte városhoz."); } else if (!tBLatvanyosagNev.Text.Equals("") && tBLatvanyosagLeiras.Text.Equals("") && (cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoság leirását ne adta meg és nem köttöte városhoz."); } else if (tBLatvanyosagNev.Text.Equals("") && tBLatvanyosagLeiras.Text.Equals("") && !(cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoság nevet és leirását ne adta meg"); } else if (tBLatvanyosagNev.Text.Equals("") && !tBLatvanyosagLeiras.Text.Equals("") && (cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoság nevet ne adta meg és nem köttöte városhoz."); } else if (tBLatvanyosagNev.Text.Equals("") && !tBLatvanyosagLeiras.Text.Equals("") && !(cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoság nevet ne adta meg"); } else if (!tBLatvanyosagNev.Text.Equals("") && tBLatvanyosagLeiras.Text.Equals("") && !(cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoság leirását ne adta meg"); } else if (!tBLatvanyosagNev.Text.Equals("") && !tBLatvanyosagLeiras.Text.Equals("") && (cBVaroshozKotes.SelectedIndex == -1)) { MessageBox.Show("a látványoságot nem köttöte városhoz."); } }