insætte ny samt opdatere gammel problem
Jeg har et dokument \'vis_journal.asp\' som kan kaldes fra fra 2 steder alt afhængigt om man vil oprettet nyt eller opdatere eksistende data. link 1 i dokumentet som kalder hedder \'ny journal\' og link 2 indeholder teksten \'de første 50 chars\'. Alle journaler listes vha. en SQL som som spørger på CRP nummer.oprette ny:
Hvis man vil oprettet en ny journal, skal følgende data skrives (journaltekst, personnummer, ændret dato, oprettet dato, læge)
opdatere eksistende:
Hvis man vil ændre i journaltekst, hentes teksten ind i formfeltet (hver journal har en unik ID / autonum) og ved klik på formfelt knappen (opdater journal) skrives de nye data ind i tabellen ved navn journal.
Problem 1. er at teksten ikke opdateres ved ændring af journaltekst. Problem 2 er at man ved oprettelse af ny journalblad ikke får en ny ID!
Jeg vedlægger \'vis_journal.asp\' og håber at der kommer nogle gode råd, tak!
****************************************************
<%@LANGUAGE=\"VBSCRIPT\"%>
<!-- #include file=\"access.asp\" -->
<!--#include file=\"Connections/connection.asp\" -->
<%
\' *** Edit Operations: declare variables
MM_editAction = CStr(Request(\"URL\"))
If (Request.QueryString <> \"\") Then
MM_editAction = MM_editAction & \"?\" & Request.QueryString
End If
\' boolean to abort record edit
MM_abortEdit = false
\' query string to execute
MM_editQuery = \"\"
%>
<%
\' *** Update Record: set variables
If (CStr(Request(\"MM_update\")) <> \"\" And CStr(Request(\"MM_recordId\")) <> \"\") Then
MM_editConnection = MM_connection_STRING
MM_editTable = \"journal\"
MM_editColumn = \"ID\"
MM_recordId = \"\" + Request.Form(\"MM_recordId\") + \"\"
MM_editRedirectUrl = \"vis_journal.asp\"
MM_fieldsStr = \"textfield|value|ændret|value\"
MM_columnsStr = \"JOURNAL|\',none,\'\'|ÆNDRET|#,none,NULL\"
\' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, \"|\")
MM_columns = Split(MM_columnsStr, \"|\")
\' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
\' append the query string to the redirect URL
If (MM_editRedirectUrl <> \"\" And Request.QueryString <> \"\") Then
If (InStr(1, MM_editRedirectUrl, \"?\", vbTextCompare) = 0 And Request.QueryString <> \"\") Then
MM_editRedirectUrl = MM_editRedirectUrl & \"?\" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & \"&\" & Request.QueryString
End If
End If
End If
%>
<%
\' *** Update Record: construct a sql update statement and execute it
If (CStr(Request(\"MM_update\")) <> \"\" And CStr(Request(\"MM_recordId\")) <> \"\") Then
\' create the sql update statement
MM_editQuery = \"update \" & MM_editTable & \" set \"
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),\",\")
Delim = MM_typeArray(0)
If (Delim = \"none\") Then Delim = \"\"
AltVal = MM_typeArray(1)
If (AltVal = \"none\") Then AltVal = \"\"
EmptyVal = MM_typeArray(2)
If (EmptyVal = \"none\") Then EmptyVal = \"\"
If (FormVal = \"\") Then
FormVal = EmptyVal
Else
If (AltVal <> \"\") Then
FormVal = AltVal
ElseIf (Delim = \"\'\") Then \' escape quotes
FormVal = \"\'\" & Replace(FormVal,\"\'\",\"\'\'\") & \"\'\"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & \",\"
End If
MM_editQuery = MM_editQuery & MM_columns(i) & \" = \" & FormVal
Next
MM_editQuery = MM_editQuery & \" where \" & MM_editColumn & \" = \" & MM_recordId
If (Not MM_abortEdit) Then
\' execute the update
Set MM_editCmd = Server.CreateObject(\"ADODB.Command\")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> \"\") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim Journal__MMColParam
Journal__MMColParam = \"1\"
if (Request.QueryString(\"ID\") <> \"\") then Journal__MMColParam = Request.QueryString(\"ID\")
%>
<%
set Journal = Server.CreateObject(\"ADODB.Recordset\")
Journal.ActiveConnection = MM_connection_STRING
Journal.Source = \"SELECT * FROM journal WHERE ID = \" + Replace(Journal__MMColParam, \"\'\", \"\'\'\") + \"\"
Journal.CursorType = 0
Journal.CursorLocation = 2
Journal.LockType = 3
Journal.Open()
Journal_numRows = 0
%>
<%
Dim journalnavn__MMColParam
journalnavn__MMColParam = \"1\"
if (Request.QueryString(\"ID\") <> \"\") then journalnavn__MMColParam = Request.QueryString(\"ID\")
%>
<%
set journalnavn = Server.CreateObject(\"ADODB.Recordset\")
journalnavn.ActiveConnection = MM_connection_STRING
journalnavn.Source = \"SELECT * FROM hentjournalnavn WHERE ID = \" + Replace(journalnavn__MMColParam, \"\'\", \"\'\'\") + \"\"
journalnavn.CursorType = 0
journalnavn.CursorLocation = 2
journalnavn.LockType = 3
journalnavn.Open()
journalnavn_numRows = 0
%>
<%
\' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
\' create the list of parameters which should not be maintained
MM_removeList = \"&index=\"
If (MM_paramName <> \"\") Then MM_removeList = MM_removeList & \"&\" & MM_paramName & \"=\"
MM_keepURL=\"\":MM_keepForm=\"\":MM_keepBoth=\"\":MM_keepNone=\"\"
\' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
NextItem = \"&\" & Item & \"=\"
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
End If
Next
\' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
NextItem = \"&\" & Item & \"=\"
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
End If
Next
\' create the Form + URL string and remove the intial \'&\' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> \"\") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL <> \"\") Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> \"\") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
\' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> \"\") Then
MM_joinChar = \"&\"
Else
MM_joinChar = \"\"
End If
End Function
%>
<html>
<head>
<title>Journal</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<link rel=\"stylesheet\" href=\"css.css\" type=\"text/css\">
</head>
<body bgcolor=\"#FFFFFF\" text=\"#000000\">
<div align=\"center\"><A HREF=\"vis_person.asp?<%= MM_keepNone & MM_joinChar(MM_keepNone) & \"CPRNUMMER=\" & Journal.Fields.Item(\"CPRNUMMER\").Value %>\"><span class=\"overskrifter_sort\"><%=(journalnavn.Fields.Item(\"FORNAVN\").Value)%> <%=(journalnavn.Fields.Item(\"EFTERNAVN\").Value)%>s persondata</span></A><br>
</div>
<form name=\"form1\" method=\"POST\" action=\"vis_person.asp?<%= MM_keepNone & MM_joinChar(MM_keepNone) & \"CPRNUMMER=\" & Journal.Fields.Item(\"CPRNUMMER\").Value %>\">
<div align=\"center\">
<textarea name=\"textfield\" cols=\"100\" rows=\"30\" class=\"formfelter\"><%=(Journal.Fields.Item(\"JOURNAL\").Value)%></textarea>
<input type=\"hidden\" name=\"ændret\" value=\"<%=now()%>\">
<br>
<input type=\"submit\" name=\"Submit\" value=\"Opdater journal\" class=\"formknap\">
<input type=\"hidden\" name=\"MM_update\" value=\"true\">
<input type=\"hidden\" name=\"MM_recordId\" value=\"<%= Journal.Fields.Item(\"ID\").Value %>\">
</div>
</form>
<div align=\"center\"><br>
</div>
</body>
</html>
<%
Journal.Close()
%>
<%
journalnavn.Close()
%>
**************************************************
