Private Sub RadAsyncUpload1_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles RadAsyncUpload1.FileUploaded
Dim strError As String = ""
Try
'the user is uploading an Excel spreadsheet.
'bring the file into a Binary Reader
Dim br As New BinaryReader(e.File.InputStream)
'convert to a byte array
Dim oByte As Byte() = br.ReadBytes(Convert.ToInt32(e.File.InputStream.Length))
'the user can add comments about the file
Dim strComments As String = ToString2(txtComment.Text)
'create a name for the document
Dim strDocName As String = String.Format("{0} {1:MMdd}", "Quote", Now)
'sql insert
SPs.fp_FPDocument_MergeWSeq2(mintQuoteID, 23, "TK", 0, oByte, strComments, "Quote", App.UserName, strDocName, "xlsx", App.ConnectionString).execute()
'this is not needed, but it is interesting. this saves the byte array to disk
System.IO.File.WriteAllBytes("c:/temp/restored.xlsx", oByte)
Catch ex As ThreadAbortException
Catch ex As Exception
ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
Me.lblError.Text = ex.Message
End Try
End Sub
IF EXISTS (SELECT name
FROM sys.objects
WHERE name = N'fp_FPDocument_MergeWSeq2'
AND type = 'P')
DROP PROCEDURE fp_FPDocument_MergeWSeq2
GO
CREATE PROCEDURE fp_FPDocument_MergeWSeq2
/*
declare @i varbinary(max)
set @i = 1
exec fp_FPDocument_MergeWSeq2 'STD10004195',2,'Delivery',0, @i , 'test note', 'DEL','sg','Delivery 0215','jpg'
select * from FPDocument
*/
@Docnumber varchar(21), -- masternumber
@Doctype int, -- 1
@FileType varchar(20), -- Signature, Delivery
@Sequence INT, -- can be 0
@ImageBLOB image,
@Notes Varchar(MAX),
@Category VARCHAR(15), -- MasterOrder
@CreatedBy VARCHAR(15),
@DocName VARCHAR(15), -- SignatureMMDD
@Extension VARCHAR(3) -- jpg
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
IF @Sequence = 0 BEGIN
select @Sequence = max(sequence) + 1 from docs..FPDocument where Docnumber = @Docnumber and Doctype = @Doctype
if @Sequence is null begin
set @Sequence = 1
end
END
--don't want more than one signature for a SOP document. Just leave the Seq = 1
--we'll just keep the most recent one.
IF @filetype = 'sig' BEGIN
SET @Sequence = 1
end
--Default the docname
DECLARE @FileTypeDesc VARCHAR(20)
SELECT @FileTypeDesc = filetypedesc
FROM dbo.FPDocCategory dc
WHERE dc.FileType = @FileType
SET @FileTypeDesc = ISNULL(@FileTypeDesc,'XX')
if not exists (select 1 from docs..FPDocument where Docnumber = @Docnumber and Doctype = @Doctype and FileType = @FileType AND Sequence = @Sequence ) BEGIN
INSERT INTO docs..FPDocument (Docnumber , Doctype , ImageBLOB , Created , FileType , Sequence , Category , Notes , CreatedBy , Extension , DocName)
VALUES (@Docnumber , @Doctype , @ImageBLOB , getdate() , @FileType , @Sequence , @Category, @Notes, @CreatedBy , @Extension, CASE WHEN @DocName = '' THEN @FileTypeDesc + ' ' + FORMAT(GETDATE(),'MMdd') ELSE @DocName end )
END ELSE BEGIN
UPDATE docs..FPDocument SET
ImageBLOB = @ImageBLOB,
Extension = @Extension,
Category = @Category,
Docname = CASE WHEN @DocName = '' THEN @FileTypeDesc + ' ' + FORMAT(Created,'MMdd') ELSE @DocName end,
Notes = @Notes
WHERE Docnumber = @Docnumber and Doctype = @Doctype and FileType = @FileType AND Sequence = @Sequence
end
GO
grant exec on fp_FPDocument_MergeWSeq2 to PUBLIC
-- sp_sps 'f'