Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Base Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid.ViewInfo Imports DigitalData.Modules.Logging Public Class frmAdmin_IDBBERelations Private GridCursorLocation As Point Private SELECTED_BEID As Integer Private SELECTED_FREE_ATTRID As Integer Private SELECTED_ID2DELETE As Integer Private DraggedAttributeID Private DragDropManager As ClassDragDrop = Nothing Private downHitInfo As GridHitInfo = Nothing Private Logger As Logger Private Function GetAvailableAttributesByBEID(beID As Integer) As DataTable Try Dim dt As DataTable Dim oSQL = $"SELECT AttributeID,Attribute,AttributeType FROM VWIDB_ATTRIBUTE_LANG WHERE LANG_CODE = '{My.Application.User.Language}' AND AttributeID NOT IN (SELECT ATTR_ID FROM TBIDB_BE_ATTRIBUTE WHERE BE_ID = {beID})" dt = My.DatabaseIDB.GetDatatable(oSQL) Return dt Catch ex As Exception ShowErrorMessage($"Error in GetAvailableAttributesByBEID with groupId {beID}", ex) Return Nothing End Try End Function Private Function GetRelatedAttributesByBEID(beID As Integer) As DataTable Try Dim dt As DataTable Dim oSQL = $"select GUID as RelID, ATTR_TITLE as Attribute, [TYPE_NAME] as [AttributeType] FROM VWIDB_BE_ATTRIBUTE WHERE BE_ID = {beID} and LANG_CODE = '{My.Application.User.Language}'" dt = My.DatabaseIDB.GetDatatable(oSQL) Return dt Catch ex As Exception ShowErrorMessage($"Error in GetAvailableAttributesByBEID with groupId {beID}", ex) Return Nothing End Try End Function Private Sub ShowErrorMessage(errorText As String, ex As Exception) MsgBox(errorText & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical, "BE Relations") End Sub Private Sub frmAdmin_IDBBERelations_Load(sender As Object, e As EventArgs) Handles Me.Load Try Logger = My.LogConfig.GetLogger() Dim oSQL = "Select Guid As ID,TITLE As BusinessEntity from TBIDB_BUSINESS_ENTITY" Dim oDT As DataTable = My.DatabaseIDB.GetDatatable(oSQL) GridControlBusinessEntities.DataSource = oDT DragDropManager = New ClassDragDrop(My.LogConfig) DragDropManager.AddGridView(GridViewFreeAttributes) DragDropManager.AddGridView(GridViewRelatedAttributes) LoadFreeAttributes() LoadRelatedAttributes() Catch ex As Exception ShowErrorMessage($"Error in FormLoad", ex) End Try End Sub Private Sub GridViewBusinessEntities_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridViewBusinessEntities.FocusedRowChanged Dim oBEID = GridViewBusinessEntities.GetFocusedRowCellValue(GridViewBusinessEntities.Columns("ID")) SELECTED_BEID = oBEID LoadFreeAttributes() LoadRelatedAttributes() End Sub Sub LoadRelatedAttributes() Dim oDT = GetRelatedAttributesByBEID(SELECTED_BEID) If Not IsNothing(oDT) Then GridControlAttributesRelated.DataSource = oDT End If End Sub Sub LoadFreeAttributes() Dim oDT = GetAvailableAttributesByBEID(SELECTED_BEID) If Not IsNothing(oDT) Then GridControlFreeAttributes.DataSource = oDT End If End Sub Private Sub GridControlFreeAttributes_DragDrop(sender As Object, e As DragEventArgs) Handles GridControlFreeAttributes.DragDrop Try Dim data As String = e.Data.GetData(DataFormats.Text) Dim AttrID As Integer = data.Split("|")(0) If AddAttr2BE(AttrID, SELECTED_BEID) Then Dim oDT = GetRelatedAttributesByBEID(SELECTED_BEID) If Not IsNothing(oDT) Then GridControlAttributesRelated.DataSource = Nothing GridControlAttributesRelated.DataSource = oDT End If End If Catch ex As Exception Logger.Error(ex) MsgBox(ex.Message, MsgBoxStyle.Critical, "Error Adding AttrID:") End Try End Sub Public Function AddAttr2BE(AttrId As Integer, BeId As Integer) As Boolean Try Dim oSQL = $" INSERT INTO TBIDB_BE_ATTRIBUTE (BE_ID,ATTR_ID,ADDED_WHO) VALUES ({BeId},{AttrId},'{My.Application.User.UserName}') " Return My.DatabaseIDB.ExecuteNonQuery(oSQL) Catch ex As Exception Logger.Error(ex) Return False End Try End Function Public Function DeleteAttrfromBE(ID As Integer) As Boolean Try Dim oSQL = $"DELETE FROM TBIDB_BE_ATTRIBUTE WHERE GUID = {ID}" Return My.DatabaseIDB.ExecuteNonQuery(oSQL) Catch ex As Exception Logger.Error(ex) Return False End Try End Function Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles btnAddAttribute.Click SELECTED_FREE_ATTRID = 0 GetFreeAttributeID() If SELECTED_FREE_ATTRID <> 0 Then If AddAttr2BE(SELECTED_FREE_ATTRID, SELECTED_BEID) Then LoadFreeAttributes() LoadRelatedAttributes() Show_bsiInfo("Attribute related") End If Else Show_bsiInfo("Error in AttributeRelation - No AttributeID") End If End Sub Private Sub GetFreeAttributeID() Dim oID = GridViewFreeAttributes.GetFocusedRowCellValue(GridViewFreeAttributes.Columns("AttributeID")) SELECTED_FREE_ATTRID = oID End Sub Private Sub GetRelatedAttributeGUID() Dim oID = GridViewRelatedAttributes.GetFocusedRowCellValue(GridViewRelatedAttributes.Columns("RelID")) SELECTED_ID2DELETE = oID End Sub Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles btnRemoveAttribute.Click SELECTED_ID2DELETE = 0 GetRelatedAttributeGUID() If SELECTED_ID2DELETE <> 0 Then If DeleteAttrfromBE(SELECTED_ID2DELETE) Then LoadFreeAttributes() LoadRelatedAttributes() SELECTED_ID2DELETE = 0 Show_bsiInfo("Attribute removed") End If Else Show_bsiInfo("Error in RemoveAttribute - No ID") End If End Sub Sub Show_bsiInfo(pInfo As String) bsiInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Always bsiInfo.Caption = pInfo & " - " & Now.ToString End Sub Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick Me.Close() End Sub End Class