Jump to content

GUICtrlCreateListView


yucatan
 Share

Recommended Posts

Hello M23.

i'm running into some problems.

one if a combobox is active and i change the week then it dont modify's the dates.

i know the cause because i have a while wend when the combo has focus.

so i dont cant detect the week change.

i dont know how to solve that.

two if i click a items and i select some text.

and i click it again then i cant modify the text in the field i only can enter new text.

this is my code.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>
#Include <GuiComboBox.au3>
#include <Misc.au3>
Opt("GUICloseOnESC", 0)
Global $fClicked = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"
Global $buswidth = 30, $monteurwidth = 60, $klantwidth = 155
$clickedweek = _WeekNumberISO()
; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")

Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)

$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1

        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)

        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)

        $hListView = _GUICtrlListView_Create($hGUI, "Bus", $iX, $iY, 285, 407, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) ; Set grid lines
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, $buswidth)
        _GUICtrlListView_SetColumnWidth($hListView, 1, $monteurwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $klantwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 27
            _GUICtrlListView_AddItem($hListView, "")
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 2)
        Next
    Next
Next

_Calculate()

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hAccel_Enter = GUICtrlCreateDummy()
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hTab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
            If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
            $clickedweek = GUICtrlRead($hTab)
            For $i = 1 To 6
                GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
            Next
        Case $hUpDown
            _Calculate()
    EndSwitch

    ; If an item was double clicked
    If $fClicked Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fClicked]
        $iListView_ID = $fClicked
        ; Reset flag
        $fClicked = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]

            ; Get column width
            Local $iWidth = _GUICtrlListView_GetColumnWidth($hListView, $aLV_Click_Info[1])
            ; Create edit combo
            $hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, $iWidth, 20)
            ; Set combo values depending on column clicked

         Switch $aLV_Click_Info[1]
                Case 0
                    GUICtrlSetData($hEdit_Combo, "1 Bus|2 Bus|3 Bus",$sItemText)
                Case 1
                    GUICtrlSetData($hEdit_Combo, "Monteur 1|Monteur 2|Monteur 3",$sItemText)
                Case 2
                    GUICtrlSetData($hEdit_Combo, "Klant 1|Klant 2|Klant 3",$sItemText)
                Case 3
                    GUICtrlSetData($hEdit_Combo, "Wvb 1|Wvb 2|Wvb 3",$sItemText)
            EndSwitch
            GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

            ; Get handle of combo edit control
            $hComboEdit = _WinAPI_GetFocus()
            ; Set flag for Enter pressed
            $iLoopCode = 0

            ; Loop while the combo has focus
            While _WinAPI_GetFocus() = $hComboEdit

                ; If combo is filled <<<<<<<<<<<<<<
                If GUICtrlRead($hEdit_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hEdit_Combo) = False Then ; <<<<<<<<<<<<<<
                    $iLoopCode = 1
                    ExitLoop
                EndIf
                ; If ESC pressed
                If _IsPressed("1B", $dll) Then ExitLoop
                ; Save CPU
                Sleep(10)
            WEnd
            ; Edit ListView if Enter pressed
            If $iLoopCode Then
                ; Set label to edit content
                $sText = GUICtrlRead($hEdit_Combo)
                _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            EndIf
            ; Delete combo
            GUICtrlDelete($hEdit_Combo)
            $hEdit_Combo = 0
        EndIf

    EndIf

WEnd


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_CLICK
                    $fClicked = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY


Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate)
    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ;ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next
EndFunc   ;==>_Calculate

Thanks Alot.

Link to comment
Share on other sites

  • Moderators

yucatan,

i'm running into some problems

Nothing new there! :lol:

if a combobox is active and i change the week then it dont modify's the dates

Easy to fix. We look for a change in the tab and just reset the tab to the current one - that way you cannot change weeks when a combo is open. Look for the section beginning with <<<<<<<<<<< 1 in the code below. :shifty:

i click it again then i cant modify the text in the field i only can enter new text

That is because you decided to add the current value of the combo as the default value. It has required a complete reworking of the code as you can see below.

What you now get is that the ListView is edited when the following happens:

- a. You open the combo and select a value from the list to be saved

- b. You press "Enter" - the current content of the combo edit control is saved

- c. You click outside the combo - the current content of the combo edit control is saved

Pressing "Escape" leaves the value unchanged.

Look for sections beginning with <<<<<<<<<<< 2 in this code - it shoudl be obvious where it fits into the script: :nuke:

; Get column width
Local $iWidth = _GUICtrlListView_GetColumnWidth($hListView, $aLV_Click_Info[1])
; Create edit combo
$hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, $iWidth, 20)
; Set combo values depending on column clicked
Switch $aLV_Click_Info[1]  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    Case 0
        $sComboList = "1 Bus|2 Bus|3 Bus"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
    Case 1
        $sComboList = "Monteur 1|Monteur 2|Monteur 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        Case 2
        $sComboList = "Klant 1|Klant 2|Klant 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
    Case 3
        $sComboList = "Wvb 1|Wvb 2|Wvb 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
EndSwitch
; Set values into combo
GUICtrlSetData($hEdit_Combo, $sComboList, $sItemText)
GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

; Get handle of combo edit control
$hComboEdit = _WinAPI_GetFocus()
; Set flag for Enter pressed
$iLoopCode = 0
; Set flag for combo opened <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
$fCombo_Opened = False

; Loop while the combo has focus
While _WinAPI_GetFocus() = $hComboEdit

    ; If combo has been opened, check if closed again ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If $fCombo_Opened Then
        ; If combo is closed again
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) = False Then
            $iLoopCode = 1
            ExitLoop
        EndIf
    Else
        ; Check if opened and set flag
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) Then $fCombo_Opened = True
    EndIf

    ; If Enter Pressed ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If _IsPressed("0D", $dll) Then
        $iLoopCode = 1
        ExitLoop
    EndIf

        ; If ESC pressed
        If _IsPressed("1B", $dll) Then
        $iLoopCode = -1
        ExitLoop
    EndIf

        ; Save CPU and prevent tab selection <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1
        Switch GUIGetMsg()
        Case $hTab
            _GUICtrlTab_ClickTab($hTab, $clickedweek)
    EndSwitch
WEnd

; Read Combo
$sText = GUICtrlRead($hEdit_Combo)

; Check if content changed manually
If Not $iLoopCode And $sText <> $sItemText Then $iLoopCode = 1 ; <<<<<<<<<<<<<<<<<<<<< 2

; Edit ListView if required
If $iLoopCode Then _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])

; Delete combo
GUICtrlDelete($hEdit_Combo)
$hEdit_Combo = 0

If you keep modifying the code, you cannot expect it to work straight away. But I would expect you to at least have tried to fix it. :P

At the moment I am doing all the work - I do not believe there is a single line of code in your script that you have written yourself. How will you maintain this code if all you do is come running to me each time you want a small change? You need to understand how it works yourself so that you can fix minor problems. After 2 months and 2 pages of this topic I have very nearly reached the limit of of my patience. If you do not begin to make more of an effort yourself, you will find that I am no longer prepared to help - so be warned. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello M23.

I have been working on it to fix it but i didnt get it done.

thanks alot i will take a look.

here is an example of the code that i have build to create searching in a listview.

the only problem i have is that i cant get it done to combine different searches.

this is my code so far.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
Global $aLVItems[4][2]
$aLVItems[0][0] = 3

$aLVItems[1][1] = "Notepad|For text writing|data1"
$aLVItems[2][1] = "WordPad|For text writing (advanced)|data2"
$aLVItems[3][1] = "Paint|Image making|data3"

$hGUI = GUICreate("Test", 330, 300)

$cListView = GUICtrlCreateListView("", 10, 110, 310, 140)

    _GUICtrlListView_InsertColumn($cListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($cListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($cListView, 2, "Column 3", 100)

For $i = 1 To $aLVItems[0][0]
$aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $cListView)
Next



$cInput_Filter1 = GUICtrlCreateInput("", 11, 80, 61, 20)
$cInput_Filter2 = GUICtrlCreateInput("", 80, 80, 130, 20)
$cInput_Filter3 = GUICtrlCreateInput("", 220, 80, 50, 20)

;$cButton_Filter = GUICtrlCreateButton("Filter", 160, 266, 75, 23)
;$cButton_All = GUICtrlCreateButton("All", 246, 266, 75, 23)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

While 1
    $msg=GuiGetMsg()
    If $msg=-3 Then Exit
Wend

Func _FilterItem($filter1,$filter2,$filter3)
    ;ConsoleWrite($filter1 & " "& $filter2& " "& $filter3&@CRLF)
    If ($filter1 = "") Then _ShowAll()
    If ($filter2 = "") Then _ShowAll()
    If ($filter3 = "") Then _ShowAll()
    Local $strNew = ''
    For $i = 1 To $aLVItems[0][0]
If StringInStr($column1&$column2&$column3, $filter1&$filter2&$filter3) Then $strNew &= '$aLVItems['&$i&'][0] = GUICtrlCreateListViewItem($aLVItems['&$i&'][1], $cListView)' & @LF
Next
;For $i = 1 To $aLVItems[0][0]
    ;If StringInStr(_GUICtrlListView_GetItemText($cListView, $i -1,1), $filter2) Then $strNew &= '$aLVItems['&$i&'][0] = GUICtrlCreateListViewItem($aLVItems['&$i&'][1], $cListView)' & @LF
    ;Next
    ;For $i = 1 To $aLVItems[0][0]
    ;If StringInStr(_GUICtrlListView_GetItemText($cListView, $i -1,2), $filter3) Then $strNew &= '$aLVItems['&$i&'][0] = GUICtrlCreateListViewItem($aLVItems['&$i&'][1], $cListView)' & @LF
    ;ConsoleWrite($strNew&@CRLF)
    ;Next



    If $strNew = '' Then Return
    _GUICtrlListView_DeleteAllItems($cListView)
    Local $aExecute = StringSplit($strNew, @LF)
    For $i = 1 To UBound($aExecute) -1
        Execute($aExecute[$i])
    Next
EndFunc   ;==>_FilterItem


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)

    If $nID = $cInput_Filter1 And $nNotifyCode = $EN_CHANGE Then
        ;ConsoleWrite('Editchanged1: ' & GUICtrlRead($cInput_Filter1) & @CRLF)
        _filteritem(GUICtrlRead($cInput_Filter1),GUICtrlRead($cInput_Filter2),GUICtrlRead($cInput_Filter3))
    EndIf
    If $nID = $cInput_Filter2 And $nNotifyCode = $EN_CHANGE Then
        ;ConsoleWrite('Editchanged2: ' & GUICtrlRead($cInput_Filter2) & @CRLF)
        _filteritem(GUICtrlRead($cInput_Filter1),GUICtrlRead($cInput_Filter2),GUICtrlRead($cInput_Filter3))
    EndIf
    If $nID = $cInput_Filter3 And $nNotifyCode = $EN_CHANGE Then
        ;ConsoleWrite('Editchanged3: ' & GUICtrlRead($cInput_Filter3) & @CRLF)
        _filteritem(GUICtrlRead($cInput_Filter1),GUICtrlRead($cInput_Filter2),GUICtrlRead($cInput_Filter3))
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

Func _ShowAll()
    If GUICtrlSendMsg($cListView, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return

    Local $i

    GUICtrlSendMsg($cListView, $LVM_DELETEALLITEMS, 0, 0)

    For $i = 1 To $aLVItems[0][0]
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $cListView)
    Next
EndFunc   ;==>_ShowAll


Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc
Link to comment
Share on other sites

  • Moderators

yucatan,

You already have a topic running on this question with people answering. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello M23.

i'm Back again :x

this is my code now.

i h ave implemented.

- if i change a week with the tab. then the listview is made emty.

- it shows mysql data inclused change the weeks

i'm working on enter new data and modify exsisting records.

but i have another problem.

the func _calculate does not work anymore for some reason.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>
#Include <GuiComboBox.au3>
#include <Misc.au3>
#include<EzMySql.au3>

Opt("GUICloseOnESC", 0)
If Not _EzMySql_Startup() Then
    MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Open("localhost", "root", "", "", "3306") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Exec("CREATE DATABASE IF NOT EXISTS planning") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SelectDB("planning") Then
    MsgBox(0, "Error setting Database to use", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

Global $fClicked = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"
Global $buswidth = 30, $monteurwidth = 60, $klantwidth = 155
global $listviews[7],$rows[1],$aok
global $maandag[1],$dinsdag[1],$woensdag[1],$donderdag[1],$vrijdag[1],$zaterdag[1],$maandagdata[1],$dinsdagdata[1],$woensdagdata[1],$donderdagdata[1],$vrijdagdata[1]

$clickedweek = _WeekNumberISO()
; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")
Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

$combo = GUICtrlCreateCombo("", 500, 45,120,50, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Kopieer vorige week|Laad Standaart", "") ; add other item snd set a new default

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)
$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1
        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)
        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", $iX, $iY, 285, 407, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _ArrayAdd($listviews,$hListView)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) ; Set grid lines
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, $buswidth)
        _GUICtrlListView_SetColumnWidth($hListView, 1, $monteurwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $klantwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 27
            _GUICtrlListView_AddItem($hListView, "")
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 2)
        Next
        Next
    Next

;_Calculate()
_refresh("week"&_WeekNumberISO())
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hAccel_Enter = GUICtrlCreateDummy()
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]
While 1
    Switch GUIGetMsg()
        Case $combo
            ConsoleWrite(GUICtrlRead($combo))
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hTab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
            If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
            $clickedweek = GUICtrlRead($hTab)
            For $i = 1 To 6
                GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
            Next
            ;_ArrayDisplay($maandag, "$avArray set manually 1D")
            ;$j = 0
            for $j = 0 to _ArrayMax($maandag, 0, 1)
            ConsoleWrite(_ArrayMax($maandag, 0, 1)&@crlf)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($dinsdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 3)
            Next
            for $j = 0 to _ArrayMax($woensdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($donderdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($vrijdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($zaterdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 3)
            Next

            _refresh("week"&$clickedweek)
        Case $hUpDown
            _Calculate()
    EndSwitch

; If an item was double clicked
    If $fClicked Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fClicked]
        $iListView_ID = $fClicked
        ; Reset flag
        $fClicked = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]

            ; Get column width
Local $iWidth = _GUICtrlListView_GetColumnWidth($hListView, $aLV_Click_Info[1])
; Create edit combo
$hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, $iWidth, 20)
; Set combo values depending on column clicked
Switch $aLV_Click_Info[1]  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    Case 0
        $sComboList = "1 Bus|2 Bus|3 Bus"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        _GUICtrlComboBox_LimitText($hEdit_Combo, 2)
    Case 1
        $sComboList = "Monteur 1|Monteur 2|Monteur 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        Case 2
        $sComboList = "Klant 1|Klant 2|Klant 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
    Case 3
        $sComboList = "Wvb 1|Wvb 2|Wvb 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        _GUICtrlComboBox_LimitText($hEdit_Combo, 3)
EndSwitch
; Set values into combo
GUICtrlSetData($hEdit_Combo, $sComboList, $sItemText)
GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

; Get handle of combo edit control
$hComboEdit = _WinAPI_GetFocus()
; Set flag for Enter pressed
$iLoopCode = 0
; Set flag for combo opened <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
$fCombo_Opened = False

; Loop while the combo has focus
While _WinAPI_GetFocus() = $hComboEdit

    ; If combo has been opened, check if closed again ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If $fCombo_Opened Then
        ; If combo is closed again
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) = False Then
            $iLoopCode = 1
            ExitLoop
        EndIf
    Else
        ; Check if opened and set flag
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) Then $fCombo_Opened = True
    EndIf

    ; If Enter Pressed ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If _IsPressed("0D", $dll) Then
        $iLoopCode = 1
        ExitLoop
    EndIf

        ; If ESC pressed
        If _IsPressed("1B", $dll) Then
        $iLoopCode = -1
        ExitLoop
    EndIf

        ; Save CPU and prevent tab selection <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1
        Switch GUIGetMsg()
        Case $hTab
            _GUICtrlTab_ClickTab($hTab, $clickedweek)
        ;Case $GUI_EVENT_CLOSE
        ;    DllClose($dll)
        ;    Exit
    EndSwitch
WEnd

; Read Combo
$sText = GUICtrlRead($hEdit_Combo)

; Check if content changed manually
If Not $iLoopCode And $sText <> $sItemText Then $iLoopCode = 1 ; <<<<<<<<<<<<<<<<<<<<< 2

; Edit ListView if required
If $iLoopCode = 1 Then
_GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])

$week = "week"&GUICtrlRead($hTab)
if $hListView = $listviews[7] then $dagread = "Maandag"
if $hListView = $listviews[9] then $dagread = "Dinsdag"
if $hListView = $listviews[11] then $dagread = "Woensdag"
if $hListView = $listviews[8] then $dagread = "Donderdag"
if $hListView = $listviews[10] then $dagread = "Vrijdag"
if $hListView = $listviews[12] then $dagread = "Zaterdag"

if $aLV_Click_Info[1] = 3 then $fields = "Wvb"
if $aLV_Click_Info[1] = 2 then $fields = "Klantenproject"
if $aLV_Click_Info[1] = 1 then $fields = "Naam"
if $aLV_Click_Info[1] = 0 then $fields = "Bus"


$value1 = ""
$value2 = ""
$value3 = ""
$value4 = ""


if $aLV_Click_Info[1] + 1 = 1 then $value1 = $sText
if $aLV_Click_Info[1] + 1 = 2 then $value2 = $sText
if $aLV_Click_Info[1] + 1 = 3 then $value3 = $sText
if $aLV_Click_Info[1] + 1 = 4 then $value4 = $sText

ConsoleWrite($aLV_Click_Info[0] + 1 & " "& $aLV_Click_Info[1] + 1 &@CRLF)

Local $sMySqlStatement = ""


$sMySqlStatement &= "INSERT INTO "&$week&" (Dag,Bus,Naam,Klantenproject,Wvb) VALUES (" & "'" & $dagread & "'," & "'" & $value1 & "'," & "'" & $value2 & "'," & "'" & $value3 & "'," & "'" & $value4 & "');"


If Not _EzMySql_Exec($sMySqlStatement) Then
    MsgBox(0, "Error inserting data to Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

$sMySqlStatement = ""
ConsoleWrite( _EzMySql_InsertID()&@CRLF)
EndIf
; Delete combo
GUICtrlDelete($hEdit_Combo)
$hEdit_Combo = 0

        EndIf

    EndIf

WEnd


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_CLICK
                    $fClicked = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY


Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year

        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        ConsoleWrite($aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]&@CRLF)
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day

    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ;ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next

EndFunc   ;==>_Calculate

func _refresh($week)
;$arraysize = UBound($aok)
ConsoleWrite($aok&@CRLF)
$aOk = _EzMySql_GetTable2d("SELECT * FROM "&$week&";")
$error = @error
If Not IsArray($aOk) Then
$create = "CREATE TABLE IF NOT EXISTS "&$week&" (" & _
                   "RowID INT NOT NULL AUTO_INCREMENT," & _
                   "Dag TEXT NOT NULL ," & _
                   "Bus TEXT NOT NULL ," & _
                   "Naam TEXT NOT NULL ," & _
                   "Klantenproject TEXT NOT NULL ," & _
                   "Wvb TEXT NOT NULL ," & _
                   "PRIMARY KEY (`RowID`) ," & _
                   "UNIQUE INDEX RowID_UNIQUE (`RowID` ASC) );"

If Not _EzMySql_Exec($create) Then
    MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    _refresh($week)
EndIf
EndIf
_ArrayDisplay($aok, "$avArray set manually 1D")
$j = 0
for $i =0 to UBound($aok) -1
    if $aok[$i][1] = "Maandag" then
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][5], 3)
    _ArrayAdd($maandagdata, $aok[$i][0])
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Dinsdag" then
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][5], 3)
    _ArrayAdd($Dinsdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Woensdag" then
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][5], 3)
    _ArrayAdd($woensdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Donderdag" then
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][5], 3)
    _ArrayAdd($donderdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Vrijdag" then
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][5], 3)
    _ArrayAdd($vrijdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Zaterdag" then
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][5], 3)
    _ArrayAdd($zaterdag, $j)
$j+=1
EndIf
Next
_ArrayDisplay($maandagdata, "$avArray set manually 1D")
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

yucatan,

the func _calculate does not work anymore for some reason

The reason is that you are missing a line in the function to move onto the next day. :x

Add the <<<<<<<<<<<<< line:

; Fill array
    ConsoleWrite($aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]] & @CRLF)
    $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
    ; Move to next day
    $sdate = _DateAdd("d", 1, $sdate) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

Did you ever think of comparing the function that does not work with an older example that did? Took me about 10 seconds to find the missing line. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

thanks alot.

yeah i have tryed to compare the code and by that way find the missing code.

but at that time the autoitscript website was down a couple of days.

when to website was back online i didnt think about it anymore.

My bad.

at this time i'm running into some other issues.

i want that if i swich a week with a tab.

that all fields are made emty.

and that the new data is added that is recieved from mysql.

i tryed to use _GUICtrlListView_SetItemText and make all fields emty.

but that is Very slow.

it takes about 3 of 4 seconds to make all fields emty.

as u understand this is to slow.

if i use _GUICtrlListView_DeleteAllItems

then users cant click in the listview so that is also not a option.

the only thing i can imagen is that i record with items (numbers) are set to some data.

and that i emty that fields that are set to some data.

but that is pretty hard.

any ideas?

Greetz

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>
#Include <GuiComboBox.au3>
#include <Misc.au3>
#include<EzMySql.au3>

Opt("GUICloseOnESC", 0)
If Not _EzMySql_Startup() Then
    MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Open("localhost", "root", "", "", "3306") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Exec("CREATE DATABASE IF NOT EXISTS planning") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SelectDB("planning") Then
    MsgBox(0, "Error setting Database to use", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

Global $fClicked = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"
Global $buswidth = 30, $monteurwidth = 60, $klantwidth = 155
global $listviews[7],$rows[1],$aok
global $maandag[1],$dinsdag[1],$woensdag[1],$donderdag[1],$vrijdag[1],$zaterdag[1],$maandagdata[1],$dinsdagdata[1],$woensdagdata[1],$donderdagdata[1],$vrijdagdata[1]

$clickedweek = _WeekNumberISO()
; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")
Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

$combo = GUICtrlCreateCombo("", 500, 45,120,50, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Kopieer vorige week|Laad Standaart", "") ; add other item snd set a new default

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)
$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1
        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)
        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", $iX, $iY, 285, 407, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _ArrayAdd($listviews,$hListView)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) ; Set grid lines
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, $buswidth)
        _GUICtrlListView_SetColumnWidth($hListView, 1, $monteurwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $klantwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 27
            _GUICtrlListView_AddItem($hListView, "")
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 2)
        Next
        Next
    Next
_Calculate()
_refresh("week"&_WeekNumberISO())
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hAccel_Enter = GUICtrlCreateDummy()
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]
While 1
    Switch GUIGetMsg()
        Case $combo
            ConsoleWrite(GUICtrlRead($combo))
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hTab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
            If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
            $clickedweek = GUICtrlRead($hTab)
            For $i = 1 To 6
                GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
            Next
            ;_ArrayDisplay($maandag, "$avArray set manually 1D")
            ;$j = 0
            for $j = 0 to _ArrayMax($maandag, 0, 1)
            ConsoleWrite(_ArrayMax($maandag, 0, 1)&@crlf)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[7], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($dinsdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[9], $j , "", 3)
            Next
            for $j = 0 to _ArrayMax($woensdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[11], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($donderdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[8], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($vrijdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[10], $j , "", 3)
            Next
            ;$j = 0
            for $j = 0 to _ArrayMax($zaterdag, 0, 1)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 0)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 1)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 2)
            _GUICtrlListView_SetItemText($listviews[12], $j , "", 3)
            Next

            _refresh("week"&$clickedweek)
        Case $hUpDown
            _Calculate()
    EndSwitch

; If an item was double clicked
    If $fClicked Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fClicked]
        $iListView_ID = $fClicked
        ; Reset flag
        $fClicked = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]

            ; Get column width
Local $iWidth = _GUICtrlListView_GetColumnWidth($hListView, $aLV_Click_Info[1])
; Create edit combo
$hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, $iWidth, 20)
; Set combo values depending on column clicked
Switch $aLV_Click_Info[1]  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    Case 0
        $sComboList = "1 Bus|2 Bus|3 Bus"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        _GUICtrlComboBox_LimitText($hEdit_Combo, 2)
    Case 1
        $sComboList = "Monteur 1|Monteur 2|Monteur 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        Case 2
        $sComboList = "Klant 1|Klant 2|Klant 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
    Case 3
        $sComboList = "Wvb 1|Wvb 2|Wvb 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        _GUICtrlComboBox_LimitText($hEdit_Combo, 3)
EndSwitch
; Set values into combo
GUICtrlSetData($hEdit_Combo, $sComboList, $sItemText)
GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

; Get handle of combo edit control
$hComboEdit = _WinAPI_GetFocus()
; Set flag for Enter pressed
$iLoopCode = 0
; Set flag for combo opened <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
$fCombo_Opened = False

; Loop while the combo has focus
While _WinAPI_GetFocus() = $hComboEdit

    ; If combo has been opened, check if closed again ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If $fCombo_Opened Then
        ; If combo is closed again
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) = False Then
            $iLoopCode = 1
            ExitLoop
        EndIf
    Else
        ; Check if opened and set flag
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) Then $fCombo_Opened = True
    EndIf

    ; If Enter Pressed ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If _IsPressed("0D", $dll) Then
        $iLoopCode = 1
        ExitLoop
    EndIf

        ; If ESC pressed
        If _IsPressed("1B", $dll) Then
        $iLoopCode = -1
        ExitLoop
    EndIf

        ; Save CPU and prevent tab selection <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1
        Switch GUIGetMsg()
        Case $hTab
            _GUICtrlTab_ClickTab($hTab, $clickedweek)
        ;Case $GUI_EVENT_CLOSE
        ;    DllClose($dll)
        ;    Exit
    EndSwitch
WEnd

; Read Combo
$sText = GUICtrlRead($hEdit_Combo)

; Check if content changed manually
If Not $iLoopCode And $sText <> $sItemText Then $iLoopCode = 1 ; <<<<<<<<<<<<<<<<<<<<< 2

; Edit ListView if required
If $iLoopCode = 1 Then
_GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])

$week = "week"&GUICtrlRead($hTab)
if $hListView = $listviews[7] then $dagread = "Maandag"
if $hListView = $listviews[9] then $dagread = "Dinsdag"
if $hListView = $listviews[11] then $dagread = "Woensdag"
if $hListView = $listviews[8] then $dagread = "Donderdag"
if $hListView = $listviews[10] then $dagread = "Vrijdag"
if $hListView = $listviews[12] then $dagread = "Zaterdag"

if $aLV_Click_Info[1] = 3 then $fields = "Wvb"
if $aLV_Click_Info[1] = 2 then $fields = "Klantenproject"
if $aLV_Click_Info[1] = 1 then $fields = "Naam"
if $aLV_Click_Info[1] = 0 then $fields = "Bus"


$value1 = ""
$value2 = ""
$value3 = ""
$value4 = ""


if $aLV_Click_Info[1] + 1 = 1 then $value1 = $sText
if $aLV_Click_Info[1] + 1 = 2 then $value2 = $sText
if $aLV_Click_Info[1] + 1 = 3 then $value3 = $sText
if $aLV_Click_Info[1] + 1 = 4 then $value4 = $sText

ConsoleWrite($aLV_Click_Info[0] + 1 & " "& $aLV_Click_Info[1] + 1 &@CRLF)

Local $sMySqlStatement = ""


$sMySqlStatement &= "INSERT INTO "&$week&" (Dag,Bus,Naam,Klantenproject,Wvb) VALUES (" & "'" & $dagread & "'," & "'" & $value1 & "'," & "'" & $value2 & "'," & "'" & $value3 & "'," & "'" & $value4 & "');"


If Not _EzMySql_Exec($sMySqlStatement) Then
    MsgBox(0, "Error inserting data to Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

$sMySqlStatement = ""
ConsoleWrite( _EzMySql_InsertID()&@CRLF)
EndIf
; Delete combo
GUICtrlDelete($hEdit_Combo)
$hEdit_Combo = 0

        EndIf

    EndIf

WEnd


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_CLICK
                    $fClicked = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY


Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year

        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        ConsoleWrite($aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]&@CRLF)
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ;ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next

EndFunc   ;==>_Calculate

func _refresh($week)
;$arraysize = UBound($aok)
ConsoleWrite($aok&@CRLF)
$aOk = _EzMySql_GetTable2d("SELECT * FROM "&$week&";")
$error = @error
If Not IsArray($aOk) Then
$create = "CREATE TABLE IF NOT EXISTS "&$week&" (" & _
                   "RowID INT NOT NULL AUTO_INCREMENT," & _
                   "Dag TEXT NOT NULL ," & _
                   "Bus TEXT NOT NULL ," & _
                   "Naam TEXT NOT NULL ," & _
                   "Klantenproject TEXT NOT NULL ," & _
                   "Wvb TEXT NOT NULL ," & _
                   "PRIMARY KEY (`RowID`) ," & _
                   "UNIQUE INDEX RowID_UNIQUE (`RowID` ASC) );"

If Not _EzMySql_Exec($create) Then
    MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    _refresh($week)
EndIf
EndIf
_ArrayDisplay($aok, "$avArray set manually 1D")
$j = 0
for $i =0 to UBound($aok) -1
    if $aok[$i][1] = "Maandag" then
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][5], 3)
    _ArrayAdd($maandagdata, $aok[$i][0])
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Dinsdag" then
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][5], 3)
    _ArrayAdd($Dinsdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Woensdag" then
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][5], 3)
    _ArrayAdd($woensdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Donderdag" then
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][5], 3)
    _ArrayAdd($donderdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Vrijdag" then
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][5], 3)
    _ArrayAdd($vrijdag, $j)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Zaterdag" then
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][2], 0)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][3], 1)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][4], 2)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][5], 3)
    _ArrayAdd($zaterdag, $j)
$j+=1
EndIf
Next
_ArrayDisplay($maandagdata, "$avArray set manually 1D")
EndFunc
Link to comment
Share on other sites

  • Moderators

yucatan,

I think this is the fastest you can get: :x

Case $hTab
    ; Do not display weeks 0 and 53 if not used
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)
    For $i = 1 To 6
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next
    ; Clear existing items
    For $j = 1 To 6
        For $i = 0 To 26 ; Because you have created 27 items initially
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "")
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 1)
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 2)
        Next
    Next
    ; Fill with new data
    _refresh("week" & $clickedweek)

This empties the ListViews in 400ms on my machine - I have no idea how long it takes to refill from your database. You keep the 27 lines you created initially and refill with as much new data as you have. However, if you ever get more than 27 lines per day then you will need to think again. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello M23.

Thanks this works alot beter.

but u did forget one rule

Case $hTab
    ; Do not display weeks 0 and 53 if not used
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)
    For $i = 1 To 6
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next
    ; Clear existing items
    For $j = 1 To 6
        For $i = 0 To 26 ; Because you have created 27 items initially
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "")
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 1)
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 2)
        Next
    Next
    ; Fill with new data
    _refresh("week" & $clickedweek)

should be:

Case $hTab
    ; Do not display weeks 0 and 53 if not used
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)
    For $i = 1 To 6
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next
    ; Clear existing items
    For $j = 1 To 6
        For $i = 0 To 26 ; Because you have created 27 items initially
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "")
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 1)
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 2)
        _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 3)
        Next
    Next
    ; Fill with new data
    _refresh("week" & $clickedweek)

anyway this is solved thanks alot!

but i'm having another issue

if i get a new week that is emty.

if i fill something in in the field monteur.

but the rest of the rule is emty.

then i only add's the value i have added to mysql.

as u proberly know mysql used rowid's

if i fill in a bus number in the same rule.

then it need to update the exsisting row instead of adding a totaly new row.

there are two ways i can think of to fix this issue.

one i log the rowid's if a new value is added.

so that if in the same rule but in another field someting is added i can update the exsisting row.

two i only send a mysql query if the rule is compleet.

so then only then all 4 fields have been filled with something.

that only then it send's a mysql query.

if we chose for the seconds way(wicht i think is the most easy one)

then we still have a problem with modifing.

if i edit a field.. i need to know the rowid that should be updated...

so thats the issue i have now.

but i dont know if i should ask this to u.

maby i need to make topic in general help and support.

instead of in the gui help and support.

What ur advice to me now?

Happy to hear from u.

Greetz Yucatan

Link to comment
Share on other sites

  • Moderators

yucatan,

I am glad we finally got your ListView GUI to work as you wish. :x

I am not very good with SQL - so I suggest that you start another topic about your new problem Make sure you put "SQL" in the title - that should get the attention of those who do know something about it. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello M23.

First i wanne thanks u for all ur help.

i still have one question.

Sometimes if i work fast in my listview.

i have to click tree times before the combo box appears.

is there something we can do about that?

this is my code now.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>
#Include <GuiComboBox.au3>
#include <Misc.au3>
#include<EzMySql.au3>

Opt("GUICloseOnESC", 0)
If Not _EzMySql_Startup() Then
    MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Open("localhost", "root", "", "", "3306") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Exec("CREATE DATABASE IF NOT EXISTS planning") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SelectDB("planning") Then
    MsgBox(0, "Error setting Database to use", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

Global $fClicked = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"
Global $buswidth = 30, $monteurwidth = 60, $klantwidth = 155
global $listviews[7],$rows[1],$aok
global $maandag[1],$dinsdag[1],$woensdag[1],$donderdag[1],$vrijdag[1],$zaterdag[1],$maandagdata[1],$dinsdagdata[1],$woensdagdata[1],$donderdagdata[1],$vrijdagdata[1]

$clickedweek = _WeekNumberISO()
; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")
Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

$combo = GUICtrlCreateCombo("", 500, 45,120,50, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Kopieer vorige week|Laad Standaart", "") ; add other item snd set a new default

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)
$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1
        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)
        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)
        $hListView = _GUICtrlListView_Create($hGUI, "RowID", $iX, $iY, 285, 407, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _ArrayAdd($listviews,$hListView)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) ; Set grid lines
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Bus")
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 0)
        _GUICtrlListView_SetColumnWidth($hListView, 1, $buswidth)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $monteurwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $klantwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 27
            _GUICtrlListView_AddItem($hListView, "")
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "", 2)
        Next
        Next
    Next
_Calculate()
_refresh("week"&_WeekNumberISO())
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hAccel_Enter = GUICtrlCreateDummy()
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]
While 1
    Switch GUIGetMsg()
        Case $combo
            ConsoleWrite(GUICtrlRead($combo))
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
Case $hTab
    ; Do not display weeks 0 and 53 if not used
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)
    For $i = 1 To 6
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next
    ; Clear existing items
    For $j = 1 To 6
        For $i = 0 To 26 ; Because you have created 27 items initially
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "")
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 1)
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 2)
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 3)
            _GUICtrlListView_SetItemText ($aLV_Handles[$j], $i, "", 4)
        Next
    Next
    ; Fill with new data
    _refresh("week" & $clickedweek)
        Case $hUpDown
            _Calculate()
    EndSwitch

; If an item was double clicked
    If $fClicked Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fClicked]
        $iListView_ID = $fClicked
        ; Reset flag
        $fClicked = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get Rowid
            $sRowid = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], 0)
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
            ; Get column width
Local $iWidth = _GUICtrlListView_GetColumnWidth($hListView, $aLV_Click_Info[1])

ConsoleWrite($sRowid &@CRLF)
; Create edit combo
$hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, $iWidth, 20)
; Set combo values depending on column clicked
Switch $aLV_Click_Info[1]  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    Case 1
        $sComboList = "1 Bus|2 Bus|3 Bus"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        _GUICtrlComboBox_LimitText($hEdit_Combo, 2)
    Case 2
        $sComboList = "Monteur 1|Monteur 2|Monteur 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
    Case 3
        $sComboList = "Klant 1|Klant 2|Klant 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
    Case 4
        $sComboList = "Wvb 1|Wvb 2|Wvb 3"
        If Not StringInStr($sComboList, $sItemText) Then $sComboList &= "|" & $sItemText
        _GUICtrlComboBox_LimitText($hEdit_Combo, 3)
EndSwitch
; Set values into combo
GUICtrlSetData($hEdit_Combo, $sComboList, $sItemText)
GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

; Get handle of combo edit control
$hComboEdit = _WinAPI_GetFocus()
; Set flag for Enter pressed
$iLoopCode = 0
; Set flag for combo opened <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
$fCombo_Opened = False

; Loop while the combo has focus
While _WinAPI_GetFocus() = $hComboEdit

    ; If combo has been opened, check if closed again ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If $fCombo_Opened Then
        ; If combo is closed again
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) = False Then
            $iLoopCode = 1
            ExitLoop
        EndIf
    Else
        ; Check if opened and set flag
        If _GUICtrlComboBox_GetDroppedState($hEdit_Combo) Then $fCombo_Opened = True
    EndIf

    ; If Enter Pressed ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2
    If _IsPressed("0D", $dll) Then
        $sText = GUICtrlRead($hEdit_Combo)
        if $sText<>"" then $iLoopCode = 1
        ExitLoop
    EndIf

        ; If ESC pressed
        If _IsPressed("1B", $dll) Then
        $iLoopCode = -1
        ExitLoop
    EndIf

        ; Save CPU and prevent tab selection <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1
        Switch GUIGetMsg()
        Case $hTab
            _GUICtrlTab_ClickTab($hTab, $clickedweek)
        ;Case $GUI_EVENT_CLOSE
        ;    DllClose($dll)
        ;    Exit
    EndSwitch
WEnd

; Read Combo
$sText = GUICtrlRead($hEdit_Combo)

; Check if content changed manually
If Not $iLoopCode And $sText <> $sItemText Then $iLoopCode = 1 ; <<<<<<<<<<<<<<<<<<<<< 2

; Edit ListView if required
If $iLoopCode = 1 Then
_GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
$week = "week"&GUICtrlRead($hTab)
if $hListView = $listviews[7] then $dagread = "Maandag"
if $hListView = $listviews[9] then $dagread = "Dinsdag"
if $hListView = $listviews[11] then $dagread = "Woensdag"
if $hListView = $listviews[8] then $dagread = "Donderdag"
if $hListView = $listviews[10] then $dagread = "Vrijdag"
if $hListView = $listviews[12] then $dagread = "Zaterdag"

if $aLV_Click_Info[1] = 4 then $fields = "Wvb"
if $aLV_Click_Info[1] = 3 then $fields = "Klantenproject"
if $aLV_Click_Info[1] = 2 then $fields = "Naam"
if $aLV_Click_Info[1] = 1 then $fields = "Bus"


$value1 = ""
$value2 = ""
$value3 = ""
$value4 = ""


if $aLV_Click_Info[1] = 1 then $value1 = $sText
if $aLV_Click_Info[1] = 2 then $value2 = $sText
if $aLV_Click_Info[1] = 3 then $value3 = $sText
if $aLV_Click_Info[1] = 4 then $value4 = $sText

if $sRowid = "" then
Local $sMySqlStatement = ""
$sMySqlStatement &= "INSERT INTO "&$week&" (Dag,Bus,Naam,Klantenproject,Wvb) VALUES (" & "'" & $dagread & "'," & "'" & $value1 & "'," & "'" & $value2 & "'," & "'" & $value3 & "'," & "'" & $value4 & "');"
;INSERT INTO week3 (Dag,Bus,Naam,Klantenproject,Wvb) VALUES ('data','data','data','data','data');
ConsoleWrite($sMySqlStatement&@CRLF)

Else
Local $sMySqlStatement = ""
$sMySqlStatement &= "UPDATE "&$week&" SET "&$fields&"='"&$sText&"' WHERE rowid="&$sRowid&";"
ConsoleWrite($sMySqlStatement&@CRLF)
EndIf
;UPDATE example SET age='22' WHERE age='21'")

If Not _EzMySql_Exec($sMySqlStatement) Then
    MsgBox(0, "Error inserting data to Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

$sMySqlStatement = ""
ConsoleWrite( _EzMySql_InsertID()&@CRLF)
EndIf
; Delete combo
GUICtrlDelete($hEdit_Combo)
$hEdit_Combo = 0

        EndIf
    EndIf
WEnd


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_CLICK
                    $fClicked = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY


Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year

        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        ;ConsoleWrite($aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]&@CRLF)
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ;ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next

EndFunc   ;==>_Calculate

func _refresh($week)
;$arraysize = UBound($aok)
;ConsoleWrite($aok&@CRLF)
$aOk = _EzMySql_GetTable2d("SELECT * FROM "&$week&";")
$error = @error
If Not IsArray($aOk) Then
$create = "CREATE TABLE IF NOT EXISTS "&$week&" (" & _
                   "RowID INT NOT NULL AUTO_INCREMENT," & _
                   "Dag TEXT NOT NULL ," & _
                   "Bus TEXT NOT NULL ," & _
                   "Naam TEXT NOT NULL ," & _
                   "Klantenproject TEXT NOT NULL ," & _
                   "Wvb TEXT NOT NULL ," & _
                   "PRIMARY KEY (`RowID`) ," & _
                   "UNIQUE INDEX RowID_UNIQUE (`RowID` ASC) );"

If Not _EzMySql_Exec($create) Then
    MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    _refresh($week)
EndIf
EndIf
;_ArrayDisplay($aok, "$avArray set manually 1D")
$j = 0
for $i =0 to UBound($aok) -1
    if $aok[$i][1] = "Maandag" then
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][0], 0)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][2], 1)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][3], 2)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][4], 3)
    _GUICtrlListView_SetItemText($listviews[7], $j , $aok[$i][5], 4)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Dinsdag" then
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][0], 0)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][2], 1)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][3], 2)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][4], 3)
    _GUICtrlListView_SetItemText($listviews[9], $j , $aok[$i][5], 4)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Woensdag" then
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][0], 0)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][2], 1)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][3], 2)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][4], 3)
    _GUICtrlListView_SetItemText($listviews[11], $j , $aok[$i][5], 4)

$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Donderdag" then
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][0], 0)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][2], 1)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][3], 2)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][4], 3)
    _GUICtrlListView_SetItemText($listviews[8], $j , $aok[$i][5], 4)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Vrijdag" then
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][0], 0)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][2], 1)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][3], 2)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][4], 3)
    _GUICtrlListView_SetItemText($listviews[10], $j , $aok[$i][5], 4)
$j+=1
EndIf
Next
$j = 0
for $i =0 to UBound($aok) -1
if $aok[$i][1] = "Zaterdag" then
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][0], 0)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][2], 1)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][3], 2)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][4], 3)
    _GUICtrlListView_SetItemText($listviews[12], $j , $aok[$i][5], 4)
$j+=1
EndIf
Next
EndFunc
Link to comment
Share on other sites

  • Moderators

yucatan,

Sometimes if i work fast in my listview [...] i have to click tree times before the combo box appears

Yes - change the "single click" firing of the message handler to "double click". :shifty:

Somewhere a long time ago in this topic (or even its predecessor) you changed my initial "double click" code in the message handler to "single click". The problem is that ListViews usually swallow the first click on them to change the selected item. Quite frankly I was amazed when your "single click" code worked. :x

So if you want a stable reaction from the ListView, I would revert to "double click" code in the handler to get the combo to show. Although it means 2 clicks every time (rather the mix of mainly 1 but sometimes 3 clicks at present) you will at least be sure to get what you want. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...