private void mostrarLista() { c = 0; dato.LeerTabla("Peliculas"); while (dato.pLector.Read()) { //creo una película Peliculas p = new Peliculas(); if (!dato.pLector.IsDBNull(0)) { p.pCodigo = dato.pLector.GetInt32(0); } if (!dato.pLector.IsDBNull(1)) { p.pNombre = dato.pLector.GetString(1); } if (!dato.pLector.IsDBNull(2)) { p.pDuracion = (int)dato.pLector["duracion"]; } if (!dato.pLector.IsDBNull(3)) { p.pAtp = dato.pLector.GetBoolean(3); } if (!dato.pLector.IsDBNull(4)) { p.pGenero = dato.pLector.GetInt32(4); } if (!dato.pLector.IsDBNull(5)) { p.pNacionalidad = dato.pLector.GetInt32(5); } if (!dato.pLector.IsDBNull(6)) { p.pFechaEstreno = dato.pLector.GetDateTime(6); } aPeliculas[c] = p; c++; } dato.pLector.Close(); dato.Desconectar(); lstPeliculas.Items.Clear(); for (int i = 0; i < c; i++) { lstPeliculas.Items.Add(aPeliculas[i].mostrarNombre()); } }
private void btnGrabar_Click(object sender, EventArgs e) { //Validaciones en mi form BorrarMensajeError(); if (validarCampos()) { btnNuevo.Enabled = false; btnEditar.Enabled = false; int atp; string date; if (nuevo) { if (rbtATPSi.Checked) { atp = 1; } else { atp = 0; } date = dtpFechaEstreno.Value.ToString("MM/dd/yyyy HH:MM"); Peliculas p = new Peliculas(); p.pNombre = txtNombre.Text; p.pDuracion = Convert.ToInt32(txtDuracion.Text); p.pGenero = (int)cboGenero.SelectedValue; p.pNacionalidad = (int)cboNacionalidad.SelectedValue; date = dtpFechaEstreno.Value.ToString("MM/dd/yyyy HH:MM"); consultaSQL = $"insert into peliculas values " + $"('{p.pNombre}', {p.pDuracion}, {atp}, {p.pGenero}, {p.pNacionalidad}, '{date}')"; dato.Actualizar(consultaSQL); nuevo = false; } else { int i = lstPeliculas.SelectedIndex; aPeliculas[i].pDuracion = Convert.ToInt32(txtDuracion.Text); aPeliculas[i].pNombre = txtNombre.Text; aPeliculas[i].pGenero = Convert.ToInt32(cboGenero.SelectedValue); if (rbtATPSi.Checked) { atp = 1; } else { atp = 0; } aPeliculas[i].pNacionalidad = Convert.ToInt32(cboNacionalidad.SelectedValue); aPeliculas[i].pFechaEstreno = dtpFechaEstreno.Value; date = aPeliculas[i].pFechaEstreno.ToString("MM/dd/yyyy HH:MM"); consultaSQL = "update peliculas set " + $"nom_pelicula='{aPeliculas[i].pNombre}', duracion={aPeliculas[i].pDuracion}, atp = {atp}, id_genero={aPeliculas[i].pGenero}, id_nacionalidad={aPeliculas[i].pNacionalidad}, fecha_estreno='{date}'" + $" where cod_pelicula = {aPeliculas[i].pCodigo}"; dato.Actualizar(consultaSQL); } limpiarCampos(); mostrarLista(); habilitarCampos(false); btnNuevo.Enabled = true; btnEditar.Enabled = true; } lstPeliculas.Enabled = true; }