26/09/2005, 03:44
|
| | | Fecha de Ingreso: noviembre-2002 Ubicación: Los Arroyos, El Escorial, Madrid
Mensajes: 2.084
Antigüedad: 22 años, 2 meses Puntos: 4 | |
Una maravilla, vamos. Pongo lo que he hecho:
En verde lo que se aplica a la base de datos y en rojo a la plantilla
Código:
'Botón Nuevo Documento
Private Sub btnNuevoDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevoDoc.Click
Dim fecha As String
If Me.txtFecha.Text <> "" Then
fecha = "'" & Me.txtFecha.Text & "'"
Else
fecha = "Null"
End If
'Para la base de datos
Dim strIns As String = "INSERT INTO documentos (titulo,autor,fecha,contenido,activada) VALUES" & _
" ('" & HTMLaBD(Me.txtTitulo.Text) & "'," & _
"'" & HTMLaBD(Me.txtAutor.Text) & "'," & _
fecha & "," & _
"'" & HTMLaBD(Me.txtContenido.Text) & "'," & _
Me.chkActivada.Checked.GetHashCode & "); SELECT @@Identity"
Dim id As Integer = DevuelveScalar(strIns)
If Me.chkActivada.Checked Then
'Se publica el documento con el formato de la plantilla
Dim arcPlantilla As File
Dim txtPlantilla As New StreamReader(Server.MapPath("..\Plantilla.aspx"), Encoding.UTF8)
Dim texto As String
texto = txtPlantilla.ReadToEnd
txtPlantilla.Close()
texto = texto.Replace("<!-- TITULO -->", HTMLaBD(Me.txtTitulo.Text))
texto = texto.Replace("<!-- AUTOR -->", HTMLaBD(Me.txtAutor.Text))
texto = texto.Replace("<!-- FECHA -->", HTMLaBD(Me.txtFecha.Text))
texto = texto.Replace("<!-- CONTENIDO -->", HTMLaBD(Me.txtContenido.Text))
Dim txtNuevo As New StreamWriter(Server.MapPath("..\" & id & ".aspx"), False, Encoding.UTF8)
txtNuevo.Write(texto)
txtNuevo.Flush()
txtNuevo.Close()
End If
Session("id") = ""
Response.Redirect("Documentos.aspx")
End Sub
'Botón Actualizar Documento
Private Sub btnActualizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnActualizar.Click
Dim fecha As String
If Me.txtFecha.Text <> "" Then
fecha = "'" & Me.txtFecha.Text & "'"
Else
fecha = "Null"
End If
Dim strUpd As String = "UPDATE documentos SET" & _
" titulo = '" & HTMLaBD(Me.txtTitulo.Text) & "'" & _
",autor = '" & HTMLaBD(Me.txtAutor.Text) & "'" & _
",fecha = " & fecha & _
",contenido = '" & HTMLaBD(Me.txtContenido.Text) & "'" & _
",activada = " & Me.chkActivada.Checked.GetHashCode & _
" WHERE id = " & Session("id")
Try
EjecutaNonQuery(strUpd)
If Me.chkActivada.Checked Then
'Se publica el documento con el formato de la plantilla
Dim arcPlantilla As File
Dim txtPlantilla As New StreamReader(Server.MapPath("..\Plantilla.aspx"), Encoding.UTF8)
Dim texto As String
texto = txtPlantilla.ReadToEnd
txtPlantilla.Close()
texto = texto.Replace("<!-- TITULO -->", HTMLaBD(Me.txtTitulo.Text))
texto = texto.Replace("<!-- AUTOR -->", HTMLaBD(Me.txtAutor.Text))
texto = texto.Replace("<!-- FECHA -->", HTMLaBD(Me.txtFecha.Text))
texto = texto.Replace("<!-- CONTENIDO -->", HTMLaBD(Me.txtContenido.Text))
Dim txtNuevo As New StreamWriter(Server.MapPath("..\" & Session("id") & ".aspx"), False, Encoding.UTF8)
txtNuevo.Write(texto)
txtNuevo.Flush()
txtNuevo.Close()
End If
Catch ex As Exception
Response.Write(strUpd)
Exit Sub
End Try
Session("id") = ""
Response.Redirect("Documentos.aspx")
End Sub
'Botón para confirmar el borrado de un documento
Private Sub btnConfirmSi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirmSi.Click
Dim strDel As String = "DELETE FROM documentos WHERE id = " & Session("BorraDoc")
EjecutaNonQuery(strDel)
Dim archivo As File
archivo.Delete(Server.MapPath("..\" & Session("BorraDoc") & ".aspx"))
Me.pnlConfirma.Visible = False
Response.Redirect("Documentos.aspx")
End Sub
Muchas gracias y un saludo.
__________________ ¡¡NO A LA GUERRA!!
Si ponemos a nuestros mensajes títulos adecuados, la gente se animará más a abrirlos y resultarán más útiles en las busquedas. ¡No a los ayuuudaaa, urgenteee y similares! |