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.

133 lines
4.8 KiB

Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.IO
Public Class VBFileManagement
Public Function Update_Vorlage(filename As String, vorlageid As String, connectionstring As String, manr As Integer)
Dim IntFilename As String
Dim Connection As New SqlConnection()
Dim DA As New SqlDataAdapter("select * from office_vorlage_datei where office_vorlage_dateinr = " + Str(vorlageid), 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
Dim fi As New IO.FileInfo(filename)
IntFilename = (fi.Name)
Try
fs.Read(mydata, 0, fs.Length)
fs.Close()
Connection.ConnectionString = connectionstring
Connection.Open()
DA.Fill(ds, "docs")
Dim myRow As DataRow
If ds.Tables(0).Rows.Count = 0 Then
' Neues Dokument speichern
myRow = ds.Tables(0).NewRow
myRow.Item(0) = vorlageid
myRow.Item(1) = 0
myRow.Item(2) = mydata
myRow.Item(3) = 1
myRow.Item(4) = Now
myRow.Item(5) = manr
myRow.Item(6) = 0
myRow.Item(7) = System.DBNull.Value
myRow.Item(8) = 0
myRow.Item(10) = IntFilename
ds.Tables(0).Rows.Add(myRow)
DA.Update(ds, "docs")
Else
'Bestehendes Dokument sichenr
myRow = ds.Tables(0).Rows(0)
myRow.Item(2) = mydata
myRow.Item(3) = 1
myRow.Item(4) = Now
myRow.Item(5) = manr
myRow.Item(6) = 0
myRow.Item(7) = System.DBNull.Value
myRow.Item(8) = 0
myRow.Item(10) = IntFilename
DA.Update(ds, "docs")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
fs = Nothing
cb = Nothing
ds = Nothing
DA = Nothing
Connection.Close()
Connection = Nothing
End Function
Public Function Get_From_DB(ByVal office_vorlagenr As Integer, ByVal filename As String, ByVal connectionstring As String, Optional ByVal Office2010_Vorlage As Boolean = False) As String
Dim connection As New SqlConnection()
Dim s As String = "Select * From office_vorlage_datei where office_vorlage_Dateinr=" + Trim(Str(office_vorlagenr))
If Office2010_Vorlage = True Then
s = "Select * from Office2010_Vorlage_datei where office_vorlage_dateinr=" + Trim(Str(office_vorlagenr))
End If
Dim da As New SqlDataAdapter(s, connection)
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
Try
connection.ConnectionString = connectionstring
connection.Open()
da.Fill(ds, "docs")
Dim myRow As DataRow
myRow = ds.Tables(0).Rows(0)
Dim MyData() As Byte
MyData = myRow.Item(2)
Dim K As Long
K = UBound(MyData)
Dim fs As New FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(MyData, 0, K)
fs.Close()
fs = Nothing
Return filename
Catch ex As Exception
MsgBox(ex.Message)
End Try
CB = Nothing
ds = Nothing
da = Nothing
connection.Close()
connection = Nothing
End Function
Public Function Get_Dok_From_DB(ByVal sDokumentID As String, ByVal sDokumentName As String, ByVal connectionstring As String) As Boolean
Dim connection As New SqlConnection()
Dim da As New SqlDataAdapter("Select * From doks where DokumentID='" + sDokumentID + "'", connection)
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
Try
'Connectionstring zur Datenbank
connection.ConnectionString = connectionstring
connection.Open()
da.Fill(ds, "docs")
Dim myRow As DataRow
myRow = ds.Tables(0).Rows(0)
Dim MyData() As Byte
MyData = myRow.Item(1)
Dim K As Long
K = UBound(MyData)
Dim fs As New FileStream(sDokumentName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(MyData, 0, K)
fs.Close()
fs = Nothing
Catch ex As Exception
Return False
End Try
CB = Nothing
ds = Nothing
da = Nothing
connection.Close()
connection = Nothing
Return True
End Function
End Class