This commit is contained in:
2024-05-06 13:38:52 +02:00
parent 8a9bdc2fcd
commit ae4032ea59
39 changed files with 8034 additions and 9053 deletions

View File

@@ -368,105 +368,5 @@ Public Class frmSAP_FuBa
Me.Cursor = Cursors.Default
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If TempTableNameTextBox.Text <> "" Then
Me.Cursor = Cursors.WaitCursor
If ClassSAP.ConnectionInit(HostTextBox.Text, SystemNumberTextBox.Text, UserNameTextBox.Text, PasswordTextBox.Text, ClientTextBox.Text, LanguageTextBox.Text) = True Then
lblConnectionopen.Visible = True
Else
lblConnectionopen.Visible = False
Me.Cursor = Cursors.Default
lblResult.Visible = False
GridControl2.DataSource = Nothing
GridView2.Columns.Clear()
lblSave.Visible = False
Exit Sub
End If
Dim rowlimit As Integer = 0
If txtLimitRows.Text <> "" Then
rowlimit = txtLimitRows.Text
End If
Dim oSAPResulttable As DataTable
If rbTable.Checked = True Then
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, False, rowlimit)
If Not IsNothing(result) Then
oSAPResulttable = result
End If
End If
If rBFuba.Checked = True Then
Dim result = ClassSAP.FuBa_Returndatatable_Seperated(TableNameTextBox.Text, FuBa_SplitCharacterTextBox.Text, rowlimit)
If Not IsNothing(result) Then
oSAPResulttable = result
End If
End If
If oSAPResulttable Is Nothing Then
ClassSAP.SAP_CONNECTION.Close()
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
GridView2.Columns.Clear()
LOGGER.Warn("SAPResulttable is nothing")
Exit Sub
Else
GridControl2.DataSource = Nothing
GridView2.Columns.Clear()
lblResult.Text = ""
End If
'######
Dim i = 0
Dim oTablename = "[TBPMO_SAP_" & TempTableNameTextBox.Text & "]"
MYDB_ECM.ExecuteNonQuery("DROP TABLE " & oTablename)
Dim createtablesql = "CREATE TABLE " & oTablename & " ( "
For Each col As System.Data.DataColumn In oSAPResulttable.Columns
If i = 0 Then
createtablesql += "[" & col.ColumnName & "] [varchar](250)"
Else
createtablesql += ", [" & col.ColumnName & "] [varchar](250)"
End If
i += 1
Next
createtablesql += ", [ADDED_WHEN] DATETIME NOT NULL DEFAULT GETDATE()"
createtablesql += ")"
''Die Tabelle anlegen
LOGGER.Debug("Create Table: " & createtablesql)
If MYDB_ECM.ExecuteNonQuery(createtablesql) = False Then
MsgBox("Error in creating TempTable: Check log", MsgBoxStyle.Critical)
Exit Sub
End If
LOGGER.Debug("table has been created")
Dim alter = String.Format("ALTER TABLE {0} ADD GUID INTEGER NOT NULL IDENTITY(1,1)", oTablename)
MYDB_ECM.ExecuteNonQuery(alter)
alter = String.Format("ALTER TABLE {0} ADD ADDED_WHEN DATETIME NOT NULL DEFAULT GETDATE()", oTablename)
MYDB_ECM.ExecuteNonQuery(alter)
Try
'Dim OwnerCS As String
'OwnerCS = ClassDatabase.GetConnectionString(1)
Dim SQLconnect As New SqlClient.SqlConnection
SQLconnect.ConnectionString = MYDB_ECM.CurrentConnectionString
SQLconnect.Open()
' 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)
bulkCopy.DestinationTableName = oTablename
Try
bulkCopy.WriteToServer(oSAPResulttable)
Catch ex As Exception
MsgBox("Unexpected Error in BulkCopy SQL: " & ex.Message, MsgBoxStyle.Critical)
End Try
End Using
SQLconnect.Close()
Me.Cursor = Cursors.Default
LOGGER.Debug("Create table from SAP was successfull " & oSAPResulttable.Rows.Count & " Rows were inserted to table '" & oTablename & "'!")
MsgBox("Create table was successfull! " & vbNewLine & oSAPResulttable.Rows.Count & " Rows were inserted to table '" & oTablename & "'!", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("Unexpected Error in SQL bulkCopy: " & ex.Message, MsgBoxStyle.Critical)
Me.Cursor = Cursors.Default
End Try
'######
End If
End Sub
End Class