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.
401 lines
15 KiB
401 lines
15 KiB
'DocMgmt Klasse
|
|
'Autor: Stefan Hutter, Unternehmensberatung
|
|
'
|
|
'01.04.2003
|
|
'
|
|
Imports System
|
|
Imports System.IO
|
|
Imports System.Data
|
|
Imports System.Data.SqlTypes
|
|
Imports System.Data.SqlClient
|
|
Imports System.ComponentModel
|
|
Imports UtilityLibrary.Win32
|
|
|
|
Public Class DocMgmt
|
|
|
|
#Region "Deklarationen"
|
|
Dim m_dokumentname As String
|
|
Dim m_dokumentid As String
|
|
|
|
Property Dokumentname() As String
|
|
Get
|
|
Return m_dokumentname
|
|
End Get
|
|
Set(ByVal Value As String)
|
|
m_dokumentname = Value
|
|
End Set
|
|
End Property
|
|
Property DokumentID() As String
|
|
Get
|
|
Return m_dokumentid
|
|
End Get
|
|
Set(ByVal Value As String)
|
|
m_dokumentid = Value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
|
|
#Region "Save"
|
|
Public Function Save_To_DB(ByVal sDokumentID As String, ByVal sDokumentName As String) As Boolean
|
|
Try
|
|
Me.DokumentID = sDokumentID
|
|
Me.Dokumentname = sDokumentName
|
|
|
|
Dim Connection As New SqlConnection()
|
|
Dim DA As New SqlDataAdapter("select * from doks where dokumentid='" + Me.DokumentID + "'", Connection)
|
|
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
|
|
Dim ds As New DataSet()
|
|
Dim fs As New FileStream(Me.Dokumentname, FileMode.Open, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
Try
|
|
Globals.PerfMon.insert_entry(Me.DokumentID + " ---- Dokument von Filesystem lesen")
|
|
fs.Read(mydata, 0, fs.Length)
|
|
fs.Close()
|
|
Connection.ConnectionString = Globals.sConnectionString
|
|
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) = Me.DokumentID
|
|
myRow.Item(1) = mydata
|
|
ds.Tables(0).Rows.Add(myRow)
|
|
DA.Update(ds, "docs")
|
|
Globals.PerfMon.insert_entry(Me.DokumentID + " ---- Neues Dokument gespeichert")
|
|
Else
|
|
'Bestehendes Dokument sichenr
|
|
myRow = ds.Tables(0).Rows(0)
|
|
myRow.Item(1) = mydata
|
|
DA.Update(ds, "docs")
|
|
Globals.PerfMon.insert_entry(Me.DokumentID + " ---- Bestehendes Dokument ersetzt")
|
|
End If
|
|
Catch ex As Exception
|
|
Globals.PerfMon.insert_entry(Me.DokumentID + " ---- Fehler bei der Dokumentspeicherung")
|
|
MyMsg.show_standardmessage(86, MsgBoxStyle.Critical)
|
|
' MsgBox(ex.Message)
|
|
Return False
|
|
End Try
|
|
fs = Nothing
|
|
cb = Nothing
|
|
ds = Nothing
|
|
DA = Nothing
|
|
|
|
Connection.Close()
|
|
Connection = Nothing
|
|
Return True
|
|
Catch EX As Exception
|
|
Globals.PerfMon.insert_entry(Me.DokumentID + " ---- Fehler bei der Dokumentspeicherung")
|
|
MyMsg.show_standardmessage(86, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Public Function Save_Layout_DB(ByVal profilnr As Integer, ByVal sDokumentName As String) As Boolean
|
|
Dim Connection As New SqlConnection()
|
|
Dim DA As New SqlDataAdapter("select * from profillayout where profilnr=" + Str(profilnr), Connection)
|
|
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
|
|
Dim ds As New DataSet()
|
|
Dim fs As New FileStream(sDokumentName, FileMode.OpenOrCreate, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
fs.Read(mydata, 0, fs.Length)
|
|
fs.Close()
|
|
Try
|
|
Connection.ConnectionString = Globals.sConnectionString
|
|
Connection.Open()
|
|
DA.Fill(ds, "profil")
|
|
Dim myRow As DataRow
|
|
If ds.Tables(0).Rows.Count = 0 Then
|
|
' Neues Dokument speichern
|
|
myRow = ds.Tables(0).NewRow
|
|
myRow.Item(0) = profilnr
|
|
'***********************************
|
|
'Je nach Layoutfile, Daten aus entsprechendem Feld lesen
|
|
'29.7.2004 / SHU
|
|
'***********************************
|
|
Select Case UCase(Right(sDokumentName, 5))
|
|
Case "T.LYT"
|
|
myRow.Item(2) = mydata
|
|
Case "M.LYT"
|
|
myRow.Item(3) = mydata
|
|
Case "V.LYT"
|
|
myRow.Item(4) = mydata
|
|
Case Else
|
|
myRow.Item(1) = mydata
|
|
End Select
|
|
ds.Tables(0).Rows.Add(myRow)
|
|
DA.Update(ds, "profil")
|
|
Else
|
|
'Bestehendes Dokument sichern
|
|
myRow = ds.Tables(0).Rows(0)
|
|
'***********************************
|
|
'Je nach Layoutfile, Daten aus entsprechendem Feld lesen
|
|
'29.7.2004 / SHU
|
|
'***********************************
|
|
Select Case UCase(Right(sDokumentName, 5))
|
|
Case "T.LYT"
|
|
myRow.Item(2) = mydata
|
|
Case "M.LYT"
|
|
myRow.Item(3) = mydata
|
|
Case "V.LYT"
|
|
myRow.Item(4) = mydata
|
|
Case Else
|
|
myRow.Item(1) = mydata
|
|
End Select
|
|
DA.Update(ds, "profil")
|
|
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 Save_SuchLayout_DB(ByVal profilnr As Integer, ByVal sDokumentName As String) As Boolean
|
|
Dim Connection As New SqlConnection()
|
|
Dim DA As New SqlDataAdapter("select * from suchprofillayout where suchprofilnr=" + Str(profilnr), Connection)
|
|
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
|
|
Dim ds As New DataSet()
|
|
Dim fs As New FileStream(sDokumentName, FileMode.OpenOrCreate, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
fs.Read(mydata, 0, fs.Length)
|
|
fs.Close()
|
|
Try
|
|
Connection.ConnectionString = Globals.sConnectionString
|
|
Connection.Open()
|
|
DA.Fill(ds, "profil")
|
|
Dim myRow As DataRow
|
|
If ds.Tables(0).Rows.Count = 0 Then
|
|
' Neues Dokument speichern
|
|
myRow = ds.Tables(0).NewRow
|
|
myRow.Item(0) = profilnr
|
|
'***********************************
|
|
'Je nach Layoutfile, Daten aus entsprechendem Feld lesen
|
|
'29.7.2004 / SHU
|
|
'***********************************
|
|
Select Case UCase(Right(sDokumentName, 6))
|
|
Case "TS.LYT"
|
|
myRow.Item(2) = mydata
|
|
Case "MS.LYT"
|
|
myRow.Item(3) = mydata
|
|
Case "VS.LYT"
|
|
myRow.Item(4) = mydata
|
|
Case Else
|
|
myRow.Item(1) = mydata
|
|
End Select
|
|
ds.Tables(0).Rows.Add(myRow)
|
|
DA.Update(ds, "profil")
|
|
Else
|
|
'Bestehendes Dokument sichern
|
|
myRow = ds.Tables(0).Rows(0)
|
|
'***********************************
|
|
'Je nach Layoutfile, Daten aus entsprechendem Feld lesen
|
|
'29.7.2004 / SHU
|
|
'***********************************
|
|
Select Case UCase(Right(sDokumentName, 6))
|
|
Case "TS.LYT"
|
|
myRow.Item(2) = mydata
|
|
Case "MS.LYT"
|
|
myRow.Item(3) = mydata
|
|
Case "VS.LYT"
|
|
myRow.Item(4) = mydata
|
|
Case Else
|
|
myRow.Item(1) = mydata
|
|
End Select
|
|
DA.Update(ds, "profil")
|
|
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
|
|
|
|
#End Region
|
|
|
|
#Region "Get"
|
|
Public Function Get_From_DB(ByVal sDokumentID As String, ByVal sDokumentName As String) As Boolean
|
|
Me.DokumentID = sDokumentID
|
|
Me.Dokumentname = sDokumentName
|
|
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From doks where DokumentID='" + Me.DokumentID + "'", connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
|
|
Try
|
|
'Connectionstring zur Datenbank
|
|
connection.ConnectionString = Globals.sConnectionString
|
|
connection.Open()
|
|
da.Fill(ds, "docs")
|
|
|
|
'Versuchen, ob es sich um ein EDKIMP-Dokument handelt - Rel. 3.73 SHU
|
|
If ds.Tables(0).Rows.Count = 0 Then
|
|
da.SelectCommand.CommandText = "Select * from doks where dokumentid='" + "EDKIMP" + Microsoft.VisualBasic.Right(Me.DokumentID, Len(Me.DokumentID) - 6) + "'"
|
|
da.Fill(ds, "Docs")
|
|
End If
|
|
|
|
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
|
|
If Not DivFnkt.isbck(Me.DokumentID) And Not DivFnkt.BDR_Dokument(Me.DokumentID) Then
|
|
MyMsg.show_standardmessage(93, MsgBoxStyle.Critical)
|
|
End If
|
|
Return False
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
connection.Close()
|
|
connection = Nothing
|
|
Return True
|
|
End Function
|
|
|
|
Public Function Get_layout_from_DB(ByVal profilnr As Integer, ByVal sdokumentname As String) As String
|
|
Me.Dokumentname = LTrim(Str(profilnr)) + ".lyt"
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From profillayout where profilnr=" + Str(profilnr), connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
Try
|
|
connection.ConnectionString = Globals.sConnectionString
|
|
connection.Open()
|
|
da.Fill(ds, "docs")
|
|
Dim myRow As DataRow
|
|
myRow = ds.Tables(0).Rows(0)
|
|
Dim MyData() As Byte
|
|
'***********************************
|
|
'Je nach Layoutfile, Daten aus entsprechendem Feld lesen
|
|
'29.7.2004 / SHU
|
|
'***********************************
|
|
Select Case UCase(Right(sdokumentname, 5))
|
|
Case "T.LYT"
|
|
MyData = myRow.Item(2)
|
|
Case "M.LYT"
|
|
MyData = myRow.Item(3)
|
|
Case "V.LYT"
|
|
MyData = myRow.Item(4)
|
|
Case Else
|
|
MyData = myRow.Item(1)
|
|
End Select
|
|
|
|
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
|
|
|
|
Public Function Get_suchlayout_from_DB(ByVal profilnr As Integer, ByVal sdokumentname As String) As String
|
|
Me.Dokumentname = LTrim(Str(profilnr)) + ".lyt"
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From suchprofillayout where suchprofilnr=" + Str(profilnr), connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
Try
|
|
connection.ConnectionString = Globals.sConnectionString
|
|
connection.Open()
|
|
da.Fill(ds, "docs")
|
|
Dim myRow As DataRow
|
|
myRow = ds.Tables(0).Rows(0)
|
|
Dim MyData() As Byte
|
|
'***********************************
|
|
'Je nach Layoutfile, Daten aus entsprechendem Feld lesen
|
|
'29.7.2004 / SHU
|
|
'***********************************
|
|
Select Case UCase(Right(sdokumentname, 6))
|
|
Case "TS.LYT"
|
|
MyData = myRow.Item(2)
|
|
Case "MS.LYT"
|
|
MyData = myRow.Item(3)
|
|
Case "VS.LYT"
|
|
MyData = myRow.Item(4)
|
|
Case Else
|
|
MyData = myRow.Item(1)
|
|
End Select
|
|
|
|
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 Region
|
|
|
|
#Region "CheckDoc"
|
|
Public Function check_doc(ByVal fnkt As Integer) As DataTable
|
|
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
|
|
Dim dtToReturn As DataTable = New DataTable()
|
|
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
|
|
scmCmdToExecute.CommandText = "dbo.sp_check_dok"
|
|
scmCmdToExecute.CommandType = CommandType.StoredProcedure
|
|
scmCmdToExecute.Connection = conn.scoDBConnection
|
|
Try
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@mitarbeiternr", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, Globals.MitarbeiterNr))
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@fnkt", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, fnkt))
|
|
' scmCmdToExecute.Parameters.Add(New SqlParameter("@stationsname", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, Environ("Computername")))
|
|
sdaAdapter.Fill(dtToReturn)
|
|
Return dtToReturn
|
|
Catch ex As Exception
|
|
Throw New Exception("Check_Doc::" & scmCmdToExecute.CommandText & "::Error occured." & ex.Message, ex)
|
|
Finally
|
|
scmCmdToExecute.Dispose()
|
|
sdaAdapter.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
|
|
|
|
End Class
|
|
|