예제 #1
0
 public void AddHotels(HotelClass hotelClass)//добавляем новый
 {
     hotelsList.Add(hotelClass);
     dataGridView1.Rows.Clear();
     dataGridView1.Columns.Clear();
     FillDGV();
 }
예제 #2
0
 public void UpdateHotels(HotelClass hotelClass)//обновляем
 {
     hotelsList.Clear();
     LoadData();
     dataGridView1.Rows.Clear();
     dataGridView1.Columns.Clear();
     FillDGV();
 }
예제 #3
0
        void LoadData()//загрузили данные
        {
            using (var cmd = new NpgsqlCommand($"SELECT hotels.id_hotel," +
                                               $"hotels.id_city, " +
                                               $"hotels.name_hotel, " +
                                               $"hotels.id_hotel_category, " +
                                               $"hotels.id_type_of_food, " +
                                               $"cities.name_city, " +
                                               $"hotels_categories.name_hotel_category, " +
                                               $"typies_of_food.name_type_of_food " +
                                               $"FROM hotels, cities, hotels_categories, typies_of_food " +
                                               $"WHERE cities.id_city = hotels.id_city " +
                                               $"AND hotels_categories.id_hotel_category = hotels.id_hotel_category " +
                                               $"AND typies_of_food.id_type_of_food = hotels.id_type_of_food", Connection))
            {
                using (var reader = cmd.ExecuteReader())
                    while (reader.Read())
                    {
                        var hotelClass = new HotelClass();
                        var idHot      = reader["id_hotel"].ToString().Trim();
                        hotelClass.idHotel = Int32.Parse(idHot);

                        hotelClass.nameHotel = reader["name_hotel"].ToString().Trim();

                        var idCities = reader["id_city"].ToString().Trim();
                        hotelClass.idCity = Int32.Parse(idCities);

                        hotelClass.nameCity = reader["name_city"].ToString().Trim();

                        var idCategHot = reader["id_hotel_category"].ToString().Trim();
                        hotelClass.idCategoryHotel = Int32.Parse(idCategHot);

                        hotelClass.nameCategoryHotel = reader["name_hotel_category"].ToString().Trim();

                        var idTypeF = reader["id_type_of_food"].ToString().Trim();
                        hotelClass.idTypeFood = Int32.Parse(idTypeF);

                        hotelClass.nameTypeFood = reader["name_type_of_food"].ToString().Trim();
                        hotelsList.Add(hotelClass);
                    }
            }
        }
예제 #4
0
        private void button_search_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();
            hotelsList.Clear();

            using (var cmdCount = new NpgsqlCommand($"SELECT COUNT(*) FROM hotels WHERE name_hotel LIKE '%" + textBox_search.Text.ToString().Trim() + "%'", Connection))
            {
                int countRows = Convert.ToInt32(cmdCount.ExecuteScalar());
                if (countRows > 0)
                {
                    using (var cmd = new NpgsqlCommand("SELECT hotels.id_hotel," +
                                                       $"hotels.id_city, " +
                                                       $"hotels.name_hotel, " +
                                                       $"hotels.id_hotel_category, " +
                                                       $"hotels.id_type_of_food, " +
                                                       $"cities.name_city, " +
                                                       $"hotels_categories.name_hotel_category, " +
                                                       $"typies_of_food.name_type_of_food " +
                                                       $"FROM hotels, cities, hotels_categories, typies_of_food " +
                                                       $"WHERE cities.id_city = hotels.id_city " +
                                                       $"AND hotels_categories.id_hotel_category = hotels.id_hotel_category " +
                                                       $"AND typies_of_food.id_type_of_food = hotels.id_type_of_food AND name_hotel LIKE '%" + textBox_search.Text.ToString().Trim() + "%'", Connection))
                    {
                        using (var reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var hotelClass = new HotelClass();
                                var idHot      = reader["id_hotel"].ToString().Trim();
                                hotelClass.idHotel = Int32.Parse(idHot);

                                hotelClass.nameHotel = reader["name_hotel"].ToString().Trim();

                                var idCities = reader["id_city"].ToString().Trim();
                                hotelClass.idCity = Int32.Parse(idCities);

                                hotelClass.nameCity = reader["name_city"].ToString().Trim();

                                var idCategHot = reader["id_hotel_category"].ToString().Trim();
                                hotelClass.idCategoryHotel = Int32.Parse(idCategHot);

                                hotelClass.nameCategoryHotel = reader["name_hotel_category"].ToString().Trim();

                                var idTypeF = reader["id_type_of_food"].ToString().Trim();
                                hotelClass.idTypeFood = Int32.Parse(idTypeF);

                                hotelClass.nameTypeFood = reader["name_type_of_food"].ToString().Trim();
                                hotelsList.Add(hotelClass);
                            }
                        }
                    }
                    FillDGV();
                    MessageBox.Show($"Найдено " + countRows + " совпадений!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Отель с таким названием отсутствует в базе данных!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }