// BOTON MODIFICAR ------------------------------------------------------------------------------------------- private void button1_Click(object sender, EventArgs e) { chequearSiHayCamposIncompletos(); if (!validarEmail(textBoxMail.Text)) { MessageBox.Show("Escriba un formato de mail correcto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int idPAIS; try { SqlCommand cmdpais = new SqlCommand("select idPais from [PISOS_PICADOS].Pais where nombrePais = @paisSelect", Globals.conexionGlobal); cmdpais.Parameters.AddWithValue("@paisSelect", comboBoxPais.Text); idPAIS = (int)cmdpais.ExecuteScalar(); } catch (Exception ex) { throw ex; } String cadenaMod = "PISOS_PICADOS.modificarHotel"; SqlCommand comandoMod = new SqlCommand(cadenaMod, Globals.conexionGlobal); comandoMod.CommandType = CommandType.StoredProcedure; //agregar parametros comandoMod.Parameters.Add("@idHotel", SqlDbType.Int); comandoMod.Parameters.Add("@nombre", SqlDbType.VarChar); comandoMod.Parameters.Add("@mail", SqlDbType.VarChar); comandoMod.Parameters.Add("@telefono", SqlDbType.VarChar); comandoMod.Parameters.Add("@calle", SqlDbType.VarChar); comandoMod.Parameters.Add("@nroCalle", SqlDbType.VarChar); comandoMod.Parameters.Add("@estrellas", SqlDbType.Int); comandoMod.Parameters.Add("@ciudad", SqlDbType.VarChar); comandoMod.Parameters.Add("@idPais", SqlDbType.Int); comandoMod.Parameters.Add("@fechaCreacion", SqlDbType.Date); comandoMod.Parameters["@idHotel"].Value = idHotel; comandoMod.Parameters["@nombre"].Value = textBoxName.Text; comandoMod.Parameters["@mail"].Value = textBoxMail.Text; comandoMod.Parameters["@telefono"].Value = textBoxTE.Text; comandoMod.Parameters["@calle"].Value = textBoxCalle.Text; comandoMod.Parameters["@nroCalle"].Value = textBoxNroCalle.Text; comandoMod.Parameters["@estrellas"].Value = int.Parse(cBestrellas.Text); comandoMod.Parameters["@ciudad"].Value = textBoxCIU.Text; comandoMod.Parameters["@idPais"].Value = idPAIS; comandoMod.Parameters["@fechaCreacion"].Value = dateTimePickerCreacion.Value.ToString("yyyy-MM-dd"); try { comandoMod.ExecuteReader(); if (checkedListBoxRegimenesAgregar.CheckedItems.Count > 0) { //agrega regimenes seleccionados for (int i = 0; i < checkedListBoxRegimenesAgregar.CheckedItems.Count; i++) { string nombreRegimen = checkedListBoxRegimenesAgregar.CheckedItems[i].ToString(); SqlCommand GETidRegimen = new SqlCommand("select codigoRegimen from [PISOS_PICADOS].Regimen where descripcion = @nombreRegimen", Globals.conexionGlobal); GETidRegimen.Parameters.AddWithValue("@nombreRegimen", nombreRegimen); int idRegimen = (int)GETidRegimen.ExecuteScalar(); SqlCommand agregarRegimen = new SqlCommand("[PISOS_PICADOS].agregarRegimen", Globals.conexionGlobal); agregarRegimen.CommandType = CommandType.StoredProcedure; agregarRegimen.Parameters.Add("@idHotel", SqlDbType.Int); agregarRegimen.Parameters["@idHotel"].Value = idHotel; agregarRegimen.Parameters.Add("@idRegimen", SqlDbType.Int); agregarRegimen.Parameters["@idRegimen"].Value = idRegimen; agregarRegimen.ExecuteNonQuery(); } } String regimenesSinModificar = ""; //QUITAR REGIMENES QUE POSEE if (checkedListBoxRegimenes.CheckedItems.Count > 0) { for (int i = 0; i < checkedListBoxRegimenes.CheckedItems.Count; i++) { string nombreRegimen = checkedListBoxRegimenes.CheckedItems[i].ToString(); SqlCommand GETidRegimen = new SqlCommand("select codigoRegimen from [PISOS_PICADOS].Regimen where descripcion = @nombreRegimen", Globals.conexionGlobal); GETidRegimen.Parameters.AddWithValue("@nombreRegimen", nombreRegimen); int idRegimen = (int)GETidRegimen.ExecuteScalar(); SqlCommand puedeQuitar = new SqlCommand("select [PISOS_PICADOS].puedeBorrarseRegimen(@nombreRegimen,@idHotel,@fecha)", Globals.conexionGlobal); puedeQuitar.Parameters.AddWithValue("@nombreRegimen", nombreRegimen); puedeQuitar.Parameters.AddWithValue("@idHotel", idHotel); puedeQuitar.Parameters.AddWithValue("@fecha", Globals.FechaDelSistema); if ((int)puedeQuitar.ExecuteScalar() == 1) { SqlCommand quitarRegimenHotel = new SqlCommand("[PISOS_PICADOS].quitarRegimen", Globals.conexionGlobal); quitarRegimenHotel.CommandType = CommandType.StoredProcedure; quitarRegimenHotel.Parameters.Add("@idHotel", SqlDbType.Int); quitarRegimenHotel.Parameters["@idHotel"].Value = idHotel; quitarRegimenHotel.Parameters.Add("@idRegimen", SqlDbType.Int); quitarRegimenHotel.Parameters["@idRegimen"].Value = idRegimen; quitarRegimenHotel.Parameters.AddWithValue("@fecha", Globals.FechaDelSistema); quitarRegimenHotel.ExecuteNonQuery(); } else { MessageBox.Show("No se puede quitar el régimen " + nombreRegimen + ", tiene habitaciones reservadas con él"); regimenesSinModificar = ", algunos regimenes no se cambiaron porque tenían reservas"; } } } pantallaHoteles.actualizarDataGrid(); MessageBox.Show("Modificación correcta" + regimenesSinModificar); this.Close(); } catch (Exception ex) { throw ex; } }
private void button1_Click(object sender, EventArgs e) { chequearSiHayCamposIncompletos(); if (textBoxMail.Text != "") { if (!validarEmail(textBoxMail.Text)) { MessageBox.Show("Escriba un formato de mail correcto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (checkedListRegimenes.CheckedItems.Count == 0) { MessageBox.Show("Seleccione Regimen/es", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int idPAIS; try { SqlCommand cmdpais = new SqlCommand("select idPais from [PISOS_PICADOS].Pais where nombrePais = @paisSelect", Globals.conexionGlobal); cmdpais.Parameters.AddWithValue("@paisSelect", comboBoxPais.Text); idPAIS = (int)cmdpais.ExecuteScalar(); } catch (Exception ex) { throw ex; } String cadenaMod = "PISOS_PICADOS.crearHotel"; SqlCommand comandoMod = new SqlCommand(cadenaMod, Globals.conexionGlobal); comandoMod.CommandType = CommandType.StoredProcedure; //agregar parametros comandoMod.Parameters.Add("@nombre", SqlDbType.VarChar); comandoMod.Parameters.Add("@mail", SqlDbType.VarChar); comandoMod.Parameters.Add("@telefono", SqlDbType.VarChar); comandoMod.Parameters.Add("@calle", SqlDbType.VarChar); comandoMod.Parameters.Add("@nroCalle", SqlDbType.VarChar); comandoMod.Parameters.Add("@estrellas", SqlDbType.Int); comandoMod.Parameters.Add("@ciudad", SqlDbType.VarChar); comandoMod.Parameters.Add("@pais", SqlDbType.Int); comandoMod.Parameters.Add("@fechaCreacion", SqlDbType.Date); comandoMod.Parameters.Add("@autorId", SqlDbType.Int); comandoMod.Parameters["@nombre"].Value = textBoxName.Text; comandoMod.Parameters["@mail"].Value = textBoxMail.Text; comandoMod.Parameters["@telefono"].Value = textBoxTE.Text; comandoMod.Parameters["@calle"].Value = textBoxCalle.Text; comandoMod.Parameters["@nroCalle"].Value = textBoxNroCalle.Text; comandoMod.Parameters["@estrellas"].Value = int.Parse(cBestrellas.Text); comandoMod.Parameters["@ciudad"].Value = textBoxCIU.Text; comandoMod.Parameters["@pais"].Value = idPAIS; comandoMod.Parameters["@fechaCreacion"].Value = dateTimePickerCreacion.Value.ToString("yyyy-MM-dd"); comandoMod.Parameters["@autorId"].Value = Globals.idUsuarioSesion; try { comandoMod.ExecuteReader(); SqlCommand idNuevoHotel = new SqlCommand("select idHotel from [PISOS_PICADOS].Hotel where nombre = @nombreNuevo", Globals.conexionGlobal); idNuevoHotel.Parameters.AddWithValue("@nombreNuevo", textBoxName.Text); int idNuevo = (int)idNuevoHotel.ExecuteScalar(); for (int i = 0; i < checkedListRegimenes.CheckedItems.Count; i++) { string nombreRegimen = checkedListRegimenes.CheckedItems[i].ToString(); SqlCommand GETidRegimen = new SqlCommand("select codigoRegimen from [PISOS_PICADOS].Regimen where descripcion = @nombreRegimen", Globals.conexionGlobal); GETidRegimen.Parameters.AddWithValue("@nombreRegimen", nombreRegimen); int idRegimen = (int)GETidRegimen.ExecuteScalar(); SqlCommand agregarRegimen = new SqlCommand("[PISOS_PICADOS].agregarRegimen", Globals.conexionGlobal); agregarRegimen.CommandType = CommandType.StoredProcedure; agregarRegimen.Parameters.Add("@idHotel", SqlDbType.Int); agregarRegimen.Parameters["@idHotel"].Value = idNuevo; agregarRegimen.Parameters.Add("@idRegimen", SqlDbType.Int); agregarRegimen.Parameters["@idRegimen"].Value = idRegimen; agregarRegimen.ExecuteNonQuery(); } pantallaHoteles.actualizarDataGrid(); MessageBox.Show("Creación correcta"); this.Close(); } catch (Exception ex) { throw ex; } }