MS RowStyle NodeNavigation

This commit is contained in:
2023-11-06 16:05:20 +01:00
parent 23e1baf2fd
commit 5d3c75abf6
6 changed files with 246 additions and 125 deletions

View File

@@ -126,20 +126,20 @@ Public Class frmSAP_FuBa
If txtLimitRows.Text <> "" Then
rowlimit = txtLimitRows.Text
End If
Dim SAPResulttable As DataTable = New DataTable
Dim oSAPResulttable As New DataTable
If rbTable.Checked = True Then
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, rowlimit)
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, True, rowlimit)
If Not IsNothing(result) Then
SAPResulttable = result
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
SAPResulttable = result
oSAPResulttable = result
End If
End If
If SAPResulttable Is Nothing Then
If oSAPResulttable Is Nothing Then
ClassSAP.SAP_CONNECTION.Close()
lblResult.Visible = False
Me.Cursor = Cursors.Default
@@ -148,6 +148,10 @@ Public Class frmSAP_FuBa
GridView2.Columns.Clear()
LOGGER.Warn("SAPResulttable is nothing")
Exit Sub
Else
GridControl2.DataSource = Nothing
GridView2.Columns.Clear()
lblResult.Text = ""
End If
'######
Dim i = 0
@@ -155,7 +159,7 @@ Public Class frmSAP_FuBa
MYDB_ECM.ExecuteNonQuery("DROP TABLE " & oTablename)
Dim createtablesql = "CREATE TABLE " & oTablename & " ( "
For Each col As System.Data.DataColumn In SAPResulttable.Columns
For Each col As System.Data.DataColumn In oSAPResulttable.Columns
If i = 0 Then
createtablesql += "[" & col.ColumnName & "] [varchar](250)"
Else
@@ -189,16 +193,15 @@ Public Class frmSAP_FuBa
Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(SQLconnect)
bulkCopy.DestinationTableName = oTablename
Try
' Write from the source to the destination.
bulkCopy.WriteToServer(SAPResulttable)
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 FuBa was successfull " & SAPResulttable.Rows.Count & " Rows were inserted to table '" & oTablename & "'!")
MsgBox("Create table was successfull! " & vbNewLine & SAPResulttable.Rows.Count & " Rows were inserted to table '" & oTablename & "'!", MsgBoxStyle.Information)
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
@@ -250,7 +253,7 @@ Public Class frmSAP_FuBa
End If
If rbTable.Checked = True Then
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, rowlimit)
Dim result = ClassSAP.Return_Datatable_for_Table(TableNameTextBox.Text, WHERE_CLAUSETextBox.Text, True, rowlimit)
If Not IsNothing(result) Then
SAPResulttable = result
End If
@@ -291,9 +294,9 @@ Public Class frmSAP_FuBa
elapsed = sw.Elapsed.TotalSeconds
sw.Stop()
If rowlimit <> 0 And SAPResulttable.Rows.Count >= rowlimit Then
lblResult.Text = "Result (limited to " & rowlimit.ToString & " rows) - Duration: " & Format(elapsed, "0.00") & " seconds"
lblResult.Text = "Result (limited to " & rowlimit.ToString & " rows) - Duration: " & Format(elapsed, "0.00") & " seconds - " & Now.ToShortTimeString
Else
lblResult.Text = "Result (unlimited) >> " & SAPResulttable.Rows.Count & " rows retrieved - Duration: " & Format(elapsed, "0.00") & " seconds"
lblResult.Text = "Result (unlimited) >> " & SAPResulttable.Rows.Count & " rows retrieved - Duration: " & Format(elapsed, "0.00") & " seconds - " & Now.ToShortTimeString
End If
lblResult.Visible = True
Me.Cursor = Cursors.Default
@@ -364,4 +367,106 @@ Public Class frmSAP_FuBa
End If
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 New 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