%@ LCID = 3082 %>
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"
%>
<%
ewCurSec = 0 ' Initialise
' User levels
Const ewAllowAdd = 1
Const ewAllowDelete = 2
Const ewAllowEdit = 4
Const ewAllowView = 8
Const ewAllowList = 8
Const ewAllowReport = 8
Const ewAllowSearch = 8
Const ewAllowAdmin = 16
%>
<%
' Initialize common variables
x_idreferencia = Null: ox_idreferencia = Null
x_NOMBRE = Null: ox_NOMBRE = Null
x_FECHA = Null: ox_FECHA = Null
x_EMAIL = Null: ox_EMAIL = Null
x_SECTOR = Null: ox_SECTOR = Null
x_TELEFONO = Null: ox_TELEFONO = Null
x_TEXTO = Null: ox_TEXTO = Null
%>
<%
Response.Buffer = True
' Load key from QueryString
bCopy = True
x_idreferencia = Request.QueryString("idreferencia")
If x_idreferencia = "" Or IsNull(x_idreferencia) Then
bCopy = False
End If
' Get action
sAction = Request.Form("a_add")
If (sAction = "" Or IsNull(sAction)) Then
If bCopy Then
sAction = "C" ' Copy record
Else
sAction = "I" ' Display blank record
End If
Else
' Get fields from form
x_idreferencia = Request.Form("x_idreferencia")
x_NOMBRE = Request.Form("x_NOMBRE")
x_FECHA = Request.Form("x_FECHA")
x_EMAIL = Request.Form("x_EMAIL")
x_SECTOR = Request.Form("x_SECTOR")
x_TELEFONO = Request.Form("x_TELEFONO")
x_TEXTO = Request.Form("x_TEXTO")
End If
' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
Select Case sAction
Case "C": ' Get a record to display
If Not LoadData() Then ' Load Record based on key
Session("ewmsg") = "No se han encontrado registros"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "lispre.asp"
End If
Case "A": ' Add
If AddData() Then ' Add New Record
Session("ewmsg") = "Nuevo Registro Aņadido Satisfactoriamente"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "lispre.asp"
Else
End If
End Select
%>
Presupuestos
Volver al Listado
<%
conn.Close ' Close Connection
Set conn = Nothing
%>
<%
'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables
Function LoadData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
sSql = "SELECT * FROM `presupuesto`"
sWhere = ""
sGroupBy = ""
sHaving = ""
sOrderBy = ""
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "(`idreferencia` = " & AdjustSql(x_idreferencia) & ")"
sSql = sSql & " WHERE " & sWhere
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSql, conn
If rs.Eof Then
LoadData = False
Else
LoadData = True
rs.MoveFirst
' Get the field contents
x_idreferencia = rs("idreferencia")
x_NOMBRE = rs("NOMBRE")
x_FECHA = rs("FECHA")
x_EMAIL = rs("EMAIL")
x_SECTOR = rs("SECTOR")
x_TELEFONO = rs("TELEFONO")
x_TEXTO = rs("TEXTO")
End If
rs.Close
Set rs = Nothing
End Function
%>
<%
'-------------------------------------------------------------------------------
' Function AddData
' - Add Data
' - Variables used: field variables
Function AddData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
Dim bCheckKey, sSqlChk, sWhereChk
sSql = "SELECT * FROM `presupuesto`"
sWhere = ""
sGroupBy = ""
sHaving = ""
sOrderBy = ""
' Check for duplicate key
bCheckKey = True
sWhereChk = sWhere
If x_idreferencia = "" Or IsNull(x_idreferencia) Then
bCheckKey = False
Else
If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND "
sWhereChk = sWhereChk & "(`idreferencia` = " & AdjustSql(x_idreferencia) & ")"
End If
If bCheckKey Then
sSqlChk = sSql & " WHERE " & sWhereChk
Set rsChk = conn.Execute(sSqlChk)
If Not rsChk.Eof Then
Session("ewmsg") = ""
rsChk.Close
Set rsChk = Nothing
AddData = False
Exit Function
End If
rsChk.Close
Set rsChk = Nothing
End If
' Add New Record
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "(0 = 1)"
sSql = sSql & " WHERE " & sWhere
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, conn, 1, 2
rs.AddNew
' Field NOMBRE
sTmp = Trim(x_NOMBRE)
If Trim(sTmp) = "" Then sTmp = Null
rs("NOMBRE") = sTmp
' Field FECHA
sTmp = EW_UnFormatDateTime(x_FECHA,7)
If IsDate(sTmp) Then
rs("FECHA") = CDate(sTmp)
Else
rs("FECHA") = Null
End If
' Field EMAIL
sTmp = Trim(x_EMAIL)
If Trim(sTmp) = "" Then sTmp = Null
rs("EMAIL") = sTmp
' Field SECTOR
sTmp = Trim(x_SECTOR)
If Trim(sTmp) = "" Then sTmp = Null
rs("SECTOR") = sTmp
' Field TELEFONO
sTmp = Trim(x_TELEFONO)
If Trim(sTmp) = "" Then sTmp = Null
rs("TELEFONO") = sTmp
' Field TEXTO
sTmp = Trim(x_TEXTO)
If Trim(sTmp) = "" Then sTmp = Null
rs("TEXTO") = sTmp
rs.Update
rs.Close
Set rs = Nothing
AddData = True
End Function
%>