Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlTypes Imports System.IO Public Class frmImportOffice2010 Dim DokTypes As New DataTable Dim ds As New DataSet() Dim Office_Vorlage_Dateinr As Integer Sub New(ByVal Office_Vorlage_Dateinr As Integer) ' Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent() Me.Office_Vorlage_Dateinr = Office_Vorlage_Dateinr ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. End Sub Private Sub btnOpenfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenfile.Click Me.OpenFileDialog1.FileName = "" Try If Me.cboxAnwendung.Text <> "" Then Me.OpenFileDialog1.Filter = Me.cboxAnwendung.Text + "|*." + Microsoft.VisualBasic.Right(Me.cboxAnwendung.Text, 4) + "|Alle Dateien (*.*)|*.*" If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK And Me.OpenFileDialog1.FileName <> "" Then Me.txtFilename.Text = Me.OpenFileDialog1.FileName End If Else Dim s As String = "Alle Dateien(*.*)|*.*" For Each dr As DataRow In ds.Tables(0).Rows s = dr.Item("Bezeichnung") + "|*." + Microsoft.VisualBasic.Right(dr.Item("Bezeichnung"), 4) + "|" + s Next Me.OpenFileDialog1.Filter = s If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK And Me.OpenFileDialog1.FileName <> "" Then Me.txtFilename.Text = Me.OpenFileDialog1.FileName End If End If Catch ex As Exception Me.OpenFileDialog1.Filter = "Alle Dateien (*.*)|*.*" If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Me.txtFilename.Text = Me.OpenFileDialog1.FileName End Try End Sub Private Sub frmImportOffice2010_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Get_Doktypes() Me.cboxAnwendung.DataSource = ds.Tables(0) Me.cboxAnwendung.DisplayMember = "Bezeichnung" Me.cboxAnwendung.ValueMember = "Anwendungnr" End Sub Private Sub Get_Doktypes() Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("Select * From Anwendung where anwendungnr > 3 and aktiv=1", connection) Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da) Try connection.ConnectionString = Globals.sConnectionString connection.Open() da.Fill(ds, "Anwendung") Catch ex As Exception MsgBox(ex.Message) End Try CB = Nothing da = Nothing connection.Close() connection = Nothing End Sub Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click If Me.Save_Vorlage_To_Db(Me.txtFilename.Text) Then MsgBox("Import erfolgreich druchgeführt.", MsgBoxStyle.Information) Me.Close() End If End Sub Private Function Save_Vorlage_To_Db(ByVal dokumentname As String) As Boolean Try Dim IntFilename As String Dim Connection As New SqlConnection() Dim DA As New SqlDataAdapter("select * from Office2010_Vorlage_datei where office_vorlage_dateinr = " + Me.Office_Vorlage_Dateinr.ToString, 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 MsgBox("Fehler bei der Datei Nr: " + Me.Office_Vorlage_Dateinr.ToString + ", " + dokumentname) fs.Close() Return False End If 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(1) = Me.Office_Vorlage_Dateinr myRow.Item(2) = mydata myRow.Item(3) = Me.cboxAnwendung.SelectedValue myRow.Item(4) = Now myRow.Item(5) = Now myRow.Item(6) = Globals.MitarbeiterNr myRow.Item(7) = Globals.MandantNr myRow.Item(10) = System.IO.Path.GetFileName(dokumentname) 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) = Me.cboxAnwendung.SelectedValue myRow.Item(5) = Now myRow.Item(6) = Globals.MitarbeiterNr DA.Update(ds, "docs") End If Catch ex As Exception MyMsg.show_standardmessage(86, MsgBoxStyle.Critical) MsgBox(ex.Message) End Try fs = Nothing cb = Nothing ds = Nothing DA = Nothing Connection.Close() Connection = Nothing Return True Catch MyMsg.show_standardmessage(86, MsgBoxStyle.Critical) Return False End Try End Function Public Function Get_From_DB_Office_2010() Me.SaveFileDialog1.FileName = "" If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("Select * From Office2010_Vorlage_datei where office_vorlage_Dateinr=" + Me.Office_Vorlage_Dateinr, 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 MyData = myRow.Item(2) Dim K As Long K = UBound(MyData) Dim fs As New FileStream(Me.SaveFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Write) fs.Write(MyData, 0, K) fs.Close() fs = Nothing Catch ex As Exception MsgBox(ex.Message) End Try End If End Function Public Function Get_Applikationnr(ByVal Dateinr As Integer) Try Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("Select * From Office2010_Vorlage_datei where Office_Vorlage_Dateinr=" + Dateinr.ToString, connection) Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet() Try connection.ConnectionString = Globals.sConnectionString connection.Open() da.Fill(ds, "docs") If ds.Tables(0).Rows.Count > 0 Then Return ds.Tables(0).Rows(0).Item(3) Else Return 0 End If Catch ex As Exception MsgBox(ex.Message) End Try CB = Nothing ds = Nothing da = Nothing connection.Close() connection = Nothing CB = Nothing ds = Nothing da = Nothing connection.Close() connection = Nothing Catch ex As Exception Return 0 End Try End Function Private Sub btnAbbruch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbbruch.Click Me.DialogResult = Windows.Forms.DialogResult.Abort Me.Close() End Sub End Class