Jump to content

Interesting array question


Go to solution Solved by FireFox,

Recommended Posts

Okay :)

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>
 
#include <GUIListView.au3>
 
Global $blGUIMinimized = False
Global $aSales = 0, $sPreviewData = ""
 
#region GUI
Global $hGUI = GUICreate("MyGUI", 840, 485)
 
GUICtrlCreateGroup("Specify Director Code, Manager Code or Buyer Code", 10, 10, 510, 80)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Director Code", 20, 37, Default, 15)
Global $iInputDirectorCode = GUICtrlCreateInput("", 100, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel("Manager Code", 180, 37, Default, 15)
Global $iInputManagerCode = GUICtrlCreateInput("", 265, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel("Buyer Code", 345, 37, Default, 15)
Global $iInputBuyerCode = GUICtrlCreateInput("", 415, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel('"*" in Director Code = List all entries', 20, 65, 240, 20)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Source Items", 10, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwSource = GUICtrlCreateListView("Director|Manager|Buyer", 10, 125, 250, 300)
Global $hLwSource = GUICtrlGetHandle($iLwSource)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSource, $i, 75)
Next
 
GUICtrlCreateLabel("Segment Items", 270, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwSegments = GUICtrlCreateListView("Director|Manager|Buyer", 270, 125, 250, 300)
Global $hLwSegments = GUICtrlGetHandle($iLwSegments)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSegments, $i, 75)
Next
 
Local $iBtnCommit = GUICtrlCreateButton("Commit", 441, 430, 80, 25)
 
GUICtrlCreateLabel("Use the left/right arrows to add or remove items from the lists.", 10, 460, 510, 20)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Preview", 530, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwPreview = GUICtrlCreateListView("Director|Manager|Buyer", 530, 30, 300, 395)
Global $hLwPreview = GUICtrlGetHandle($iLwPreview)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwPreview, $i, 92)
Next
 
Local $iBtnSubmit = GUICtrlCreateButton("Submit...", 751, 430, 80, 25)
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
 
_LoadDb()
_HotKey_Enable()
 
GUISetState(@SW_SHOW, $hGUI)
#endregion GUI
 
While 1
    Sleep(10)
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnCommit
            _Commit()
        Case $iBtnSubmit
            _Submit()
    EndSwitch
WEnd
 
GUIDelete($hGUI)
 
Func _Commit()
    _GUICtrlListView_BeginUpdate($hLwPreview)
    _GUICtrlListView_DeleteAllItems($hLwPreview)
 
    Local $aData = _GUICtrlListView_GetItemTextArray($hLwSegments, $i), $sData = ""
 
    $sPreviewData = ""
    For $i = 0 To _GUICtrlListView_GetItemCount($hLwSegments) -1
        $sPreviewData &= $aData[0] & ";" & $aData[1] & ";" & $aData[2] & @CrLf
        GUICtrlCreateListViewItem(_ArrayToString($aData, "|"), $iLwPreview)
    Next
    _GUICtrlListView_EndUpdate($hLwPreview)
 
    _GUICtrlListView_DeleteAllItems($hLwSegments)
EndFunc
 
Func _Submit()
    Local $sPath = FileSaveDialog("save", "", "CSV file (*.csv)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE))
    If @error Then Return 0
 
    If StringRight($sPath, 4) <> ".csv" Then $sPath &= ".csv"
 
    Local $hFile = FileOpen($sPath, $FO_OVERWRITE)
    FileWrite($hFile, $sPreviewData)
    FileClose($hFile)
EndFunc
 
Func _LoadDb()
    Local $sData = FileRead(@ScriptDir & "\Dir_man_Buyer.txt")
 
    Local $aBase = StringSplit($sData, @CRLF, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
 
    ;-2/-3 for the UBound because the first line is a header and the last line is empty
 
    Global $aSales[UBound($aBase) - 2][3]
    Local $aTmp = 0
 
    For $i = 0 To UBound($aBase) - 3
        $aTmp = StringSplit($aBase[$i + 1], ",", BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
 
        $aSales[$i][0] = $aTmp[0]
        $aSales[$i][1] = $aTmp[1]
        $aSales[$i][2] = $aTmp[2]
    Next
EndFunc   ;==>_LoadDb
 
Func _MoveFromSourceToSegments()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSource)
    If $sSelectedItem = "" Then Return 0
 
    Local $iSelItem = Number($sSelectedItem)
 
    GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSource, $iSelItem), $iLwSegments)
    _GUICtrlListView_DeleteItem($hLwSource, $iSelItem)
EndFunc   ;==>_MoveFromSourceToSegments
 
Func _MoveFromSegmentsToSource()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSegments)
    If $sSelectedItem = "" Then Return 0
 
    Local $iSelItem = Number($sSelectedItem)
 
    GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSegments, $iSelItem), $iLwSource)
    _GUICtrlListView_DeleteItem($hLwSegments, $iSelItem)
EndFunc   ;==>_MoveFromSegmentsToSource
 
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom = 0, $iCode = 0
 
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)
 
    Switch $iIDFrom
        Case $iInputDirectorCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputManagerCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputDirectorCode)
                    If StringRegExp($sInput, "^([A-Z]|\*)$") = 1 Then
                        _ArraySort($aSales, 0, 0, 0, 0)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        If $sInput = "*" Then
                            For $i = 0 To UBound($aSales) - 1
                                GUICtrlCreateListViewItem($aSales[$i][0] & "|" & $aSales[$i][1] & "|" & $aSales[$i][2], $iLwSource)
                            Next
                        Else
                            For $i = 0 To UBound($aSales) - 1
                                If $sInput <> StringStripWS($aSales[$i][0], $STR_STRIPTRAILING) Then ContinueLoop
                                GUICtrlCreateListViewItem($aSales[$i][0] & "|" & $aSales[$i][1] & "|" & $aSales[$i][2], $iLwSource)
                            Next
                        EndIf
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputManagerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputManagerCode)
                    If StringRegExp($sInput, "^\d+$") = 1 Then
                        _ArraySort($aSales, 0, 0, 0, 1)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aSales) - 1
                            If $sInput <> $aSales[$i][1] Then ContinueLoop
                            GUICtrlCreateListViewItem($aSales[$i][0] & "|" & $aSales[$i][1] & "|" & $aSales[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputBuyerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputManagerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputBuyerCode)
                    If StringRegExp($sInput, "^[\dA-Z]+$") = 1 Then
                        _ArraySort($aSales, 0, 0, 0, 2)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aSales) - 1
                            If $sInput <> $aSales[$i][2] Then ContinueLoop
                            GUICtrlCreateListViewItem($aSales[$i][0] & "|" & $aSales[$i][1] & "|" & $aSales[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
 
Func WM_ACTIVATE($hWnd, $iMsg, $iwParam, $ilParam)
    If $iwParam And Not $blGUIMinimized Then
        _HotKey_Enable()
    Else
        _Hotkey_Disable()
    EndIf
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_ACTIVATE
 
Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local Const $SC_MINIMIZE = 0xF020, $SC_RESTORE = 0xF120
 
    Switch BitAND($wParam, 0xFFF0)
        Case $SC_MINIMIZE
            _Hotkey_Disable()
            $blGUIMinimized = True
        Case $SC_RESTORE
            $blGUIMinimized = False
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND
 
Func _HotKey_Enable()
    HotKeySet("{RIGHT}", "_MoveFromSourceToSegments")
    HotKeySet("{LEFT}", "_MoveFromSegmentsToSource")
EndFunc   ;==>_HotKey_Enable
 
Func _Hotkey_Disable()
    HotKeySet("{RIGHT}")
    HotKeySet("{LEFT}")
EndFunc   ;==>_Hotkey_Disable
Br, FireFox.
Link to comment
Share on other sites

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You will need the latest beta, because I use some constants which are not in the stable version. I hope it won't be a problem for you :)

 

hmm.. don't know?

Can one compile and distribute  applications built on beta the same as the stable releases?

Link to comment
Share on other sites

Can one compile and distribute  applications built on beta the same as the stable releases?

Yes of course.

I meant it was to inform you about the errors in the script if you had some, in order to download and install the beta.

Edited by FireFox
Link to comment
Share on other sites

Yes of course.

I meant it was to inform you about the errors in the script if you had some, in order to download and install the beta.

 

Morning FF

Thanks for your time and knowledge on this.

I downloaded the Beta but got and error saying the stringconstants couldn't be found (I did run in Scite using alt-f5.. honest :) )

I just copied the stringconstants to my user includes and ran under autoit.

It's taking shape and looking good but I don't know what all the WM_ function stuff is about?

A few things I note:

  • The search works fine although it only accepts uppercase for the alpha inputs so I changed the code for that and I have aslo changed the array variable name for local requirement(see code 1).
  • I need multi-select in the listviews else it could be a laborious process.(see code 2)
  • The ability to drag selections between listviews would be of benefit.(see code 2)
  • The segment build is good and works fine but when 'commited' I get spurious results in the preview.. eg. numerics in the director column, repeated values, sometimes no values.
  • The preview should be appended to and only cleared on submit as it is the representation of  x number of segments.
  • Prior to a commit of a segment the user should annotate the segment using two input boxes somewhere near the segment listview and the text in box 1 added as an additional column at the beginning of the preview record and the text in box 2 added as an additional column at the end of the preview record eg. W13 | W | 38 | 0S7 | 17.Ladieswear (see sample output '17 way split.txt' attached).
  • I need the ability to delete records from preview if the user has made an error.

 

Sorry to cause you pain.

 

Code 1 (Your code slightly ammended:)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include "StringConstants.au3"

#include <GUIListView.au3>

Global $blGUIMinimized = False
Global $aKalRecs = 0, $sPreviewData = ""

#region GUI
Global $hGUI = GUICreate("MyGUI", 840, 485)

GUICtrlCreateGroup("Specify Director Code, Manager Code or Buyer Code", 10, 10, 510, 80)
GUICtrlSetFont(-1, 10, 800)

GUICtrlCreateLabel("Director Code", 20, 37, Default, 15)
Global $iInputDirectorCode = GUICtrlCreateInput("", 100, 33, 40, 20, $ES_AUTOHSCROLL)

GUICtrlCreateLabel("Manager Code", 180, 37, Default, 15)
Global $iInputManagerCode = GUICtrlCreateInput("", 265, 33, 40, 20, $ES_AUTOHSCROLL)

GUICtrlCreateLabel("Buyer Code", 345, 37, Default, 15)
Global $iInputBuyerCode = GUICtrlCreateInput("", 415, 33, 40, 20, $ES_AUTOHSCROLL)

GUICtrlCreateLabel('"*" in Director Code = List all entries', 20, 65, 240, 20)
GUICtrlSetFont(-1, 10, 800)

GUICtrlCreateLabel("Source Items", 10, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)

Global $iLwSource = GUICtrlCreateListView("Director|Manager|Buyer", 10, 125, 250, 300)
Global $hLwSource = GUICtrlGetHandle($iLwSource)

For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSource, $i, 75)
Next

GUICtrlCreateLabel("Segment Items", 270, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)

Global $iLwSegments = GUICtrlCreateListView("Director|Manager|Buyer", 270, 125, 250, 300)
Global $hLwSegments = GUICtrlGetHandle($iLwSegments)

For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSegments, $i, 75)
Next

Local $iBtnCommit = GUICtrlCreateButton("Commit", 441, 430, 80, 25)

GUICtrlCreateLabel("Use the left/right arrows to add or remove items from the lists.", 10, 460, 510, 20)
GUICtrlSetFont(-1, 10, 800)

GUICtrlCreateLabel("Preview", 530, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)

Global $iLwPreview = GUICtrlCreateListView("Director|Manager|Buyer", 530, 30, 300, 395)
Global $hLwPreview = GUICtrlGetHandle($iLwPreview)

For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwPreview, $i, 92)
Next

Local $iBtnSubmit = GUICtrlCreateButton("Submit...", 751, 430, 80, 25)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

_LoadDb()
_HotKey_Enable()

GUISetState(@SW_SHOW, $hGUI)
#endregion GUI

While 1
    Sleep(10)

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnCommit
            _Commit()
        Case $iBtnSubmit
            _Submit()
    EndSwitch
WEnd

GUIDelete($hGUI)

Func _Commit()
    _GUICtrlListView_BeginUpdate($hLwPreview)
    _GUICtrlListView_DeleteAllItems($hLwPreview)

    Local $aData = _GUICtrlListView_GetItemTextArray($hLwSegments, $i), $sData = ""

    $sPreviewData = ""
    For $i = 0 To _GUICtrlListView_GetItemCount($hLwSegments) - 1
        $sPreviewData &= $aData[0] & ";" & $aData[1] & ";" & $aData[2] & @CRLF
        GUICtrlCreateListViewItem(_ArrayToString($aData, "|"), $iLwPreview)
    Next
    _GUICtrlListView_EndUpdate($hLwPreview)

    _GUICtrlListView_DeleteAllItems($hLwSegments)
EndFunc   ;==>_Commit

Func _Submit()
    Local $sPath = FileSaveDialog("save", "", "CSV file (*.csv)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE))
    If @error Then Return 0

    If StringRight($sPath, 4) <> ".csv" Then $sPath &= ".csv"

    Local $hFile = FileOpen($sPath, $FO_OVERWRITE)
    FileWrite($hFile, $sPreviewData)
    FileClose($hFile)
EndFunc   ;==>_Submit

Func _LoadDb()
    Local $sData = FileRead(@ScriptDir & "\Dir_man_Buyer.csv")

    Local $aBase = StringSplit($sData, @CRLF, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))

    ;-2/-3 for the UBound because the first line is a header and the last line is empty

    Global $aKalRecs[UBound($aBase) - 2][3]
    Local $aTmp = 0

    For $i = 0 To UBound($aBase) - 3
        $aTmp = StringSplit($aBase[$i + 1], ",", BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))

        $aKalRecs[$i][0] = $aTmp[0]
        $aKalRecs[$i][1] = $aTmp[1]
        $aKalRecs[$i][2] = $aTmp[2]
    Next
EndFunc   ;==>_LoadDb

Func _MoveFromSourceToSegments()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSource)
    If $sSelectedItem = "" Then Return 0

    Local $iSelItem = Number($sSelectedItem)

    GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSource, $iSelItem), $iLwSegments)
    _GUICtrlListView_DeleteItem($hLwSource, $iSelItem)
EndFunc   ;==>_MoveFromSourceToSegments

Func _MoveFromSegmentsToSource()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSegments)
    If $sSelectedItem = "" Then Return 0

    Local $iSelItem = Number($sSelectedItem)

    GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSegments, $iSelItem), $iLwSource)
    _GUICtrlListView_DeleteItem($hLwSegments, $iSelItem)
EndFunc   ;==>_MoveFromSegmentsToSource

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $item_txt

    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)

    Switch $iIDFrom
        Case $iInputDirectorCode
            $iInputDirectorCode = StringUpper($iInputDirectorCode)
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputManagerCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")

                    Local $sInput = StringUpper(GUICtrlRead($iInputDirectorCode))
                    If StringRegExp($sInput, "^([A-Z]|\*)$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 0)

                        $iSourceSelItem = -1

                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        If $sInput = "*" Then
                            For $i = 0 To UBound($aKalRecs) - 1
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        Else
                            For $i = 0 To UBound($aKalRecs) - 1
                                If $sInput <> StringStripWS($aKalRecs[$i][0], $STR_STRIPTRAILING) Then ContinueLoop
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        EndIf
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputManagerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")

                    Local $sInput = GUICtrlRead($iInputManagerCode)
                    If StringRegExp($sInput, "^\d+$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 1)

                        $iSourceSelItem = -1

                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aKalRecs) - 1
                            If $sInput <> $aKalRecs[$i][1] Then ContinueLoop
                            GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputBuyerCode
            StringUpper($iInputBuyerCode)
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputManagerCode, "")

                    Local $sInput = StringUpper(GUICtrlRead($iInputBuyerCode))
                    If StringRegExp($sInput, "^[\dA-Z]+$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 2)

                        $iSourceSelItem = -1

                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aKalRecs) - 1
                            If $sInput <> $aKalRecs[$i][2] Then ContinueLoop
                            GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func WM_ACTIVATE($hWnd, $iMsg, $iwParam, $ilParam)
    If $iwParam And Not $blGUIMinimized Then
        _HotKey_Enable()
    Else
        _Hotkey_Disable()
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_ACTIVATE

Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local Const $SC_MINIMIZE = 0xF020, $SC_RESTORE = 0xF120

    Switch BitAND($wParam, 0xFFF0)
        Case $SC_MINIMIZE
            _Hotkey_Disable()
            $blGUIMinimized = True
        Case $SC_RESTORE
            $blGUIMinimized = False
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

Func _HotKey_Enable()
    HotKeySet("{RIGHT}", "_MoveFromSourceToSegments")
    HotKeySet("{LEFT}", "_MoveFromSegmentsToSource")
EndFunc   ;==>_HotKey_Enable

Func _Hotkey_Disable()
    HotKeySet("{RIGHT}")
    HotKeySet("{LEFT}")
EndFunc   ;==>_Hotkey_Disable

Code 2 (Multi Select and drag)

; Includes first! Must must must!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <SendMessage.au3>

; Switch on the 'onEvent' notifications

Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 2)

; Generate the GUI.
Global $gw = 16
Global $gh = 16
Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc
Global $MainForm, $list_source, $list_target, $drag_gui, $hSplash

$MainForm = GUICreate(" Segment Builder ", 517, 500)

;Headers..
$hSource = GUICtrlCreateLabel("Source Items", 85, 8, 100, 30)
GUICtrlSetFont($hSource, 10, 700)
$hSegment = GUICtrlCreateLabel("Segment Items", 330, 8, 100, 30)
GUICtrlSetFont($hSegment, 10, 700)

; Source list box
$list_source = _GUICtrlListView_Create($MainForm, "Director|Manager|Buyer", 13, 25, 240, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))

; Target list box
$list_target = _GUICtrlListView_Create($MainForm, "Director|Manager|Buyer", 261, 25, 240, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\left_right_arrow_keys.jpg", 186, 400, 124, 84)

; Populate box with some instructions
$text1 = GUICtrlCreateLabel("Select items and drag from source to segment and vice-versa.... OR...", 45, 340, 450, 30)
GUICtrlSetBkColor($text1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont($text1, 9, 800, -1, 'courier new')
GUICtrlSetColor($text1, 0x0000ff)

$text2 = GUICtrlCreateLabel("Use the left/right arrows to add or remove items from the lists.", 45, 380, 450, 30)
GUICtrlSetBkColor($text2, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont($text2, 9, 800, -1, 'courier new')
GUICtrlSetColor($text2, 0x0000ff)

$left = GUICtrlCreateDummy()
GUICtrlSetOnEvent($left, "leftpressed")
$right = GUICtrlCreateDummy()
GUICtrlSetOnEvent($right, "rightpressed")
Dim $aHotkey[2][2] = [["{LEFT}", $left],["{RIGHT}", $right]]
GUISetAccelerators($aHotkey)

Func leftpressed()
    _GUICtrlListView_CopyItems($list_target, $list_source, 1)
EndFunc   ;==>leftpressed
Func rightpressed()
    _GUICtrlListView_CopyItems($list_source, $list_target, 1)
EndFunc   ;==>rightpressed

For $i = 0 To 29
    $item = _GUICtrlListView_AddItem($list_source, _makeJunkName())
    _GUICtrlListView_AddSubItem($list_source, $item, _makeJunkName(), 1)
Next

; Handle GUI events
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetOnEvent($GUI_EVENT_CLOSE, "_formEvents")

$drag_gui = GUICreate("Drag", $gw, $gh, 300, 300, BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $MainForm)
$cursor_icon = GUICtrlCreateIcon("Shell32.dll", -147, 0, 0, 16, 16)
GUISetState(@SW_SHOW, $drag_gui)
setTrans()
GUISetState(@SW_HIDE, $drag_gui)
GUISetState(@SW_SHOW, $MainForm)
; Main program loop
While 1
    Sleep(10)
WEnd

; Function to handle other form events
Func chase()
    $mp = MouseGetPos()
    _WinAPI_UpdateWindow($MainForm)
    _WinAPI_UpdateWindow($drag_gui)
    WinMove($drag_gui, "", $mp[0] + 0, $mp[1] + 0)
    ;ToolTip($moving_txt, $mp[0] + 18, $mp[1])
    WinMove($hSplash, "", $mp[0] + 28, $mp[1] + 0)
EndFunc   ;==>chase

Func _formEvents()
    Exit
EndFunc   ;==>_formEvents

Func setTrans()
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)
    $rct = DllStructCreate("int;int;int;inr", $aM_Mask[0])
    $TestCol = PixelGetColor(0, 0)
    $Startx = -1
    $Starty = -1
    $Endx = 0
    $Endy = 0
    For $i = 0 To $gw
        For $j = 0 To $gh
            If PixelGetColor($i, $j) = $TestCol And $j < $gh Then
                If $Startx = -1 Then
                    $Startx = $i
                    $Starty = $j
                    $Endx = $i
                    $Endy = $j
                Else
                    $Endx = $i
                    $Endy = $j
                EndIf
            Else
                If $Startx <> -1 Then addRegion()
                $Startx = -1
                $Starty = -1
            EndIf
        Next
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $drag_gui, "long", $aM_Mask[0], "int", 1)
EndFunc   ;==>setTrans

Func addRegion()
    $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $Startx, "long", $Starty, "long", $Endx + 1, "long", $Endy + 1)
    $nc += 1
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc   ;==>addRegion

; Create a junk name for testing
Func _makeJunkName()
    Local $labelout = ''
    For $i = 1 To 20
        $labelout &= Chr(Random(65, 90, 1))
    Next
    Return $labelout
EndFunc   ;==>_makeJunkName

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $item_txt

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    $hWndListView = $hWndFrom
    If Not IsHWnd($hWndFrom) Then $hWndListView = GUICtrlGetHandle($hWndFrom)
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_BEGINDRAG ; A drag-and-drop operation involving the left mouse button is being initiated
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    If $hWndFrom = $list_source Then
                        $direction = 1
                    ElseIf $hWndFrom = $list_target Then
                        ; Or are we moving from destination to source
                        $direction = 2
                    Else
                        MsgBox(0, "", "bad")
                    EndIf
                    $aidx = _GUICtrlListView_GetSelectedIndices($hWndFrom, True)
                    $iselecteditems = $aidx[0]
                    ;retrieve all item text, not just first item
                    For $i = 1 To $aidx[0]
                        $item_txt &= _GUICtrlListView_GetItemText($hWndFrom, $aidx[$i]) & @CRLF
                    Next
                    $item_txt = StringStripWS($item_txt, 1 + 2)
                    _WinAPI_ShowCursor(False)
                    ;$atemp = _GUICtrlListBox_GetItemRect($cinfo[4], Int($idx))
                    $atemp = _GUICtrlListView_ApproximateViewRect($hWndFrom, $iselecteditems)
                    $hSplash = SplashTextOn("", $item_txt, $atemp[0] - 10, $atemp[1] - 5, -1, -1, 1 + 32, "", 12)
                    Sleep(5)
                    ;MsgBox(0, "", $item_txt)
                    GUISetState(@SW_SHOW, $drag_gui)
                    While _IsPressed(1)
                        chase()
                    WEnd
                    GUISetState(@SW_HIDE, $drag_gui)
                    _WinAPI_ShowCursor(True)
                    SplashOff()
                    ; Get new position
                    Local $newcinfo = GUIGetCursorInfo(WinGetHandle($MainForm))
                    ; If we were moving from source to destination and we ARE in the destination box
                    If $direction = 1 And $newcinfo[4] = GUICtrlGetHandle($list_target) Then
                        ;ConsoleWrite("Moved " & $iselecteditems & " items from source to destination" & @CRLF)
                        _GUICtrlListView_CopyItems($list_source, $list_target, 1)
                    EndIf
                    ; If we are moving from destination to source and we ARE in source box
                    If $direction = 2 And $newcinfo[4] = GUICtrlGetHandle($list_source) Then
                        ;ConsoleWrite("Moved " & $iselecteditems & " items from destination to source" & @CRLF)
                        _GUICtrlListView_CopyItems($list_target, $list_source, 1)
                    EndIf



            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

17 way split.txt

Link to comment
Share on other sites

Sorry to cause you pain.

No problem :)

Here you go:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>
 
#include <GUIListView.au3>
#include <GUIImageList.au3>
 
Global $blDragging = False, $hDragImage = 0, $hLwDragFrom = 0, $sInputSeason = "", $sInput17WS = ""
Global $aKalRecs = 0, $sPreviewData = ""
 
#region GUI
Global $hGUI = GUICreate("MyGUI", 840, 485)
 
GUICtrlCreateGroup("Specify Director Code, Manager Code or Buyer Code", 10, 10, 510, 80)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Director Code", 20, 37, Default, 15)
Global $iInputDirectorCode = GUICtrlCreateInput("", 100, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel("Manager Code", 180, 37, Default, 15)
Global $iInputManagerCode = GUICtrlCreateInput("", 265, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel("Buyer Code", 345, 37, Default, 15)
Global $iInputBuyerCode = GUICtrlCreateInput("", 415, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel('"*" in Director Code = List all entries', 20, 65, 260, 20)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Source Items", 10, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwSource = GUICtrlCreateListView("Director|Manager|Buyer", 10, 125, 250, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Global $hLwSource = GUICtrlGetHandle($iLwSource)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSource, $i, 75)
Next
 
GUICtrlCreateLabel("Segment Items", 270, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwSegments = GUICtrlCreateListView("Director|Manager|Buyer", 270, 125, 250, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Global $hLwSegments = GUICtrlGetHandle($iLwSegments)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSegments, $i, 75)
Next
 
Global $iInputSeason = GUICtrlCreateInput("", 270, 430, 80, 20)
 
Global $iInput17WS = GUICtrlCreateInput("", 360, 430, 80, 20)
 
Global $iBtnCommit = GUICtrlCreateButton("Commit", 451, 430, 70, 25)
GUICtrlSetState($iBtnCommit, $GUI_DISABLE)
 
GUICtrlCreateLabel("Use the left/right arrows to add or remove items from the lists.", 10, 460, 510, 20)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Preview", 530, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwPreview = GUICtrlCreateListView("Director|Manager|Buyer", 530, 30, 300, 395)
Global $hLwPreview = GUICtrlGetHandle($iLwPreview)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwPreview, $i, 92)
Next
 
Local $iBtnSubmit = GUICtrlCreateButton("Submit...", 751, 430, 80, 25)
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_LBUTTONUP, "WM_LBUTTONUP")
 
_LoadDb()
 
$iDyLeft = GUICtrlCreateDummy()
$iDyRight = GUICtrlCreateDummy()
 
Local $aHotkey[2][2] = [["{LEFT}", $iDyLeft],["{RIGHT}", $iDyRight]]
GUISetAccelerators($aHotkey)
 
GUISetState(@SW_SHOW, $hGUI)
#endregion GUI
 
While 1
    Sleep(10)
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnCommit
            _Commit()
        Case $iBtnSubmit
            _Submit()
        Case $iDyLeft
            _MoveFromSegmentsToSource()
        Case $iDyRight
            _MoveFromSourceToSegments()
    EndSwitch
WEnd
 
GUIDelete($hGUI)
 
Func _Commit()
    _GUICtrlListView_BeginUpdate($hLwPreview)
 
    Local $aData = 0, $sData = ""
 
    For $i = 0 To _GUICtrlListView_GetItemCount($hLwSegments) - 1
$aData = _GUICtrlListView_GetItemTextArray($hLwSegments, $i)
        $sPreviewData &= $sInputSeason & ";" & $aData[0] & ";" & $aData[1] & ";" & $aData[2] & ";" & $sInput17WS & @CRLF
        GUICtrlCreateListViewItem(_ArrayToString($aData, "|"), $iLwPreview)
    Next
    _GUICtrlListView_EndUpdate($hLwPreview)
 
    _GUICtrlListView_DeleteAllItems($hLwSegments)
EndFunc   ;==>_Commit
 
Func _Submit()
    Local $sPath = FileSaveDialog("save", "", "CSV file (*.csv)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE))
    If @error Then Return 0
 
    If StringRight($sPath, 4) <> ".csv" Then $sPath &= ".csv"
 
    Local $hFile = FileOpen($sPath, $FO_OVERWRITE)
    FileWrite($hFile, "SEASON,DIRECTOR_CODE,MERCH_MANAGER_CODE,BUYER_CODE,17_Way_Split" & @CRLF & $sPreviewData)
    FileClose($hFile)
 
    $sPreviewData = ""
    _GUICtrlListView_DeleteAllItems($hLwPreview)
EndFunc   ;==>_Submit
 
Func _LoadDb()
    Local $sData = FileRead(@ScriptDir & "\Dir_man_Buyer.txt")
    If @error Then Exit 1
 
    Local $aBase = StringSplit($sData, @CRLF, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
 
    ;-2/-3 for the UBound because the first line is a header and the last line is empty
 
    Global $aKalRecs[UBound($aBase) - 2][3]
    Local $aTmp = 0
 
    For $i = 0 To UBound($aBase) - 3
        $aTmp = StringSplit($aBase[$i + 1], ",", BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
 
        $aKalRecs[$i][0] = $aTmp[0]
        $aKalRecs[$i][1] = $aTmp[1]
        $aKalRecs[$i][2] = $aTmp[2]
    Next
EndFunc   ;==>_LoadDb
 
Func _MoveFromSourceToSegments()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSource)
    If $sSelectedItem = "" Then Return 0
 
    Local $aSelectedItem = StringSplit($sSelectedItem, "|")
 
    _GUICtrlListView_BeginUpdate($hLwSource)
    _GUICtrlListView_BeginUpdate($hLwSegments)
    For $i = 1 To $aSelectedItem[0]
        GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSource, Number($aSelectedItem[$i]) - ($i - 1)), $iLwSegments)
        _GUICtrlListView_DeleteItem($hLwSource, Number($aSelectedItem[$i]) - ($i - 1))
    Next
    _GUICtrlListView_EndUpdate($hLwSegments)
    _GUICtrlListView_EndUpdate($hLwSource)
EndFunc   ;==>_MoveFromSourceToSegments
 
Func _MoveFromSegmentsToSource()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSegments)
    If $sSelectedItem = "" Then Return 0
 
    Local $aSelectedItem = StringSplit($sSelectedItem, "|")
 
    _GUICtrlListView_BeginUpdate($hLwSegments)
    _GUICtrlListView_BeginUpdate($hLwSource)
    For $i = 1 To $aSelectedItem[0]
        GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSegments, Number($aSelectedItem[$i]) - ($i - 1)), $iLwSource)
        _GUICtrlListView_DeleteItem($hLwSegments, Number($aSelectedItem[$i]) - ($i - 1))
    Next
    _GUICtrlListView_EndUpdate($hLwSource)
    _GUICtrlListView_EndUpdate($hLwSegments)
EndFunc   ;==>_MoveFromSegmentsToSource
 
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom = 0, $iCode = 0
 
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)
 
    Switch $iIDFrom
        Case $iInputDirectorCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputManagerCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputDirectorCode)
                    If StringRegExp($sInput, "^([A-Za-z]|\*)$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 0)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        If $sInput = "*" Then
                            For $i = 0 To UBound($aKalRecs) - 1
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        Else
                            For $i = 0 To UBound($aKalRecs) - 1
                                If $sInput <> StringStripWS($aKalRecs[$i][0], $STR_STRIPTRAILING) Then ContinueLoop
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        EndIf
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputManagerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputManagerCode)
                    If StringRegExp($sInput, "^\d+$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 1)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aKalRecs) - 1
                            If $sInput <> $aKalRecs[$i][1] Then ContinueLoop
                            GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputBuyerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputManagerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputBuyerCode)
                    If StringRegExp($sInput, "^[\dA-Za-z]+$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 2)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aKalRecs) - 1
                            If $sInput <> $aKalRecs[$i][2] Then ContinueLoop
                            GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInput17WS, $iInputSeason
            Switch $iCode
                Case $EN_UPDATE
                    $sInputSeason = GUICtrlRead($iInputSeason)
                    $sInput17WS = GUICtrlRead($iInput17WS)
 
                    If $sInputSeason = "" Or $sInput17WS = "" Then
                        GUICtrlSetState($iBtnCommit, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($iBtnCommit, $GUI_ENABLE)
                    EndIf
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
 
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
 
    Local $tNMHDR = 0, $hWndFrom = 0, $iIDFrom = 0, $iCode = 0
 
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
 
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
 
    Switch $iIDFrom
        Case $iLwSource, $iLwPreview
            Switch $iCode
                Case $LVN_BEGINDRAG
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
 
                    Local $aImageData = _GUICtrlListView_CreateDragImage($hWndFrom, $iItem)
 
                    $hDragImage = $aImageData[0]
                    _GUIImageList_BeginDrag($hDragImage, 0, -7, 3)
 
                    $hLwDragFrom = $hWndFrom
 
                    $blDragging = True
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
Func WM_LBUTTONUP($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
 
    If Not $blDragging Then Return $GUI_RUNDEFMSG
 
    _GUIImageList_DragLeave($hLwDragFrom)
    _GUIImageList_EndDrag()
    _GUIImageList_Destroy($hDragImage)
 
    ; Get new position
    Local $aNewCInfo = GUIGetCursorInfo($hGUI)
    ; If we were moving from source to destination and we ARE in the destination box
    If $hLwDragFrom = $hLwSource And $aNewCInfo[4] = $iLwSegments Then
        _GUICtrlListView_CopyItems($hLwSource, $hLwSegments, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $hLwDragFrom = $hLwSegments And $aNewCInfo[4] = $iLwSource Then
        _GUICtrlListView_CopyItems($hLwSegments, $hLwSource, 1)
    EndIf
 
    $blDragging = False
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_LBUTTONUP
Br, FireFox.
Link to comment
Share on other sites

 

No problem :)

Here you go:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>
 
#include <GUIListView.au3>
#include <GUIImageList.au3>
 
Global $blDragging = False, $hDragImage = 0, $hLwDragFrom = 0, $sInputSeason = "", $sInput17WS = ""
Global $aKalRecs = 0, $sPreviewData = ""
 
#region GUI
Global $hGUI = GUICreate("MyGUI", 840, 485)
 
GUICtrlCreateGroup("Specify Director Code, Manager Code or Buyer Code", 10, 10, 510, 80)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Director Code", 20, 37, Default, 15)
Global $iInputDirectorCode = GUICtrlCreateInput("", 100, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel("Manager Code", 180, 37, Default, 15)
Global $iInputManagerCode = GUICtrlCreateInput("", 265, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel("Buyer Code", 345, 37, Default, 15)
Global $iInputBuyerCode = GUICtrlCreateInput("", 415, 33, 40, 20, $ES_AUTOHSCROLL)
 
GUICtrlCreateLabel('"*" in Director Code = List all entries', 20, 65, 260, 20)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Source Items", 10, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwSource = GUICtrlCreateListView("Director|Manager|Buyer", 10, 125, 250, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Global $hLwSource = GUICtrlGetHandle($iLwSource)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSource, $i, 75)
Next
 
GUICtrlCreateLabel("Segment Items", 270, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwSegments = GUICtrlCreateListView("Director|Manager|Buyer", 270, 125, 250, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Global $hLwSegments = GUICtrlGetHandle($iLwSegments)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSegments, $i, 75)
Next
 
Global $iInputSeason = GUICtrlCreateInput("", 270, 430, 80, 20)
 
Global $iInput17WS = GUICtrlCreateInput("", 360, 430, 80, 20)
 
Global $iBtnCommit = GUICtrlCreateButton("Commit", 451, 430, 70, 25)
GUICtrlSetState($iBtnCommit, $GUI_DISABLE)
 
GUICtrlCreateLabel("Use the left/right arrows to add or remove items from the lists.", 10, 460, 510, 20)
GUICtrlSetFont(-1, 10, 800)
 
GUICtrlCreateLabel("Preview", 530, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
 
Global $iLwPreview = GUICtrlCreateListView("Director|Manager|Buyer", 530, 30, 300, 395)
Global $hLwPreview = GUICtrlGetHandle($iLwPreview)
 
For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwPreview, $i, 92)
Next
 
Local $iBtnSubmit = GUICtrlCreateButton("Submit...", 751, 430, 80, 25)
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_LBUTTONUP, "WM_LBUTTONUP")
 
_LoadDb()
 
$iDyLeft = GUICtrlCreateDummy()
$iDyRight = GUICtrlCreateDummy()
 
Local $aHotkey[2][2] = [["{LEFT}", $iDyLeft],["{RIGHT}", $iDyRight]]
GUISetAccelerators($aHotkey)
 
GUISetState(@SW_SHOW, $hGUI)
#endregion GUI
 
While 1
    Sleep(10)
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnCommit
            _Commit()
        Case $iBtnSubmit
            _Submit()
        Case $iDyLeft
            _MoveFromSegmentsToSource()
        Case $iDyRight
            _MoveFromSourceToSegments()
    EndSwitch
WEnd
 
GUIDelete($hGUI)
 
Func _Commit()
    _GUICtrlListView_BeginUpdate($hLwPreview)
 
    Local $aData = 0, $sData = ""
 
    For $i = 0 To _GUICtrlListView_GetItemCount($hLwSegments) - 1
$aData = _GUICtrlListView_GetItemTextArray($hLwSegments, $i)
        $sPreviewData &= $sInputSeason & ";" & $aData[0] & ";" & $aData[1] & ";" & $aData[2] & ";" & $sInput17WS & @CRLF
        GUICtrlCreateListViewItem(_ArrayToString($aData, "|"), $iLwPreview)
    Next
    _GUICtrlListView_EndUpdate($hLwPreview)
 
    _GUICtrlListView_DeleteAllItems($hLwSegments)
EndFunc   ;==>_Commit
 
Func _Submit()
    Local $sPath = FileSaveDialog("save", "", "CSV file (*.csv)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE))
    If @error Then Return 0
 
    If StringRight($sPath, 4) <> ".csv" Then $sPath &= ".csv"
 
    Local $hFile = FileOpen($sPath, $FO_OVERWRITE)
    FileWrite($hFile, "SEASON,DIRECTOR_CODE,MERCH_MANAGER_CODE,BUYER_CODE,17_Way_Split" & @CRLF & $sPreviewData)
    FileClose($hFile)
 
    $sPreviewData = ""
    _GUICtrlListView_DeleteAllItems($hLwPreview)
EndFunc   ;==>_Submit
 
Func _LoadDb()
    Local $sData = FileRead(@ScriptDir & "\Dir_man_Buyer.txt")
    If @error Then Exit 1
 
    Local $aBase = StringSplit($sData, @CRLF, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
 
    ;-2/-3 for the UBound because the first line is a header and the last line is empty
 
    Global $aKalRecs[UBound($aBase) - 2][3]
    Local $aTmp = 0
 
    For $i = 0 To UBound($aBase) - 3
        $aTmp = StringSplit($aBase[$i + 1], ",", BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
 
        $aKalRecs[$i][0] = $aTmp[0]
        $aKalRecs[$i][1] = $aTmp[1]
        $aKalRecs[$i][2] = $aTmp[2]
    Next
EndFunc   ;==>_LoadDb
 
Func _MoveFromSourceToSegments()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSource)
    If $sSelectedItem = "" Then Return 0
 
    Local $aSelectedItem = StringSplit($sSelectedItem, "|")
 
    _GUICtrlListView_BeginUpdate($hLwSource)
    _GUICtrlListView_BeginUpdate($hLwSegments)
    For $i = 1 To $aSelectedItem[0]
        GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSource, Number($aSelectedItem[$i]) - ($i - 1)), $iLwSegments)
        _GUICtrlListView_DeleteItem($hLwSource, Number($aSelectedItem[$i]) - ($i - 1))
    Next
    _GUICtrlListView_EndUpdate($hLwSegments)
    _GUICtrlListView_EndUpdate($hLwSource)
EndFunc   ;==>_MoveFromSourceToSegments
 
Func _MoveFromSegmentsToSource()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSegments)
    If $sSelectedItem = "" Then Return 0
 
    Local $aSelectedItem = StringSplit($sSelectedItem, "|")
 
    _GUICtrlListView_BeginUpdate($hLwSegments)
    _GUICtrlListView_BeginUpdate($hLwSource)
    For $i = 1 To $aSelectedItem[0]
        GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSegments, Number($aSelectedItem[$i]) - ($i - 1)), $iLwSource)
        _GUICtrlListView_DeleteItem($hLwSegments, Number($aSelectedItem[$i]) - ($i - 1))
    Next
    _GUICtrlListView_EndUpdate($hLwSource)
    _GUICtrlListView_EndUpdate($hLwSegments)
EndFunc   ;==>_MoveFromSegmentsToSource
 
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom = 0, $iCode = 0
 
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)
 
    Switch $iIDFrom
        Case $iInputDirectorCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputManagerCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputDirectorCode)
                    If StringRegExp($sInput, "^([A-Za-z]|\*)$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 0)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        If $sInput = "*" Then
                            For $i = 0 To UBound($aKalRecs) - 1
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        Else
                            For $i = 0 To UBound($aKalRecs) - 1
                                If $sInput <> StringStripWS($aKalRecs[$i][0], $STR_STRIPTRAILING) Then ContinueLoop
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        EndIf
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputManagerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputManagerCode)
                    If StringRegExp($sInput, "^\d+$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 1)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aKalRecs) - 1
                            If $sInput <> $aKalRecs[$i][1] Then ContinueLoop
                            GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInputBuyerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputManagerCode, "")
 
                    Local $sInput = GUICtrlRead($iInputBuyerCode)
                    If StringRegExp($sInput, "^[\dA-Za-z]+$") = 1 Then
                        _ArraySort($aKalRecs, 0, 0, 0, 2)
 
                        $iSourceSelItem = -1
 
                        _GUICtrlListView_BeginUpdate($hLwSource)
                        _GUICtrlListView_DeleteAllItems($hLwSource)
                        For $i = 0 To UBound($aKalRecs) - 1
                            If $sInput <> $aKalRecs[$i][2] Then ContinueLoop
                            GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                        Next
                        _GUICtrlListView_EndUpdate($hLwSource)
                    EndIf
            EndSwitch
        Case $iInput17WS, $iInputSeason
            Switch $iCode
                Case $EN_UPDATE
                    $sInputSeason = GUICtrlRead($iInputSeason)
                    $sInput17WS = GUICtrlRead($iInput17WS)
 
                    If $sInputSeason = "" Or $sInput17WS = "" Then
                        GUICtrlSetState($iBtnCommit, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($iBtnCommit, $GUI_ENABLE)
                    EndIf
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
 
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
 
    Local $tNMHDR = 0, $hWndFrom = 0, $iIDFrom = 0, $iCode = 0
 
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
 
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
 
    Switch $iIDFrom
        Case $iLwSource, $iLwPreview
            Switch $iCode
                Case $LVN_BEGINDRAG
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
 
                    Local $aImageData = _GUICtrlListView_CreateDragImage($hWndFrom, $iItem)
 
                    $hDragImage = $aImageData[0]
                    _GUIImageList_BeginDrag($hDragImage, 0, -7, 3)
 
                    $hLwDragFrom = $hWndFrom
 
                    $blDragging = True
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
Func WM_LBUTTONUP($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
 
    If Not $blDragging Then Return $GUI_RUNDEFMSG
 
    _GUIImageList_DragLeave($hLwDragFrom)
    _GUIImageList_EndDrag()
    _GUIImageList_Destroy($hDragImage)
 
    ; Get new position
    Local $aNewCInfo = GUIGetCursorInfo($hGUI)
    ; If we were moving from source to destination and we ARE in the destination box
    If $hLwDragFrom = $hLwSource And $aNewCInfo[4] = $iLwSegments Then
        _GUICtrlListView_CopyItems($hLwSource, $hLwSegments, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $hLwDragFrom = $hLwSegments And $aNewCInfo[4] = $iLwSource Then
        _GUICtrlListView_CopyItems($hLwSegments, $hLwSource, 1)
    EndIf
 
    $blDragging = False
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_LBUTTONUP
Br, FireFox.

 

 

Thanks FF.. I'll have a play and see if I can break it :shifty:;)

Link to comment
Share on other sites

It's really good now FF.. :thumbsup:

There are some issues like the preview columns are not displaying in the correct order and there are some enhancements that I could do with but I'm gonna try them all myself. :unsure:

Don't worry, I'll be back to pester the community if when I bollax it up!

Link to comment
Share on other sites

Ok..

Thanks again FF for the code.

I have made some enhancements(whether they are coded correctly or optimally is another thing).

  • Created addition preview/output columns
  • Added output file name input requirement
  • Allowed multiple search criteria
  • Annotated the controls

 

One of the requirements I'm having difficulty with is preventing duplicate rows from being input to the preview.

I've tried all sorts of listview to array examples from the forums to achieve this but am getting nowhere.

Basically, when the commit button is clicked there should be a check to see if a row in the Segments list view already exists in the Preview list view and if there is the commit is stopped and the user informed of the offending row so they can do something.

Current code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>

#include <GUIListView.au3>
#include <GUIImageList.au3>

;Dim Globals
Global $blDragging = False, $hDragImage = 0, $hLwDragFrom = 0, $sInputSeason = "", $sInput17WS = ""
Global $aKalRecs = 0, $sPreviewData = ""

#region GUI
Global $hGUI = GUICreate("Kaleidoscope Segment Builder", 1020, 535)

GUICtrlSetDefColor(0x0043737)

GUICtrlCreateGroup("File Search... (Multiple search items must be seperated by comma)", 10, 10, 510, 80)
GUICtrlSetFont(-1, 10, 800)

GUICtrlCreateLabel("Director Code", 20, 37, Default, 15)
Global $iInputDirectorCode = GUICtrlCreateInput("", 100, 33, 40, 20, $ES_AUTOHSCROLL)

GUICtrlCreateLabel("Manager Code", 180, 37, Default, 15)
Global $iInputManagerCode = GUICtrlCreateInput("", 265, 33, 40, 20, $ES_AUTOHSCROLL)

GUICtrlCreateLabel("Buyer Code", 345, 37, Default, 15)
Global $iInputBuyerCode = GUICtrlCreateInput("", 415, 33, 40, 20, $ES_AUTOHSCROLL)

GUICtrlCreateLabel('* in Director Code = List all Items', 20, 65, 280, 20)
GUICtrlSetFont(-1, 8, 600, 0, "Verdana", 2)

;Define Source listview to recieve search results - 3 columns
GUICtrlCreateLabel("Source Items", 10, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)

Global $iLwSource = GUICtrlCreateListView("Director|Manager|Buyer", 10, 125, 250, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Global $hLwSource = GUICtrlGetHandle($iLwSource)

For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSource, $i, 75)
Next

;Define Segment listview to recieve segment selections - 3 columns
GUICtrlCreateLabel("Segment Items", 270, 105, 250, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)

Global $iLwSegments = GUICtrlCreateListView("Director|Manager|Buyer", 270, 125, 250, 300, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Global $hLwSegments = GUICtrlGetHandle($iLwSegments)

For $i = 0 To 2
    _GUICtrlListView_SetColumnWidth($hLwSegments, $i, 75)
Next

;Input the season code
GUICtrlCreateLabel("Season", 270, 430, 80, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
Global $iInputSeason = GUICtrlCreateInput("", 270, 450, 80, 20)

;Input segment description
GUICtrlCreateLabel("Desc.", 360, 430, 80, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
Global $iInput17WS = GUICtrlCreateInput("", 360, 450, 80, 20)

;Output File name
GUICtrlCreateLabel("Output File", 600, 430, 80, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)
Global $iOutputFname = GUICtrlCreateInput("", 600, 450, 130, 20)

;Define the commit button - disable until season and segment description is entered.
Global $iBtnCommit = GUICtrlCreateButton("Commit...", 451, 448, 70, 25)
GUICtrlSetState($iBtnCommit, $GUI_DISABLE)

GUICtrlCreateLabel("Use the left/right arrows to add or remove items from the lists.", 10, 490, 510, 20)
GUICtrlSetFont(-1, 10, 800)

GUICtrlCreateLabel("Preview", 600, 10, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800)

;Define Preview listview to recieve segment selections - 5 columns
Global $iLwPreview = GUICtrlCreateListView("Season|Director|Manager|Buyer|Description", 530, 30, 480, 395)
Global $hLwPreview = GUICtrlGetHandle($iLwPreview)

For $i = 0 To 4
    _GUICtrlListView_SetColumnWidth($hLwPreview, $i, 92)
Next

;Define the submit to csv button.
Local $iBtnSubmit = GUICtrlCreateButton("Submit...", 751, 448, 80, 25)
GUICtrlSetState($iBtnSubmit, $GUI_DISABLE)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_LBUTTONUP, "WM_LBUTTONUP")

;Call array load
_LoadDb()

;Create dummy controls to enable hotkey detection
$iDyLeft = GUICtrlCreateDummy()
$iDyRight = GUICtrlCreateDummy()

;Hotkey definition enabling left/right arrow use for moving items between listviews
Local $aHotkey[2][2] = [["{LEFT}", $iDyLeft],["{RIGHT}", $iDyRight]]
GUISetAccelerators($aHotkey)

GUISetState(@SW_SHOW, $hGUI)
#endregion GUI

;Main control loop
While 1
    Sleep(10)

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnCommit
            _Commit()
        Case $iBtnSubmit
            _Submit()
        Case $iDyLeft
            _MoveFromSegmentsToSource()
        Case $iDyRight
            _MoveFromSourceToSegments()
    EndSwitch
WEnd

GUIDelete($hGUI)

;The commit function takes all entries in the segment listview and the
;annotations in the input boxes and populates(appends) to the preview listview
Func _Commit()
    _GUICtrlListView_BeginUpdate($hLwPreview)

    Local $aData = 0, $sData = ""

    For $i = 0 To _GUICtrlListView_GetItemCount($hLwSegments) - 1
        $aData = _GUICtrlListView_GetItemTextArray($hLwSegments, $i)
        ;_ArrayDisplay($aData)
        $sPreviewData &= $sInputSeason & "," & $aData[1] & "," & $aData[2] & "," & $aData[3] & "," & $sInput17WS & @CRLF
        GUICtrlCreateListViewItem($sInputSeason & "|" & _ArrayToString($aData, "|", 1) & "|" & $sInput17WS, $iLwPreview)
    Next

    GUICtrlCreateListViewItem("----------------|----------------|----------------|----------------|---------------- ", $iLwPreview)
    ;MsgBox(4096,"wibble",$sPreviewData)
    _GUICtrlListView_EndUpdate($hLwPreview)

    _GUICtrlListView_DeleteAllItems($hLwSegments)

    ;Clear description for next segment
    GUICtrlSetData($iInput17WS, "")
    ;Initialise output description var
    $sInput17WS = ""

EndFunc   ;==>_Commit


;The submit function takes all entries in the preview listview and creates a save dialog to create the output file.
Func _Submit()

    Local $cColtitle = GUICtrlRead($iOutputFname)
    $cColtitle = "" & $cColtitle & ""

    Local $sPath = FileSaveDialog("save", "", "CSV file (*.csv)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE), $cColtitle)
    If @error Then Return 0

    If StringRight($sPath, 4) <> ".csv" Then $sPath &= ".csv"

    Local $hFile = FileOpen($sPath, $FO_OVERWRITE)
    FileWrite($hFile, "SEASON,DIRECTOR_CODE,MERCH_MANAGER_CODE,BUYER_CODE," & $cColtitle & @CRLF & $sPreviewData)
    FileClose($hFile)

    $sPreviewData = ""
    _GUICtrlListView_DeleteAllItems($hLwPreview)
    GUICtrlSetData($iInputSeason, "")
    GUICtrlSetData($iOutputFname, "")

EndFunc   ;==>_Submit

;Array load function from current csv version
Func _LoadDb()
    Local $sData = FileRead(@ScriptDir & "\Dir_man_Buyer.csv")
    If @error Then Exit 1

    Local $aBase = StringSplit($sData, @CRLF, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))

    ;-2/-3 for the UBound because the first line is a header and the last line is empty

    Global $aKalRecs[UBound($aBase) - 2][3]
    Local $aTmp = 0

    For $i = 0 To UBound($aBase) - 3
        $aTmp = StringSplit($aBase[$i + 1], ",", BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))

        $aKalRecs[$i][0] = $aTmp[0]
        $aKalRecs[$i][1] = $aTmp[1]
        $aKalRecs[$i][2] = $aTmp[2]
    Next
EndFunc   ;==>_LoadDb

;Move the selected items from source to segment
Func _MoveFromSourceToSegments()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSource)
    If $sSelectedItem = "" Then Return 0

    Local $aSelectedItem = StringSplit($sSelectedItem, "|")

    _GUICtrlListView_BeginUpdate($hLwSource)
    _GUICtrlListView_BeginUpdate($hLwSegments)
    For $i = 1 To $aSelectedItem[0]
        GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSource, Number($aSelectedItem[$i]) - ($i - 1)), $iLwSegments)
        _GUICtrlListView_DeleteItem($hLwSource, Number($aSelectedItem[$i]) - ($i - 1))
    Next
    _GUICtrlListView_EndUpdate($hLwSegments)
    _GUICtrlListView_EndUpdate($hLwSource)
EndFunc   ;==>_MoveFromSourceToSegments


Func _Dupes($aSels)



EndFunc   ;==>_Dupes

;Move the selected items from segment to source
Func _MoveFromSegmentsToSource()
    Local $sSelectedItem = _GUICtrlListView_GetSelectedIndices($hLwSegments)
    If $sSelectedItem = "" Then Return 0

    Local $aSelectedItem = StringSplit($sSelectedItem, "|")

    _GUICtrlListView_BeginUpdate($hLwSegments)
    _GUICtrlListView_BeginUpdate($hLwSource)
    For $i = 1 To $aSelectedItem[0]
        GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($hLwSegments, Number($aSelectedItem[$i]) - ($i - 1)), $iLwSource)
        _GUICtrlListView_DeleteItem($hLwSegments, Number($aSelectedItem[$i]) - ($i - 1))
    Next
    _GUICtrlListView_EndUpdate($hLwSource)
    _GUICtrlListView_EndUpdate($hLwSegments)
EndFunc   ;==>_MoveFromSegmentsToSource

;Receive a message from an input and populate source listview with search results
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom = 0, $iCode = 0

    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)

    Switch $iIDFrom

        Case $iInputDirectorCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputManagerCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
                    _GUICtrlListView_BeginUpdate($hLwSource)
                    _GUICtrlListView_DeleteAllItems($hLwSource)
                    Local $sInput = GUICtrlRead($iInputDirectorCode)
                    Local $aInput = StringSplit($sInput, ",", 0)
                    For $j = 1 to $aInput[0]
                        If StringRegExp($aInput[$j], "^([A-Za-z]|\*)$") = 1 Then
                            _ArraySort($aKalRecs, 0, 0, 0, 0)
                            If $sInput = "*" Then
                                For $i = 0 To UBound($aKalRecs) - 1
                                    GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                                Next
                            Else
                                For $i = 0 To UBound($aKalRecs) - 1
                                    If $aInput[$j] <> StringStripWS($aKalRecs[$i][0], $STR_STRIPTRAILING) Then ContinueLoop
                                    GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                                Next
                            EndIf
                        EndIf
                    Next
                    _GUICtrlListView_EndUpdate($hLwSource)
            EndSwitch

        Case $iInputManagerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputBuyerCode, "")
                    _GUICtrlListView_BeginUpdate($hLwSource)
                    _GUICtrlListView_DeleteAllItems($hLwSource)
                    Local $sInput = GUICtrlRead($iInputManagerCode)
                    Local $aInput = StringSplit($sInput, ",", 0)
                    For $j = 1 to $aInput[0]
                        If StringRegExp($aInput[$j], "^\d+$") = 1 Then
                            _ArraySort($aKalRecs, 0, 0, 0, 1)
                            For $i = 0 To UBound($aKalRecs) - 1
                                If $aInput[$j] <> $aKalRecs[$i][1] Then ContinueLoop
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                        EndIf
                    Next
                    _GUICtrlListView_EndUpdate($hLwSource)
            EndSwitch

        Case $iInputBuyerCode
            Switch $iCode
                Case $EN_UPDATE
                    GUICtrlSetData($iInputDirectorCode, "")
                    GUICtrlSetData($iInputManagerCode, "")
                    _GUICtrlListView_BeginUpdate($hLwSource)
                    _GUICtrlListView_DeleteAllItems($hLwSource)
                    Local $sInput = GUICtrlRead($iInputBuyerCode)
                    Local $aInput = StringSplit($sInput, ",", 0)
                    For $j = 1 to $aInput[0]
                        If StringRegExp($aInput[$j], "^[\dA-Za-z]+$") = 1 Then
                            _ArraySort($aKalRecs, 0, 0, 0, 2)
                            For $i = 0 To UBound($aKalRecs) - 1
                                If $aInput[$j] <> $aKalRecs[$i][2] Then ContinueLoop
                                GUICtrlCreateListViewItem($aKalRecs[$i][0] & "|" & $aKalRecs[$i][1] & "|" & $aKalRecs[$i][2], $iLwSource)
                            Next
                            _GUICtrlListView_EndUpdate($hLwSource)
                        EndIf
                    Next
            EndSwitch

        Case $iInput17WS, $iInputSeason
            Switch $iCode
                Case $EN_UPDATE
                    $sInputSeason = GUICtrlRead($iInputSeason)
                    $sInput17WS = GUICtrlRead($iInput17WS)
                    If $sInputSeason = "" Or $sInput17WS = "" Then
                        GUICtrlSetState($iBtnCommit, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($iBtnCommit, $GUI_ENABLE)
                    EndIf
            EndSwitch

        Case $iOutputFname
            Switch $iCode
                Case $EN_UPDATE
                    $sOutputFname = GUICtrlRead($iOutputFname)
                    If $sOutputFname = "" Then
                        GUICtrlSetState($iBtnSubmit, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($iBtnSubmit, $GUI_ENABLE)
                    EndIf
            EndSwitch

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam

    Local $tNMHDR = 0, $hWndFrom = 0, $iIDFrom = 0, $iCode = 0

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $iLwSource, $iLwPreview
            Switch $iCode
                Case $LVN_BEGINDRAG

                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")

                    Local $aImageData = _GUICtrlListView_CreateDragImage($hWndFrom, $iItem)

                    $hDragImage = $aImageData[0]
                    _GUIImageList_BeginDrag($hDragImage, 0, -7, 3)

                    $hLwDragFrom = $hWndFrom

                    $blDragging = True
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_LBUTTONUP($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam

    If Not $blDragging Then Return $GUI_RUNDEFMSG

    _GUIImageList_DragLeave($hLwDragFrom)
    _GUIImageList_EndDrag()
    _GUIImageList_Destroy($hDragImage)

    ; Get new position
    Local $aNewCInfo = GUIGetCursorInfo($hGUI)
    ; If we were moving from source to destination and we ARE in the destination box
    If $hLwDragFrom = $hLwSource And $aNewCInfo[4] = $iLwSegments Then
        _GUICtrlListView_CopyItems($hLwSource, $hLwSegments, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $hLwDragFrom = $hLwSegments And $aNewCInfo[4] = $iLwSource Then
        _GUICtrlListView_CopyItems($hLwSegments, $hLwSource, 1)
    EndIf

    $blDragging = False

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_LBUTTONUP

Regards

Link to comment
Share on other sites

One of the requirements I'm having difficulty with is preventing duplicate rows from being input to the preview.

The same kind of question was asked >here (your code will be simpler, you don't need to delete the duplicated items).

Link to comment
Share on other sites

The same kind of question was asked >here (your code will be simpler, you don't need to delete the duplicated items).

Yeah, I looked at that before but it's different to the requirement as I need to inform the user before the row is added to preview so they can amend segment.

Don't worry, I understand that you can't keep on coding for me.. I'll just keep trying.

Take care.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...