RecordOrganizer/app/DD-Record-Organizer/frmRight_Management.vb
2025-06-18 09:33:52 +02:00

315 lines
14 KiB
VB.net

Imports DD_Record_Organizer.ControlLoader
Public Class frmRight_Management
Private Shared _Instance As frmRight_Management = Nothing
Private insert As Boolean = False
Private formloaded As Boolean = False
Private updateIP As Boolean = False
Private ID_CURR As Integer = 0
Public Shared Function Instance() As frmRight_Management
If _Instance Is Nothing OrElse _Instance.IsDisposed = True Then
_Instance = New frmRight_Management
End If
_Instance.BringToFront()
Return _Instance
End Function
Private Sub Save_User_Rights_Data()
Try
Me.Validate()
'Me.TBPMO_RIGHT_USERBindingSource.EndEdit()
If DD_DMSDataSet.TBPMO_RIGHT_USER.GetChanges() Is Nothing = False Then
'Me.TBPMO_RIGHT_USERDataGridView.CurrentRow.Cells("colADDED_WHO").Value = USER_USERNAME
'Me.TBPMO_RIGHT_USERBindingSource.EndEdit()
'Me.TBPMO_RIGHT_USERTableAdapter.Update(DD_DMSDataSet.TBPMO_RIGHT_USER)
tschangedlabel.Text = "Right User changed - " & Now
tschangedlabel.Visible = True
Else
tschangedlabel.Visible = False
End If
Catch ex As Exception
MsgBox("Error in Save_User_Rights_Data:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub frmGroup_Rights_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Refresh_Entities()
Try
Me.TBWH_USER_GROUPSTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
Me.TBWH_USER_GROUPSTableAdapter.Fill(Me.DD_ECMAdmin.TBWH_USER_GROUPS)
'Me.TBDD_USER_GROUPSTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
'Me.TBDD_USER_GROUPSTableAdapter.Fill(Me.DD_DMSDataSet.TBDD_USER_GROUPS)
Me.TBDD_GROUPSTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
Me.TBDD_GROUPSTableAdapter.Fill(Me.DD_ECMAdmin.TBDD_GROUPS)
Me.TBDD_USERTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
Me.TBDD_USERTableAdapter.Fill(Me.DD_DMSDataSet.TBDD_USER)
VWPMO_RIGHT_GROUPTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
Catch ex As Exception
MsgBox("Error in Loading Form:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
Refresh_Rights_Groups()
End Sub
Sub Refresh_Rights_Users(ENTITY_ID As Integer)
Try
USER_RIGHTSTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
Me.USER_RIGHTSTableAdapter.Fill(Me.DD_ECMAdmin.USER_RIGHTS, USER_LANGUAGE, ENTITY_ID)
Catch ex As Exception
MsgBox("Error loading users:" & vbNewLine & ex.Message)
End Try
End Sub
Sub Refresh_Rights_Groups()
Try
Me.VWPMO_RIGHT_GROUPTableAdapter.Fill(Me.DD_ECMAdmin.VWPMO_RIGHT_GROUP)
Catch ex As Exception
MsgBox("Error in Refresh_Rights_Groups:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Refresh_Entities()
Try
Me.TBWH_ENTITIESTableAdapter.Connection.ConnectionString = MYDB_ECM.CurrentConnectionString
Me.TBWH_ENTITIESTableAdapter.Fill(Me.DD_ECMAdmin.TBWH_ENTITIES, USER_LANGUAGE, 1, USER_GUID)
Catch ex As System.Exception
MsgBox("Error in Refresh_Entities:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub TBPMO_RIGHT_GROUPBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBPMO_RIGHT_GROUPBindingSource.AddingNew
Me.DD_DMSDataSet.TBPMO_RIGHT_GROUP.ADDED_WHOColumn.DefaultValue = USER_USERNAME
Me.DD_DMSDataSet.TBPMO_RIGHT_GROUP.ENTITY_IDColumn.DefaultValue = MYDB_ECM.GetScalarValue("SELECT MIN(GUID) FROM TBPMO_FORM")
End Sub
Private Sub TBPMO_RIGHT_GROUPBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBPMO_RIGHT_GROUPBindingSource.CurrentChanged
tschangedlabel.Visible = False
End Sub
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
updateIP = True
Refresh_Rights_Groups()
updateIP = False
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs)
Save_User_Rights_Data()
End Sub
Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click
Refresh_Rights_Users(cmbEntity.SelectedValue)
End Sub
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
Select Case TabControl1.SelectedIndex
Case 1
Dim sql = String.Format("select T1.FORM_ID, [dbo].[FNPMO_GETOBJECTCAPTION]('{0}','FORMVIEW_TITLE' + CONVERT(VARCHAR(5), T1.GUID), 1) AS 'FORM_TITLE' FROM TBPMO_FORM_VIEW T1 " &
"WHERE T1.SCREEN_ID = 1 ORDER BY T1.FORM_TITLE", USER_LANGUAGE)
Dim DT As DataTable = MYDB_ECM.GetDatatable(sql)
If Not IsNothing(DT) Then
cmbEntity.DataSource = DT
cmbEntity.DisplayMember = DT.Columns(1).ColumnName
cmbEntity.ValueMember = DT.Columns(0).ColumnName
End If
Refresh_Free_Users()
Refresh_Rights_Users(cmbEntity.SelectedValue)
End Select
End Sub
Sub Refresh_Free_Users()
Dim Sql = $"SELECT T.* FROM TBDD_USER T INNER JOIN TBDD_USER_MODULES T1 ON T.GUID = T1.USER_ID INNER JOIN TBDD_MODULES T2 ON T1.MODULE_ID = T2.GUID
WHERE T2.SHORT_NAME = 'ADDI' AND T.GUID NOT IN (SELECT USER_ID FROM TBPMO_RIGHT_USER WHERE ENTITY_ID = {cmbEntity.SelectedValue}) ORDER BY USERNAME"
Dim DT_USER = MYDB_ECM.GetDatatable(Sql)
Try
DD_ECMAdmin.TBAD_Users.Clear()
For Each row As DataRow In DT_USER.Rows
Dim newUserRow As DD_ECMAdmin.TBAD_UsersRow
newUserRow = DD_ECMAdmin.TBAD_Users.NewTBAD_UsersRow
newUserRow.Username = row.Item("USERNAME")
Try
newUserRow.Surname = row.Item("NAME")
Catch ex As Exception
newUserRow.Surname = ""
End Try
Try
newUserRow.Prename = row.Item("PRENAME")
Catch ex As Exception
newUserRow.Prename = ""
End Try
Try
newUserRow.Email = row.Item("EMAIL")
Catch ex As Exception
newUserRow.Email = ""
End Try
newUserRow.ID = row.Item("GUID")
DD_ECMAdmin.TBAD_Users.Rows.Add(newUserRow)
' chklbxUserForGroup.Items.Add(New MyListBoxItem() With {.Text = row.Item(1), .ExtraData = row.Item(0)})
Next
Catch ex As Exception
ClassHelper.MSGBOX_Handler("ERROR", "Error Refresh_Free_Users:", ex.Message)
End Try
End Sub
Private Sub cmbEntity_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbEntity.SelectedIndexChanged
If cmbEntity.SelectedIndex <> -1 Then
Try
Dim i As Integer = cmbEntity.SelectedValue
Catch ex As Exception
Exit Sub
End Try
Refresh_Free_Users()
Refresh_Rights_Users(cmbEntity.SelectedValue)
End If
End Sub
Private Sub btnAddUser2ConstructorREL_Click(sender As Object, e As EventArgs) Handles btnAddUser2ConstructorREL.Click
Try
Try
Dim i As Integer = cmbEntity.SelectedValue
Catch ex As Exception
Exit Sub
End Try
For Each row As DataRow In DD_ECMAdmin.TBAD_Users.Rows
If row.Item(0) = CBool(True) Then
Dim insert = String.Format("INSERT INTO TBPMO_RIGHT_USER (USER_ID,ENTITY_ID) VALUES ({0},{1})", row.Item(5), cmbEntity.SelectedValue)
If MYDB_ECM.ExecuteNonQuery(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 DD_ECMAdmin.TBAD_Users.Rows
row.Item(0) = CBool(False)
Next
Refresh_Free_Users()
Refresh_Rights_Users(cmbEntity.SelectedValue)
Catch ex As Exception
ClassHelper.MSGBOX_Handler("ERROR", "Error while adding user-rights:", ex.Message)
End Try
End Sub
Private Sub btndeleteUserRight_Click(sender As Object, e As EventArgs) Handles btndeleteUserRight.Click
Try
Dim ID = GridView1.GetFocusedRowCellValue(GridView1.Columns("GUID"))
Try
Dim I As Integer = CInt(ID)
Catch ex As Exception
ClassHelper.MSGBOX_Handler("ERROR", "Error while deleting rights:", ex.Message)
Exit Sub
End Try
Dim del = String.Format("DELETE FROM TBPMO_RIGHT_USER WHERE GUID = {0}", ID)
If MYDB_ECM.ExecuteNonQuery(del) = True Then
Refresh_Rights_Users(cmbEntity.SelectedValue)
Refresh_Free_Users()
End If
Catch ex As Exception
ClassHelper.MSGBOX_Handler("ERROR", "Unexpected error in deleting rights:", ex.Message)
End Try
End Sub
Private Sub GridView1_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles GridView1.CellValueChanged
Try
GridView1.EndSelection()
Dim column = e.Column.FieldName
Dim ID = GridView1.GetFocusedRowCellValue(GridView1.Columns("GUID"))
Try
Dim I As Integer = CInt(ID)
Catch ex As Exception
ClassHelper.MSGBOX_Handler("ERROR", "Error getting row-ID:", ex.Message)
Exit Sub
End Try
Dim int_bool As Integer
If e.Value.ToString = "True" Then
int_bool = 1
Else
int_bool = 0
End If
Dim upd = String.Format("UPDATE TBPMO_RIGHT_USER SET {0} = {1} WHERE GUID = {2}", column, int_bool, ID)
If MYDB_ECM.ExecuteNonQuery(upd) = False Then
ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", "Could not Update Right-details!")
statelbl.Text = ""
Else
statelbl.Text = "ID: " & ID.ToString & " - '" & e.Column.Caption.ToString & "' updated. - " & Now.ToString
End If
Catch ex As Exception
ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", "Error in grvwGridPos_CellValueChanged: ", ex.Message)
End Try
End Sub
Private Sub Update_RightGroup()
updateIP = True
ID_CURR = IDTextBox.Text
Dim oID = IDTextBox.Text
Dim oupdate = $"UPDATE TBPMO_RIGHT_GROUP SET EDIT_REC = '{EDIT_RECCheckBox.Checked}',
ADD_REC = '{ADD_RECCheckBox.Checked}',
DELETE_REC = '{DELETE_DOCCheckBox.Checked}',
ADD_DOC = '{ADD_DOCCheckBox.Checked}',
VIEW_DOC = '{VIEW_DOCCheckBox.Checked}',
DELETE_DOC = '{DELETE_DOCCheckBox.Checked}',
CHANGED_WHO = '{Environment.UserName}' WHERE GUID = {oID}"
If MYDB_ECM.ExecuteNonQuery(oupdate) Then
InfoLabel.Text = $"Group_Definition updated successfully - {Now.ToLongTimeString}"
Refresh_Rights_Groups()
VWPMO_RIGHT_GROUPBindingSource2.Position = VWPMO_RIGHT_GROUPBindingSource2.Find("ID", oID)
updateIP = False
End If
End Sub
Private Sub frmRight_Management_Shown(sender As Object, e As EventArgs) Handles Me.Shown
formloaded = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If cmbSicht.SelectedIndex <> -1 And cmbGroupNew.SelectedIndex <> -1 Then
Dim oinsert = $"INSERT INTO [dbo].[TBPMO_RIGHT_GROUP] ([ENTITY_ID],[GROUP_ID],[ADDED_WHO])
VALUES ({cmbSicht.SelectedValue},{cmbGroupNew.SelectedValue},'{Environment.UserName}')"
If MYDB_ECM.ExecuteNonQuery(oinsert) Then
InfoLabel.Text = $"New rightGroup Added successfully - {Now.ToLongTimeString}"
updateIP = True
Refresh_Rights_Groups()
updateIP = False
End If
End If
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
If MessageBox.Show("Do You really want to delete this relation", "Question", MessageBoxButtons.YesNo) _
= Windows.Forms.DialogResult.Yes Then
Dim odelete = $"DELETE FROM [dbo].[TBPMO_RIGHT_GROUP] WHERE GUID = {IDTextBox.Text}"
If MYDB_ECM.ExecuteNonQuery(odelete) Then
updateIP = True
Refresh_Rights_Groups()
updateIP = False
End If
End If
End Sub
Private Sub VWPMO_RIGHT_GROUPBindingSource2_PositionChanged(sender As Object, e As EventArgs) Handles VWPMO_RIGHT_GROUPBindingSource2.PositionChanged
If formloaded = False Then
Exit Sub
End If
Try
Dim oID = VWPMO_RIGHT_GROUPDataGridView.SelectedRows(0).Cells(0).Value
ID_CURR = oID
InfoLabel.Text = oID
Catch ex As Exception
InfoLabel.Text = ex.Message
End Try
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
If IDTextBox.Text <> "" Then
Update_RightGroup()
End If
End Sub
End Class