Timas API

This commit is contained in:
2023-07-10 16:00:50 +02:00
parent d5312abd36
commit 565e1f9942
2 changed files with 22 additions and 256 deletions

View File

@@ -771,7 +771,7 @@ Partial Class frmMitarbDetails
Me.dgvData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.dgvData.Location = New System.Drawing.Point(2, 29)
Me.dgvData.Name = "dgvData"
Me.dgvData.Size = New System.Drawing.Size(364, 110)
Me.dgvData.Size = New System.Drawing.Size(364, 142)
Me.dgvData.TabIndex = 118
'
'rtfInfoTimas
@@ -787,7 +787,7 @@ Partial Class frmMitarbDetails
Me.btngetInfo.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btngetInfo.BackColor = System.Drawing.Color.White
Me.btngetInfo.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.btngetInfo.Location = New System.Drawing.Point(322, 145)
Me.btngetInfo.Location = New System.Drawing.Point(395, 145)
Me.btngetInfo.Name = "btngetInfo"
Me.btngetInfo.Size = New System.Drawing.Size(44, 26)
Me.btngetInfo.TabIndex = 117
@@ -819,7 +819,7 @@ Partial Class frmMitarbDetails
Me.btnMAanlegen.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btnMAanlegen.BackColor = System.Drawing.Color.White
Me.btnMAanlegen.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.btnMAanlegen.Location = New System.Drawing.Point(298, 145)
Me.btnMAanlegen.Location = New System.Drawing.Point(371, 145)
Me.btnMAanlegen.Name = "btnMAanlegen"
Me.btnMAanlegen.Size = New System.Drawing.Size(68, 26)
Me.btnMAanlegen.TabIndex = 54

View File

@@ -29,6 +29,7 @@ Public Class frmMitarbDetails
Dim ZOLLDATENBEARB = False
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Dim FirmaTmp = ""
Dim timas As cTimasAPI
Sub New()
@@ -852,15 +853,13 @@ Public Class frmMitarbDetails
ZOLLDATENBEARB = True
ElseIf tbcntr.SelectedIndex = 3 Then
timas = New VERAG_PROG_ALLGEMEIN.cTimasAPI()
If IsNothing(mitarbeiter.mit_timasId) Then
cbxTimasAngelegt.Checked = False
Dim dt As New DataTable
dt.Columns.Add("id", GetType(Integer))
dt.Columns.Add("name", GetType(String))
dt.Columns.Add("info", GetType(String))
dt.Columns.Add("set", GetType(Boolean))
getGroups("application,json", dt)
timas.getGroups(dt)
initDGV(dt)
Else
cbxTimasAngelegt.Checked = True
@@ -1121,144 +1120,13 @@ Public Class frmMitarbDetails
End Function
Public Function checkConnectionTImas(ByRef rest As Chilkat.Rest, ByRef API_String As String) As Boolean
API_String = "https://zeit.verag.ag"
Dim success As Boolean
rest.VerboseLogging = True
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect(API_String, port, bTls, bAutoReconnect)
If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
rtfInfoTimas.Text = rest.LastErrorText
Return False
End If
success = rest.SetAuthBasic("admin", "BmWr501956")
If (success <> True) Then
Debug.WriteLine("BAFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
rtfInfoTimas.Text = rest.LastErrorText
Return False
End If
Return True
End Function
Private Sub btnMAanlegen_Click(sender As Object, e As EventArgs) Handles btnMAanlegen.Click
Try
If Not checkMandatoryFields() Then Exit Sub
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim rest As New Chilkat.Rest
Dim API_STRING As String
If Not checkConnectionTImas(rest, API_STRING) Then
Exit Sub
End If
rest.AddHeader("Content-Type", "application/json")
Dim success As Boolean
Dim json As New Chilkat.JsonObject
success = json.UpdateString("externid", mitarbeiter.mit_id)
success = json.UpdateString("markingColor", "#3acc2d")
success = json.UpdateString("pnr1", txtPersonalNr.Text)
'success = json.UpdateString("pnr2", "ZZ-3A-Q")
success = json.UpdateString("firstname", mitarbeiter.mit_vname)
success = json.UpdateString("lastname", mitarbeiter.mit_nname)
success = json.UpdateString("gender", IIf(mitarbeiter.mit_geschlecht = "m", "male", "female"))
'success = json.UpdateInt("card", 42)
'success = json.UpdateString("info", "Gebäude 2, 1. OG, Büro 54")
'success = json.UpdateString("clientNumber", "5600-02")
'success = json.UpdateInt("rfid", 178230359)
success = json.UpdateString("birthday", CDate(mitarbeiter.mit_gebdat).ToString("yyyy-MM-dd"))
success = json.UpdateString("entry", CDate(mitarbeiter.mit_einstiegsdatum).ToString("yyyy-MM-dd"))
success = json.UpdateNull("exit")
success = json.UpdateString("importSign", "AX-034511")
success = json.UpdateString("login", mitarbeiter.mit_AliasAD_Username)
success = json.UpdateBool("loginActive", 0)
success = json.UpdateString("email", mitarbeiter.mit_email)
success = json.UpdateString("street", mitarbeiter.mit_strasse)
success = json.UpdateString("city", mitarbeiter.mit_ort)
success = json.UpdateString("zipcode", mitarbeiter.mit_plz)
success = json.UpdateString("phone1", mitarbeiter.mit_telefonnr & " " & mitarbeiter.mit_durchwahl)
success = json.UpdateString("phone2", mitarbeiter.mit_mobiltel)
success = json.UpdateString("password", "password")
success = json.UpdateBool("resetPassword", 1)
For Each r In dgvData.Rows
Dim i As Integer = 0
If r.Cells("set").Value = True Then
success = json.UpdateInt("groups[" & i & "]", r.Cells("id").Value)
End If
Next
'Standardgruppe
'success = json.UpdateInt("groups[1]", 334)
Debug.WriteLine(json.Emit())
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestSb("POST", "/rest/web-api/employees", sbRequestBody, sbResponseBody)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
rtfInfoTimas.Text = rest.LastErrorText
Exit Sub
End If
If (rest.ResponseStatusCode <> 201) Then
Debug.WriteLine(rest.ResponseHeader)
rtfInfoTimas.Text = rest.ResponseStatusCode & " " & rest.ResponseStatusText
If sbResponseBody.GetAsString <> "" Then
rtfInfoTimas.Text &= vbNewLine & sbResponseBody.GetAsString
End If
Exit Sub
Else
rtfInfoTimas.Text = "Mitarbeiter angelegt!"
Dim jsonResult As New Chilkat.JsonObject
success = jsonResult.LoadSb(sbResponseBody)
jsonResult.Emit()
rtfInfoTimas.Text &= "Timas-ID: " & jsonResult.StringOf("id") & vbNewLine
rtfInfoTimas.Text &= "MA-ID: " & jsonResult.StringOf("externid") & vbNewLine
rtfInfoTimas.Text &= "Name: " & jsonResult.StringOf("firstname") & " " & jsonResult.StringOf("lastname")
cbxTimasAngelegt.Checked = True
mitarbeiter.mit_timasId = jsonResult.StringOf("id")
mitarbeiter.SAVE()
End If
rest.ClearAllHeaders()
rest.ClearAllParts()
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
If checkMandatoryFields() Then
timas.createMA(mitarbeiter, rtfInfoTimas.Text, dgvData)
tbcntr_TabIndexChanged(sender, e)
End If
End Sub
@@ -1268,52 +1136,7 @@ Public Class frmMitarbDetails
Exit Sub
End If
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim rest As New Chilkat.Rest
Dim API_STRING As String
If Not checkConnectionTImas(rest, API_STRING) Then
Exit Sub
End If
Dim responseJson As String = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & mitarbeiter.mit_timasId)
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseHeader)
rtfInfoTimas.Text = rest.ResponseStatusCode & " " & rest.ResponseStatusText
Exit Sub
End If
Debug.WriteLine(responseJson)
Dim json As New Chilkat.JsonObject
Dim success = json.Load(responseJson)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
End If
Debug.WriteLine(json)
rtfInfoTimas.Text = "Timas-ID: " & json.StringOf("id") & vbNewLine
rtfInfoTimas.Text &= "MA-ID: " & json.StringOf("externid") & vbNewLine
rtfInfoTimas.Text &= "PersonalNr: " & json.StringOf("pnr1") & vbNewLine
rtfInfoTimas.Text &= "Name: " & json.StringOf("firstname") & " " & json.StringOf("lastname") & vbNewLine
rtfInfoTimas.Text &= "Info: " & json.StringOf("info") & vbNewLine
rtfInfoTimas.Text &= "Startdatum: " & json.StringOf("entry") & vbNewLine
If json.BoolOf("loginActive") Then
rtfInfoTimas.Text &= "Login: " & json.StringOf("login")
End If
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
timas.getInfo(mitarbeiter, rtfInfoTimas.Text)
End Sub
@@ -1333,20 +1156,24 @@ Public Class frmMitarbDetails
If Not cbxEinsteigsDat.Checked Or mitarbeiter.mit_einstiegsdatum = "" Then
MsgBox("Einstiegsdatum prüfen!")
Return False
If CDate(mitarbeiter.mit_einstiegsdatum).ToShortDateString <= DateTime.Parse("01/01/2000") Then
End If
If CDate(mitarbeiter.mit_einstiegsdatum).ToShortDateString <= DateTime.Parse("01/01/2000") Then
MsgBox("Einstiegsdatum darf nicht vor 01.01.2000 liegen!")
Return False
End If
ElseIf mitarbeiter.mit_gekuendigt Then
If mitarbeiter.mit_gekuendigt Then
MsgBox("Bereits gekündige MA können nicht angelegt werden!")
Return False
ElseIf mitarbeiter.mit_vname = "" Or mitarbeiter.mit_nname = "" Then
MsgBox("Vor- und Nachnamen angeben!")
Return False
End If
Return True
If mitarbeiter.mit_vname = "" Or mitarbeiter.mit_nname = "" Then
MsgBox("Vor- und Nachnamen angeben!")
Return False
End If
Return True
End Function
@@ -1369,67 +1196,6 @@ Public Class frmMitarbDetails
End Sub
Private Sub getGroups(acceptContentType As String, ByRef dataTable As DataTable)
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim rest As New Chilkat.Rest
Dim API_STRING As String
If Not checkConnectionTImas(rest, API_STRING) Then
Exit Sub
End If
Dim responseBody As String = rest.FullRequestNoBody("GET", API_STRING & "/rest/web-api/groups3")
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseStatusCode & " " & rest.ResponseStatusText)
End If
Dim jsonArray As New Chilkat.JsonArray
Dim success As Boolean = jsonArray.Load(responseBody)
If (success <> True) Then
Debug.WriteLine(jsonArray.LastErrorText)
Exit Sub
End If
Dim num As Integer = jsonArray.Size
If num = -1 Then
Exit Sub
End If
Dim j As Integer = 0
While j < num
Dim groups As Chilkat.JsonObject = jsonArray.ObjectAt(j)
Dim R As DataRow = dataTable.NewRow
R("id") = groups.IntOf("id")
R("name") = groups.StringOf("name")
R("info") = groups.StringOf("info")
R("set") = IIf(R("id") = "19", True, False)
dataTable.Rows.Add(R)
j = j + 1
End While
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
End Class