B4J Question Drag & Drop many panes

LucaMs

Expert
Licensed User
Longtime User
This question is meant to drive @stevel05 crazy 😄


With a lot of "hard work", I managed to modify his jDragAndDrop2 project so that a Pane is dragged onto another and the latter becomes its parent.

java_H5fCYrSEAP.gif


Having N Panes and wanting to move one of them, how do I detect on which of them I release the moved Pane?


Goal (not easy): use the native TreeView giving the user the ability to move nodes, modify the TreeView structure.
 
Last edited:

MicroDrie

Well-Known Member
Licensed User
Longtime User
I don't know how exactly you created the layout, nor how you detect drops, but for those initial panels you may be able to determine the order of which panel is being dragged based on a panel tag.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In the _DragDropped sub you can use e.GetEventTarget method to get the view that was dropped on.
I stopped at the first property that seemed the most suitable:
e.GetAcceptingObject
which returns a very strange thing.

e.GetEventTarget is very useful but the problem remains that you have to set MakeDragSource and MakeDragTarget for a single DragAndDrop object.

I'm afraid I should create a DragAndDrop object for every existing node pair. :(
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I'm afraid I should create a DragAndDrop object for every existing node pair
Yes a daunting task indeed. The most straightforward way to achieve this, although by no means simple, would be to create a Cell Factory for the Treeview and handle that in there.

You would need to delve into Java to achieve this method.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
would be to create a Cell Factory for the Treeview and handle that in there.

You would need to delve into Java to achieve this method.
Thanks, but I should study for about 88 days (just because I like the number 88) 😄

I could try using my library:
https://www.b4x.com/android/forum/threads/b4x-b4xlib-lmb4xpermutations.165073/#content

but I still don't know if it would work, detecting everything, which DragAndDrop object is "running", which nodes and who knows what else.

By the way, I should do the first test on a TreeView, directly setting the source and target node.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I could not get the base node of a TreeItem (I assume it exists).

So I'll have to create a TreeView from scratch.
I had forgotten that I have to create a TreeView anyway from scratch, because I want it to have another type of view in addition to the nodes (branches-leaves), which allows me to place "AND" or "OR" between branches and/or leaves.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Video


I have a form with a variable number of listviews which get loaded with a variable number of Jobs which are dragged on to the listviews and inserted at the location of the job they are dropped on. Additionally each job can be dragged (drug?) to a different location on the same LV or to another LV. I will post some of the code and if you have any questions post them here and I will answer them when I can. Perhaps some of this will give you inspiration.
Note, I used listviews as I recall because trying to figure out CLVs AND Horizontal was more complicated. This a B$J only project.
note that the MakeDragSource and MakeDragTarget are the last things done. As I recall it just didn't work right if I did it early:
            Do While Crsr.NextRow = True
                P = MachinesMap.Get(Crsr.GetString("SchM_Machine"))
                If P.IsInitialized Then  'if not initialized then we are not doing this machine
                    Dim M As Map
                    DADMod.FillJobMap(Crsr, M, False)
                    LV = P.GetView(1)
                    M.Put("ListView", LV)
                    LV.Items.Add(FormatOpData(M))
                End If
                #If Debug
                    zx=zx+1 'for testing
'                    Sleep(0)
'                    Log(LV.PrefWidth)
                #End If
            Loop


Sub FormatOpData(MP As Map) As Node
'    TXTFL.SetColor(xui.col)
    TXTFL.Reset
    TXTFL.Append(MP.Get("Jb_Part_Num")).SetUnderline(True).Append(CRLF)
    TXTFL.Append(MP.Get("Os_JobNum")).SetFont(xui.CreateDefaultBoldFont(14)).Append(" Rel ").Append(MP.Get("Os_ReleaseNum"))
    TXTFL.Append(" Seq ").Append(NumberFormat(MP.Get("Os_SeqNum"), 1, 0)).Append(CRLF)
    Dim FC As Int = 0
    DateTime.DateFormat = "MM/dd/yy"
    If 0 = MP.Get("Os_HoursTodate") Then
        If DateTime.DateParse(IIf(DADMod.IsDate(MP.Get("Os_StartbyDate")), MP.Get("Os_StartbyDate"), "01/01/2000")) < DateTime.Now Then   '5/20/22 -IIF for invalid dates
            FC = xui.Color_Red
        Else
            FC = DADMod.GoGreen
        End If
    Else If DateTime.DateParse(IIf(DADMod.IsDate(MP.Get("Os_FinishbyDate")), MP.Get("Os_FinishbyDate"), "01/01/2000")) < DateTime.Now Then   '5/20/22 -IIF for invalid dates
        FC = xui.Color_Yellow
    End If
    DateTime.DateFormat = Main.MyDateFormat
    If FC = 0 Then
        TXTFL.Append(MP.Get("StartDisplayDate"))
    Else
        TXTFL.Append(MP.Get("StartDisplayDate")).SetColor(FC).SetFont(xui.CreateDefaultBoldFont(16))
    End If
    TXTFL.Append($"-${MP.Get("FinishDisplayDate")}"$)
    TXTFL.Append(CRLF).Append(" Qty: ").Append(IIf(MP.Get("Os_QtyToMake") > 0, MP.Get("Os_QtyToMake"), MP.Get("Jr_StartQty")))
    'TXTFL.Append(" Hr: ").Append(MP.Get("HrsRequired")).Append(CRLF).Append(MP.Get("Os_Description")).Append(CRLF).Append("NextDue: ")
    TXTFL.Append(" Hr: ").Append(MP.Get("HrsRequired")).Append(CRLF).Append("Next Due: ")
    TXTFL.Append(MP.Get("Jr_FirstDueDate"))
    Dim T2 As Pane
    T2.Initialize("JobsTA")
    Dim TL As Int = (MP.Get("Os_JobNum").As(String).Length + MP.Get("Os_ReleaseNum").As(String).Length) + NumberFormat(MP.Get("Os_SeqNum"), 1, 0).Length
    'Log("TL: " & TL & "  " & MP.Get("Os_JobNum"))
    If TL < 11 Then
        T2.SetSize(125dip, 85)
    Else If TL < 15 Then
        T2.SetSize(155dip, 85)
    Else If TL < 25 Then
        T2.SetSize(200dip, 85)
    Else
        T2.SetSize(225dip, 85)
    End If
    T2.Alpha = 1   
    T2.Enabled = True
    T2.PickOnBounds = True
    Dim T As Pane = TXTFL.CreateTextFlow
    T.As(JavaObject).RunMethod("setLineSpacing", Array(-2.0))  'tighten up the spacing between lines
    'Jr_Released = 1 means it is a HOT job
    T.Tag = "Text"
    If 1 = MP.Get("Jr_Released") Then   'stolen field: Jr_Released = HOT
        T.As(B4XView).SetColorAndBorder(xui.Color_ARGB(50, 255, 0, 0), 2dip, xui.Color_Red, 0)
        If TL < 11 Then T2.SetSize(T2.PrefWidth * 1.07, 85)
    End If
    'DIFFERENT WORKCENTER
    If Not(MP.Get("ListView").As(ListView).Parent.As(Pane).GetNode(0).Tag.As(Map).Get("SchM_WCCode").As(String).EqualsIgnoreCase(MP.Get("Os_WCCode"))) Then
        T.As(B4XView).SetColorAndBorder(T.As(B4XView).Color, 2dip, xui.Color_ARGB(180, 255, 255, 0), 0)
        If TL < 11 Then T2.SetSize(T2.PrefWidth * 1.07, 85)
    End If
    If DADMod.LightTheme Then T2.As(B4XView).SetColorAndBorder(xui.Color_White, 0, 0, 0)
    T2.AddNode(T, 0, 0, T2.PrefWidth, T2.PrefHeight)
    T2.Tag = MP
    MoveMachine2.MakeDragSource(T2, "MToMMoveS")
    MoveMachine2.MakeDragTarget(T2, "MToMMoveT")
    'Next line is REQUIRED!!! I don't know why
    TXTFL.Reset
    Return T2
    
End Sub

B4X:
Sub MToMMoveS_DragDetected(e As MouseEvent)
    HideMoreJobData
    If MasterTA.IsInitialized = False Then Return
    Dim M As Map = MasterTA.Tag
    Dim ToastTxt As String = ""
    '11/16/24 - critical parts
    If Main.CriticalPartMap.ContainsKey(M.Get("Os_ID").As(Int)) Then    '11/16/24 - critical parts
        Main.CurrentCPFlag = True
        Main.CurrentCPMachinesMap = Main.CriticalPartMap.Get(M.Get("Os_ID").As(Int))
        If Main.CurrentCPMachinesMap.Size = 0 Then
            ToastTxt = $"[textsize=30][color=red]This job requires approved machines${CRLF}but you have no machines qualified to do this OP![/color][/textsize]"$
        Else
            Dim ML As String
            For Each Mac As String In Main.CurrentCPMachinesMap.Values
                ML = $"${ML}, ${Mac}"$
            Next
            ML = ML.SubString(2)
            ToastTxt = $"[textsize=30][color=0xFF0300FF]This job can use the following approved machines:${CRLF}${ML}[/color][/textsize]"$
        End If
    Else
        Main.CurrentCPFlag = False
    End If
    '11/16/24 - critical parts
    If ToastTxt.Length > 0 Then
        Toast.VerticalCenterPercentage = 5
        Toast.DurationMs = 5000
        Toast.Show(ToastTxt, Null)
        Toast.DurationMs = 3000
    End If

    MoveMachine2.SetDragModeAndData2(TransferMode.ANY, Array As String("MoveJob", "MToMMove" & WCName, "Os_WCCode", "Os_ID", "SchO_ID", "SchO_Order", "Height", "Width", "Text"), Array As Object(WCName, "", M.Get("Os_WCCode"), M.Get("Os_ID"), M.Get("SchO_ID"), M.Get("SchO_Order"), MasterTA.Height, MasterTA.Width, ""), MasterTA.Snapshot)
    Sleep(1)
End Sub


Sub MToMMoveT_DragEntered(e As DragEvent)
Dim L As Node = e.GetEventTarget, StyleTxt As String
If L Is TextArea Then StyleTxt = ";-fx-control-inner-background: " Else StyleTxt = "-fx-background-color: "
Dim Db As Dragboard = e.GetDragboard
Dim TF As Boolean = False
If Db.HasContent("MToMMove" & WCName) Then
    TF = (e.GetGestureSource <> e.GetEventTarget)  'We are over ourself so we can't move in front of ourself so go RED below
End If
DADSaveStyle = L.Style
Dim ThisMachMap As Map = L.Tag.as(Map).Get("ListView").As(ListView).Parent.As(Pane).GetNode(2).Tag  '11/16/24 - critical parts - moved this   
If Main.CurrentCPFlag Then  '11/16/24 - critical parts
    If Not(Main.CurrentCPMachinesMap.ContainsKey(ThisMachMap.get("SchM_ID"))) Then
        L.Style = StyleTxt & "red;"
        Return
    End If
End If

If Main.UsingWCsBool Then
    If Db.HasContent("AddNewOP") Then
        If WCName.EqualsIgnoreCase(Db.GetContent("Os_WCCode")) Then
            L.Style = StyleTxt & "green;"  '#adff2f;"
        Else
            L.Style = StyleTxt & "yellow;"   
        End If
    Else if (Db.HasContent("MoveJob")) And TF Then
        L.Style = StyleTxt & "green;"
    Else If (Db.HasContent("MoveJob")) And  Not(Db.HasContent("MToMMove" & WCName))  Then
        L.Style = StyleTxt & "yellow;"
    Else
        L.Style = StyleTxt & "red;"
    End If
Else
    If (Db.HasContent("MoveJob")) And Not(TF) Then
        L.Style = StyleTxt & "red;"
    Else If ThisMachMap.Get("SchM_WCCode").As(String).EqualsIgnoreCase(Db.GetContent("Os_WCCode")) Then
        L.Style = StyleTxt & "green;"
    Else If (Db.HasContent("MoveJob")) And  Not(Db.HasContent("MToMMove" & WCName))  Then
        L.Style = StyleTxt & "yellow;"
    Else
        L.Style = StyleTxt & "yellow;"   
    End If
End If

End Sub

Sub MToMMoveT_DragDone(e As DragEvent)
'    Log("DragDone : transfer mode " & e.GetTransferMode & " completed") ' null if not successfull
    RightScrollPane.PrefWidth = 8dip

End Sub

Sub MToMMoveT_DragOver(e As DragEvent)
    Dim Db As Dragboard = e.GetDragboard
    Dim TF As Boolean = False
    If Db.HasContent("MToMMove" & WCName) Then
        TF = ((e.GetGestureSource <> e.GetEventSource))
    End If
    If ((e.GetDragboard.HasContent("MToMMove" & WCName) And TF) Or Db.HasContent("AddNewOP") Or Db.HasContent("MoveJob")) Then
        e.AcceptTransferModes(TransferMode.MOVE)
    End If

End Sub

Sub MToMMoveT_DragExited(e As DragEvent)
    Dim L As Node = e.GetEventSource
    L.Style = DADSaveStyle ' ";-fx-control-inner-background: rgba(95,158,160,.2);"
    L.RequestFocus   'KEEPS FROM JUMPING TO TOP!!
End Sub

Sub MToMMoveT_DragDropped(e As DragEvent)

Dim SchedSaved As Boolean = False  'Flag to indicate we HAVE saved the change in case of an error
Dim DroppingWC As String
Dim L As Node = e.GetGestureTarget
Try
    If e.GetDragboard.HasContent("MoveMachine") Then Return
    If e.GetDragboard.HasContent("MToMMove" & WCName) Then
        If (e.GetGestureSource = e.GetGestureTarget) Then Return   'We are on top of ourself
    End If
    Dim ThisMachMap As Map = L.Tag.as(Map).Get("ListView").As(ListView).Parent.As(Pane).GetNode(2).Tag  '11/16/24 - critical parts this line moved here
    If Main.CurrentCPFlag Then  '11/16/24 - critical parts
        If Not(Main.CurrentCPMachinesMap.ContainsKey(ThisMachMap.get("SchM_ID"))) Then
            Return
        End If
    End If
    Dim Crsr As JdbcResultSet
    Dim TATarget As Pane
    TATarget = e.GetGestureTarget
    Dim TargetMap As Map = TATarget.Tag, WCCode As String, Order As Int, TargetMachMap As Map
    'If it is a gap Item then we want to use the NEXT REAL Items Data
    Dim LV As ListView = TargetMap.Get("ListView")
    Dim P As Pane
    If TargetMap.ContainsKey("GapItem") Then
        P = LV.Items.Get(LV.Items.IndexOf(TATarget) + 1)
        TargetMap = P.Tag  'in this case these two are the same
        TargetMachMap = P.Tag
    Else
        TargetMachMap = LV.Tag
    End If
    If 0 = TargetMap.GetDefault("Os_ID", 0) Then  'we  are dropping on machine, not another job so it goes at the end GetDefault Os_ID is not IN this MAP
        Order = 0
    Else
        Order = TargetMap.Get("SchO_Order")
    End If
    WCCode = e.GetDragboard.GetContent("Os_WCCode")
    If Main.UsingWCsBool Then
        DroppingWC = WCName
    Else
        DroppingWC = ThisMachMap.Get("SchM_WCCode")
    End If
    'Warn if different WC
    If DroppingWC.ToLowerCase.CompareTo(WCCode.tolowercase) <> 0 Then
        If Not(DADMod.NoDifWCWarning) Then
            Dim DSA As DSADlgMod
            DSA.Initialize(MachinesFrm, WCCode, DroppingWC, "", "")
            DADMod.NoDifWCWarning = DSA.DontShowAgain
            If Not(DSA.DSADlgYes) Then Return
        End If
    End If

    If e.GetDragboard.HasContent("MoveJob") Then
        Dim TATarget As Pane, LVTarget As ListView, TASource As Pane, LVSource As ListView   ', T3 As TextArea
        TATarget = e.GetGestureTarget
        Dim MapSource As Map
        If e.GetDragboard.HasContent("MToMMove" & DroppingWC) Then   'same WC
            TASource = e.GetGestureSource
            MapSource = TASource.Tag
        Else
            Dim Db As Dragboard = e.GetDragboard
            Dim MFM As MachinesFrmMod = Main.MachineFrmModList.get(Db.GetContent("MoveJob"))
            TASource = MFM.FindOp(Db.GetContent("SchO_ID"), False)
            MapSource = TASource.Tag
        End If
        #If Debug
            Dim MapSourceMachHOLD As Int = MapSource.Get("SchO_SchMTID")  'For Testing
        #End If
        'This next line fixes a problem if you try to move things too quickly'
        'It moves the last TARGET or the previous SOURCE not the selected item so make sure the dragbord and Map soure are the same
        'If they are not then exit
        If e.GetDragboard.GetContent("SchO_ID") <> MapSource.Get("SchO_ID") Then Return
        'We are dropping on the on NEXT ON THE SAME MACHINE one which would simply put us right back where we are
        If Order = (MapSource.Get("SchO_Order") + 1) And (TargetMap.Get("SchM_ID").As(String).EqualsIgnoreCase(MapSource.Get("SchO_SchMTID"))) Then Return
        '                                            MOVING TO MACHINE            NEW ORDER       
        'We pass the             [ScheduleOp]         @SchO_SchMTID,     @InsertOs_ID,@SchO_Order,                     @RemoveSchO_ID            , @MoveSchO_ID
        Dim SQLStr As String = $"ScheduleOp ${TargetMap.Get("SchM_ID")}, 0, ${Order}, 0, ${e.GetDragboard.GetContent("SchO_ID")};"$
        #If Debug
            Log($"ScheduleOp 0, SchO_OSId, SchO_Order, SchO_ID"$)
        #End If
        Dim SenderFilter As Object = Main.SKSQL.ExecQueryAsync ("MoveOp", SQLStr, Null)   '1/30/19 - Added SW57
        Wait For (SenderFilter) MoveOp_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
        If Success Then
            If Crsr.NextRow Then
                If Crsr.GetString("RESULT").As(String).Contains("SUCCESS") Then
                    SchedSaved = True
                    LVTarget = TargetMap.Get("ListView")
                    LVSource = MapSource.Get("ListView")
                    MapSource.Put("SchO_Order", IIf(Order > 0, Order, LVTarget.Items.Size) + 1)  'Note that we haven't set the item yet so it is plus 1
                    MapSource.Put("SchO_SchMTID", TargetMap.Get("SchM_ID"))
                    MapSource.Put("SchM_Machine", Crsr.GetString("SchM_Machine"))
                    MapSource.Put("SchM_HrsPerWk", Crsr.GetString("SchM_HrsPerWk"))
                    MapSource.Put("SchM_ID", TargetMap.Get("SchM_ID"))
                    LVTarget = TargetMap.Get("ListView")
                    LVSource = MapSource.Get("ListView")
                    MapSource.Remove("ListView")  'remove and re-add - might be a different machine
                    MapSource.Put("ListView", LVTarget)
                    Dim ND As Node
                    If Order = 0 Then  'at the end so no need to reorder
                        ND = FormatOpData(TASource.Tag)
                        LVTarget.Items.Add(ND)
                    Else
                        ND = FormatOpData(TASource.Tag)
                        LVTarget.Items.InsertAt(LVTarget.Items.IndexOf(TATarget), ND)
                        ReOrderList(LVTarget)
                        Order = LVTarget.Items.IndexOf(TATarget)
                    End If
                    Dim HP As Double = MachinesSP.VPosition
                    LVSource.Items.RemoveAt(LVSource.Items.IndexOf(TASource))
                    ReOrderList(LVSource)
                    Sleep(1)
                    '7/10/24 - made MovePicture return boolean so we know if ther is a node 1
                    If MovePicture(TASource, ND.As(Pane)) Then ND.As(Pane).GetNode(1).Alpha = TextAlpha
'                    Canv.Alpha = PicAlpha
'                    PPane.GetNode(1).Alpha = TextAlpha
                    Sleep(1)
'                    If SchedInfoRB.Selected Then ShowGaps Else ShowGapsAboveLV
    Wait For (DADMod.TestAndShowGaps(SchedInfoRB.Selected, ShowGapsStatusAbove, MapSource.Get("ListView").As(ListView).Parent.as(Pane).GetNode(2).Tag, MapSource, Me)) Complete (CCC As Boolean)
                    ResizeLists(MachinesFrm.Width)
                    MachinesSP.VPosition = HP
                    LoadGraphs($"'${LVSource.Id}'${IIf(LVSource.Id.EqualsIgnoreCase(LVTarget.Id), "", $", '${LVTarget.Id}'"$)}"$)
#Region Debug1
'                #If Debug               
'                    'For TESTING
'                    Log("Drop Completed")
'                    Dim SQLStr As String = $"SELECT SchO_ID, SchO_OSId, SchO_SchMTID, SchO_Order FROM ScheduledOps WHERE SchO_SchMTID = ${TargetMap.Get("SchM_ID")} ORDER BY SchO_Order;"$
'                    Dim SenderFilter As Object = Main.SKSQL.ExecQueryAsync ("MoveOp", SQLStr, Null)   '1/30/19 - Added SW57
'                    Wait For (SenderFilter) MoveOp_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
'                    If Success Then
'                        Dim ZZX As Int = 0, MMM As Map
'                        Do While Crsr.NextRow
'                            MMM = LVTarget.Items.Get(ZZX).As(Pane).Tag
'                            If Not(MMM.ContainsKey("GapItem")) Then
'    '                            Log($"${ZZX +1} - ${Crsr.GetInt("SchO_Order")}"$)
'    '                            Log($"${MMM.Get("SchO_ID")} - ${Crsr.GetInt("SchO_ID")}"$)
'                                If (MapSourceMachHOLD = TargetMap.Get("SchM_ID")) And LVTarget.Items.Size = (ZZX +1) Then Exit
'                                If ((ZZX +1) <> Crsr.GetInt("SchO_Order")) Or (Crsr.GetInt("SchO_ID") <> MMM.Get("SchO_ID")) Then   'ignore
'                                    xui.MsgboxAsync($"${ZZX +1} - ${Crsr.GetInt("SchO_Order")}${CRLF}${MMM.Get("SchO_ID")} - ${Crsr.GetInt("SchO_ID")}"$, "")
'                                End If
'                                ZZX = ZZX + 1
'                            End If
'                        Loop
'                    End If
'                    If MapSourceMachHOLD <> TargetMap.Get("SchM_ID") Then  'we only check this if it is different machines
'                        Dim SQLStr As String = $"SELECT SchO_ID, SchO_OSId, SchO_SchMTID, SchO_Order FROM ScheduledOps WHERE SchO_SchMTID = ${MapSourceMachHOLD} ORDER BY SchO_Order;"$
'                        Dim SenderFilter As Object = Main.SKSQL.ExecQueryAsync ("MoveOp", SQLStr, Null)   '1/30/19 - Added SW57
'                        Wait For (SenderFilter) MoveOp_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
'                        If Success Then
'                            Dim ZZX As Int = - 1, MMM As Map
'                            Do While Crsr.NextRow
'                                ZZX = ZZX + 1
'                                MMM = LVSource.Items.Get(ZZX).As(Pane).Tag
''                                Log($"${ZZX +1} - ${Crsr.GetInt("SchO_Order")}"$)
''                                Log($"${MMM.Get("SchO_ID")} - ${Crsr.GetInt("SchO_ID")}"$)
'                                If ((ZZX +1) <> Crsr.GetInt("SchO_Order")) Or (Crsr.GetInt("SchO_ID") <> MMM.Get("SchO_ID")) Then   'ignore
'                                    xui.MsgboxAsync($"${ZZX +1} - ${Crsr.GetInt("SchO_Order")}${CRLF}${MMM.Get("SchO_ID")} - ${Crsr.GetInt("SchO_ID")}"$, "")
'                                End If
'                            Loop
'                        End If
'                    End If
'                #End if
#End Region               
                Else
                    xui.MsgboxAsync("SQL Error: " & CRLF & Crsr.GetString("RESULT"), "Error in MToMMoveT_DragDropped (MoveJob)")
                End If
            Else
                xui.MsgboxAsync("Query executed but did not return Rowcount. Failed To perform move", "Error in MToMMoveT_DragDropped (MoveJob)")
            End If
        Else
            xui.MsgboxAsync("Query Failed to execute. Failed To perform move", "Error in MToMMoveT_DragDropped (MoveJob)")
        End If
        e.SetDropCompleted(True)
    Else If e.GetDragboard.HasContent("AddNewOP") Then
        #If Debug
            Log("InsertAddNewOP")
        #End If
        Dim Db As Dragboard = e.GetDragboard
'        Dim T As Pane, LV As ListView, M As Map
'        T = e.GetGestureTarget
'        M = T.Tag
        'We pass the             [ScheduleOp]         @SchO_SchMTID,                 @InsertOs_ID,            @SchO_Order,                     @RemoveSchO_ID            , @MoveSchO_ID
        Dim SQLStr As String = "ScheduleOp " & TargetMap.Get("SchM_ID") & ", " & Db.GetContent("Os_ID") & ", " &  Order
        Dim SenderFilter As Object = Main.SKSQL.ExecQueryAsync ("InsertOp", SQLStr, Null)   '1/30/19 - Added SW57
        Wait For (SenderFilter) InsertOp_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
        If Success Then
            If Crsr.NextRow Then
                If Crsr.GetString("RESULT").EqualsIgnoreCase("SUCCESS") Then
'Remove this code after a
Try
    SQLStr = Crsr.GetString("Pmp_PictureName")
Catch
    xui.MsgboxAsync("Pmp_PictureName is missing! Contact Insite Software. Run ScheduleOp.sql.", "Server update required")
    Wait For Msgbox_Result (Result As Int)
End Try
                    SchedSaved = True
                    LV = TargetMap.Get("ListView")
                    Dim MAdd As Map
                    DADMod.FillJobMap(Crsr, MAdd, False)
                    MAdd.Put("ListView", LV)
                    Dim ND As Node = FormatOpData(MAdd)
                    If Order = 0 Then
                        LV.Items.Add(ND)
                    Else
                        LV.Items.InsertAt(Order - 1, ND)
                        ReOrderList(LV)
                    End If
'                    If SchedInfoRB.Selected Then ShowGaps Else ShowGapsAboveLV
    DADMod.TestAndShowGaps(SchedInfoRB.Selected, ShowGapsStatusAbove, MAdd.Get("ListView").As(ListView).Parent.as(Pane).GetNode(2).Tag, MAdd, Me)
                    ResizeLists(-1)
                    e.SetDropCompleted(True)
                    If .1 < PicAlpha Then
                        Sleep(10)
                        Add1Picture(ND)
                    End If
                    'If we are draging from JOBopslist rather UnscheduledOPsList we MIGHT not have an ID because we might be on a different list
                    If Main.ActiveMap.Get("RowId") > -500 Then
                        Main.UnSchedOpsList.DeleteRow(Main.ActiveMap.Get("RowId"))
                    End If
                    'If our opslist is , in fact the job we are scheduling then we need to change the color of the item in Main.JobOpsList
                    If Main.JobNumLbl.text.EqualsIgnoreCase(MAdd.get("Os_JobNum")) And Main.RelNumLbl.text.EqualsIgnoreCase(MAdd.get("Os_ReleaseNum")) Then
                        Dim XXX As Int, JOLM As Map
                        For XXX = 0 To Main.JobOpsList.Size - 1
                            JOLM = Main.JobOpsList.GetValue(XXX).As(Pane).Tag
                            If JOLM.Get("Os_ID").As(Int) = MAdd.Get("Os_ID").As(Int) Then
                                'JOLM.Get("BBLbl").As(BBCodeView).sv.ScrollViewInnerPanel.Color = xui.Color_RGB(255, 255, 167)
                                JOLM.Put("Scheduled", True)
                                JOLM.Put("SchM_WCCode", DroppingWC)
                                JOLM.Put("SchO_ID", Crsr.GetInt("SchO_ID"))
                                If JOLM.Get("Os_WCCode") <> TargetMachMap.Get("SchM_WCCode") Then  'Red - Scheduled ON THE WRONG WORKCENTER!!
                                    JOLM.Get("BBLbl").As(BBCodeView).sv.ScrollViewInnerPanel.Color = xui.Color_RGB(255, 255, 0)   'Dark Yellow
                                Else
                                    JOLM.Get("BBLbl").As(BBCodeView).sv.ScrollViewInnerPanel.Color = xui.Color_RGB(255, 255, 167)  'Yellow - Scheduled
                                End If
                                Exit
                            End If
                        Next
                    End If
                    LoadGraphs($"'${MAdd.Get("SchM_Machine")}'"$)
#Region Debug2
'                #If Debug   
'                    'For TESTING
'                    Dim LVTarget As ListView = M.Get("ListView")
'                    Dim SQLStr As String = $"SELECT SchO_ID, SchO_OSId, SchO_SchMTID, SchO_Order FROM ScheduledOps WHERE SchO_SchMTID = ${TargetMap.Get("SchM_ID")} ORDER BY SchO_Order;"$
'                    Dim SenderFilter As Object = Main.SKSQL.ExecQueryAsync ("MoveOp", SQLStr, Null)   '1/30/19 - Added SW57
'                    Wait For (SenderFilter) MoveOp_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
'                    If Success Then
'                        Dim ZZX As Int = - 1, MMM As Map
'                        Do While Crsr.NextRow
'                            ZZX = ZZX + 1
'                            MMM = LVTarget.Items.Get(ZZX).As(Pane).Tag
'                            Log($"${ZZX +1} - ${Crsr.GetInt("SchO_Order")}"$)
'                            Log($"${MMM.Get("SchO_ID")} - ${Crsr.GetInt("SchO_ID")}"$)
'                            If ((ZZX +1) <> Crsr.GetInt("SchO_Order")) Or (Crsr.GetInt("SchO_ID") <> MMM.Get("SchO_ID")) Then   'ignore
'                                xui.MsgboxAsync($"${Crsr.GetInt("SchO_SchMTID")} / ${ZZX +1} - ${Crsr.GetInt("SchO_Order")}${CRLF}${MMM.Get("SchO_ID")} - ${Crsr.GetInt("SchO_ID")}"$, "")
'                            End If
'                        Loop
'                    End If
'                #End If
#End Region
                Else
                    xui.MsgboxAsync(Crsr.GetString("RESULT"), "Error in MToMMoveT_DragDropped")
                End If
            Else
                xui.MsgboxAsync("Query executed but did not return Rowcount. Failed To Add Record", "Error in MToMMoveT_DragDropped")
            End If
        Else
            xui.MsgboxAsync("Query Failed to execute. Failed To Add Record", "Error in MToMMoveT_DragDropped")
        End If
    End If
    If Crsr.IsInitialized Then Crsr.Close
    'WaitForLastDrag = False
Catch
    If Crsr.IsInitialized Then Crsr.Close
    If SchedSaved = True Then
        Main.MainLTT.Text = $"An error occurred while formatting your date but the changes were made. Refreshing data.${CRLF & LastException.Message.SubString2(0, Min(LastException.Message.Length, 500))}"$
        MachErrDlg.Title = "Error in MToMMoveT_DragDropped"
        Wait For (MachErrDlg.ShowTemplate(Main.MainLTT, "OK", "", "")) Complete (Result As Int)
        Dim MOE As MouseEvent
        RefreshDataBtn_MouseClicked(MOE)
    Else
        Main.MainLTT.Text = LastException.Message
        MachErrDlg.Title = "Error in MToMMoveT_DragDropped"
        Wait For (MachErrDlg.ShowTemplate(Main.MainLTT, "OK", "", "")) Complete (Result As Int)
    End If

End Try

End Sub


Sub ReOrderList(LV As ListView)
    Dim X As Int, T As Pane, M As Map, Y As Int
    Y = 1
For X = 0 To LV.Items.Size - 1
    T = LV.Items.Get(X)
    M = T.Tag
    If M.ContainsKey("GapItem") Then
        'DON'T INCREMENT!!!
        M.Put("GapItem", Y)
    Else
        M.Put("SchO_Order", Y)
        Y= Y + 1
    End If
Next

End Sub
 
Upvote 0
Top