You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.3 KiB
130 lines
4.3 KiB
Imports System.Data.Sql
|
|
Imports System.Data.SqlClient
|
|
Imports System.Data.SqlTypes
|
|
Imports System.IO
|
|
|
|
Public Class clsDok
|
|
|
|
Dim m_stream As MemoryStream
|
|
Property Documentstream As MemoryStream
|
|
Get
|
|
Return m_stream
|
|
|
|
End Get
|
|
Set(value As MemoryStream)
|
|
m_stream = value
|
|
End Set
|
|
End Property
|
|
Public Function Save_Document(ByVal Dokumentnr As Integer, ByVal Filename As String) As Boolean
|
|
Dim Connection As New SqlConnection()
|
|
Dim DA As New SqlDataAdapter("select * from dms_dokument where nreintrag =" + Str(Dokumentnr), Connection)
|
|
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
|
|
Dim ds As New DataSet()
|
|
Dim fs As New FileStream(Filename, FileMode.OpenOrCreate, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
fs.Read(mydata, 0, fs.Length)
|
|
fs.Close()
|
|
Try
|
|
Connection.ConnectionString = My.Settings.ConnectionString
|
|
Connection.Open()
|
|
DA.Fill(ds, "Dokument")
|
|
Dim myRow As DataRow
|
|
If ds.Tables(0).Rows.Count = 0 Then
|
|
Return False
|
|
Else
|
|
myRow = ds.Tables(0).Rows(0)
|
|
myRow.Item(14) = mydata
|
|
DA.Update(ds, "Dokument")
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
Return False
|
|
End Try
|
|
fs = Nothing
|
|
cb = Nothing
|
|
ds = Nothing
|
|
DA = Nothing
|
|
Connection.Close()
|
|
Connection = Nothing
|
|
Return True
|
|
End Function
|
|
|
|
Public Function Get_Dokument(ByVal DokumentNr As Integer) As String
|
|
Dim Filename As String = My.Settings.TempPath
|
|
If Right(Filename, 1) <> "\" Then Filename = Filename + "\"
|
|
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From dms_Dokument where nreintrag=" + Str(DokumentNr), connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
Try
|
|
connection.ConnectionString = My.Settings.ConnectionString
|
|
connection.Open()
|
|
da.Fill(ds, "Dokument")
|
|
Dim myRow As DataRow
|
|
myRow = ds.Tables(0).Rows(0)
|
|
Dim MyData() As Byte
|
|
MyData = myRow.Item(14)
|
|
|
|
Dim K As Long
|
|
K = UBound(MyData)
|
|
Filename = Filename + System.IO.Path.GetFileName(myRow.Item(4))
|
|
Dim fs As New FileStream(Filename, FileMode.OpenOrCreate, FileAccess.Write)
|
|
fs.Write(MyData, 0, K)
|
|
fs.Close()
|
|
fs = Nothing
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical)
|
|
Return ""
|
|
Finally
|
|
connection.Close()
|
|
connection = Nothing
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
Return Filename
|
|
End Function
|
|
|
|
Public Function Get_Dokument_stram(ByVal DokumentNr As Integer) As MemoryStream
|
|
Dim Filename As String = My.Settings.TempPath
|
|
If Right(Filename, 1) <> "\" Then Filename = Filename + "\"
|
|
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From dms_Dokument where nreintrag=" + Str(DokumentNr), connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
Try
|
|
connection.ConnectionString = My.Settings.ConnectionString
|
|
connection.Open()
|
|
da.Fill(ds, "Dokument")
|
|
Dim myRow As DataRow
|
|
myRow = ds.Tables(0).Rows(0)
|
|
Dim MyData() As Byte
|
|
MyData = myRow.Item(14)
|
|
|
|
Dim K As Long
|
|
K = UBound(MyData)
|
|
Dim ms As New MemoryStream(MyData)
|
|
|
|
Return ms
|
|
|
|
Filename = Filename + System.IO.Path.GetFileName(myRow.Item(4))
|
|
Dim fs As New FileStream(Filename, FileMode.OpenOrCreate, FileAccess.Write)
|
|
fs.Write(MyData, 0, K)
|
|
fs.Close()
|
|
fs = Nothing
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
Finally
|
|
connection.Close()
|
|
connection = Nothing
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
Return Nothing
|
|
End Function
|
|
End Class
|