Ejemplo n.º 1
0
        private void btn_varos_edit_Click(object sender, EventArgs e)
        {
            Varosok v                   = (Varosok)lbox_varosok.SelectedItem;
            int     id                  = v.Id;
            int     lakossag            = Convert.ToInt32(numeric_lakossag.Value);
            List <Latvanyossagok> lista = new List <Latvanyossagok>();

            List <string> varosnevek = new List <string>();

            for (int i = 0; i < lbox_varosok.Items.Count; i++)
            {
                Varosok va = (Varosok)lbox_varosok.Items[i];
                varosnevek.Add(va.Nev);
            }

            if (varosnevek.Contains(text_nev.Text))
            {
                MessageBox.Show("ilyen város név már létezik!");
                text_nev.Text = v.Nev;
            }
            else
            {
                Varosok v2 = new Varosok(id, text_nev.Text, lakossag, lista);
                lbox_varosok.Items[lbox_varosok.SelectedIndex] = v2;
                var editComm = conn.CreateCommand();
                editComm.CommandText = @"
UPDATE varosok SET nev = @nev, lakossag = @lakossag WHERE varosok.id = @id;
";

                editComm.Parameters.AddWithValue("@id", id);
                editComm.Parameters.AddWithValue("@nev", text_nev.Text);
                editComm.Parameters.AddWithValue("@lakossag", lakossag);
                int erintettSorok = editComm.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
 internal VarosModositas(Varosok v)
 {
     selectedVaros = v;
     conn          = new MySqlConnection("Server=localhost;Port=3307;Database=latvanyossagokdb;Uid=root;");
     conn.Open();
     InitializeComponent();
 }
Ejemplo n.º 3
0
        void varosadatBetoltes()
        {
            string sql  = @"
SELECT id, nev, lakossag 
FROM `varosok` 
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");
                    int    lakossag             = reader.GetInt32("lakossag");
                    List <Latvanyossagok> lista = new List <Latvanyossagok>();

                    //string uzlet;

                    //try
                    //{
                    //    uzlet = reader.GetString("uzlet");
                    //}
                    //catch (SqlNullValueException ex)
                    //{
                    //    uzlet = null;
                    //}

                    var varos = new Varosok(id, nev, lakossag, lista);
                    lbox_varosok.Items.Add(varos);
                }
            }
        }
Ejemplo n.º 4
0
        public void VarosokListaz()
        {
            lib_varosok.Items.Clear();
            var command = conn.CreateCommand();

            command.CommandText = @"SELECT 
                                        id,nev,lakossag 
                                    FROM 
                                        varosok
                                    ORDER BY 
                                        nev";

            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var id       = reader.GetInt32("id");
                    var nev      = reader.GetString("nev");
                    var lakossag = reader.GetInt32("lakossag");


                    var varosok = new Varosok(id, nev, lakossag);

                    lib_varosok.Items.Add(varosok);
                }
            }
        }
Ejemplo n.º 5
0
        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);
                }
            }
        }
Ejemplo n.º 6
0
        private void btn_varos_delete_Click(object sender, EventArgs e)
        {
            int latvanyossagdb = latvanyossagokszama();

            if (latvanyossagdb == 0)
            {
                var deleteComm = conn.CreateCommand();
                deleteComm.CommandText = @"
DELETE FROM `varosok` WHERE varosok.id = @id;
";
                var foreigncheckonComm = conn.CreateCommand();

                foreigncheckonComm.CommandText = @"SET FOREIGN_KEY_CHECKS=0;";
                foreigncheckonComm.ExecuteNonQuery();

                Varosok v  = (Varosok)lbox_varosok.SelectedItem;
                int     id = v.Id;
                deleteComm.Parameters.AddWithValue("@id", id);
                int erintettSorok = deleteComm.ExecuteNonQuery();
                lbox_varosok.Items.RemoveAt(lbox_varosok.SelectedIndex);

                var foreigncheckoffComm = @"SET FOREIGN_KEY_CHECKS=0;";
                foreigncheckonComm.ExecuteNonQuery();
                btn_varos_delete.Visible = false;
                btn_varos_edit.Visible   = false;
            }
            else
            {
                MessageBox.Show("Ennek a városnak van látványossága nem lehet törölni!");
            }
        }
 private void VarosokListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (VarosokListBox.SelectedIndex > -1)
     {
         Varosok v = (Varosok)VarosokListBox.SelectedItem;
         nevtb.Text        = v.Nev;
         numLakossag.Value = v.Lakossag;
     }
 }
Ejemplo n.º 8
0
        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);
                }
            }
        }
Ejemplo n.º 9
0
        public void VarosListazas()
        {
            var cmd = conn.CreateCommand();

            cmd.CommandText = "SELECT id, nev, lakossag FROM varosok ORDER BY nev";
            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var id       = reader.GetInt32("id");
                    var nev      = reader.GetString("nev");
                    var lakossag = reader.GetInt32("lakossag");
                    var varosok  = new Varosok(id, nev, lakossag);
                }
            }
        }
Ejemplo n.º 10
0
        void comboboxfeltoltes()
        {
            cbox_varos.Items.Clear();
            List <string> varosnevek = new List <string>();

            for (int i = 0; i < lbox_varosok.Items.Count; i++)
            {
                Varosok va = (Varosok)lbox_varosok.Items[i];
                varosnevek.Add(va.Nev);
            }

            for (int i = 0; i < varosnevek.Count; i++)
            {
                cbox_varos.Items.Add(varosnevek[i]);
            }
        }
Ejemplo n.º 11
0
        private void btnModositL_Click(object sender, EventArgs e)
        {
            string  nev    = LatNevText.Text;
            string  leiras = LeirasText.Text;
            int     ar     = Convert.ToInt32(numAr.Value);
            Varosok v      = (Varosok)VarosokListBox.SelectedItem;
            var     comm   = this.conn.CreateCommand();

            comm.Parameters.AddWithValue("@nev", nev);
            string sql = "";

            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));
                }
            }
            sql = @"UPDATE latvanyossagok 
                    SET id=@id, nev=@nev,leiras=@leiras,ar=@ar,varos_id=@varosid
                    WHERE id=@id";
            comm.CommandText = sql;
            comm.Parameters.AddWithValue("@id", id);

            comm.Parameters.AddWithValue("@leiras", leiras);
            comm.Parameters.AddWithValue("@ar", ar);


            if (VarosokListBox.SelectedIndex < 0)
            {
                MessageBox.Show("A várost mindenképp választani kell");
            }
            else
            {
                comm.Parameters.AddWithValue("@varosid", v.Id);
                comm.ExecuteNonQuery();
                LatvanyossagList.Items.RemoveAt(LatvanyossagList.SelectedIndex);
                LatvanyossagList.Items.Add(new Latvanyossag(id, nev, leiras, ar, v.Id));
                LatvanyossagList.SelectedIndex = -1;
            }
        }
Ejemplo n.º 12
0
        void VarosListazas()
        {
            Varosok_ListBox.Items.Clear();
            var cmd = conn.CreateCommand();

            cmd.CommandText = "SELECT id, nev, lakossag FROM varosok ORDER BY nev";
            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var id       = reader.GetInt32("id");
                    var nev      = reader.GetString("nev");
                    var lakossag = reader.GetInt32("lakossag");
                    var varosok  = new Varosok(id, nev, lakossag);

                    Varosok_ListBox.Items.Add(varosok);
                }
            }
            comboBoxElemek();
        }
Ejemplo n.º 13
0
        private int latvanyossagokszama()
        {
            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;
            }

            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));
                }
            }
            return(v.Latvanyossagok.Count);
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        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);
                }
            }
        }
Ejemplo n.º 16
0
        private void varosTorles()
        {
            Varosok v = (Varosok)VarosokListBox.SelectedItem;

            if (VarosokListBox.SelectedIndex > -1)
            {
                List <Latvanyossag> lv = new List <Latvanyossag>();
                foreach (var item in LatvanyossagList.Items)
                {
                    lv.Add((Latvanyossag)item);
                }
                int db = 0;
                foreach (var item in lv)
                {
                    if (item.Varos_id == v.Id)
                    {
                        db++;
                    }
                }
                if (db == 0)
                {
                    string sql  = @"DELETE FROM varosok 
                                       WHERE id=@id";
                    var    comm = conn.CreateCommand();
                    comm.CommandText = sql;
                    comm.Parameters.AddWithValue("@id", v.Id);
                    comm.ExecuteNonQuery();
                    VarosokListBox.Items.RemoveAt(VarosokListBox.SelectedIndex);
                    VarosokListBox.SelectedIndex = -1;
                }
                else
                {
                    MessageBox.Show("Nem törölhető mert tartozik hozzá látványosság");
                }
            }
        }
Ejemplo n.º 17
0
        private void btn_add_Click(object sender, System.EventArgs e)
        {
            int id = 0;

            for (int i = 0; i < lbox_varosok.Items.Count; i++)
            {
                Varosok v = (Varosok)lbox_varosok.Items[i];
                id = v.Id;
                id++;
            }
            string nev                  = text_nev.Text;
            int    lakossag             = (int)numeric_lakossag.Value;
            bool   letezik              = false;
            List <Latvanyossagok> lista = new List <Latvanyossagok>();



            var varos = new Varosok(id, nev, lakossag, lista);

            //ellenőrzések
            List <string> varosnevek = new List <string>();

            for (int i = 0; i < lbox_varosok.Items.Count; i++)
            {
                Varosok va = (Varosok)lbox_varosok.Items[i];
                varosnevek.Add(va.Nev);
            }

            if (varosnevek.Contains(nev))
            {
                MessageBox.Show("ilyen név már létezik");
                letezik = true;
            }
            if (nev.Length == 0)
            {
                MessageBox.Show("nem lehet üres a név mező!");
            }
            if (lakossag == 0)
            {
                MessageBox.Show("nem lehet 0 a lakosság!");
            }



            if (lakossag != 0 && nev.Length != 0 && letezik == false)
            {
                var insertComm = conn.CreateCommand();
                insertComm.CommandText = @"
INSERT INTO varosok (id, nev, lakossag)
VALUES (@id, @nev, @lakossag);
";

                insertComm.Parameters.AddWithValue("@id", null);
                insertComm.Parameters.AddWithValue("@nev", nev);
                insertComm.Parameters.AddWithValue("@lakossag", lakossag);
                int erintettSorok = insertComm.ExecuteNonQuery();

                lbox_varosok.Items.Add(varos);
                comboboxfeltoltes();
            }
        }