Hej!
Då har jag fått till funktionaliteten, med vissa avsteg, så som jag vill ha det.. Och det fungerar!
Så här kommer koden:
Spm vanligt är jag tacksam för synpunkter på koden, om jag gjort några riktiga grodor eller om det går att optimera och förkorta... Klarmarkerar dock denna tråd nu!
Mvh
Henrik
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<!--#include virtual="/uppdragNu/includes/functions.asp" -->
<%
' -----------------------------------------------------------------------------------
' addArticle.asp
' Version 1.000
' Senast modifierad 2005-12-29
' Kvar att göra:
' Buggar/förbättringar:
' Logg:
' -----------------------------------------------------------------------------------
'Förhindra att användare som inte är inloggade får åtkomst till sidan.
If Request.Cookies("sydostel")("userId") <> "" then
'Deklarera variabler
Dim sSQL, objRS, objConn, sTasks, iNewTaskId, i, itaskId, iTaskStatus, iRemoteId, sCreatedBy, sTaskNr, iPlanType, dPlanStopDate, dPlanStartDate, sUser, sCustomerNr, sCustomerName, sCustomerRef, sTask, sCustomT1, sCustomT2, sCustomT3, sAction, SCustomA1, SCustomA2, SCustomA3, dStartDate, dStopDate, sLog, sObject1Nr, sObject1Name, sObject2Nr, sObject2Name, sObject3Nr, sObject3Name, sObject4Nr, sObject4Name, iPlanDateType, sTaskJoined, sInitials, dLogDate
sCreatedBy = request.Cookies("sydostel")("User")
'Öppna databasen
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=uppdragNu"
objConn.Open
'Hämta Id från tblNextId som det nya uppdraget får
iNewTaskId = CLng( objConn.Execute("SELECT nextId FROM tblNextId WHERE table = 'tblTask'")("NextId") )
'Skapa det nya uppdraget
sSQL = "INSERT INTO tblTask (Id, Modified, CreatedBy, CreatedDate) VALUES (" & iNewTaskId & ", Now(), '" & sCreatedBy & "', Now())"
objConn.Execute sSQL,,128
'Uppdatera tblNextId
sSQL = "UPDATE tblNextId SET nextId = nextId + 1 WHERE Table = 'tblTask'"
objConn.Execute sSQL,, 128
'Loopa ut informationen för de uppdragen som skall slås ihop
For i = 1 To Request.Form("checkTask").Count
'Hämta information från vart och ett av uppdragen
iTaskId = cLng(request.form("checkTask")(i))
'SQL-fråga för att hämta uppdraget i databasen
sSQL = "SELECT * FROM tblTask WHERE Id = " & iTaskId & " ORDER BY ID"
Set objRS = objConn.Execute(sSQL)
'Tilldela värden till variablerna
iTaskstatus = objRS("Status")
iRemoteId = objRS("RemoteId")
sCreatedBy = objRS("createdBy")
sTaskNr = objRS("TaskNr")
iPlanDateType = objRS("PlanDateType")
dPlanStartDate = objRS("planStartDate")
dPlanStopDate = objRS("planStopDate")
sUser = "(Flera)"
sCustomerNr = objRS("CustomerNr")
sCustomerName = objRS("customerName")
sCustomerRef = objRS("customerRef")
sTask = objRS("Task")
sCustomT1 = objRS("CustomT1")
sCustomT2 = objRS("CustomT2")
sCustomT3 = objRS("CustomT3")
sAction = objRS("Action")
SCustomA1 = objRS("CustomA1")
SCustomA2 = objRS("CustomA2")
SCustomA3 = objRS("CustomA3")
dStartDate = objRS("StartDate")
dStopDate = objRS("StopDate")
sLog =objRS("Log")
sObject1Nr = objRS("Object1Nr")
sObject1Name = objRS("Object1Name")
sObject2Nr = objRS("Object2Nr")
sObject2Name = objRS("Object2Name")
sObject3Nr = objRS("Object3Nr")
sObject3Name = objRS("Object3Name")
sObject4Nr = objRS("Object4Nr")
sObject4Name = objRS("Object4Name")
objRS.Close
Set objRS = Nothing
'Bygga en kommaseparerad sträng med de sammanslagna uppdragsnumrena
sTaskJoined = sTaskJoined & sTaskNr & ", "
'Kontrolera om fältet Task är tomt
sSQL = "SELECT Task FROM tblTask WHERE Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
if not objRS.EOF then
if "" & objRS("task") <> "" then sTask = vbCrlF & sTask
End If
objRS.Close
Set objRS = Nothing
'Kontrolera om fältet Action är tomt
sSQL = "SELECT Action FROM tblTask WHERE Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
if not objRS.EOF then
if "" & objRS("Action") <> "" then sAction = vbCrlF & sAction
End If
objRS.Close
Set objRS = Nothing
'-------------------------------------Block för Custom T1 till T3
'Kontrollera CustomT1
sSQL = "SELECT CustomT1 From tblTask Where Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
If Not objRS.EOF Then
if objRS("customT1") <> sCustomT1 then
sCustomT1 = sCustomT1 & ", " & objRs("customT1")
end if
End If
objRS.Close
Set objRS = Nothing
'Kontrollera CustomT2
sSQL = "SELECT CustomT2 From tblTask Where Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
If Not objRS.EOF Then
if objRS("customT2") <> sCustomT2 then
sCustomT2 = sCustomT2 & ", " & objRs("customT2")
end if
End If
objRS.Close
Set objRS = Nothing
'Kontrollera CustomT3
sSQL = "SELECT CustomT3 From tblTask Where Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
If Not objRS.EOF Then
if objRS("customT3") <> sCustomT3 then
sCustomT3 = sCustomT3 & ", " & objRs("customT3")
end if
End If
objRS.Close
Set objRS = Nothing
'------------------------------------------------------Slut block
'-------------------------------------Block för Custom A1 till A3
'Kontrollera CustomA1
sSQL = "SELECT CustomA1 From tblTask Where Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
If Not objRS.EOF Then
if objRS("customA1") <> sCustomA1 then
sCustomA1 = sCustomA1 & ", " & objRs("customA1")
end if
End If
objRS.Close
Set objRS = Nothing
'Kontrollera CustomA2
sSQL = "SELECT CustomA2 From tblTask Where Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
If Not objRS.EOF Then
if objRS("customA2") <> sCustomA2 then
sCustomA2 = sCustomA2 & ", " & objRs("customA2")
end if
End If
objRS.Close
Set objRS = Nothing
'Kontrollera CustomT3
sSQL = "SELECT CustomA3 From tblTask Where Id = " & iNewTaskId
Set objRS = objConn.Execute(sSQL)
If Not objRS.EOF Then
if objRS("customA3") <> sCustomA3 then
sCustomA3 = sCustomT3 & ", " & objRs("customA3")
end if
End If
objRS.Close
Set objRS = Nothing
'------------------------------------------------------Slut block
'Uppdatera det nya uppdraget
sSQL = "UPDATE tblTask Set Status = " & iTaskStatus & ", RemoteId = " & iRemoteId & ", CreatedBy = '" & sCreatedBy & "', TaskNr = '" & sTaskNr & "', " &_
"PlanDateType = " & iPlanDateType & ", PlanStartDate = #" & dPlanStartDate & "#, PlanStopDate = #" & dPlanStopDate & "#, User = '" & sUser & "', " &_
"CustomerNr = '" & sCustomerNr & "', CustomerName = '" & sCustomerName & "', CustomerRef = '" & sCustomerRef & "', Task = Task & '" & sTask & "', " &_
"CustomT1 = '" & sCustomT1 & "', CustomT2 = '" & sCustomT2 & "', CustomT3 = '" & sCustomT3 & "', " &_
"Action = Action & '" & sAction & "', CustomA1 = '" & sCustomA1 & "', CustomA2 = '" & sCustomA2 & "', " &_
"CustomA3 = '" & sCustomA3 & "', StartDate = #" & dStartDate & "#, StopDate = #" & dStopDate & "#, Log = Log & '" & vbCrLf & sLog & "', " &_
"Object1Nr = '" & sObject1Nr & "', Object1Name = '" & sObject1Name & "', Object2Nr = '" & sObject2Nr & "', Object2Name = '" & sObject2Name & "', " &_
"Object3Nr = '" & sObject3Nr & "', Object3Name = '" & sObject3Name & "', Object4Nr = '" & sObject4Nr & "', Object4Name = '" & sObject4Name & "' " &_
"WHERE Id = " & iNewTaskId & ""
objConn.Execute sSQL,, 128
'Radera uppdraget som sammanfogats
sSQL = "DELETE * FROM tblTask WHERE Id = " & iTaskId
objConn.execute(sSQL),,128
'För över tiderna till det nya uppdraget
sSQL = "UPDATE tblTime Set TaskId = " & iNewTaskId & " Where TaskId = " & iTaskId
objConn.execute(sSQL),,128
'För över materialet till det nya uppdraget
sSQL = "UPDATE tblMaterial Set TaskId = " & iNewTaskId & " Where TaskId = " & iTaskId
objConn.execute(sSQL),,128
Next
'Skapa kommaseparerad sträng med uppdragsnummer, samt ta bort det sista kommat.
if len(sTaskJoined) > 2 then sTaskJoined = left(sTaskJoined, len(sTaskJoined)-2)
'Skapa logmeddelande
sInitials = Request.Cookies("sydostel")("userInitials")
dLogDate = formatDateTime(Now(), 2) & " " & formatDateTime(Now(), 4)
sLog = dLogDate & " Sammanslaget från uppdrag: " & sTaskJoined & " i UppdragNu Intranät /" & sInitials
'Uppdtatera datumen i det nya uppdraget samt lägg till loggmeddelande
sSQL = "UPDATE tblTask set Modified = Now(), CreatedDate = Now(), Log = Log & '" & vbCrLf & sLog & "' WHERE Id = " & iNewTaskId
objConn.Execute sSQL,, 128
'Skapa logmeddelande
sLog = dLogDate & " Uppdraget har Skapats i UppdragNu Intranät /" & sInitials
'Lägg till loggmeddelande
sSQL = "UPDATE tblTask set Modified = Now(), Log = Log & '" & vbCrLf & sLog & "' WHERE Id = " & iNewTaskId
objConn.Execute sSQL,, 128
'Stäng databas
objConn.Close
Set objConn = Nothing
Response.redirect "listTask.asp"
Else
Response.redirect "notLoggedOn.asp"
End If
%>
</body>
</html>