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.
305 lines
12 KiB
305 lines
12 KiB
Imports System.Data.SqlClient
|
|
Imports System.Data.SqlDbType
|
|
Imports System.Data.SqlTypes
|
|
Imports System.IO
|
|
|
|
Public Class clsdms
|
|
|
|
Dim conn_int As String
|
|
Dim conn_prod As String
|
|
Dim Vorlagen As New DataTable
|
|
Dim db As clsdb
|
|
Dim Vorlagenverzeichnis As String = My.Settings.Vorlagenverzeichnis
|
|
|
|
Sub New(ByVal connint As String, connprod As String)
|
|
Me.conn_int = connint
|
|
Me.conn_prod = connprod
|
|
db = New clsdb(conn_int, conn_prod)
|
|
End Sub
|
|
|
|
#Region "Export"
|
|
|
|
Public Function Get_Vorlagen()
|
|
Vorlagen = db.Get_Vorlagen()
|
|
Export_Vorlagen()
|
|
End Function
|
|
|
|
Sub Export_Vorlagen()
|
|
Globals.Journal.Insert_RunJOurnal("Export Vorlagen")
|
|
Globals.conn.sConnectionString = conn_int
|
|
Dim i As Integer
|
|
Dim x As Integer
|
|
Dim da As New DataTable()
|
|
Dim counter As Integer
|
|
Dim s As String
|
|
Dim ovd As New edokaDB.clsOffice_Vorlage_Datei()
|
|
ovd.cpMainConnectionProvider = Globals.conn
|
|
FileOpen(1, Vorlagenverzeichnis + "\uebernahme.txt", OpenMode.Output)
|
|
PrintLine(1, "Vorlagenübernahme Produktion: " + Now)
|
|
counter = 0
|
|
|
|
For Each r As DataRow In Vorlagen.Rows
|
|
ovd.iOffice_vorlage_dateinr = New SqlInt32(CType(r.Item("dateinr"), Int32))
|
|
da = ovd.SelectOne()
|
|
If ovd.bFreigegeben.Value = True Then
|
|
s = Get_From_DB(r.Item("dateinr"), Vorlagenverzeichnis + "\")
|
|
Dim anr As String = get_anwendungnr(s)
|
|
x = s.LastIndexOf("\")
|
|
s = Microsoft.VisualBasic.Right(s, Len(s) - (x + 1))
|
|
ovd.daUebernahme_produktion = New SqlDateTime(CType(Now, DateTime))
|
|
Globals.conn.OpenConnection()
|
|
If My.Settings.Debug = "False" Then ovd.Update()
|
|
Globals.conn.CloseConnection(True)
|
|
s = ovd.daFragabe_am.ToString + "|" + ovd.iFreigabe_durch.ToString + "|" + ovd.iMutierer.ToString + "|" + ovd.daMutiert_am.ToString + "|" + s + "|" + anr
|
|
PrintLine(1, Trim(Str(r("nr")) + "|" + s))
|
|
End If
|
|
Next
|
|
|
|
FileClose(1)
|
|
ovd.Dispose()
|
|
End Sub
|
|
|
|
Private Function get_anwendungnr(ByVal dokumentname As String) As Integer
|
|
Dim extension As String = System.IO.Path.GetExtension(dokumentname)
|
|
Select Case UCase(extension)
|
|
Case ".DOC"
|
|
Return 1
|
|
Case ".XLS"
|
|
Return 2
|
|
Case ".PDF"
|
|
Return 3
|
|
Case ".DOCX"
|
|
Return 4
|
|
Case ".DOCM"
|
|
Return 5
|
|
Case ".DOTX"
|
|
Return 6
|
|
Case ".DOTM"
|
|
Return 7
|
|
Case ".XLSX"
|
|
Return 8
|
|
Case ".XLSM"
|
|
Return 9
|
|
Case ".XLTX"
|
|
Return 10
|
|
Case ".XLTM"
|
|
Return 11
|
|
Case Else
|
|
Return 4
|
|
End Select
|
|
End Function
|
|
|
|
Public Function Get_From_DB(ByVal office_vorlagenr As Integer, ByVal pfad 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
|
|
Dim filename As String
|
|
connection.ConnectionString = conn_int
|
|
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)
|
|
filename = pfad + "" + myRow.Item(10)
|
|
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
|
|
Globals.Journal.Insert_RunJOurnal("Fehler Get_From_DB:" + ex.Message)
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
connection.Close()
|
|
connection = Nothing
|
|
End Function
|
|
#End Region
|
|
|
|
#Region "Import"
|
|
|
|
Public Function Check_Import_Vorlagen()
|
|
Globals.Journal.Insert_RunJOurnal("Check Import Vorlagen")
|
|
Globals.conn.sConnectionString = conn_prod
|
|
Dim s As String
|
|
Dim Fehler As String = ""
|
|
Dim Splitter
|
|
Dim da As DataTable
|
|
Dim ov As New edokaDB.clsOffice_vorlage()
|
|
ov.cpMainConnectionProvider = conn
|
|
FileOpen(1, Vorlagenverzeichnis + "\uebernahme.txt", OpenMode.Input)
|
|
Input(1, s)
|
|
While Not EOF(1)
|
|
Input(1, s)
|
|
Splitter = Microsoft.VisualBasic.Split(s, "|")
|
|
ov.iOffice_vorlagenr = New SqlInt32(CType(Splitter(0), Int32))
|
|
da = ov.SelectOne()
|
|
If da.Rows.Count = 0 Then
|
|
If Fehler <> "" Then Fehler = Fehler + ", "
|
|
Fehler = Fehler + Trim(Splitter(0))
|
|
End If
|
|
End While
|
|
ov.Dispose()
|
|
FileClose(1)
|
|
If Len(Fehler) > 0 Then
|
|
Globals.Journal.Insert_RunJOurnal("Vorlagen nicht vorhandne: " + Fehler)
|
|
Return False
|
|
Else
|
|
Return True
|
|
End If
|
|
End Function
|
|
|
|
Public Function Import_Vorlagen() As Integer
|
|
Globals.conn.sConnectionString = conn_prod
|
|
Dim ovd As New edokaDB.clsOffice_Vorlage_Datei()
|
|
Dim anr As Integer
|
|
Dim da As New DataTable()
|
|
Dim s As String
|
|
Dim splitter
|
|
Dim counter As Integer
|
|
ovd.cpMainConnectionProvider = Globals.conn
|
|
counter = 0
|
|
FileOpen(1, Vorlagenverzeichnis + "\uebernahme.txt", OpenMode.Input)
|
|
Input(1, s)
|
|
While Not EOF(1)
|
|
Input(1, s)
|
|
splitter = Microsoft.VisualBasic.Split(s, "|")
|
|
ovd.iOffice_vorlage_dateinr = New SqlInt32(CType(splitter(0), Int32))
|
|
da = ovd.SelectOne
|
|
If My.Settings.Debug = "False" Then
|
|
If da.Rows.Count = 0 Then
|
|
ovd.iOffice_vorlage_dateinr = New SqlInt32(CType(splitter(0), Int32))
|
|
ovd.bAktiv = New SqlBoolean(CType(True, Boolean))
|
|
ovd.bFreigegeben = New SqlBoolean(CType(True, Boolean))
|
|
ovd.daFragabe_am = New SqlDateTime(CType(splitter(1), DateTime))
|
|
ovd.daMutiert_am = New SqlDateTime(CType(splitter(4), DateTime))
|
|
ovd.daUebernahme_produktion = New SqlDateTime(CType(Now, DateTime))
|
|
ovd.iFreigabe_durch = New SqlInt32(CType(splitter(2), Int32))
|
|
ovd.iMutierer = New SqlInt32(CType(9998, Int32))
|
|
ovd.iOffice_vorlagenr = ovd.iOffice_vorlage_dateinr
|
|
ovd.sDateiname = New SqlString(CType(splitter(5), String))
|
|
Try
|
|
anr = splitter(6)
|
|
Catch ex As Exception
|
|
anr = -1
|
|
End Try
|
|
Globals.conn.OpenConnection()
|
|
ovd.Insert()
|
|
Globals.conn.CloseConnection(True)
|
|
Else
|
|
ovd.bAktiv = New SqlBoolean(CType(True, Boolean))
|
|
ovd.bFreigegeben = New SqlBoolean(CType(True, Boolean))
|
|
ovd.daFragabe_am = New SqlDateTime(CType(splitter(1), DateTime))
|
|
ovd.daMutiert_am = New SqlDateTime(CType(splitter(4), DateTime))
|
|
ovd.daUebernahme_produktion = New SqlDateTime(CType(Now, DateTime))
|
|
ovd.iFreigabe_durch = New SqlInt32(CType(splitter(2), Int32))
|
|
ovd.iMutierer = New SqlInt32(CType(9998, Int32))
|
|
ovd.iOffice_vorlagenr = ovd.iOffice_vorlage_dateinr
|
|
ovd.sDateiname = New SqlString(CType(splitter(3), String))
|
|
Try
|
|
anr = splitter(6)
|
|
Catch ex As Exception
|
|
anr = -1
|
|
End Try
|
|
Globals.conn.OpenConnection()
|
|
ovd.Update()
|
|
Globals.conn.CloseConnection(True)
|
|
End If
|
|
End If
|
|
|
|
If Save_Vorlage_To_Db_Import(Vorlagenverzeichnis + "\" + splitter(5), ovd.iOffice_vorlage_dateinr.Value) Then
|
|
counter = counter + 1
|
|
End If
|
|
If anr <> -1 Then update_applikation(splitter(0), anr)
|
|
Globals.Journal.Insert_Uebernahmejournal(splitter(0) + " - " + splitter(5))
|
|
End While
|
|
da.Dispose()
|
|
ovd.Dispose()
|
|
FileClose(1)
|
|
Globals.Journal.Insert_RunJOurnal("Anzahl importierte Vorlagen: " + Str(counter))
|
|
Return counter
|
|
End Function
|
|
|
|
Sub update_applikation(ByVal officevorlagenr As Integer, ByVal anwendungnr As Integer)
|
|
If Not My.Settings.Debug = "False" Then
|
|
Exit Sub
|
|
End If
|
|
Try
|
|
Dim Connection As New SqlConnection()
|
|
Dim c As New SqlCommand("Update office_vorlage set anwendungnr=" + anwendungnr.ToString + " where office_vorlagenr=" + officevorlagenr.ToString, Connection)
|
|
Connection.ConnectionString = conn_prod
|
|
Connection.Open()
|
|
c.ExecuteNonQuery()
|
|
Connection.Close()
|
|
Catch
|
|
End Try
|
|
|
|
|
|
End Sub
|
|
|
|
Private Function Save_Vorlage_To_Db_Import(ByVal dokumentname As String, ByVal nr As Integer) As Boolean
|
|
If Not My.Settings.Debug = "False" Then
|
|
Return True
|
|
Exit Function
|
|
|
|
End If
|
|
Try
|
|
Dim IntFilename As String
|
|
Dim Connection As New SqlConnection()
|
|
Dim DA As New SqlDataAdapter("select * from office_vorlage_datei where office_vorlagenr = " + Trim(Str(nr)), Connection)
|
|
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
|
|
Dim ds As New DataSet()
|
|
Dim fs As New FileStream(dokumentname, FileMode.OpenOrCreate, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
Dim fi As New IO.FileInfo(dokumentname)
|
|
IntFilename = (fi.Name)
|
|
Try
|
|
fs.Read(mydata, 0, fs.Length)
|
|
If fs.Length = 0 Then
|
|
Globals.Journal.Insert_RunJOurnal("Fehler bei der Datei Nr: " + Trim(nr) + ", " + dokumentname)
|
|
fs.Close()
|
|
Return False
|
|
End If
|
|
fs.Close()
|
|
Connection.ConnectionString = conn_prod
|
|
Connection.Open()
|
|
DA.Fill(ds, "docs")
|
|
Dim myRow As DataRow
|
|
|
|
myRow = ds.Tables(0).Rows(0)
|
|
myRow.Item(2) = mydata
|
|
myRow.Item(10) = IntFilename
|
|
DA.Update(ds, "docs")
|
|
Return True
|
|
Catch ex As Exception
|
|
Globals.Journal.Insert_RunJOurnal("Fehler Save_Vorlage:" + ex.Message)
|
|
Return False
|
|
End Try
|
|
fs = Nothing
|
|
cb = Nothing
|
|
ds = Nothing
|
|
DA = Nothing
|
|
|
|
Connection.Close()
|
|
Connection = Nothing
|
|
Catch ex1 As Exception
|
|
Globals.Journal.Insert_RunJOurnal("Fehler Save_Vorlage:" + ex1.Message)
|
|
End Try
|
|
End
|
|
End Function
|
|
|
|
#End Region
|
|
|
|
End Class
|