2019-07-25 16:18:41 +02:00

420 lines
18 KiB
VB.net

Imports DD_LIB_Standards
Public Class frmAdministration
Private SelectedProcessName As String
Class ProfileType
Public Name As String
Public Id As Int16
Public Overrides Function ToString() As String
Return Name
End Function
End Class
Dim PID As Integer
Private Sub TBCW_PROFILESBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBCW_PROFILESBindingNavigatorSaveItem.Click
Save_Profile()
Me.TableAdapterManager.UpdateAll(Me.MyDataset)
End Sub
Sub Load_Profiles()
Try
TBCW_PROFILESTableAdapter.Connection.ConnectionString = MyConnectionString
TBCW_PROFILESTableAdapter.Fill(Me.MyDataset.TBCW_PROFILES)
Catch ex As Exception
MsgBox("Unexpected Error in Load Profiles: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Sub Load_ProfileTypes()
Dim oTypeNames As New Dictionary(Of Integer, String) From {
{0, "Dokumente und Daten"},
{1, "Nur Dokumente"},
{2, "Nur Daten"}
}
For Each oTypeName As KeyValuePair(Of Integer, String) In oTypeNames
Dim oRow = MyDataset.TBWH_PROFILE_TYPE.NewTBWH_PROFILE_TYPERow()
oRow.TYPE_ID = oTypeName.Key
oRow.TYPE_NAME = oTypeName.Value
MyDataset.TBWH_PROFILE_TYPE.Rows.Add(oRow)
Next
End Sub
Sub Save_Profile()
Try
Me.TBCW_PROFILESBindingSource.EndEdit()
If Not IsNothing(MyDataset.TBCW_PROFILES.GetChanges) Then
Me.CHANGED_WHOTextBox.Text = Environment.UserName
Me.TBCW_PROFILESBindingSource.EndEdit()
Me.TBCW_PROFILESTableAdapter.Update(MyDataset.TBCW_PROFILES)
Status_Changed("Profil gespeichert - " & Now.ToString, Color.Yellow)
Else
Status_Changed("Keine Änderung - " & Now.ToString, Color.Transparent)
End If
Catch ex As Exception
MsgBox("Unexpected Error in Save Profile: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub frmAdministration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Load_Profiles()
Load_ProfileTypes()
lbllicenseCount.Text = LICENSE_COUNT
If LICENSE_DATE.ToString.Contains("2099") Then
lblLicenseDate.Text = "Unlimited"
Else
lblLicenseDate.Text = LICENSE_DATE
End If
End Sub
Sub Status_Changed(text As String, col As System.Drawing.Color)
statuslabel.Text = text
statuslabel.BackColor = col
End Sub
Private Sub TBCW_PROFILESBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBCW_PROFILESBindingSource.AddingNew
MyDataset.TBCW_PROFILES.ADDED_WHOColumn.DefaultValue = Environment.UserName
MyDataset.TBCW_PROFILES.PROFILE_TYPEColumn.DefaultValue = 0
End Sub
Private Sub btnaddSearch_Click(sender As Object, e As EventArgs) Handles btnaddSearch.Click
If Not Me.WD_SEARCHTextBox.Text = "" Then
Me.OFDWindreamsuche.FileName = Me.WD_SEARCHTextBox.Text
End If
If Me.OFDWindreamsuche.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Me.WD_SEARCHTextBox.Text = Me.OFDWindreamsuche.FileName
End If
End Sub
Private Sub GUIDTextBox_TextChanged(sender As Object, e As EventArgs) Handles GUIDTextBox.TextChanged
If GUIDTextBox.Text <> "" Then
Refresh_ProfileData()
Refresh_Free_Users(GUIDTextBox.Text)
Refresh_Free_Groups(GUIDTextBox.Text)
Load_Profile_Process()
TBCW_PROF_DOC_SEARCHTableAdapter.Connection.ConnectionString = MyConnectionString
TBCW_PROF_DOC_SEARCHTableAdapter.Fill(MyDataset.TBCW_PROF_DOC_SEARCH, GUIDTextBox.Text)
TBCW_PROF_DATA_SEARCHTableAdapter.Connection.ConnectionString = MyConnectionString
TBCW_PROF_DATA_SEARCHTableAdapter.Fill(MyDataset.TBCW_PROF_DATA_SEARCH, GUIDTextBox.Text)
End If
End Sub
Sub Refresh_ProfileData()
Try
VWUSER_PROFILETableAdapter.Connection.ConnectionString = MyConnectionString
VWUSER_PROFILETableAdapter.Fill(MyDataset.VWUSER_PROFILE, GUIDTextBox.Text)
VWCW_GROUP_PROFILETableAdapter.Connection.ConnectionString = MyConnectionString
VWCW_GROUP_PROFILETableAdapter.Fill(MyDataset.VWCW_GROUP_PROFILE, GUIDTextBox.Text)
Catch ex As Exception
MsgBox("Unexpected Error in Refresh Profile User: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub btnAddUser2Profile_Click(sender As Object, e As EventArgs) Handles btnAddUserToProfile.Click
Try
Try
Dim i As Integer = CInt(GUIDTextBox.Text)
Catch ex As Exception
Exit Sub
End Try
For Each row As DataRow In MyDataset.TBWH_User.Rows
If row.Item(0) = CBool(True) Then
Dim insert = String.Format("INSERT INTO TBCW_USER_PROFILE (PROFILE_ID,USER_ID) VALUES ({0},{1})", GUIDTextBox.Text, row.Item(5))
If clsDatabase.Execute_non_Query(insert) = False Then
MsgBox("Could not insert the User-Definition....Check the logfile!", MsgBoxStyle.Exclamation)
End If
End If
Next
For Each row As DataRow In MyDataset.TBWH_User.Rows
row.Item(0) = CBool(False)
Next
If GUIDTextBox.Text <> "" Then
Refresh_Free_Users(GUIDTextBox.Text)
Refresh_ProfileData()
End If
Catch ex As Exception
MsgBox("Unexpected Error while adding user-rights: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Sub Refresh_Free_Users(PROFILE_ID As Integer)
Dim Sql = String.Format("SELECT DISTINCT * FROM VWDD_USER_MODULE_CW WHERE GUID NOT IN (SELECT USER_ID FROM TBCW_USER_PROFILE WHERE PROFILE_ID = {0}) ORDER BY USERNAME", PROFILE_ID)
Dim DT_USER = clsDatabase.Return_Datatable(Sql)
Try
MyDataset.TBWH_User.Clear()
For Each row As DataRow In DT_USER.Rows
Dim newUserRow As MyDataset.TBWH_UserRow
newUserRow = MyDataset.TBWH_User.NewTBWH_UserRow
newUserRow.Username = row.Item("USERNAME")
newUserRow.Surname = row.Item("NAME")
newUserRow.Prename = row.Item("PRENAME")
Try
newUserRow.Email = row.Item("EMAIL")
Catch ex As Exception
newUserRow.Email = ""
End Try
newUserRow.ID = row.Item("GUID")
MyDataset.TBWH_User.Rows.Add(newUserRow)
' chklbxUserForGroup.Items.Add(New MyListBoxItem() With {.Text = row.Item(1), .ExtraData = row.Item(0)})
Next
Catch ex As Exception
MsgBox("Unexpected Error in Refresh_Free_Users: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Sub Refresh_Free_Groups(PROFILE_ID As Integer)
Dim Sql = String.Format("SELECT DISTINCT * FROM TBDD_GROUPS WHERE GUID NOT IN (SELECT GROUP_ID FROM TBCW_GROUP_PROFILE WHERE PROFILE_ID = {0}) ORDER BY NAME", PROFILE_ID)
Dim oDataTable = clsDatabase.Return_Datatable(Sql)
Try
MyDataset.TBWH_GROUP.Clear()
For Each row As DataRow In oDataTable.Rows
Dim oNewRow As MyDataset.TBWH_GROUPRow
oNewRow = MyDataset.TBWH_GROUP.NewTBWH_GROUPRow
oNewRow.NAME = row.Item("NAME")
oNewRow.ID = row.Item("GUID")
MyDataset.TBWH_GROUP.Rows.Add(oNewRow)
Next
Catch ex As Exception
MsgBox("Unexpected Error in Refresh_Free_Groups: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub btndeleteUserConstructorRel_Click(sender As Object, e As EventArgs) Handles btnRemoveUserFromProfile.Click
Try
Dim ID = GridViewUserInProfile.GetFocusedRowCellValue(GridViewUserInProfile.Columns("GUID"))
Try
Dim I As Integer = CInt(ID)
Catch ex As Exception
Exit Sub
End Try
Dim del = String.Format("DELETE FROM TBCW_USER_PROFILE WHERE GUID = {0}", ID)
If clsDatabase.Execute_non_Query(del) = True Then
Refresh_ProfileData()
If GUIDTextBox.Text <> "" Then
Refresh_Free_Users(GUIDTextBox.Text)
End If
End If
Catch ex As Exception
MsgBox("Unexpected Error in deleting ProfileUserRelation: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Load_Profile_Process()
Try
If IsNothing(GUIDTextBox.Text) Or GUIDTextBox.Text = "" Then
Exit Sub
End If
Me.TBCW_PROFILE_PROCESSTableAdapter.Connection.ConnectionString = MyConnectionString
Me.TBCW_PROFILE_PROCESSTableAdapter.Fill(Me.MyDataset.TBCW_PROFILE_PROCESS, GUIDTextBox.Text)
Catch ex As System.Exception
MsgBox("Unexpected Error in Load_Profile_Process: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub WD_SEARCHTextBox_MouseHover(sender As Object, e As EventArgs) Handles WD_SEARCHTextBox.MouseHover
ToolTip1.SetToolTip(WD_SEARCHTextBox, "Replace patterns for string fields: " & vbNewLine & "@Clipboard" & vbNewLine & "@CLIPBOARD" & vbNewLine & "@Zwischenablage" &
vbNewLine & "Replace patterns for integer fields: " & vbNewLine & "123456789" & vbNewLine & "4711")
ToolTip1.ToolTipTitle = "Replace patterns:"
ToolTip1.IsBalloon = True
ToolTip1.ToolTipIcon = ToolTipIcon.Info
ToolTip1.UseAnimation = True
End Sub
Private Sub frmAdministration_Shown(sender As Object, e As EventArgs) Handles Me.Shown
If GUIDTextBox.Text = "" Then
Refresh_Free_Users(0)
Refresh_Free_Groups(0)
End If
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
Dim swl = String.Format("EXEC PRCW_DELETE_PROFILE {0}", GUIDTextBox.Text)
Dim result As MsgBoxResult = MsgBox("Sind Sie sicher, dass Sie das Profil löschen wollen?", MsgBoxStyle.YesNo, "Bestätigung erforderlich:")
' wenn Speichern ja
If result = MsgBoxResult.Yes Then
If clsDatabase.Execute_non_Query(swl) = True Then
Load_Profiles()
End If
End If
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Load_Profiles()
Refresh_ProfileData()
Try
Dim ID = CInt(GUIDTextBox.Text)
Catch ex As Exception
Exit Sub
End Try
Refresh_Free_Users(GUIDTextBox.Text)
Refresh_Free_Groups(GUIDTextBox.Text)
End Sub
Private Sub TBCW_PROF_DATA_SEARCHBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBCW_PROF_DATA_SEARCHBindingSource.AddingNew
MyDataset.TBCW_PROF_DATA_SEARCH.ADDED_WHOColumn.DefaultValue = Environment.UserName
MyDataset.TBCW_PROF_DATA_SEARCH.PROFILE_IDColumn.DefaultValue = GUIDTextBox.Text
MyDataset.TBCW_PROF_DATA_SEARCH.CONN_IDColumn.DefaultValue = 1
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
Try
TBCW_PROF_DATA_SEARCHBindingSource.EndEdit()
If Not IsNothing(MyDataset.TBCW_PROF_DATA_SEARCH.GetChanges) Then
CHANGED_WHOTextBox1.Text = Environment.UserName
TBCW_PROF_DATA_SEARCHBindingSource.EndEdit()
TBCW_PROF_DATA_SEARCHTableAdapter.Update(MyDataset.TBCW_PROF_DATA_SEARCH)
End If
Catch ex As Exception
MsgBox("Unexpected Error in Save Data Search: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
Try
TBCW_PROF_DOC_SEARCHBindingSource.EndEdit()
If Not IsNothing(MyDataset.TBCW_PROF_DOC_SEARCH.GetChanges) Then
CHANGED_WHOTextBox2.Text = Environment.UserName
TBCW_PROF_DOC_SEARCHBindingSource.EndEdit()
TBCW_PROF_DOC_SEARCHTableAdapter.Update(MyDataset.TBCW_PROF_DOC_SEARCH)
End If
Catch ex As Exception
MsgBox("Unexpected Error in Save Data Search: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub btnAddGroupToProfile_Click(sender As Object, e As EventArgs) Handles btnAddGroupToProfile.Click
Try
Dim oSelectedGroups = GridViewGroupNotInProfile.GetSelectedRows()
For Each oRowHandle In oSelectedGroups
Dim oRow As MyDataset.TBWH_GROUPRow = DirectCast(GridViewGroupNotInProfile.GetRow(oRowHandle), DataRowView).Row
Dim oGroupId As Integer = oRow.ID
Dim oSQL As String = $"INSERT INTO TBCW_GROUP_PROFILE (PROFILE_ID,GROUP_ID) VALUES ({GUIDTextBox.Text},{oGroupId})"
If clsDatabase.Execute_non_Query(oSQL) = False Then
MsgBox("Could not insert the Group-Definition....Check the logfile!", MsgBoxStyle.Exclamation)
End If
Next
GridViewGroupNotInProfile.ClearSelection()
Refresh_Free_Groups(GUIDTextBox.Text)
Refresh_ProfileData()
Catch ex As Exception
MsgBox("Unexpected Error while adding Group-Rights: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub btnRemoveGroupFromProfile_Click(sender As Object, e As EventArgs) Handles btnRemoveGroupFromProfile.Click
Try
Dim oSelectedGroups = GridViewGroupInProfile.GetSelectedRows()
For Each oRowHandle In oSelectedGroups
Dim oRow As MyDataset.VWCW_GROUP_PROFILERow = DirectCast(GridViewGroupInProfile.GetRow(oRowHandle), DataRowView).Row
Dim oGroupId As Integer = oRow.GUID
Dim oSQL As String = $"DELETE FROM TBCW_GROUP_PROFILE WHERE GUID = ({oGroupId})"
If clsDatabase.Execute_non_Query(oSQL) = False Then
MsgBox("Could not delete the Group-Definition....Check the logfile!", MsgBoxStyle.Exclamation)
End If
Next
GridViewGroupInProfile.ClearSelection()
Refresh_Free_Groups(GUIDTextBox.Text)
Refresh_ProfileData()
Catch ex As Exception
MsgBox("Unexpected Error in deleting Group-Rights: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub ToolStripButton6_Click(sender As Object, e As EventArgs) Handles ToolStripButton6.Click
Dim oForm As New frmProcessCapture()
Dim oResult = oForm.ShowDialog()
If oResult = DialogResult.OK Then
Try
Dim oProcessName As String = oForm.ProcessName
If oProcessName <> "" Then
Dim insert = String.Format("INSERT INTO TBCW_PROFILE_PROCESS (PROFILE_ID,PROC_NAME,ADDED_WHO) VALUES ({0},'{1}','{2}')", GUIDTextBox.Text, oProcessName, Environment.UserName)
If clsDatabase.Execute_non_Query(insert) = False Then
MsgBox("Could not insert the Process-Profile-Link....Check the logfile!", MsgBoxStyle.Exclamation)
End If
End If
Load_Profile_Process()
clsHotkey.Refresh_Profile_Links()
Catch ex As Exception
MsgBox("Unexpected Error while adding Process-Profile-link: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End If
End Sub
Private Sub ToolStripButton5_Click(sender As Object, e As EventArgs) Handles ToolStripButton5.Click
Try
Dim oGuid = GridViewProcessProfile.GetFocusedRowCellValue(GridViewProcessProfile.Columns("GUID"))
Dim oSQL = String.Format("DELETE FROM TBCW_PROFILE_PROCESS WHERE GUID = {0}", oGuid)
If clsDatabase.Execute_non_Query(oSQL) Then
Load_Profile_Process()
End If
Catch ex As Exception
MsgBox("Unexpected Error in deleting ProfileProcess-Relation: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub GridViewProcessProfile_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridViewProcessProfile.FocusedRowChanged
If e.FocusedRowHandle < 0 Then
Exit Sub
End If
Dim oSelectedRow As DataRow = GridViewProcessProfile.GetDataRow(e.FocusedRowHandle)
Dim oProcessName As String = oSelectedRow.Item("PROC_NAME")
SelectedProcessName = oProcessName
TBCW_PROF_REL_WINDOWTableAdapter.Connection.ConnectionString = MyConnectionString
TBCW_PROF_REL_WINDOWTableAdapter.Fill(MyDataset.TBCW_PROF_REL_WINDOW, SelectedProcessName, GUIDTextBox.Text)
End Sub
Private Sub ToolStripButton7_Click(sender As Object, e As EventArgs) Handles ToolStripButton7.Click
Try
TBCW_PROF_REL_WINDOWBindingSource.EndEdit()
If Not IsNothing(MyDataset.TBCW_PROF_REL_WINDOW.GetChanges) Then
CHANGED_WHOTextBox3.Text = Environment.UserName
TBCW_PROF_REL_WINDOWBindingSource.EndEdit()
TBCW_PROF_REL_WINDOWTableAdapter.Update(MyDataset.TBCW_PROF_REL_WINDOW)
End If
TBCW_PROF_REL_WINDOWTableAdapter.Fill(MyDataset.TBCW_PROF_REL_WINDOW, SelectedProcessName, GUIDTextBox.Text)
Catch ex As Exception
MsgBox("Unexpected Error in Save Profile: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub TBCW_PROF_REL_WINDOWBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBCW_PROF_REL_WINDOWBindingSource.AddingNew
MyDataset.TBCW_PROF_REL_WINDOW.ADDED_WHOColumn.DefaultValue = Environment.UserName
MyDataset.TBCW_PROF_REL_WINDOW.PROFILE_IDColumn.DefaultValue = GUIDTextBox.Text
MyDataset.TBCW_PROF_REL_WINDOW.PROCESS_NAMEColumn.DefaultValue = SelectedProcessName
End Sub
End Class