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.
135 lines
4.3 KiB
135 lines
4.3 KiB
Imports System.Data
|
|
Imports System.Data.SqlClient
|
|
Imports System.Data.SqlTypes
|
|
Imports System.IO
|
|
Imports System.Data.OleDb
|
|
Imports System.Threading
|
|
Imports System.Windows.Forms
|
|
|
|
Public Class clsImport
|
|
Dim m_dsdaten As DataSet
|
|
Property dsdaten As DataSet
|
|
Get
|
|
Return m_dsdaten
|
|
End Get
|
|
Set(value As DataSet)
|
|
m_dsdaten = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New()
|
|
Me.m_dsdaten = New DataSet
|
|
End Sub
|
|
|
|
Public Function Import_file() As Boolean
|
|
Dim openfdialog As New OpenFileDialog
|
|
openfdialog.Filter() = "Excel-Dateien (*.xlsx)|*.xlsx|Excel-Dateien (*.xls)|*.xls|CSV-Dateien (*.csv)|*.csv|Text-Dateien (*.txt)|*.txt|Alle Dateien (*.*)|*.*"
|
|
openfdialog.FilterIndex = Globals.defaultextension
|
|
If openfdialog.ShowDialog() <> DialogResult.OK Then
|
|
Return False
|
|
End If
|
|
FillDataTableFromText(openfdialog.FileName)
|
|
Return True
|
|
End Function
|
|
|
|
Private Function FillDataTableFromText(ByVal file As String) As DataTable
|
|
Select Case UCase(Microsoft.VisualBasic.Right(file, 3))
|
|
Case "CSV"
|
|
Dim csv As New MyNameSpace.CSVDataAdapter(file, True, ";")
|
|
csv.Fill(Me.dsdaten)
|
|
'Rel 4.03 3: Wenn die erste Spalte <> "Parternr" dann Meldung ausgeben und alle Rows löchen
|
|
|
|
Me.dsdaten.Tables(0).TableName = "empfdatatable"
|
|
Case "TXT"
|
|
Dim csv As New MyNameSpace.CSVDataAdapter(file, True, ";")
|
|
csv.Fill(Me.dsdaten)
|
|
|
|
Me.dsdaten.Tables(0).TableName = "empfdatatable"
|
|
Case "XLS"
|
|
If oledbimport(file, "XLS") Then
|
|
Me.dsdaten.Tables(0).TableName = "empfdatatable"
|
|
End If
|
|
Case "XLSX"
|
|
If oledbimport(file, "XLSX") Then
|
|
Me.dsdaten.Tables(0).TableName = "empfdatatable"
|
|
End If
|
|
End Select
|
|
'Rel. Office Migration
|
|
If UCase(Microsoft.VisualBasic.Right(file, 5)) = ".XLSX" Then
|
|
If oledbimport(file, "XLSX") Then
|
|
Me.dsdaten.Tables(0).TableName = "empfdatatable"
|
|
End If
|
|
|
|
End If
|
|
Dim dv As DataRow
|
|
|
|
End Function
|
|
|
|
Private Function oledbimport(ByVal file As String, ByVal filetype As String) As Boolean
|
|
Dim dt As New DataTable()
|
|
Dim conn As OleDbConnection
|
|
Dim sql As String
|
|
Dim FileConnection As String
|
|
Dim oda As New OleDbDataAdapter()
|
|
Dim msg As String
|
|
|
|
Select Case filetype
|
|
Case "XLS"
|
|
Try
|
|
Dim xls As New XLSLib.clsXLSLib
|
|
dt = xls.Get_Excel(file)
|
|
|
|
Me.dsdaten.Tables.Add(dt)
|
|
Return True
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
Case "XLSX"
|
|
Try
|
|
Dim xls As New XLSLib.clsXLSLib
|
|
dt = xls.Get_Excel(file)
|
|
|
|
Me.dsdaten.Tables.Add(dt)
|
|
Return True
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
End Select
|
|
|
|
Try
|
|
Try
|
|
conn = New OleDbConnection()
|
|
conn.ConnectionString = FileConnection
|
|
conn.Open()
|
|
Catch ex As Exception
|
|
msg = ex.Message
|
|
End Try
|
|
oda = New OleDbDataAdapter(sql, conn)
|
|
oda.Fill(dt)
|
|
'Rel 4.03 4: Sofern die erste Spalte der importierten Daten keine Partnernummer ist, Meldung ausgeben
|
|
If dt.Columns(0).Caption <> "Partnernr" Then
|
|
' MyMsg.show_standardmessage(50001, MsgBoxStyle.Exclamation)
|
|
dt.Rows.Clear()
|
|
End If
|
|
Me.dsdaten.Tables.Add(dt)
|
|
Return True
|
|
Catch ex As Exception
|
|
Finally
|
|
oda.Dispose()
|
|
conn.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
Private Function Get_Sheetname(ByVal excelfile As String) As String
|
|
Dim f As New frmExcelSheets
|
|
f.ExcelFile = excelfile
|
|
f.ShowDialog()
|
|
If f.DialogResult = Windows.Forms.DialogResult.OK Then
|
|
Return f.ExcelSheet
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Function
|
|
|
|
End Class
|