Ejemplo n.º 1
0
        public static void Hotels()
        {
            Hotels hotels = new Hotels();

            hotels.Show();
        }
Ejemplo n.º 2
0
        private void PictureBoxSave_Click(object sender, EventArgs e)
        {
            string name = textBoxName.Text.Trim();
            string country = textBoxCountry.Text.Trim();
            string city = textBoxCity.Text.Trim();
            string address = textBoxAddress.Text.Trim();
            string phone = textBoxPhone.Text.Trim();
            string email = textBoxEmail.Text.Trim();
            string stars = textBoxStars.Text.Trim();
            string wifi, spa, petFriendly, gym, pool;

            wifi        = (radioButtonWifiYes.Checked == true) ? "Yes" : "No";
            spa         = (radioButtonSpaYes.Checked == true) ? "Yes" : "No";
            petFriendly = (radioButtonPetFriendlyYes.Checked == true) ? "Yes" : "No";
            gym         = (radioButtonGymYes.Checked == true) ? "Yes" : "No";
            pool        = (radioButtonPoolYes.Checked == true) ? "Yes" : "No";

            //If there is not empty field insert new hotel
            if (name != "" || country != "" || city != "" || address != "" || phone != "" || email != "" || stars != "" || wifi != "" || spa != "" || petFriendly != "" || gym != "" || pool != "")
            {
                SqlCommand cmd = conn.Command("INSERT INTO Hotels(name, country, city, address, phone, email, stars, wifi, spa, pet_friendly, gym, pool) VALUES " +
                                              "(@Name, @Country, @City, @Address, @Phone, @Email, @Stars, @Wifi, @Spa, @PetFriendly, @Gym, @Pool)");
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@Name", name);
                cmd.Parameters.AddWithValue("@Country", country);
                cmd.Parameters.AddWithValue("@City", city);
                cmd.Parameters.AddWithValue("@Address", address);
                cmd.Parameters.AddWithValue("@Phone", phone);
                cmd.Parameters.AddWithValue("@Email", email);
                cmd.Parameters.AddWithValue("@Stars", stars);
                cmd.Parameters.AddWithValue("@Wifi", wifi);
                cmd.Parameters.AddWithValue("@Spa", spa);
                cmd.Parameters.AddWithValue("@PetFriendly", petFriendly);
                cmd.Parameters.AddWithValue("@Gym", gym);
                cmd.Parameters.AddWithValue("@Pool", pool);

                try
                {
                    conn.OpenConnection();
                    int result = cmd.ExecuteNonQuery();

                    if (result > 0)
                    {
                        MessageBox.Show("New hotel is successfully added.");

                        Hotels hotels = new Hotels();
                        hotels.Show();
                        this.Hide();
                        this.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    conn.CloseConnection();
                }
            }
            else
            {
                MessageBox.Show("All fields are required, please try again.");
            }
        }