MS_12052016

This commit is contained in:
SchreiberM
2016-05-12 13:55:04 +02:00
parent e6265cd227
commit 7ca78e8d65
6 changed files with 365 additions and 80 deletions

View File

@@ -60,6 +60,7 @@ Public Class frmSAP_FuBa
If LogErrorsOnly = False Then ClassLogger.Add(">> SAP-Connection erfolgreich aufgebaut!", False)
If LogErrorsOnly = False Then ClassLogger.Add("", False)
lblConnectionopen.Visible = True
Me.Cursor = Cursors.Default
Catch ex As Exception
MsgBox("Unexpected Error in SAP Connect: " & ex.Message, MsgBoxStyle.Critical)
lblConnectionopen.Visible = False
@@ -67,6 +68,7 @@ Public Class frmSAP_FuBa
lblResult.Visible = False
GridControl2.DataSource = Nothing
lblSave.Visible = False
Me.Cursor = Cursors.Default
Exit Sub
End Try
End Sub
@@ -88,11 +90,12 @@ Public Class frmSAP_FuBa
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnInsertData.Click
If TempTableNameTextBox.Text <> "" Then
Me.Cursor = Cursors.WaitCursor
Dim con As New R3Connection
Try
Me.Cursor = Cursors.WaitCursor
If LogErrorsOnly = False Then ClassLogger.Add("", False)
If LogErrorsOnly = False Then ClassLogger.Add(">> SAP Connect started:", False)
ERPConnect.LIC.SetLic("W86DWC992C")
@@ -215,24 +218,25 @@ Public Class frmSAP_FuBa
End Sub
Private Sub btnGetResult_Click(sender As Object, e As EventArgs) Handles btnGetResult.Click
Dim con As New R3Connection
Dim SAPCon As New R3Connection
Try
Me.Cursor = Cursors.WaitCursor
If LogErrorsOnly = False Then ClassLogger.Add("", False)
If LogErrorsOnly = False Then ClassLogger.Add(">> SAP Connect started:", False)
ERPConnect.LIC.SetLic("W86DWC992C")
con.Host = HostTextBox.Text
con.SystemNumber = SystemNumberTextBox.Text
con.UserName = UserNameTextBox.Text
con.Password = PasswordTextBox.Text
con.Client = ClientTextBox.Text
con.Language = LanguageTextBox.Text
SAPCon.Host = HostTextBox.Text
SAPCon.SystemNumber = SystemNumberTextBox.Text
SAPCon.UserName = UserNameTextBox.Text
SAPCon.Password = PasswordTextBox.Text
SAPCon.Client = ClientTextBox.Text
SAPCon.Language = LanguageTextBox.Text
If LogErrorsOnly = False Then ClassLogger.Add(">> HOST: " & HostTextBox.Text & " |SystemNumber: " & SystemNumberTextBox.Text & " |UserName: " & UserNameTextBox.Text & " |Password: " & PasswordTextBox.Text & " |Client: " & ClientTextBox.Text & " |Language: " & LanguageTextBox.Text, False)
con.Open(False)
If LogErrorsOnly = False Then ClassLogger.Add(">> SAP-Connection erfolgreich aufgebaut!", False)
SAPCon.Open(False)
If LogErrorsOnly = False Then ClassLogger.Add(">> SAP-Connection created and connected!", False)
If LogErrorsOnly = False Then ClassLogger.Add("", False)
lblConnectionopen.Visible = True
Catch ex As Exception
ClassLogger.Add(">> Unexpected Error in SAP Connect: " & ex.Message, False)
MsgBox("Unexpected Error in SAP Connect: " & ex.Message, MsgBoxStyle.Critical)
lblConnectionopen.Visible = False
Me.Cursor = Cursors.Default
@@ -241,9 +245,11 @@ Public Class frmSAP_FuBa
lblSave.Visible = False
Exit Sub
End Try
Dim SAPResulttable As DataTable = New DataTable
If rbTable.Checked = True Then
Try
Dim table As New ERPConnect.Utils.ReadTable(con)
If LogErrorsOnly = False Then ClassLogger.Add(">> Get data from SAP Table", False)
Dim table As New ERPConnect.Utils.ReadTable(SAPCon)
'Dim cWhereClause = "SAP_OBJECT EQ '<ObjectType>' AND AR_DATE GE '<AR_DATE>'"
'Dim sSearchDate1 = "20160101"
'cWhereClause = Replace(cWhereClause, "<ObjectType>", Objekttyp.Text)
@@ -262,41 +268,240 @@ Public Class frmSAP_FuBa
If txtLimitRows.Text <> "" Then
table.RowCount = CInt(txtLimitRows.Text)
End If
If LogErrorsOnly = False Then ClassLogger.Add(">>Table.Run executed", False)
table.Run()
Dim resulttable As DataTable
resulttable = table.Result
SAPResulttable = table.Result
Try
GridControl2.DataSource = resulttable
GridControl2.DataSource = SAPResulttable
Catch ex As Exception
MsgBox("Fehler bei GridControl2 >> DataTable: " & ex.Message, MsgBoxStyle.Critical)
ClassLogger.Add(">> Unexpected Error in GridControl2 >> DataTable 1: " & ex.Message, False)
MsgBox("Unexpected Error in GridControl2 >> DataTable: " & ex.Message, MsgBoxStyle.Critical)
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
End Try
Dim i As Integer
'For Each row As DataRow In resulttable.Rows
' ClassLogger.Add(">> " & row.Item(0).ToString & "|" & row.Item(1).ToString & "|" & row.Item(2).ToString)
'Next
con.Close()
SAPCon.Close()
If txtLimitRows.Text <> "" Then
lblResult.Text = "Result of FuBa (limited to " & txtLimitRows.Text & " rows)"
lblResult.Text = "Result of SAP Table (limited to " & txtLimitRows.Text & " rows)"
Else
lblResult.Text = "Result of FuBa (unlimited) >> " & resulttable.Rows.Count & " rows retreived"
lblResult.Text = "Result of SAP Table (unlimited) >> " & SAPResulttable.Rows.Count & " rows retreived"
End If
lblResult.Visible = True
Me.Cursor = Cursors.Default
lblSave.Visible = False
Catch ex As Exception
ClassLogger.Add(">> Unexpected Error in SAP Table Result: " & ex.Message, False)
MsgBox("Unexpected Error in SAP Table Result: " & ex.Message, MsgBoxStyle.Critical)
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
End Try
Else
sss()
End If
If rBFuba.Checked = True Then
If LogErrorsOnly = False Then ClassLogger.Add(" >> Get data from FuBa-Function", False)
Dim func As RFCFunction
Try
func = SAPCon.CreateFunction(TableNameTextBox.Text)
If LogErrorsOnly = False Then ClassLogger.Add(" >> func.Execute", False)
func.Execute()
If LogErrorsOnly = False Then ClassLogger.Add(" >> function was executed", False)
Catch ex As Exception
ClassLogger.Add(">> Unexpected Error in Create SAP Function: " & ex.Message, False)
MsgBox("Error in Create SAP Function: " & ex.Message, MsgBoxStyle.Critical)
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
Exit Sub
End Try
Dim FUNCT_ROW_COUNT As Integer = 1
Dim RowMaskresult As String
Try
If LogErrorsOnly = False Then ClassLogger.Add(" >> Checking FunctionExecute", False)
'Den ersten Wert ausgeben lassen um die Spalten zu splitten
For Each row As RFCStructure In func.Tables("T_INDEX").Rows
Try
If row.Item(1).ToString.Contains(FuBa_SplitCharacterTextBox.Text) Then
RowMaskresult = row.Item(1).ToString
If LogErrorsOnly = False Then ClassLogger.Add(" >> RowMask result: " & RowMaskresult, False)
FUNCT_ROW_COUNT = 2
End If
Catch ex As Exception
RowMaskresult = "ErrorInGetSeperatedResult: " & ex.Message
End Try
If FUNCT_ROW_COUNT = 2 Then Exit For
Next
Catch ex As Exception
ClassLogger.Add(">> Unexpected Error in Checking FunctionExecute: " & ex.Message, False)
MsgBox("Error in Checking FunctionExecute: " & ex.Message, MsgBoxStyle.Critical)
SAPCon.Close()
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
Exit Sub
End Try
FUNCT_ROW_COUNT = 1
Dim ColCount As Integer
If FuBa_SplitCharacterTextBox.Text <> "" And RowMaskresult.Contains(FuBa_SplitCharacterTextBox.Text) Then
Try
If LogErrorsOnly = False Then ClassLogger.Add(" >> Define Datatable with SplitCharacter method", False)
Dim split() = RowMaskresult.Split(FuBa_SplitCharacterTextBox.Text)
If split.Length > 0 Then
ColCount = split.Length - 1
If LogErrorsOnly = False Then
ClassLogger.Add(" >> ColCount: " & ColCount.ToString, False)
ClassLogger.Add(" >> Split-Results: ", False)
For Each s As String In split
ClassLogger.Add(" # " & s, False)
Next
End If
For x = 0 To ColCount
' Declare DataColumn and DataRow variables.
Dim column As DataColumn
column = New DataColumn()
column = New DataColumn()
column.DataType = Type.GetType("System.String")
column.ColumnName = "Column " & x.ToString
SAPResulttable.Columns.Add(column)
Next
If LogErrorsOnly = False Then ClassLogger.Add(" >> Datatable Columns after Split created", False)
' Create new DataRow objects and add to DataTable.
'Jetzt die Zeilen der Function durchlaufen
For Each row As RFCStructure In func.Tables("T_INDEX").Rows
Dim new_row As DataRow
If txtLimitRows.Text <> "" Then
If CInt(txtLimitRows.Text) = FUNCT_ROW_COUNT Then
Exit For
End If
End If
new_row = SAPResulttable.NewRow()
Dim Rowresult As String = row.Item(1).ToString
If Rowresult.Contains(FuBa_SplitCharacterTextBox.Text) Then
Dim RowSplit() = RowMaskresult.Split(FuBa_SplitCharacterTextBox.Text)
Dim col_index = 0
'Jetzt die Spaltenwerte in die NewRow eintragen
For x = 0 To ColCount
new_row(x) = RowSplit(x)
Next
SAPResulttable.Rows.Add(new_row)
End If
Next
End If
Catch ex As Exception
ClassLogger.Add(">> Unexpected Error in Create Datatable with split-method: " & ex.Message, False)
MsgBox("Unexpected Error in Create Datatable with split-method: " & ex.Message, MsgBoxStyle.Critical)
SAPCon.Close()
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
Exit Sub
End Try
Else
If LogErrorsOnly = False Then ClassLogger.Add(" >> Define Datatable WITHOUT SplitCharacter method", False)
' Declare DataColumn and DataRow variables.
Dim column As DataColumn
' Create new DataColumn, set DataType, ColumnName and add to DataTable.
column = New DataColumn()
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = "id"
SAPResulttable.Columns.Add(column)
' Create second column.
column = New DataColumn()
column.DataType = Type.GetType("System.String")
column.ColumnName = "FuBa-Result"
SAPResulttable.Columns.Add(column)
If LogErrorsOnly = False Then ClassLogger.Add(" >> Datatable Columns created", False)
' Create new DataRow objects and add to DataTable.
Try
For Each row As RFCStructure In func.Tables("T_INDEX").Rows
Dim new_row As DataRow
If LogErrorsOnly = False And FUNCT_ROW_COUNT = 1 Then
ClassLogger.Add(" >> The first 30 rows will be logged", False)
End If
If txtLimitRows.Text <> "" Then
If CInt(txtLimitRows.Text) = FUNCT_ROW_COUNT Then
Exit For
End If
End If
new_row = SAPResulttable.NewRow()
Dim Result As String
Try
Result = row.Item(1).ToString
Catch ex As Exception
Result = "2 Empty"
End Try
new_row("id") = FUNCT_ROW_COUNT
new_row("FuBa-Result") = Result
If LogErrorsOnly = False And FUNCT_ROW_COUNT <= 30 Then
ClassLogger.Add(" >> Result Row: " & Result, False)
End If
FUNCT_ROW_COUNT += 1
SAPResulttable.Rows.Add(new_row)
Next
Catch ex As Exception
ClassLogger.Add(">> Unexpected Error in Create SAP Function-Create Datatable: " & ex.Message, False)
MsgBox("Error in Create Datatable: " & ex.Message, MsgBoxStyle.Critical)
SAPCon.Close()
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
Exit Sub
End Try
End If
'Jetzt dem Grid die Datasource zuordnen
Try
If SAPResulttable.Rows.Count > 0 Then
GridControl2.DataSource = SAPResulttable
End If
SAPCon.Close()
If txtLimitRows.Text <> "" Then
lblResult.Text = "Result of FuBa (limited to " & txtLimitRows.Text & " rows)"
Else
lblResult.Text = "Result of FuBa (unlimited) >> " & SAPResulttable.Rows.Count & " rows retreived"
End If
lblResult.Visible = True
Me.Cursor = Cursors.Default
lblSave.Visible = False
Catch ex As Exception
SAPCon.Close()
lblResult.Visible = False
Me.Cursor = Cursors.Default
lblSave.Visible = False
GridControl2.DataSource = Nothing
ClassLogger.Add(">> Unexpected Error in GridControl2 >> DataTable 2: " & ex.Message, False)
MsgBox("Error in GridControl2 >> DataTable: " & ex.Message, MsgBoxStyle.Critical)
End Try
End If
End Sub
Private Sub rBFuba_CheckedChanged(sender As Object, e As EventArgs) Handles rBFuba.CheckedChanged
If rBFuba.Checked = True Then
Me.FuBa_SplitCharacterTextBox.Visible = True
lblSplitchr.Visible = True
Else
Me.FuBa_SplitCharacterTextBox.Visible = False
lblSplitchr.Visible = False
End If
End Sub
End Class