This commit is contained in:
SchreiberM
2016-07-01 09:00:01 +02:00
parent b8f390b15b
commit fa66fe01eb
20 changed files with 1526 additions and 725 deletions

View File

@@ -120,13 +120,19 @@ Public Class frmSAP_FuBa
lblSave.Visible = False
Exit Sub
End If
Dim rowlimit As Integer = 0
If txtLimitRows.Text <> "" Then
rowlimit = txtLimitRows.Text
End If
Dim SAPResulttable As DataTable = New DataTable
If rbTable.Checked = True Then
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, rowlimit)
If Not IsNothing(result) Then
SAPResulttable = result
End If
End If
If rBFuba.Checked = True Then
Dim result = ClassSAP.FuBa_Returndatatable_Seperated(TableNameTextBox.Text, FuBa_SplitCharacterTextBox.Text, txtLimitRows.Text)
Dim result = ClassSAP.FuBa_Returndatatable_Seperated(TableNameTextBox.Text, FuBa_SplitCharacterTextBox.Text, rowlimit)
If Not IsNothing(result) Then
SAPResulttable = result
End If
@@ -143,61 +149,50 @@ Public Class frmSAP_FuBa
'######
Dim i = 0
Dim tablename = "[TBPMO_SAP_" & TempTableNameTextBox.Text & "]"
Dim createtablesql = "CREATE TABLE TBPMO_SAP_" & TempTableNameTextBox.Text & " ("
ClassDatabase.Execute_non_Query_withConn("DROP TABLE " & tablename, 1)
Dim createtablesql = "CREATE TABLE " & tablename & " ( "
For Each col As System.Data.DataColumn In SAPResulttable.Columns
If i = 0 Then
createtablesql += "[" & col.ColumnName & "] [varchar](100)"
createtablesql += "[" & col.ColumnName & "] [varchar](250)"
Else
createtablesql += ", [" & col.ColumnName & "] [varchar](100)"
createtablesql += ", [" & col.ColumnName & "] [varchar](250)"
End If
i += 1
Next
createtablesql += ")"
Dim check = String.Format("SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='{0}'", tablename)
If ClassDatabase.Execute_Scalar(check) = 1 Then
If LogErrorsOnly = False Then ClassLogger.Add(">> TempTable " & tablename & " exists and will now be deleted!", False)
ClassDatabase.Execute_non_Query_withConn("DROP TABLE " & tablename, 1)
End If
''Die Tabelle anlegen
If LogErrorsOnly = False Then ClassLogger.Add(">> Create Table: " & createtablesql, False)
ClassDatabase.Execute_non_Query_withConn(createtablesql, 1)
Dim del = "delete from " & tablename
ClassDatabase.Execute_non_Query_withConn(del, 1)
If ClassDatabase.Execute_non_Query_withConn(createtablesql, 1) = False Then
MsgBox("Error in creating TempTable: Check log", MsgBoxStyle.Critical)
Exit Sub
End If
If LogErrorsOnly = False Then ClassLogger.Add(">> table has been created", False)
Dim alter = String.Format("ALTER TABLE {0} ADD GUID INTEGER NOT NULL IDENTITY(1,1)", tablename)
ClassDatabase.Execute_non_Query_withConn(alter, 1)
'Dim del = "delete from " & tablename
'ClassDatabase.Execute_non_Query_withConn(del, 1)
'If ClassDatabase.Execute_non_Query_withConn(createtablesql, 1) = False Then
' Me.Cursor = Cursors.Default
' MsgBox("Error while creating the temporary table. Please check the logfile!", MsgBoxStyle.Critical)
' Exit Sub
'End If
Dim ins = "Insert into " & tablename & "("
Dim DT As DataTable = ClassDatabase.Return_Datatable("SELECT * FROM " & tablename)
If Not IsNothing(DT) Then
Dim anz As Integer = 0
For Each col As DataColumn In DT.Columns
If anz = 0 Then
ins = ins & col.ColumnName
Else
ins = ins & ", " & col.ColumnName
End If
anz += 1
Next
ins = ins & ") VALUES ("
End If
'Dim ins = "Insert into " & tablename & "("
'Dim DT As DataTable = ClassDatabase.Return_Datatable("SELECT * FROM " & tablename)
'If Not IsNothing(DT) Then
' Dim anz As Integer = 0
' For Each col As DataColumn In DT.Columns
' If anz = 0 Then
' ins = ins & col.ColumnName
' Else
' ins = ins & ", " & col.ColumnName
' End If
' anz += 1
' Next
' ins = ins & ") VALUES ("
'End If
Try
'For Each row As DataRow In SAPResulttable.Rows
' For x = 0 To CURRENT_COL_COUNT
' If x = 0 Then
' ins = ins & "'" & row.Item(x).ToString & "', "
' Else
' ins = ins & "'" & row.Item(x).ToString & "'"
' End If
' ins = ins & ")"
' Next
' ClassDatabase.Execute_non_Query_withConn(ins, 1)
'Next
Dim OwnerCS As String
OwnerCS = ClassDatabase.GetConnectionString(1)
Dim SQLconnect As New SqlClient.SqlConnection
@@ -206,8 +201,7 @@ Public Class frmSAP_FuBa
' Note that the column positions in the source DataTable
' match the column positions in the destination table,
' so there is no need to map columns.
Using bulkCopy As SqlBulkCopy = _
New SqlBulkCopy(SQLconnect)
Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(SQLconnect)
bulkCopy.DestinationTableName = tablename
Try
' Write from the source to the destination.
@@ -264,13 +258,18 @@ Public Class frmSAP_FuBa
End If
Dim SAPResulttable As DataTable = New DataTable
Dim rowlimit As Integer = 0
If txtLimitRows.Text <> "" Then
rowlimit = txtLimitRows.Text
End If
If rbTable.Checked = True Then
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, txtLimitRows.Text)
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, rowlimit)
If Not IsNothing(result) Then
SAPResulttable = result
End If
ElseIf rBFuba.Checked = True Then 'FUBA Abruf
Dim result = ClassSAP.FuBa_Returndatatable_Seperated(TableNameTextBox.Text, FuBa_SplitCharacterTextBox.Text, txtLimitRows.Text)
Dim result = ClassSAP.FuBa_Returndatatable_Seperated(TableNameTextBox.Text, FuBa_SplitCharacterTextBox.Text, rowlimit)
If Not IsNothing(result) Then
SAPResulttable = result
End If
@@ -297,8 +296,8 @@ Public Class frmSAP_FuBa
Dim elapsed As Double
elapsed = sw.Elapsed.TotalSeconds
sw.Stop()
If txtLimitRows.Text <> "" And SAPResulttable.Rows.Count >= CInt(txtLimitRows.Text) Then
lblResult.Text = "Result (limited to " & txtLimitRows.Text & " rows) - Duration: " & Format(elapsed, "0.00") & " seconds"
If rowlimit <> 0 And SAPResulttable.Rows.Count >= rowlimit Then
lblResult.Text = "Result (limited to " & rowlimit.ToString & " rows) - Duration: " & Format(elapsed, "0.00") & " seconds"
Else
lblResult.Text = "Result (unlimited) >> " & SAPResulttable.Rows.Count & " rows retrieved - Duration: " & Format(elapsed, "0.00") & " seconds"
End If