Subversion Repositories DevTools

Rev

Rev 29 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29 Rev 4807
Line 26... Line 26...
26
<!--#include file="_access_control_general.asp"-->
26
<!--#include file="_access_control_general.asp"-->
27
<%
27
<%
28
'------------ Variable Definition -------------
28
'------------ Variable Definition -------------
29
Dim objUpload
29
Dim objUpload
30
Dim sFileName
30
Dim sFileName
31
Dim sPath
-
 
32
Dim newID
-
 
33
Dim retErrCode
-
 
34
'------------ Constants Declaration -----------
31
'------------ Constants Declaration -----------
35
'------------ Variable Init -------------------
32
'------------ Variable Init -------------------
36
Set objUpload = New clsUpload
33
Set objUpload = New clsUpload
37
'parPv_id = objUpload.Fields("pv_id").Value
34
'parPv_id = objUpload.Fields("pv_id").Value
38
'----------------------------------------------
35
'----------------------------------------------
Line 49... Line 46...
49
		sFileName = objUpload.Fields("results_file").FileName
46
		sFileName = objUpload.Fields("results_file").FileName
50
	Else
47
	Else
51
		sFileName = objUpload.Fields("results_file").FilePath
48
		sFileName = objUpload.Fields("results_file").FilePath
52
	End If
49
	End If
53
	
50
	
54
	If sFileName <> "" Then
-
 
55
		sPath = rootPath &"\pdf\"& sFileName
-
 
56
	End If
51
    '
57
	
-
 
58
	' Delete the file if already exists
52
    ' Save file name into the BOMS table for backward compatability
59
	Call DeleteFile( sPath )
-
 
60
		
53
    '
61
	' Save the binary data to the file system
-
 
62
	objUpload("results_file").SaveAs sPath
-
 
63
	
-
 
64
	' Put the file path into the database
-
 
65
	OraSession.BeginTrans
54
	OraSession.BeginTrans
66
	OraDatabase.ExecuteSQL "UPDATE BOMS SET PDF_ATTACHMENT_PATH='"& sFileName &"' WHERE BOM_ID ="& objUpload.Fields("bom_id").Value
55
	OraDatabase.ExecuteSQL "UPDATE BOMS SET PDF_ATTACHMENT_PATH='"& sFileName &"' WHERE BOM_ID ="& objUpload.Fields("bom_id").Value
67
	OraSession.CommitTrans
56
	OraSession.CommitTrans
68
	
57
	
-
 
58
    '
-
 
59
    '   Save the binary file into the Database as a blob
-
 
60
    '
-
 
61
    Dim OraParameters
-
 
62
    Dim OraBlob 
-
 
63
    Dim PartImage
-
 
64
    Dim amount_written
-
 
65
 
-
 
66
    Set OraParameters = OraDatabase.Parameters
-
 
67
    OraParameters.Add "PartImage", Empty,ORAPARM_OUTPUT, ORATYPE_BLOB 
69
	
68
 
-
 
69
    'BeginTrans needs to be called since LOB locators become invalid after the ExecuteSQL call 
-
 
70
    On Error Resume Next
-
 
71
    OraSession.BeginTrans
-
 
72
 
-
 
73
    '   Only retain one entry, so delete any that exist
-
 
74
	OraDatabase.ExecuteSQL "DELETE FROM BOM_ATTACHMENTS WHERE BOM_ID="& objUpload.Fields("bom_id").Value
-
 
75
     
-
 
76
    '   Create the entry with an empty blob
-
 
77
    OraDatabase.ExecuteSQL ("insert into BOM_ATTACHMENTS (BOM_ID, LENGTH, CONTENTTYPE, NAME, DATA) values ("&_
-
 
78
            objUpload.Fields("bom_id").Value &","&_
-
 
79
            objUpload("results_file").Length &",'"&_
-
 
80
            objUpload("results_file").ContentType &"','"&_
-
 
81
            sFileName & "', EMPTY_BLOB()) RETURNING DATA INTO :PartImage") 
-
 
82
    Set PartImage = OraDatabase.Parameters("PARTIMAGE").Value 
-
 
83
     
-
 
84
    '
-
 
85
    '   Need to send the data in chuncks
-
 
86
    '       Not sure what the chunk limit is, but we will try 1Meg lumps
-
 
87
    Dim data
-
 
88
    Dim dataLen
-
 
89
    Dim dataIndex
-
 
90
    Dim sendSize
-
 
91
    Dim sendType
-
 
92
 
-
 
93
    data = objUpload("results_file").BLOB
-
 
94
    dataLen = objUpload("results_file").Length
-
 
95
    dataIndex = 0
-
 
96
    sendSize = 1048576
-
 
97
    sendSize = 1024
-
 
98
    sendType = ORALOB_FIRST_PIECE
-
 
99
 
-
 
100
    Set OraBlob = OraDatabase.Parameters("PartImage").Value
-
 
101
    Do While dataLen > 0
-
 
102
 
-
 
103
        If Err.number <> 0 Then Exit Do
-
 
104
 
-
 
105
        If  dataIndex = 0 Then
-
 
106
            If sendSize > dataLen  Then
-
 
107
                sendSize = dataLen
-
 
108
                sendType = ORALOB_ONE_PIECE
-
 
109
            Else
-
 
110
                sendType = ORALOB_FIRST_PIECE
-
 
111
            End If
-
 
112
        Else
-
 
113
            If sendSize > dataLen  Then
-
 
114
                sendSize = dataLen
-
 
115
                sendType = ORALOB_LAST_PIECE
-
 
116
            End If
-
 
117
        End If
-
 
118
 
-
 
119
        amount_written = OraBlob.Write(MidB( data, 1+dataIndex, sendSize), sendSize , sendType)
-
 
120
 
-
 
121
        dataLen   = dataLen - sendSize
-
 
122
        dataIndex = dataIndex + sendSize
-
 
123
        sendType = ORALOB_NEXT_PIECE
-
 
124
    Loop
-
 
125
     
-
 
126
     
-
 
127
    ' Rollback or commit the transaction
-
 
128
	If Err.number <> 0 Then
-
 
129
        OraSession.Rollback 
-
 
130
    Else
-
 
131
        OraSession.CommitTrans 
-
 
132
    End If
-
 
133
 
-
 
134
	'   Either update the parent display or display an error message
70
	If Err.number <> 0 Then
135
	If Err.number <> 0 Then
71
		Call RaiseMsgInParent ( enum_MSG_ERROR, "Upload is not completed.<br>"& Err.description )
136
		Call RaiseMsgInParent ( enum_MSG_ERROR, "Upload is not completed.<br>" & Err.description  )
72
	Else
137
	Else
73
		Call OpenInParentWindow ("Bom_Home.asp?bom_id="& objUpload.Fields("bom_id").Value)
138
		Call OpenInParentWindow ("Bom_Home.asp?bom_id="& objUpload.Fields("bom_id").Value)
74
	End If
139
	End If
75
	
140
	
76
	Set objUpload = Nothing
141
	Set objUpload = Nothing