Imports DD_LIB_Standards Imports DevExpress.XtraEditors Imports DevExpress.XtraEditors.Controls Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Imports DigitalData.Controls.RegexEditor Public Class ctrlApplicationAssignment Public AppSelectionString As String Private Current_ProfileId As Integer Private Current_WindowId As Integer Private Current_ProcessGUID As Integer Private Sub ctrlApplicationAssignment_Load(sender As Object, e As EventArgs) Handles Me.Load TBCW_PROFILE_PROCESSTableAdapter.Connection.ConnectionString = MyConnectionString TBCW_PROF_REL_WINDOWTableAdapter.Connection.ConnectionString = MyConnectionString TBCW_PROF_REL_CONTROLTableAdapter.Connection.ConnectionString = MyConnectionString AddHandler RepositoryItemRegexEdit.ButtonClick, AddressOf RepositoryItemRegexEdit_Click AddHandler RepositoryItemButtonEdit1.ButtonClick, AddressOf RepositoryItemRegexEdit_Click End Sub Public Function AssignProfileID(ProfileId As Integer) As Boolean Try Current_ProfileId = ProfileId Return True Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Process_Load(ProfileId As Integer) As Boolean Try TBCW_PROFILE_PROCESSTableAdapter.Fill(MyDataset.TBCW_PROFILE_PROCESS, ProfileId) Return True Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Process_CreateAssignment(ProfileId As Integer) As Boolean Dim oForm As New frmProcessCapture() Dim oResult = oForm.ShowDialog() If oResult = DialogResult.OK Then Try Dim oWindowTitle As String = GetSQLFriendlyString(oForm.WindowTitle) Dim oProcessName As String = oForm.ProcessName If oProcessName <> "" Then Dim oSQL = String.Format("INSERT INTO TBCW_PROFILE_PROCESS (PROFILE_ID,PROC_NAME,ADDED_WHO) VALUES ({0},'{1}','{2}')", ProfileId, oProcessName, Environment.UserName) If Database.ExecuteNonQuery(oSQL) = False Then Return False Else Dim oNewProcessId = Database.GetScalarValue("SELECT MAX(GUID) FROM TBCW_PROFILE_PROCESS") oSQL = String.Format("INSERT INTO TBCW_PROF_REL_WINDOW (DESCRIPTION, REGEX, ADDED_WHO, PROCESS_ID) VALUES ('{0}', '^{1}$', '{2}' ,{3})", oWindowTitle, oWindowTitle, Environment.UserName, oNewProcessId) If Database.ExecuteNonQuery(oSQL) = False Then Return False End If End If End If Process_Load(Current_ProfileId) Return True Catch ex As Exception Logger.Error(ex) Return False End Try End If End Function Public Function Process_DeleteAssignment() As Boolean Try Dim oProcessId = GridViewProcessProfile.GetFocusedRowCellValue(GridViewProcessProfile.Columns("GUID")) Dim oSQL = String.Format("EXEC PRCW_DELETE_PROCESS {0}", oProcessId) If Database.ExecuteNonQuery(oSQL) Then Process_Load(Current_ProfileId) Return True End If Return False Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Window_Load() As Boolean Try TBCW_PROF_REL_WINDOWTableAdapter.Fill(MyDataset.TBCW_PROF_REL_WINDOW, CURRENT_PROCESSID) Return True Catch ex As Exception Logger.Error(ex) Return False End Try End Function Private Sub RepositoryItemRegexEdit_Click(sender As Object, e As ButtonPressedEventArgs) Dim oButtonEdit As ButtonEdit = sender Dim oGridControl As GridControl = oButtonEdit.Parent Dim oGridView As GridView = oGridControl.FocusedView Dim oRowHandle As Integer = oGridView.FocusedRowHandle Dim oForm As New frmRegexEditor(oButtonEdit.EditValue) If oForm.ShowDialog() = DialogResult.OK Then oButtonEdit.EditValue = oForm.RegexString End If Console.WriteLine() End Sub Public Function Window_CreateAssignment(ProfileId As Integer) As Boolean Dim oForm As New frmProcessCapture() Dim oResult = oForm.ShowDialog() If oResult = DialogResult.OK Then Try Dim oWindowTitle As String = GetSQLFriendlyString(oForm.WindowTitle) Dim oProcessName As String = oForm.ProcessName If oWindowTitle <> "" Then Dim insert = String.Format("INSERT INTO TBCW_PROF_REL_WINDOW (DESCRIPTION, REGEX, ADDED_WHO,PROCESS_ID) VALUES ('{0}', '^{1}$','{2}',{3})", oWindowTitle, oWindowTitle, Environment.UserName, CURRENT_PROCESSID) If Database.ExecuteNonQuery(insert) = False Then Return False End If End If Window_Load() Return True Catch ex As Exception Logger.Error(ex) Return False End Try End If End Function Public Function Window_DeleteAssignment() As Boolean Try Dim oGuid = GridView_Window.GetFocusedRowCellValue(GridView_Window.Columns("GUID")) Dim oSQL = String.Format("EXEC PRCW_DELETE_WINDOW {0}", oGuid) If Database.ExecuteNonQuery(oSQL) Then Process_Load(Current_ProfileId) Return True End If Return False Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Window_SaveAssignment() As Boolean Try TBCW_PROF_REL_WINDOWBindingSource.EndEdit() GridView_Window.CloseEditor() If Not IsNothing(MyDataset.TBCW_PROF_REL_WINDOW.GetChanges) Then TBCW_PROF_REL_WINDOWBindingSource.EndEdit() TBCW_PROF_REL_WINDOWTableAdapter.Update(MyDataset.TBCW_PROF_REL_WINDOW) Return True End If Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Control_Load() As Boolean Try TBCW_PROF_REL_CONTROLTableAdapter.Fill(MyDataset.TBCW_PROF_REL_CONTROL, Current_WindowId) Return True Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Control_CreateAssignment() As Boolean Dim oForm As New frmControlCapture() Dim oResult = oForm.ShowDialog() If oResult = DialogResult.OK Then Try Dim oControlTitle As String = GetSQLFriendlyString(oForm.ControlName) Dim oProcessName As String = oForm.ProcessName Dim oAutomationId As String = oForm.AutomationId Dim oFrameworkId As String = oForm.FrameworkId Dim oDefaultRegex As String = "\.+" If oControlTitle <> "" Or oAutomationId <> "" Then Dim insert = String.Format("INSERT INTO TBCW_PROF_REL_CONTROL (WINDOW_ID, DESCRIPTION, AUTOMATION_ID, FRAMEWORK_ID, REGEX, ADDED_WHO) VALUES ({0}, '{1}', '{2}', '{3}', '^{4}$','{5}')", Current_WindowId, oControlTitle, oAutomationId, oFrameworkId, oDefaultRegex, Environment.UserName) If Database.ExecuteNonQuery(insert) = False Then Return False End If End If Control_Load() Return True Catch ex As Exception Logger.Error(ex) Return False End Try Else Return True End If End Function Public Function Control_SaveAssignment() As Boolean Try TBCW_PROF_REL_CONTROLBindingSource.EndEdit() GridView_Control.CloseEditor() If Not IsNothing(MyDataset.TBCW_PROF_REL_CONTROL.GetChanges) Then TBCW_PROF_REL_CONTROLBindingSource.EndEdit() TBCW_PROF_REL_CONTROLTableAdapter.Update(MyDataset.TBCW_PROF_REL_CONTROL) End If Return True Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function Control_DeleteAssignment() As Boolean Try Dim oGuid = GridView_Control.GetFocusedRowCellValue(GridView_Control.Columns("GUID")) Dim oSQL = String.Format("DELETE FROM TBCW_PROF_REL_CONTROL WHERE GUID = {0}", oGuid) If Database.ExecuteNonQuery(oSQL) Then Window_Load() Return True End If Return False Catch ex As Exception Logger.Error(ex) Return False End Try End Function 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") Dim oPRocessGUID = oSelectedRow.Item("GUID") AppSelectionString = $"Selected Profile: {oPRocessGUID}-{oProcessName}" CURRENT_PROCESSID = oPRocessGUID CURRENT_PROCESSNAME = oProcessName MyDataset.TBCW_PROF_REL_CONTROL.Clear() MyDataset.TBCW_PROF_REL_WINDOW.Clear() If Window_Load() = False Then MsgBox($"Error while loading windows for process {oProcessName}", vbCritical, "") End If End Sub Private Function GetSQLFriendlyString(UnfriendlyString As String) As String Return UnfriendlyString. Trim(). Replace(vbNullChar, "") End Function Private Sub GridView_Window_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles GridView_Window.FocusedRowChanged Try If e.FocusedRowHandle < 0 Then Exit Sub End If Dim oSelectedRow As DataRow = GridView_Window.GetDataRow(e.FocusedRowHandle) Dim oWindowId As String = oSelectedRow.Item("GUID") Current_WindowId = oWindowId AppSelectionString = AppSelectionString & $" / WindowID: {oWindowId}" If Control_Load() = False Then MsgBox($"Error while loading controls for window {oWindowId}", vbCritical, "") End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub GridView_Control_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles GridView_Control.FocusedRowChanged If e.FocusedRowHandle < 0 Then Exit Sub End If Dim oSelectedRow As DataRow = GridView_Control.GetDataRow(e.FocusedRowHandle) Dim oControlGUID = oSelectedRow.Item("GUID") AppSelectionString = AppSelectionString & $" - Selected ControlGUID: {oControlGUID}" End Sub End Class