TIMAS API ausgelagert

This commit is contained in:
2023-07-10 13:45:07 +02:00
parent d98669dde2
commit 7b0aeda931
3 changed files with 380 additions and 9 deletions

View File

@@ -330,10 +330,10 @@ Public Class frmMitarbeitersuche
Exit Sub
End If
Dim dt As New DataTable
dt.Columns.Add("statusid", GetType(Integer))
dt.Columns.Add("stamp", GetType(DateTime))
dt.Columns.Add("type", GetType(String))
'Dim dt As New DataTable
'dt.Columns.Add("statusid", GetType(Integer))
'dt.Columns.Add("stamp", GetType(DateTime))
'dt.Columns.Add("type", GetType(String))
@@ -346,11 +346,11 @@ Public Class frmMitarbeitersuche
If CDate(timeEntry.StringOf("stamp")) >= Today() Then
Dim R As DataRow = dt.NewRow
R("statusid") = timeEntry.StringOf("statusid")
R("stamp") = timeEntry.StringOf("stamp")
R("type") = timeEntry.StringOf("type")
dt.Rows.Add(R)
'Dim R As DataRow = dt.NewRow
'R("statusid") = timeEntry.StringOf("statusid")
'R("stamp") = timeEntry.StringOf("stamp")
'R("type") = timeEntry.StringOf("type")
'dt.Rows.Add(R)
lblTimasZeiten.Text &= " " & IIf(timeEntry.StringOf("type") = "in", "+", " - ") & CDate(timeEntry.StringOf("stamp")).ToString("hh:mm:ss")
If jsonArray.Size - 1 = j Then

View File

@@ -0,0 +1,370 @@
Imports System.Net
Public Class cTimasAPI
Dim API_STRING = "https://zeit.verag.ag"
Dim rest As New Chilkat.Rest
Sub New()
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
End Sub
Public Function checkConnectionTImas(ByRef failureText As String) As Boolean
Try
Dim success As Boolean
rest.VerboseLogging = False
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)
failureText = rest.LastErrorText
Return False
End If
success = rest.SetAuthBasic("admin", "BmWr501956")
If (success <> True) Then
Debug.WriteLine("BAFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
failureText = rest.LastErrorText
Return False
End If
Return True
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function
Public Sub getTimeSaldo(ByVal maid As Integer, ByRef info As String, Optional ByRef requestDone As Boolean = False)
Try
Dim returnText As String = ""
Dim failureText As String = ""
If maid < 1 Then
Exit Sub
End If
If Not checkConnectionTImas(failureText) Then
Exit Sub
End If
Dim success As Boolean
Dim responseJson As String = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & maid & "/balance")
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseHeader)
'lblTimas.Text = rest.ResponseStatusCode & " " & rest.ResponseStatusText
Exit Sub
End If
Debug.WriteLine(responseJson)
Dim json As New Chilkat.JsonObject
success = json.Load(responseJson)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
End If
Debug.WriteLine(json)
'"overallBalance" 101580,
'"dailyBalance": -17340,
'"monthlyBalance": -328380,
'"actualTimeOfDay": 4260,
Dim saldo = json.StringOf("dailyBalanceYesterday") 'Tagessaldo (gestern) in Sekunden
If saldo IsNot Nothing Then
Dim saldoAsDouble = CDbl(saldo)
saldoAsDouble = Math.Round(saldoAsDouble / 3600, 2)
info = "Saldo Vortag: " & saldoAsDouble & "h"
End If
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Public Sub getTimeEntries(ByVal maid As Integer, ByRef info As String, Optional ByRef requestDone As Boolean = False)
Try
Dim returnText As String = ""
Dim failureText As String = ""
If maid < 1 Then
Exit Sub
End If
If Not checkConnectionTImas(failureText) Then
Exit Sub
End If
Dim success As Boolean
Dim yesterdayMidnight As DateTime
yesterdayMidnight = Today().AddDays(-1)
rest.AddQueryParam("id", maid)
rest.AddQueryParam("from", yesterdayMidnight.ToString("yyyy-MM-ddThh:mm:ss"))
rest.AddQueryParam("to", Now().ToString("yyyy-MM-ddThh:mm:ss"))
Dim Response As String
Response = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & maid & "/bookings")
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseHeader)
'rest.ResponseStatusCode & " " & rest.ResponseStatusText
Exit Sub
End If
Debug.WriteLine(Response)
Dim jsonArray As New Chilkat.JsonArray
success = jsonArray.Load(Response)
If (success <> True) Then
Debug.WriteLine(jsonArray.LastErrorText)
Exit Sub
End If
If jsonArray.Size = -1 Then
Exit Sub
End If
'Dim dt As New DataTable
'dt.Columns.Add("statusid", GetType(Integer))
'dt.Columns.Add("stamp", GetType(DateTime))
'dt.Columns.Add("type", GetType(String))
Dim j As Integer = 0
While j < jsonArray.Size
Dim timeEntry As Chilkat.JsonObject = jsonArray.ObjectAt(j)
If IsDate(timeEntry.StringOf("stamp")) Then
If CDate(timeEntry.StringOf("stamp")) >= Today() Then
'Dim R As DataRow = dt.NewRow
'R("statusid") = timeEntry.StringOf("statusid")
'R("stamp") = timeEntry.StringOf("stamp")
'R("type") = timeEntry.StringOf("type")
'dt.Rows.Add(R)
info &= " " & IIf(timeEntry.StringOf("type") = "in", "+", " - ") & CDate(timeEntry.StringOf("stamp")).ToString("hh:mm:ss")
If jsonArray.Size - 1 = j Then
info &= " Status: " & IIf(timeEntry.StringOf("type") = "in", "Anwesend", "Abwesend")
End If
End If
End If
j = j + 1
End While
requestDone = True
rest.ClearAllQueryParams()
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Public Function createMA(ByVal mitarbeiter As cMitarbeiter, ByVal txtPersonalnr As Integer, ByRef info As String, ByRef dgvData As MyDatagridview, Optional ByRef requestDone As Boolean = False)
Try
rest.ClearAllHeaders()
rest.ClearAllParts()
Dim timasEmployeeCreated As Boolean = False
Dim returnText As String = ""
Dim failureText As String = ""
If Not checkConnectionTImas(failureText) Then
Return timasEmployeeCreated
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)
'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
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)
Return timasEmployeeCreated
End If
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
info = rest.LastErrorText
Return timasEmployeeCreated
End If
If (rest.ResponseStatusCode <> 201) Then
Debug.WriteLine(rest.ResponseHeader)
info = rest.ResponseStatusCode & " " & rest.ResponseStatusText
If sbResponseBody.GetAsString <> "" Then
info &= vbNewLine & sbResponseBody.GetAsString
End If
Return timasEmployeeCreated
Else
info = "Mitarbeiter angelegt!"
Dim jsonResult As New Chilkat.JsonObject
success = jsonResult.LoadSb(sbResponseBody)
jsonResult.Emit()
info &= "Timas-ID: " & jsonResult.StringOf("id") & vbNewLine
info &= "MA-ID: " & jsonResult.StringOf("externid") & vbNewLine
info &= "Name: " & jsonResult.StringOf("firstname") & " " & jsonResult.StringOf("lastname")
mitarbeiter.mit_timasId = jsonResult.StringOf("id")
mitarbeiter.SAVE()
timasEmployeeCreated = True
Return timasEmployeeCreated
End If
Return timasEmployeeCreated
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function
Public Sub getInfo(ByVal mitarbeiter As cMitarbeiter, ByVal txtPersonalnr As Integer, ByRef info As String)
Dim failureText As String = ""
'If Not cbxTimasAngelegt.Checked Then
' info = "Mitarbeiter nicht im Timas angelegt!"
' Exit Sub
'End If
Try
If Not checkConnectionTImas(failureText) 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)
info = 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)
info &= "Startdatum: " & json.StringOf("entry") & vbNewLine
info &= "MA-ID: " & json.StringOf("externid") & vbNewLine
info &= "PersonalNr: " & json.StringOf("pnr1") & vbNewLine
info &= "Name: " & json.StringOf("firstname") & " " & json.StringOf("lastname") & vbNewLine
info &= "Info: " & json.StringOf("info") & vbNewLine
info = "Timas-ID: " & json.StringOf("id") & vbNewLine
If json.BoolOf("loginActive") Then
info &= "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
End Sub
End Class

View File

@@ -586,6 +586,7 @@
<Compile Include="Schnittstellen\cNorsware.vb" />
<Compile Include="Schnittstellen\cSyska_Interface.vb" />
<Compile Include="Schnittstellen\cTherefore.vb" />
<Compile Include="Schnittstellen\cTimasAPI.vb" />
<Compile Include="Schnittstellen\Finanzonline\cFinanzOnlineWebService.vb" />
<Compile Include="Schnittstellen\GASTON_SCHUL\agsCustomsExchange.Designer.vb" />
<Compile Include="Schnittstellen\IDEV_Intrastat\instat6.2.Designer.vb" />