REST-API Timas
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
|
||||
Imports System.DirectoryServices
|
||||
Imports System.Globalization
|
||||
Imports System.IO
|
||||
Imports System.Net
|
||||
Imports System.Net.Http
|
||||
Imports System.Net.WebRequestMethods
|
||||
Imports System.Security.Policy
|
||||
Imports System.Text
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Windows
|
||||
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel
|
||||
Imports DAKOSY_Worker.DEERRE
|
||||
Imports GrapeCity.ActiveReports.ReportsCore.Tools
|
||||
Imports GrapeCity.Enterprise.Data.Expressions.Evaluation
|
||||
Imports itextsharp.text.pdf.codec.wmf
|
||||
Imports Microsoft.VisualBasic.ApplicationServices
|
||||
Imports Newtonsoft.Json
|
||||
Imports VERAG_PROG_ALLGEMEIN
|
||||
@@ -272,6 +274,7 @@ Public Class frmMitarbDetails
|
||||
cboAbteilung.changeItem(mitarbeiter.mit_abteilung)
|
||||
cboPosition.Text = mitarbeiter.mit_position
|
||||
txtDurchwahl.Text = mitarbeiter.mit_durchwahl
|
||||
txtTelNr.Text = mitarbeiter.mit_telefonnr
|
||||
txtEmail.Text = mitarbeiter.mit_email
|
||||
txtMobiltel.Text = mitarbeiter.mit_mobiltel
|
||||
cbxAnrufen.Checked = mitarbeiter.mit_allowAnruf
|
||||
@@ -281,6 +284,7 @@ Public Class frmMitarbDetails
|
||||
txtTelotecSB.Text = mitarbeiter.mit_TELOTEC_SB
|
||||
txtCSUser.Text = mitarbeiter.mit_CSuser
|
||||
txtCSPW.Text = mitarbeiter.mit_CSpwd
|
||||
txtPersonalNr.Text = mitarbeiter.mit_PersonalNr
|
||||
|
||||
cboALIASDomain.changeItem(mitarbeiter.mit_AliasAD_Domain)
|
||||
txtALIASUser.Text = mitarbeiter.mit_AliasAD_Username
|
||||
@@ -847,7 +851,27 @@ Public Class frmMitarbDetails
|
||||
End If
|
||||
|
||||
ZOLLDATENBEARB = True
|
||||
ElseIf tbcntr.SelectedIndex = 3 Then
|
||||
|
||||
If IsNothing(mitarbeiter.mit_timasId) Then
|
||||
cbxTimasAngelegt.Checked = False
|
||||
|
||||
If Not cbxTimasAngelegt.Checked Then
|
||||
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)
|
||||
initDGV(dt)
|
||||
End If
|
||||
|
||||
Else
|
||||
'txtPersonalNr.Enabled = False
|
||||
cbxTimasAngelegt.Checked = True
|
||||
End If
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
|
||||
@@ -1019,11 +1043,12 @@ Public Class frmMitarbDetails
|
||||
If (isFilled(de.Properties("company").Value)) Then de.Properties("company").Value = cboFirma.SelectedValue
|
||||
If (isFilled(de.Properties("sn").Value)) Then de.Properties("sn").Value = txtNname.Text
|
||||
If (isFilled(de.Properties("mail").Value)) Then de.Properties("mail").Value = txtEmail.Text
|
||||
|
||||
If (isFilled(de.Properties("streetAdress").Value)) Then de.Properties("streetAdress").Value = txtStrasse.Text
|
||||
If (isFilled(de.Properties("postalCode").Value)) Then de.Properties("postalCode").Value = txtPlz.Text
|
||||
If (isFilled(de.Properties("I").Value)) Then de.Properties("I").Value = txtOrt.Text
|
||||
If (isFilled(de.Properties("Mobile").Value)) Then de.Properties("Mobile").Value = txtMobiltel.Text
|
||||
If (isFilled(de.Properties("mobile").Value)) Then de.Properties("mobile").Value = txtMobiltel.Text
|
||||
If (isFilled(de.Properties("telephoneNumber").Value)) Then de.Properties("telephoneNumber").Value = txtTelNr.Text
|
||||
If (isFilled(de.Properties("otherTelephone").Value)) Then de.Properties("otherTelephone").Value = txtDurchwahl.Text
|
||||
|
||||
If cbxGekuendigt.Checked Then
|
||||
Dim expire As DateTime = datGekuendigtAm.Value
|
||||
@@ -1043,15 +1068,25 @@ Public Class frmMitarbDetails
|
||||
If txtStrasse.Text = "" Then txtStrasse.Text = de.Properties("streetAdress").Value
|
||||
If txtPlz.Text = "" Then txtPlz.Text = de.Properties("postalCode").Value
|
||||
If txtOrt.Text = "" Then txtOrt.Text = de.Properties("I").Value
|
||||
If txtMobiltel.Text = "" Then txtMobiltel.Text = de.Properties("Mobile").Value
|
||||
If txtDurchwahl.Text = "" Then txtDurchwahl.Text = de.Properties("telephoneNumber").Value
|
||||
If txtMobiltel.Text = "" Then txtMobiltel.Text = de.Properties("mobile").Value
|
||||
If txtDurchwahl.Text = "" Then txtDurchwahl.Text = de.Properties("otherTelephone").Value
|
||||
If txtALIASUser.Text = "" Then txtALIASUser.Text = de.Properties("sAMAccountName").Value
|
||||
If txtEmailExtension.Text = "" Then txtEmailExtension.Text = de.Properties("extensionAttribute7").Value
|
||||
Dim phoneNr = de.Properties("telephoneNumber").Value
|
||||
If phoneNr <> "" Then
|
||||
|
||||
Dim pattern = "-.*" 'enfernt alle zeichen nach -
|
||||
Dim myString = Regex.Replace(phoneNr, pattern, "")
|
||||
pattern = "DW.*" 'enfernt alle zeichen nach DW
|
||||
myString = Regex.Replace(myString, pattern, "")
|
||||
If txtTelNr.Text = "" Then txtTelNr.Text = myString.Trim()
|
||||
|
||||
End If
|
||||
|
||||
'cboALIASDomain.changeItem(frmAD.activeDirectoryObj.domain)
|
||||
'cboAbteilung.changeItem(frmAD.setNoNullableValue(frmAD.activeDirectoryObj.ADEntry.Properties("department").Value))
|
||||
'cboNiederlassung.changeItem(frmAD.setNoNullableValue(frmAD.activeDirectoryObj.ADEntry.Properties("company").Value))
|
||||
|
||||
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -1084,6 +1119,309 @@ 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
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub btngetInfo_Click(sender As Object, e As EventArgs) Handles btngetInfo.Click
|
||||
If Not cbxTimasAngelegt.Checked Then
|
||||
rtfInfoTimas.Text = "Mitarbeiter nicht im Timas angelegt!"
|
||||
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 &= "Name: " & json.StringOf("firstname") & " " & json.StringOf("lastname")
|
||||
|
||||
|
||||
Catch ex As WebException
|
||||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub cbxTimasAngelegt_CheckedChanged(sender As Object, e As EventArgs) Handles cbxTimasAngelegt.CheckedChanged
|
||||
|
||||
txtPersonalNr.Enabled = Not cbxTimasAngelegt.Checked
|
||||
btnMAanlegen.Enabled = Not cbxTimasAngelegt.Checked
|
||||
btngetInfo.Enabled = cbxTimasAngelegt.Checked
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Function checkMandatoryFields() As Boolean
|
||||
|
||||
|
||||
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
|
||||
MsgBox("Einstiegsdatum darf nicht vor 01.01.2000 liegen!")
|
||||
Return False
|
||||
End If
|
||||
|
||||
ElseIf 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
|
||||
|
||||
End Function
|
||||
|
||||
Sub initDGV(dt As DataTable)
|
||||
|
||||
dgvData.DataSource = dt
|
||||
|
||||
If dgvData.Columns.Count > 0 Then
|
||||
With dgvData
|
||||
.RowHeadersWidth = 10
|
||||
.Columns("id").Visible = False
|
||||
.Columns("name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
|
||||
.Columns("info").Width = 50
|
||||
.Columns("set").Width = 20
|
||||
.Columns("set").HeaderText = "X"
|
||||
|
||||
End With
|
||||
|
||||
|
||||
End If
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user