Public Class frmMenuDesigner

    Private Sub frmMenuDesigner_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.TBPMO_FORMTableAdapter.Connection.ConnectionString = MyConnectionString
        Me.TBPMO_MENU_FORMTableAdapter.Connection.ConnectionString = MyConnectionString
        Me.TBPMO_MENU_FORM_ENTRIESTableAdapter.Connection.ConnectionString = MyConnectionString


        Me.TBPMO_FORMTableAdapter.FillByAll(Me.DD_DMSDataSet.TBPMO_FORM)
        'Me.TBPMO_MENU_FORM_ENTRIESTableAdapter.Fill(Me.DD_DMSDataSetMenuDesigner.TBPMO_MENU_FORM_ENTRIES)
        Me.TBPMO_MENU_FORMTableAdapter.Fill(Me.DD_DMSDataSetMenuDesigner.TBPMO_MENU_FORM)
    End Sub

    Private Sub MenuBindingSource_PositionChanged(sender As Object, e As EventArgs) Handles MenuBindingSource.PositionChanged
        RefreshMenuEntries()
    End Sub

    Private Sub RefreshMenuEntries()
        Dim guid As Integer = MenuBindingSource.Item(MenuBindingSource.Position).Item("GUID")
        Me.TBPMO_MENU_FORM_ENTRIESTableAdapter.FillBy(DD_DMSDataSetMenuDesigner.TBPMO_MENU_FORM_ENTRIES, guid)
    End Sub

    Private Sub dgvForm_MouseDown(sender As Object, e As MouseEventArgs) Handles dgvForm.MouseDown
        Dim i As Integer
        i = dgvForm.CurrentRow.Index

        If dgvForm.Item(0, i).Value Is Nothing = False Then
            Dim p As Integer
            p = dgvForm.CurrentRow.Index

            Me.dgvForm.DoDragDrop(dgvForm.Item(0, i).Value.ToString, DragDropEffects.Copy)
        End If
    End Sub

    Private Sub dgvMenuEntry_DragEnter(sender As Object, e As DragEventArgs) Handles dgvMenuEntry.DragEnter
        ' Check the format of the data being dropped. 
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            ' Display the copy cursor. 
            e.Effect = DragDropEffects.Copy
        Else
            ' Display the no-drop cursor. 
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub dgvMenuEntry_DragDrop(sender As Object, e As DragEventArgs) Handles dgvMenuEntry.DragDrop
        Try
            Dim FormID = e.Data.GetData(DataFormats.Text)
            Dim MenuID = MenuBindingSource.Item(MenuBindingSource.Position).Item("GUID")
            Dim Name = FormBindingSource.Item(FormBindingSource.Position).Item("NAME")

            If IsNothing(FormID) = False Then
                TBPMO_MENU_FORM_ENTRIESTableAdapter.Insert(MenuID, FormID, "", Name, 1, Environment.UserName, Date.Now, Nothing, Nothing)
                RefreshMenuEntries()
            End If
        Catch ex As Exception
            MsgBox("Error in Save dgvMenuEntry_DragDrop:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    
    Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
        Try
            Me.MenuBindingSource.EndEdit()
            If DD_DMSDataSetMenuDesigner.TBPMO_MENU_FORM.GetChanges() Is Nothing = False Then
                Me.MenuBindingSource.EndEdit()
                Me.TBPMO_MENU_FORMTableAdapter.Update(DD_DMSDataSetMenuDesigner)
                MsgBox("Changes saved successfully.", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox("Error in Save Form_Menu:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
        Try
            Me.MenuEntryBindingSource.EndEdit()
            If DD_DMSDataSetMenuDesigner.TBPMO_MENU_FORM_ENTRIES.GetChanges() Is Nothing = False Then
                Me.MenuEntryBindingSource.EndEdit()
                Me.TBPMO_MENU_FORM_ENTRIESTableAdapter.Update(DD_DMSDataSetMenuDesigner)
                MsgBox("Changes saved successfully.", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox("Error in Save Form_Menu_Entries:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
End Class