Rest-API WIKI, Mitarbeiter kopieren Rechte übernehmen

This commit is contained in:
2023-06-28 16:55:54 +02:00
parent 4466dc259e
commit 6ce26b0614
6 changed files with 255 additions and 18 deletions

View File

@@ -1,7 +1,10 @@
Imports System.ComponentModel
Imports GrapeCity.Viewer.Common.Model
Imports VERAG_PROG_ALLGEMEIN
Imports VERAG_PROG_ALLGEMEIN.TESTJSON
Imports System.Net
Imports System.Text
Imports System.Windows.Controls
Imports VERAG_PROG_ALLGEMEIN.cChilkat_Helper
Public Class usrCntlMitarbeiter
@@ -13,6 +16,7 @@ Public Class usrCntlMitarbeiter
Private Anzahl As Integer
Private locZeilen As Integer = -1
Public mid As Integer = -1
Dim FUNC = New cProgramFunctions
Private Sub uctrlMitarbeiter_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ConnStr = frmMain.ConnStr
@@ -54,7 +58,7 @@ Public Class usrCntlMitarbeiter
Dim sql As String = "SELECT mit_id,mit_username,mit_vname, mit_nname ,mit_niederlassung,mit_abteilung,mit_email,mit_durchwahl,mit_gekuendigt FROM tblMitarbeiter WHERE (mit_firma='" & firma & "' OR (mit_firma='ALL' AND mit_FirmaHaupt='" & firma & "' )) "
Dim sql As String = "SELECT mit_id,mit_username,mit_vname, mit_nname ,mit_niederlassung,mit_abteilung,mit_email,mit_durchwahl,mit_gekuendigt, isnull(mit_foto_DocId,'') as mit_foto_DocId FROM tblMitarbeiter WHERE (mit_firma='" & firma & "' OR (mit_firma='ALL' AND mit_FirmaHaupt='" & firma & "' )) "
If txtSuche.Text <> "" Then
sql &= " AND (mit_username LIKE '%" & txtSuche.Text & "%' OR mit_nname LIKE '%" & txtSuche.Text & "%' OR mit_vname LIKE '%" & txtSuche.Text & "%') "
@@ -223,6 +227,8 @@ Public Class usrCntlMitarbeiter
.Columns(8).Width = 80
.Columns(8).HeaderText = "Gekündigt"
'.Columns(9).Visible = False
End With
End Sub
@@ -466,13 +472,202 @@ Public Class usrCntlMitarbeiter
Me.Cursor = Cursors.WaitCursor
Dim frmMitarbDetails As New frmMitarbDetails()
frmMitarbDetails.mid = id
frmMitarbDetails.Show(Me)
frmMitarbDetails.isUpdate = False
frmMitarbDetails.txtVname.Text = "Kopie von" & frmMitarbDetails.txtVname.Text
frmMitarbDetails.Label1.Text = "Mitarbeiterkopie"
frmMitarbDetails.txtPwd.Text = ""
frmMitarbDetails.txtCSPW.Text = ""
frmMitarbDetails.txtVname.Text = "Kopie von " & frmMitarbDetails.txtVname.Text
frmMitarbDetails.Label48.Text = "00"
Me.Cursor = Cursors.Default
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Try
Me.Cursor = Cursors.WaitCursor
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Dim sqlstr As String = "SELECT '|' + mit_vname + '|' + mit_nname + '|' + isnull(mit_niederlassung,'-') + '|' + isnull(mit_abteilung,'-') + '|' + isnull(mit_email,'-') + '|' + isnull(mit_durchwahl,'-') + '|' + CASE WHEN mit_firma='ALL' THEN mit_firmaHaupt ELSE mit_firma + '|' END as Firma FROM tblMitarbeiter WHERE mit_gekuendigt=0 AND [mit_TESTonly]=0 AND [mit_pseudoUser]=0 And isnull(mit_niederlassung,'')<>'' and isnull(mit_abteilung,'')<>'' and isnull(mit_nname,'') <>'' And isnull(mit_vname,'') <>'' Order by mit_id"
Dim sqlstrpic As String = "SELECT isnull(mit_foto_DocId,0) as MAfoto FROM tblMitarbeiter WHERE mit_gekuendigt=0 AND [mit_TESTonly]=0 AND [mit_pseudoUser]=0 And isnull(mit_niederlassung,'') <>'' and isnull(mit_abteilung,'')<>'' and isnull(mit_nname,'') <>'' And isnull(mit_vname,'') <>'' Order by mit_id"
Dim dt As DataTable = SQL.loadDgvBySql_Param(sqlstr, "ADMIN")
Dim dt2 As DataTable = SQL.loadDgvBySql_Param(sqlstrpic, "ADMIN")
dt2.Columns.Add("path", GetType(String))
For Each row As DataRow In dt2.Rows
Dim filename As String
If row.Item("MAfoto") > 0 Then
Dim filePath = New StringBuilder()
Dim file = VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(row(0))
Dim filenameFull = New IO.FileInfo(file).Name.ToLower
filePath.Append("|![")
filePath.Append(filenameFull)
filePath.Append("](/mitarbeiterfotos/")
filePath.Append(filenameFull)
filePath.Append(" =150x150)") 'Bildgröße
filename = filePath.ToString
Else
filename = "|-"
End If
row.Item("path") = filename
Next
Dim content = New StringBuilder()
content.Append("|Foto|Name|Nachname|Niederlassung|Abteilung|EMail|Telefonnummer|Firma|" & vbNewLine)
content.Append("|-|-|-|-|-|-|-|-|" & vbNewLine)
For Each row As DataRow In dt.Rows
Dim index = dt.Rows.IndexOf(row)
content.Append(dt2.Rows(index).Item("path"))
content.Append(row(0))
content.Append(vbNewLine)
Next
content.Append("{.interactive-table}")
Dim data As New DataObject()
data.SetData(DataFormats.Text, content)
Clipboard.SetDataObject(data)
Me.Cursor = Cursors.Default
MsgBox("Daten in Zwischenablage gespeichert")
Catch ex As Exception
MsgBox(ex.Message & ex.StackTrace)
Me.Cursor = Cursors.Default
End Try
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Me.Cursor = Cursors.WaitCursor
Dim token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGkiOjEsImdycCI6MSwiaWF0IjoxNjg3OTMzNDU3LCJleHAiOjE3MTk0OTEwNTcsImF1ZCI6InVybjp3aWtpLmpzIiwiaXNzIjoidXJuOndpa2kuanMifQ.ul2loFYVHdco2Ia2LcS4nme4PdgcuU6QKrunucECebX5LhcsSyuEg-lKiP2X3JXW57Ym4oCBjamDd5-5uqbQd9hOQ5CDO6yqK2r8TPNxivK29oAl2wfcHaKOe7QNti0yRlMpomJjc_5qaegeeLjN5w-lYbbqtSz_6y8GkPPr0P3l4coIk5IzngGazj8XLYGGN6y5qT4s8IR0sNhfz0hJAlIeVTeFKl8KFZMpFKvBnOjkL0GYOYjrHzPLSUAhe8hCGVcA7rWsweVjjvOclFDDFwZ0SwOY0TZqvz-LOsZ3V7ucQaT3flAjuHiEhODGJguQRBs67U8lVO2cxbJJyR3FUA"
Dim dgv As New DataGridView
If TabControl1.SelectedIndex = 0 Then
dgv = dgvVERAG
ElseIf TabControl1.SelectedIndex = 1 Then
dgv = dgvATILLA
ElseIf TabControl1.SelectedIndex = 2 Then
dgv = dgvIMEX
ElseIf TabControl1.SelectedIndex = 3 Then
dgv = dgvUNISPED
ElseIf TabControl1.SelectedIndex = 4 Then
dgv = dgvAMBAR
ElseIf TabControl1.SelectedIndex = 5 Then
dgv = dgvFRONTOFFICE
ElseIf TabControl1.SelectedIndex = 5 Then
dgv = dgvVERIMEX
End If
For Each row As DataGridViewRow In dgv.Rows
Dim test As Boolean = False
If row.Cells("mit_foto_DocId").Value > 0 Then
Dim file = VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(row.Cells("mit_foto_DocId").Value)
Dim succeess = uploadPictureToWiki(token, 4, file)
test = True
End If
Next
Me.Cursor = Cursors.Default
Try
Catch ex As Exception
Me.Cursor = Cursors.Default
MsgBox(ex.Message & ex.StackTrace)
End Try
End Sub
Private Function uploadPictureToWiki(authenticationToken As String, folderIDx As Integer, image As String) As String
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim API_STRING = "https://wiki.verag.ag"
Dim rest As New Chilkat.Rest
Dim success As Boolean
Dim failureDesc As String
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)
failureDesc = rest.LastErrorText
Return failureDesc
End If
API_STRING &= "/u"
rest.AddHeader("Authorization", "Bearer " & authenticationToken)
rest.AddHeader("Content-Type", "multipart/form-data")
Dim filename = New IO.FileInfo(image).Name
Dim fileStream As New Chilkat.Stream
fileStream.SourceFile = image
rest.PartSelector = "1"
rest.AddHeader("Content-Disposition", "form-data; name=""mediaUpload""")
rest.AddHeader("Content-Type", "text")
Dim json As New Chilkat.JsonObject
success = json.AddIntAt(-1, "folderId", folderIDx)
Debug.WriteLine(json.Emit())
success = rest.SetMultipartBodyString(json.Emit())
rest.PartSelector = "2"
rest.AddHeader("Content-Disposition", "form-data; name=""mediaUpload""; filename=""" & filename & """")
rest.AddHeader("Content-Type", "image/jpeg")
success = rest.SetMultipartBodyStream(fileStream)
Dim responseBody As String = rest.FullRequestMultipart("POST", API_STRING)
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Return rest.LastErrorText
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseHeader)
Return rest.ResponseStatusCode & " " & rest.ResponseStatusText
Else
Debug.WriteLine("File uploaded")
End If
rest.ClearAllHeaders()
rest.ClearAllParts()
rest.PartSelector = ""
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function
End Class