Пример #1
0
        void loadData()
        {
            var command = this.conn.CreateCommand();

            command.CommandText = @"SELECT * FROM varosok";
            using (var reader = command.ExecuteReader())
            {
                listBox_city.Items.Add(string.Format("{0,-40}\t{1,-40}", "Név", "Populáció"));
                while (reader.Read())
                {
                    int    id         = reader.GetInt32("id");
                    string name       = reader.GetString("name");
                    int    population = reader.GetInt32("population");
                    var    city       = new City(id, name, population);
                    list_city.Add(city);
                    listBox_city.Items.Add(string.Format("{0,-40}\t{1,-60}", name, population));
                    shew_id.Items.Add(name);
                }
            }

            command.CommandText = @"SELECT * FROM latvanyossagok";
            using (var reader = command.ExecuteReader())
            {
                listBox_shew.Items.Add(string.Format("{0,-40}\t{1,-40}", "Név", "Ár"));
                while (reader.Read())
                {
                    int    id          = reader.GetInt32("id");
                    string name        = reader.GetString("name");
                    string description = reader.GetString("description");
                    int    price       = reader.GetInt32("price");
                    int    city_id     = reader.GetInt32("city_id");
                    var    shew        = new Shew(id, name, description, price, city_id);
                    list_shew.Add(shew);

                    if (price == 0)
                    {
                        listBox_shew.Items.Add(string.Format("{0,-20}\t{1,-40}", name, "Ingyenes"));
                    }
                    else
                    {
                        listBox_shew.Items.Add(string.Format("{0,-40}\t{1,-40}", name, price));
                    }
                }
            }
        }
Пример #2
0
        private void button_shew_Click(object sender, EventArgs e)
        {
            if (shew_name.Text.Length > 0 && shew_description.Text.Length > 0 && shew_id.Text.Length > 0)
            {
                foreach (Shew item in list_shew)
                {
                    if (shew_name.Text.Equals(item))
                    {
                        MessageBox.Show("Már létezik ilyen látványosság");
                        return;
                    }
                }

                int city_id = 0;
                foreach (City item in list_city)
                {
                    if (shew_id.SelectedItem.Equals(item.getId()))
                    {
                        city_id = item.getId();
                    }
                }

                var command = this.conn.CreateCommand();
                command.CommandText = @"INSERT INTO latvanyossagok (name, description, price, city_id) VALUES('" + shew_name.Text + "', '" + shew_description.Text + "', '" + shew_price.Text + "', '" + city_id + "')";
                command.ExecuteNonQuery();
                var shew = new Shew((list_shew.Count + 1), shew_name.Text, shew_description.Text, (int)shew_price.Value, city_id);
                list_shew.Add(shew);
                listBox_shew.Items.Add(string.Format("{0,-40}\t{1,-40}", shew_name.Text, city_id));
                MessageBox.Show("Új város sikeresen létrehozva!");
            }
            else
            {
                MessageBox.Show("Tölts ki minden mezőt!");
                foreach (City item in list_city)
                {
                    MessageBox.Show("" + item.getName());
                }
            }
        }