992 lines
34 KiB
VB.net
992 lines
34 KiB
VB.net
Imports System.Diagnostics.Tracing
|
|
Imports System.Net
|
|
Imports System.Runtime.Remoting
|
|
Imports System.Text
|
|
Imports System.Threading
|
|
Imports System.Windows.Forms
|
|
|
|
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 = 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)
|
|
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(maid As Integer, ByRef info As String, ByRef Optional isEndpointRunning As Boolean = True)
|
|
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
|
|
|
|
rest.IdleTimeoutMs = 5000
|
|
Dim responseJson As String = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & maid & "/balance")
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
isEndpointRunning = rest.LastMethodSuccess
|
|
rest.IdleTimeoutMs = 30000 'defualt
|
|
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)
|
|
Dim infoBuilder As New StringBuilder
|
|
'infoBuilder.Append("Vortag ")
|
|
infoBuilder.Append(saldoAsDouble)
|
|
infoBuilder.Append(" h")
|
|
info = infoBuilder.ToString()
|
|
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 Function getTimeEntries(ByVal maid As Integer, ByRef dtZeiten As DataTable, Optional ByRef entryExistingToday As Boolean = True, Optional ByRef requestDone As Boolean = False, Optional ByRef isEndpointRunning As Boolean = True) As Boolean
|
|
Try
|
|
|
|
Dim isPresent = False
|
|
Dim failureText As String = ""
|
|
|
|
|
|
If maid < 1 Then
|
|
Return isPresent
|
|
End If
|
|
|
|
If Not checkConnectionTImas(failureText) Then
|
|
Return isPresent
|
|
End If
|
|
|
|
Dim success As Boolean
|
|
|
|
rest.AddQueryParam("id", maid)
|
|
rest.AddQueryParam("from", Today().AddDays(-1).ToString("yyyy-MM-ddTHH:mm:ss"))
|
|
rest.AddQueryParam("to", Now().ToString("yyyy-MM-ddTHH:mm:ss"))
|
|
|
|
|
|
|
|
Dim Response As String
|
|
rest.IdleTimeoutMs = 5000 '5 sec
|
|
Response = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & maid & "/bookings")
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
isEndpointRunning = rest.LastMethodSuccess
|
|
rest.IdleTimeoutMs = 30000 'defualt
|
|
Return isPresent
|
|
Else
|
|
rest.IdleTimeoutMs = 30000
|
|
End If
|
|
|
|
If (rest.ResponseStatusCode <> 200) Then
|
|
Debug.WriteLine(rest.ResponseHeader)
|
|
Debug.WriteLine(rest.ResponseStatusCode & " " & rest.ResponseStatusText)
|
|
Return isPresent
|
|
End If
|
|
|
|
Debug.WriteLine(Response)
|
|
Dim jsonArray As New Chilkat.JsonArray
|
|
success = jsonArray.Load(Response)
|
|
If (success <> True) Then
|
|
Debug.WriteLine(jsonArray.LastErrorText)
|
|
Return isPresent
|
|
End If
|
|
|
|
|
|
If jsonArray.Size = -1 Then
|
|
Return isPresent
|
|
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))
|
|
|
|
|
|
entryExistingToday = False
|
|
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")) >= CDate(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)
|
|
entryExistingToday = True
|
|
'info &= " " & IIf(timeEntry.StringOf("type") = "in", "+", " - ") & CDate(timeEntry.StringOf("stamp")).ToString("HH:mm:ss")
|
|
If jsonArray.Size - 1 = j Then
|
|
If timeEntry.StringOf("type") = "in" Then
|
|
isPresent = True
|
|
End If
|
|
End If
|
|
|
|
End If
|
|
End If
|
|
j = j + 1
|
|
End While
|
|
|
|
If dtZeiten IsNot Nothing Then dtZeiten = dt
|
|
requestDone = True
|
|
rest.ClearAllQueryParams()
|
|
Return isPresent
|
|
|
|
Catch ex As WebException
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
End Function
|
|
|
|
Public Function createEmployee(ByVal mitarbeiter As cMitarbeiter, ByRef info As String, ByRef datatableTimas As DataTable, 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", mitarbeiter.mit_PersonalNr) 'für Personalverr.
|
|
'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", mitarbeiter.mit_id)
|
|
success = json.UpdateString("info", mitarbeiter.mit_firma & " - " & mitarbeiter.mit_abteilung)
|
|
If mitarbeiter.mit_gebdat <> "" And IsDate(mitarbeiter.mit_gebdat) Then
|
|
success = json.UpdateString("birthday", CDate(mitarbeiter.mit_gebdat).ToString("yyyy-MM-dd"))
|
|
End If
|
|
|
|
success = json.UpdateString("entry", CDate(mitarbeiter.mit_einstiegsdatum).ToString("yyyy-MM-dd"))
|
|
success = json.UpdateNull("exit")
|
|
success = json.UpdateString("importSign", "Import from Aviso")
|
|
success = json.UpdateString("login", mitarbeiter.mit_username)
|
|
success = json.UpdateBool("loginActive", 1)
|
|
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", mitarbeiter.mit_pwd)
|
|
success = json.UpdateBool("resetPassword", 0)
|
|
|
|
Dim i As Integer = 0
|
|
For Each r As DataRow In datatableTimas.Rows
|
|
If r("set") = True Then
|
|
success = json.UpdateInt("groups[" & i & "]", r("id"))
|
|
i = i + 1
|
|
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)
|
|
info = 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!" & vbNewLine
|
|
|
|
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, 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
|
|
|
|
info &= IIf(json.StringOf("entry") <> "", "Startdatum: " & json.StringOf("entry") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("externid") <> "", "MA-ID: " & json.StringOf("externid") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("pnr1") <> "", "PersonalNr: " & json.StringOf("pnr1") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("firstname") <> "", "Vorame: " & json.StringOf("firstname") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("lastname") <> "", "Nachname: " & json.StringOf("lastname") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("info") <> "", "Info: " & json.StringOf("info") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("id") <> "", "Timas-ID: " & json.StringOf("id") & vbNewLine, "")
|
|
If json.BoolOf("loginActive") Then
|
|
info &= IIf(json.StringOf("login") <> "", "Login: " & json.StringOf("login") & vbNewLine, "")
|
|
info &= IIf(json.StringOf("password") <> "", "PW: " & json.StringOf("password"), "")
|
|
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 Function getEmployee(mitarbeiterID As String) As cTimasEmployee
|
|
|
|
Try
|
|
|
|
If Not checkConnectionTImas("") Then
|
|
Return Nothing
|
|
End If
|
|
|
|
Dim responseJson As String = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & mitarbeiterID)
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
Return Nothing
|
|
End If
|
|
|
|
If (rest.ResponseStatusCode <> 200) Then
|
|
Debug.WriteLine(rest.ResponseHeader)
|
|
MsgBox(rest.ResponseStatusCode & " " & rest.ResponseStatusText)
|
|
Return Nothing
|
|
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
|
|
|
|
|
|
Dim emp As New cTimasEmployee()
|
|
|
|
emp.ID = json.StringOf("id")
|
|
emp.externid = json.StringOf("externid")
|
|
emp.pnr1 = json.StringOf("pnr1")
|
|
emp.pnr2 = json.StringOf("pnr2")
|
|
emp.firstname = json.StringOf("firstname")
|
|
emp.lastname = json.StringOf("lastname")
|
|
emp.gender = json.StringOf("gender")
|
|
emp.clientNumber = json.StringOf("clientNumber")
|
|
emp.card = json.StringOf("card")
|
|
emp.info = json.StringOf("info")
|
|
emp.rfid = json.StringOf("rfid")
|
|
emp.login = json.StringOf("login")
|
|
emp.email = json.StringOf("email")
|
|
emp.loginActive = json.BoolOf("loginActive")
|
|
emp.password = json.StringOf("password")
|
|
|
|
emp.street = json.StringOf("street")
|
|
emp.zipcode = json.StringOf("zipcode")
|
|
emp.city = json.StringOf("city")
|
|
emp.phone1 = json.StringOf("phone1")
|
|
emp.phone2 = json.StringOf("phone2")
|
|
|
|
Debug.WriteLine(json.StringOf("birthday"))
|
|
|
|
|
|
If (json.StringOf("birthday") <> "null") Then
|
|
emp.birthdayDate = CDate(json.StringOf("birthday")).ToString("yyyy-MM-dd")
|
|
End If
|
|
|
|
If (json.StringOf("entry") <> "null") Then
|
|
emp.entryDate = CDate(json.StringOf("entry")).ToString("yyyy-MM-dd")
|
|
End If
|
|
|
|
If (json.StringOf("exit") <> "null") Then
|
|
emp.exitDate = CDate(json.StringOf("exit")).ToString("yyyy-MM-dd")
|
|
End If
|
|
|
|
Dim groups As Chilkat.JsonArray = json.ArrayOf("groups")
|
|
If (json.LastMethodSuccess = False) Then
|
|
Debug.WriteLine("groups member not found.")
|
|
End If
|
|
|
|
emp.Gruppen = New List(Of cTimasGruppe)
|
|
Dim numGroups As Integer = groups.Size
|
|
Dim i As Integer = 0
|
|
While i < numGroups
|
|
Dim TIMASGroups As New cTimasGruppe(emp.ID)
|
|
TIMASGroups.Id = groups.IntAt(i)
|
|
emp.Gruppen.Add(TIMASGroups)
|
|
i = i + 1
|
|
End While
|
|
|
|
|
|
Debug.WriteLine(json)
|
|
|
|
Return emp
|
|
|
|
Catch ex As WebException
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
End Function
|
|
|
|
|
|
Public Function updateEmployee(emp As cTimasEmployee, dgvGroups As DataGridView) As Boolean
|
|
|
|
Try
|
|
|
|
Dim success As Boolean
|
|
|
|
If True Then
|
|
|
|
|
|
If Not checkConnectionTImas("") Then
|
|
Return Nothing
|
|
End If
|
|
|
|
Dim json As New Chilkat.JsonObject
|
|
|
|
|
|
success = json.UpdateString("externid", emp.externid)
|
|
success = json.UpdateString("pnr1", emp.pnr1)
|
|
success = json.UpdateString("pnr2", emp.pnr2)
|
|
success = json.UpdateString("firstname", emp.firstname)
|
|
success = json.UpdateString("lastname", emp.lastname)
|
|
success = json.UpdateString("gender", emp.gender)
|
|
|
|
success = json.UpdateString("card", emp.card)
|
|
success = json.UpdateString("info", emp.info)
|
|
success = json.UpdateString("rfid", emp.rfid)
|
|
success = json.UpdateString("login", emp.login)
|
|
success = json.UpdateString("email", emp.email)
|
|
success = json.UpdateBool("loginActive", emp.loginActive)
|
|
success = json.UpdateString("password", emp.password)
|
|
|
|
success = json.UpdateString("street", emp.street)
|
|
success = json.UpdateString("city", emp.city)
|
|
success = json.UpdateString("phone1", emp.phone1)
|
|
success = json.UpdateString("phone2", emp.phone2)
|
|
|
|
If IsDate(emp.birthdayDate) Then
|
|
success = json.UpdateString("birthday", CDate(emp.birthdayDate).ToString("yyyy-MM-dd"))
|
|
Else
|
|
success = json.UpdateString("birthday", "")
|
|
End If
|
|
|
|
If IsDate(emp.entryDate) Then
|
|
success = json.UpdateString("entry", CDate(emp.entryDate).ToString("yyyy-MM-dd"))
|
|
Else
|
|
success = json.UpdateString("entry", "")
|
|
End If
|
|
|
|
If IsDate(emp.exitDate) Then
|
|
success = json.UpdateString("exit", CDate(emp.exitDate).ToString("yyyy-MM-dd"))
|
|
Else
|
|
success = json.UpdateString("exit", "")
|
|
End If
|
|
|
|
|
|
Dim sbRequestBody As New Chilkat.StringBuilder
|
|
json.EmitSb(sbRequestBody)
|
|
|
|
Dim sbResponseBody As New Chilkat.StringBuilder
|
|
success = rest.FullRequestSb("PUT", "/rest/web-api/employees/" & emp.ID, sbRequestBody, sbResponseBody)
|
|
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
Return Nothing
|
|
End If
|
|
|
|
If (rest.ResponseStatusCode <> 201) Then
|
|
Debug.WriteLine(rest.ResponseHeader)
|
|
MsgBox(rest.ResponseStatusCode & " " & rest.ResponseStatusText & vbNewLine & sbResponseBody.ToString)
|
|
Return Nothing
|
|
End If
|
|
|
|
Debug.WriteLine(sbResponseBody)
|
|
End If
|
|
|
|
If dgvGroups IsNot Nothing AndAlso dgvGroups.RowCount > 0 AndAlso emp.Gruppen IsNot Nothing Then
|
|
|
|
|
|
|
|
For Each r As DataGridViewRow In dgvGroups.Rows
|
|
For Each i As cTimasGruppe In emp.Gruppen
|
|
If r.Cells("set").Value = False AndAlso r.Cells("id").Value = i.Id Then
|
|
deleteGroupmembers(i.Id, emp.ID)
|
|
Exit For
|
|
ElseIf r.Cells("set").Value = True AndAlso r.Cells("id").Value <> i.Id Then
|
|
addGroupmembers(r.Cells("id").Value, emp.ID)
|
|
Exit For
|
|
|
|
End If
|
|
|
|
Next
|
|
Next
|
|
|
|
End If
|
|
|
|
Return success
|
|
|
|
Catch ex As WebException
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
End Function
|
|
|
|
Public Sub getAllGroups(ByRef dt As DataTable, Optional initialGroup As Boolean = True)
|
|
|
|
Try
|
|
|
|
Dim failureText As String = ""
|
|
If Not checkConnectionTImas(failureText) 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
|
|
|
|
If dt IsNot Nothing And Not dt.Columns.Contains("id") Then
|
|
|
|
dt.Columns.Add("id", GetType(Integer))
|
|
dt.Columns.Add("name", GetType(String))
|
|
dt.Columns.Add("groupType", GetType(String))
|
|
dt.Columns.Add("info", GetType(String))
|
|
dt.Columns.Add("set", GetType(Boolean))
|
|
|
|
While j < num
|
|
|
|
Dim groups As Chilkat.JsonObject = jsonArray.ObjectAt(j)
|
|
|
|
Dim R As DataRow = dt.NewRow
|
|
R("id") = groups.IntOf("id")
|
|
R("name") = groups.StringOf("name")
|
|
R("groupType") = groups.StringOf("groupType")
|
|
R("info") = groups.StringOf("info")
|
|
If initialGroup = True Then
|
|
If R("id") = "19" Or R("id") = "129" Then 'Typ Mitarbeiter und Standardgruppe für Mitarbeiter Default true
|
|
R("set") = True
|
|
Else
|
|
R("set") = False
|
|
End If
|
|
End If
|
|
dt.Rows.Add(R)
|
|
j = j + 1
|
|
End While
|
|
|
|
dt.DefaultView.Sort = " groupType asc, name asc"
|
|
dt = dt.DefaultView.ToTable()
|
|
|
|
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 getGroupsFromEmployee(ByRef dt As DataTable)
|
|
|
|
Try
|
|
|
|
Dim failureText As String = ""
|
|
If Not checkConnectionTImas(failureText) 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
|
|
|
|
If dt IsNot Nothing And Not dt.Columns.Contains("id") Then
|
|
|
|
dt.Columns.Add("id", GetType(Integer))
|
|
dt.Columns.Add("name", GetType(String))
|
|
dt.Columns.Add("groupType", GetType(String))
|
|
dt.Columns.Add("info", GetType(String))
|
|
dt.Columns.Add("set", GetType(Boolean))
|
|
|
|
While j < num
|
|
|
|
Dim groups As Chilkat.JsonObject = jsonArray.ObjectAt(j)
|
|
|
|
Dim R As DataRow = dt.NewRow
|
|
R("id") = groups.IntOf("id")
|
|
R("name") = groups.StringOf("name")
|
|
R("groupType") = groups.StringOf("groupType")
|
|
R("info") = groups.StringOf("info")
|
|
If R("id") = "19" Or R("id") = "129" Then 'Typ Mitarbeiter und Standardgruppe für Mitarbeiter Default true
|
|
R("set") = True
|
|
Else
|
|
R("set") = False
|
|
End If
|
|
dt.Rows.Add(R)
|
|
j = j + 1
|
|
End While
|
|
|
|
dt.DefaultView.Sort = " groupType asc, name asc"
|
|
dt = dt.DefaultView.ToTable()
|
|
|
|
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 addGroupmembers(ByVal groupID As Integer, ByVal maId As Integer)
|
|
|
|
Try
|
|
|
|
Dim success As Boolean
|
|
Dim jarr As New Chilkat.JsonArray
|
|
jarr.AddIntAt(-1, maId)
|
|
|
|
Dim sbRequestBody As New Chilkat.StringBuilder
|
|
jarr.EmitSb(sbRequestBody)
|
|
|
|
Dim sbResponseBody As New Chilkat.StringBuilder
|
|
|
|
success = rest.FullRequestSb("POST", "/rest/web-api/groups/" & groupID & "/addmembers", sbRequestBody, sbResponseBody)
|
|
If (success <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
|
|
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 deleteGroupmembers(ByVal groupID As Integer, ByVal maId As Integer)
|
|
|
|
Try
|
|
|
|
Dim success As Boolean
|
|
Dim jarr As New Chilkat.JsonArray
|
|
jarr.AddIntAt(-1, maId)
|
|
|
|
Dim sbRequestBody As New Chilkat.StringBuilder
|
|
jarr.EmitSb(sbRequestBody)
|
|
|
|
Dim sbResponseBody As New Chilkat.StringBuilder
|
|
|
|
success = rest.FullRequestSb("POST", "/rest/web-api/groups/" & groupID & "/removemembers", sbRequestBody, sbResponseBody)
|
|
If (success <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
|
|
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 Function setTimeEntry(ByVal mitarbeiter As cMitarbeiter, ByVal timeEntry As DateTime, ByRef info As String, ByRef inout As String, Optional ByRef art As Integer = 0)
|
|
Dim failureText As String = ""
|
|
Dim timeEntryCreated As Boolean = False
|
|
|
|
If Not checkConnectionTImas(failureText) Then
|
|
Return timeEntryCreated
|
|
End If
|
|
|
|
If Not mitarbeiter.mit_timasId > 0 Then
|
|
info = "Mitarbeiter besitzt keine Timas-Zuordnung"
|
|
Return timeEntryCreated
|
|
End If
|
|
|
|
Dim entryType As String
|
|
|
|
Select Case inout
|
|
Case "in"
|
|
entryType = "KOMMT"
|
|
|
|
Case "out"
|
|
entryType = "GEHT"
|
|
|
|
Case Else
|
|
entryType = "falscher ErfassgsTyp: " & inout
|
|
info = entryType
|
|
Return timeEntryCreated
|
|
End Select
|
|
|
|
|
|
Dim json As New Chilkat.JsonObject
|
|
json.UpdateString("stamp", timeEntry.ToString("yyyy-MM-ddTHH:mm:ss"))
|
|
json.UpdateInt("statusnumber", art) '0 Standardanwesenheit, 3 Homeoffice, 6 Postgang
|
|
json.UpdateString("type", inout)
|
|
json.UpdateString("employeeid", mitarbeiter.mit_timasId)
|
|
|
|
Dim sbRequestBody As New Chilkat.StringBuilder
|
|
json.EmitSb(sbRequestBody)
|
|
|
|
Dim sbResponseBody As New Chilkat.StringBuilder
|
|
Dim success = rest.FullRequestSb("POST", "/rest/web-api/bookings", sbRequestBody, sbResponseBody)
|
|
If (success <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
Return timeEntryCreated
|
|
End If
|
|
|
|
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
info = rest.LastErrorText
|
|
Return timeEntryCreated
|
|
End If
|
|
|
|
If (rest.ResponseStatusCode <> 200) Then
|
|
Debug.WriteLine(rest.ResponseHeader)
|
|
info = rest.ResponseStatusCode & " " & rest.ResponseStatusText
|
|
If sbResponseBody.GetAsString <> "" Then
|
|
info &= vbNewLine & sbResponseBody.GetAsString
|
|
End If
|
|
Return timeEntryCreated
|
|
Else
|
|
|
|
info = "Zeiteintrag " & entryType & " angelegt! " & timeEntry.ToString("HH:mm:ss")
|
|
|
|
'Dim jsonResult As New Chilkat.JsonObject
|
|
'success = jsonResult.LoadSb(sbResponseBody)
|
|
'jsonResult.Emit()
|
|
timeEntryCreated = True
|
|
|
|
End If
|
|
|
|
Return timeEntryCreated
|
|
|
|
|
|
End Function
|
|
|
|
Public Function getEmployeeList(ByRef dt As DataTable) As String
|
|
|
|
Dim failureText As String = ""
|
|
|
|
Try
|
|
|
|
If Not checkConnectionTImas(failureText) Then
|
|
Return failureText
|
|
|
|
End If
|
|
|
|
Dim responseJson As String = rest.FullRequestNoBody("GET", "/rest/web-api/employees/")
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
Return rest.LastErrorText
|
|
End If
|
|
|
|
If (rest.ResponseStatusCode <> 200) Then
|
|
Debug.WriteLine(rest.ResponseHeader)
|
|
failureText = rest.ResponseStatusCode & " " & rest.ResponseStatusText
|
|
Return rest.ResponseStatusCode & " " & rest.ResponseStatusText
|
|
End If
|
|
|
|
Debug.WriteLine(responseJson)
|
|
|
|
Dim jsonArray As New Chilkat.JsonArray
|
|
Dim success As Boolean = jsonArray.Load(responseJson)
|
|
If (success <> True) Then
|
|
Debug.WriteLine(jsonArray.LastErrorText)
|
|
Return jsonArray.LastErrorText
|
|
End If
|
|
|
|
|
|
Dim num As Integer = jsonArray.Size
|
|
If num = -1 Then
|
|
Return "Array Failure"
|
|
End If
|
|
|
|
If dt IsNot Nothing AndAlso Not dt.Columns.Contains("Id") Then
|
|
dt.Columns.Add("Id", GetType(Integer))
|
|
'dt.Columns.Add("externid", GetType(String))
|
|
dt.Columns.Add("Personal-Nr (Lohn)", GetType(String))
|
|
dt.Columns.Add("Vorname", GetType(String))
|
|
dt.Columns.Add("Nachname", GetType(String))
|
|
dt.Columns.Add("Geschlecht", GetType(String))
|
|
dt.Columns.Add("Ausweis-Nr", GetType(Integer))
|
|
dt.Columns.Add("Info", GetType(String))
|
|
End If
|
|
|
|
dt.Clear()
|
|
|
|
Dim j As Integer = 0
|
|
While j < num
|
|
|
|
Dim employee As Chilkat.JsonObject = jsonArray.ObjectAt(j)
|
|
|
|
Dim R As DataRow = dt.NewRow
|
|
R("Id") = employee.IntOf("id")
|
|
'("externid") = employee.StringOf("externid")
|
|
R("Personal-Nr (Lohn)") = employee.StringOf("pnr1")
|
|
R("Vorname") = employee.StringOf("firstname")
|
|
R("Nachname") = employee.StringOf("lastname")
|
|
R("Geschlecht") = employee.StringOf("gender")
|
|
R("Ausweis-Nr") = employee.IntOf("card")
|
|
R("Info") = employee.StringOf("info")
|
|
dt.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 Function
|
|
|
|
|
|
End Class
|
|
|
|
Public Class cTimasEmployee
|
|
|
|
Public ID As Integer
|
|
Public externid As String
|
|
Public pnr1 As String 'ID für Lohnprogramm
|
|
Public pnr2 As String
|
|
Public firstname As String
|
|
Public lastname As String
|
|
Public gender As String
|
|
Public clientNumber As String
|
|
Public rfid As String
|
|
Public card As Integer
|
|
Public info As String
|
|
Public login As String
|
|
Public email As String
|
|
Public loginActive As Boolean
|
|
Public password As String
|
|
|
|
Public street As String
|
|
Public city As String
|
|
Public zipcode As String
|
|
Public phone1 As String
|
|
Public phone2 As String
|
|
|
|
Public birthdayDate As String
|
|
Public entryDate As String
|
|
Public exitDate As String
|
|
|
|
Public Gruppen As List(Of cTimasGruppe)
|
|
|
|
Sub New()
|
|
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class cTimasGruppe
|
|
|
|
Public empID As Integer
|
|
Public Id As Integer
|
|
Public name As String
|
|
Public groupType As String
|
|
Public info As String
|
|
|
|
Sub New(empId)
|
|
Me.empID = empId
|
|
End Sub
|
|
|
|
|
|
|
|
End Class |