Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim valor As Integer
REM Decrementa numero de libros en uno tras realizar prestamo
Dim docLibro As NotesDocument
Dim alquilerCorrecto As String
Dim noUnidades As String
REM No permite repetir préstamo de mismo libro
Dim docPrestamos As NotesDocument
Dim prestamos As Integer
Dim agotados As String
REM Acceder a campos de usuario concreto
Dim view1 As NotesView
Dim doc1 As NotesDocument
Dim libro As String
Dim fecha As Variant
Dim dni As String
Dim nombre As String
On Error Goto errores
Set db = session.CurrentDatabase
If db Is Nothing Then
Print "No se ha encontrado la base de datos"
End If
REM Es necesario crear una nueva vista ordenada por titulo de libros
Set view = db.GetView( "Libros por Titulo" )
If view Is Nothing Then
Print "No se ha encontrado la vista"
End If
REM Hago referencia al documento actual
Set doc = session.DocumentContext
REM Guardo en la variable el documento que me interesa
REM La vista debe estar ordenada por titulo del libro y libroPrestado debe ser el primer campo en el documento
Set docLibro = view.GetDocumentByKey( doc.libroPrestado(0), True )
If docLibro Is Nothing Then
Print "No se ha encontrado el documento"
Exit Sub
End If
agotados = |<head>
<style>body{font: bold 14px Sans-Serif;color:black}.celdaInicio{text-align: center;align: center;color: black; font-size: 20; width: 100%;height: 100 px;vertical-align: middle;font: bold 25px Helvetica, Sans-Serif;} .botonSalir{align: center;text-align: center; background-color: #DeDeDe; width: 100px; padding: 10px 25px 10px 25px; font-family: Verdana, sans-serif; font-size: 14px; text-decoration: none; color: #000000; border: 1px solid #000000; border-radius: 9px; -moz-border-radius: 9px; -webkit-border-radius: 9px;}</style>
</head>
<body><TABLE class=tablaInicio width="100%" border=1><TBODY><TR vAlign=top><TD width="50%"><DIV align=center><IMG src="/ceres.nsf/c30b018cd22385a4c1257ede0020d8ae/$Body/0.218?OpenElement&FieldElemFormat=jpg" width=200 height=140></DIV></TD><TD class=celdaInicio width="50%">Biblioteca Pública de Cataluña</TD></TR></TBODY></TABLE></br></br>Ha agotado el número de préstamos esta semana.</br></br>Vuelva a intentarlo más adelante.</br></br><div align="center"><input class="botonSalir" onclick="window.close();" type="button" value="Salir"></input></div>
</body>|
prestamos = Cint(docLibro.numPrestamos(0))
If prestamos = 0 Then
prestamos = prestamos + 1
docLibro.numPrestamos = Cstr(prestamos)
Else
Print agotados
Exit Sub
End If
alquilerCorrecto = |<head>
<style>body{font: bold 14px Sans-Serif;color:black}.celdaInicio{text-align: center;align: center;color: black; font-size: 20; width: 100%;height: 100 px;vertical-align: middle;font: bold 25px Helvetica, Sans-Serif;} .botonSalir{align: center;text-align: center; background-color: #DeDeDe; width: 100px; padding: 10px 25px 10px 25px; font-family: Verdana, sans-serif; font-size: 14px; text-decoration: none; color: #000000; border: 1px solid #000000; border-radius: 9px; -moz-border-radius: 9px; -webkit-border-radius: 9px;}</style>
</head>
<body><TABLE class=tablaInicio width="100%" border=1><TBODY><TR vAlign=top><TD width="50%"><DIV align=center><IMG src="/ceres.nsf/c30b018cd22385a4c1257ede0020d8ae/$Body/0.218?OpenElement&FieldElemFormat=jpg" width=200 height=140></DIV></TD><TD class=celdaInicio width="50%">Biblioteca Pública de Cataluña</TD></TR></TBODY></TABLE></br></br>Su solicitud ha sido realizada correctamente.</br></br>Gracias por su visita.</br></br><div align="center"><input class="botonSalir" onclick="window.close();" type="button" value="Salir"></input></div>
</body>|
noUnidades = |<head>
<style>body{font: bold 14px Sans-Serif;color:black}.celdaInicio{text-align: center;align: center;color: black; font-size: 20; width: 100%;height: 100 px;vertical-align: middle;font: bold 25px Helvetica, Sans-Serif;} .botonSalir{align: center;text-align: center; background-color: #DeDeDe; width: 100px; padding: 10px 25px 10px 25px; font-family: Verdana, sans-serif; font-size: 14px; text-decoration: none; color: #000000; border: 1px solid #000000; border-radius: 9px; -moz-border-radius: 9px; -webkit-border-radius: 9px;}</style>
</head>
<body><TABLE class=tablaInicio width="100%" border=1><TBODY><TR vAlign=top><TD width="50%"><DIV align=center><IMG src="/ceres.nsf/c30b018cd22385a4c1257ede0020d8ae/$Body/0.218?OpenElement&FieldElemFormat=jpg" width=200 height=140></DIV></TD><TD class=celdaInicio width="50%">Biblioteca Pública de Cataluña</TD></TR></TBODY></TABLE></br></br>No existen unidades disponibles de este libro en este momento.</br></br>Gracias por su visita.</br></br><div align="center"><input class="botonSalir" onclick="window.close();" type="button" value="Salir"></input></div>
</body>|
REM Realizo el decremento del numero de libros
valor = Cint(docLibro.num(0))
If valor > 0 Then
valor = valor - 1
docLibro.num = Cstr(valor)
Print alquilerCorrecto
Else
Print noUnidades
End If
doc1.libroPrestamo = libro
doc1.fechaPrestamo = fecha
Set view1 = db.GetView( "Libros alquilados" )
If view1 Is Nothing Then
Print "No se ha encontrado la vista"
End If
libro = Cstr(docLibro.txtTitulo(0))
fecha = Cstr(docLibro.fechaAhora(0))
Set doc1 = view1.GetDocumentByKey( doc.libroPrestamo(0), True )
If doc1 Is Nothing Then
Print "No se ha encontrado el documento doc1"
Exit Sub
End If
REM Guardo los cambios en el documento
Call docLibro.Save(True, True)
Exit Sub
errores:
Print "<br>" & Str(Err) & ": " & Error$ & " on line: " & Cstr(Erl)
End Sub