269 lines
10 KiB
VB.net
269 lines
10 KiB
VB.net
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
|
|
|
|
Private Current_ProfileId As Integer
|
|
Private Current_WindowId As Integer
|
|
Private Current_ProcessName As String
|
|
|
|
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 Process_Load(ProfileId As Integer) As Boolean
|
|
Try
|
|
Current_ProfileId = ProfileId
|
|
|
|
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
|
|
oSQL = String.Format("INSERT INTO TBCW_PROF_REL_WINDOW (PROFILE_ID, DESCRIPTION, PROCESS_NAME, REGEX, ADDED_WHO) VALUES ({0}, '{1}', '{2}','^{3}$','{4}')", ProfileId, oProcessName, oProcessName, oWindowTitle, Environment.UserName)
|
|
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_ProcessName, Current_ProfileId)
|
|
|
|
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 (PROFILE_ID, DESCRIPTION, PROCESS_NAME, REGEX, ADDED_WHO) VALUES ({0}, '{1}', '{2}','^{3}$','{4}')", ProfileId, oProcessName, oProcessName, oWindowTitle, Environment.UserName)
|
|
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("DELETE FROM TBCW_PROF_REL_WINDOW WHERE GUID = {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
|
|
GridView_Window.CloseEditor()
|
|
TBCW_PROF_REL_WINDOWBindingSource.EndEdit()
|
|
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)
|
|
End If
|
|
|
|
Return True
|
|
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_ProcessName, Current_WindowId, Current_ProfileId)
|
|
|
|
Return True
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Public Function Control_CreateAssignment(ProfileId As Integer) 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 (PROFILE_ID, DESCRIPTION, AUTOMATION_ID, FRAMEWORK_ID, PROCESS_NAME, REGEX, WINDOW_ID, ADDED_WHO) VALUES ({0}, '{1}', '{2}', '{3}', '{4}','^{5}$',{6},'{7}')", ProfileId, oControlTitle, oAutomationId, oFrameworkId, Current_ProcessName, oDefaultRegex, Current_WindowId, 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
|
|
GridView_Control.CloseEditor()
|
|
TBCW_PROF_REL_CONTROLBindingSource.EndEdit()
|
|
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")
|
|
Current_ProcessName = oProcessName
|
|
|
|
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
|
|
If e.FocusedRowHandle < 0 Then
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim oSelectedRow As DataRow = GridViewProcessProfile.GetDataRow(e.FocusedRowHandle)
|
|
Dim oWindowId As String = oSelectedRow.Item("GUID")
|
|
Current_WindowId = oWindowId
|
|
|
|
If Control_Load() = False Then
|
|
MsgBox($"Error while loading controls for window {oWindowId}", vbCritical, "")
|
|
End If
|
|
End Sub
|
|
End Class
|