Sign in to follow this  
Followers 0
ca143508

Schedule App

3 posts in this topic

Guys,

I am writing this little app to read from a CSV file and change the list view according to the data that is returned. So far I have got the basics working. The colours of the time slots will change for a single day. The problem I have got to at the moment is that if there is more than one schdule on the day, it throws an error. The second problem is that when you change days and there is nothing scheduled for that day I need the colour of the time slots to revert back to white. Later on I will want to set it up so that the colour will also change depending on the status. Ie/ Unavailable is Red, Pending approval - Pink, Available - Green etc......

The code is below and the CSV info is below that. I would really appreciate some help on this one. Thanks.

#Include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiList.au3>
#include <File.au3>

$Form1 = GUICreate("AForm1", 408, 447, 193, 115)
$Group1 = GUICtrlCreateGroup("   Select a Schedule Date   ", 8, 7, 226, 60)
$Date1 = GUICtrlCreateDate("", 27, 32, 186, 21, $WS_TABSTOP)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$List1 = GUICtrlCreateListView("  Time  ", 8, 103, 226, 266)
_GUICtrlListViewSetColumnWidth ( $List1, 0, 200 )
_GUICtrlListViewJustifyColumn ( $List1, 0 , 2)

GUICtrlSendMsg($list1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($list1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($list1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_TRACKSELECT, $LVS_EX_TRACKSELECT)


$Button1 = GUICtrlCreateButton("Request a Time Slot", 240, 103, 156, 25, 0)
$Label1 = GUICtrlCreateLabel("", 11, 78, 222, 24, $SS_CENTER)
GuiCtrlSetData(-1, GUICtrlRead($Date1))

$current = _GUICtrlListViewGetHoverTime ($list1)

Dim $listview, $Btn_FindExact, $Btn_FindPartial, $Btn_FindByID, $Btn_Exit, $msg, $ret, $input_find, $index, $item[61]


$item[0] = GUICtrlCreateListViewItem("07:00|", $List1)
$item[1] = GUICtrlCreateListViewItem("07:15|", $list1)
$item[2] = GUICtrlCreateListViewItem("07:30|", $list1)
$item[3] = GUICtrlCreateListViewItem("07:45|", $list1)
$item[4] = GUICtrlCreateListViewItem("08:00|", $list1)
$item[5] = GUICtrlCreateListViewItem("08:15|", $List1)
$item[6] = GUICtrlCreateListViewItem("08:30|", $list1)
$item[7] = GUICtrlCreateListViewItem("08:45|", $list1)
$item[8] = GUICtrlCreateListViewItem("09:00|", $list1)
$item[9] = GUICtrlCreateListViewItem("09:15|", $list1)
$item[10] = GUICtrlCreateListViewItem("09:30|", $list1)
$item[11] = GUICtrlCreateListViewItem("09:45|", $list1)
$item[12] = GUICtrlCreateListViewItem("10:00|", $list1)
$item[13] = GUICtrlCreateListViewItem("10:15|", $list1)
$item[14] = GUICtrlCreateListViewItem("10:30|", $list1)
$item[15] = GUICtrlCreateListViewItem("10:45|", $list1)
$item[16] = GUICtrlCreateListViewItem("11:00|", $list1)
$item[17] = GUICtrlCreateListViewItem("11:15|", $list1)
$item[18] = GUICtrlCreateListViewItem("11:30|", $list1)
$item[19] = GUICtrlCreateListViewItem("11:45|", $list1)
$item[20] = GUICtrlCreateListViewItem("12:00|", $list1)
$item[21] = GUICtrlCreateListViewItem("12:15|", $list1)
$item[22] = GUICtrlCreateListViewItem("12:30|", $list1)
$item[23] = GUICtrlCreateListViewItem("12:45|", $list1)
$item[24] = GUICtrlCreateListViewItem("13:00|", $list1)
$item[25] = GUICtrlCreateListViewItem("12:15|", $list1)
$item[26] = GUICtrlCreateListViewItem("12:30|", $list1)
$item[27] = GUICtrlCreateListViewItem("12:45|", $list1)
$item[28] = GUICtrlCreateListViewItem("13:00|", $list1)
$item[29] = GUICtrlCreateListViewItem("12:15|", $list1)
$item[30] = GUICtrlCreateListViewItem("12:30|", $list1)
$item[31] = GUICtrlCreateListViewItem("12:45|", $list1)
$item[32] = GUICtrlCreateListViewItem("13:00|", $list1)
$item[33] = GUICtrlCreateListViewItem("12:15|", $list1)
$item[34] = GUICtrlCreateListViewItem("12:30|", $list1)
$item[35] = GUICtrlCreateListViewItem("12:45|", $list1)
$item[36] = GUICtrlCreateListViewItem("13:00|", $list1)
$item[37] = GUICtrlCreateListViewItem("13:15|", $list1)
$item[38] = GUICtrlCreateListViewItem("13:30|", $list1)
$item[39] = GUICtrlCreateListViewItem("13:45|", $list1)
$item[40] = GUICtrlCreateListViewItem("14:00|", $list1)
$item[41] = GUICtrlCreateListViewItem("14:15|", $list1)
$item[42] = GUICtrlCreateListViewItem("14:30|", $list1)
$item[43] = GUICtrlCreateListViewItem("14:45|", $list1)
$item[44] = GUICtrlCreateListViewItem("15:00|", $list1)
$item[45] = GUICtrlCreateListViewItem("15:15|", $list1)
$item[46] = GUICtrlCreateListViewItem("15:30|", $list1)
$item[47] = GUICtrlCreateListViewItem("15:45|", $list1)
$item[48] = GUICtrlCreateListViewItem("16:00|", $list1)
$item[49] = GUICtrlCreateListViewItem("16:15|", $list1)
$item[50] = GUICtrlCreateListViewItem("16:30|", $list1)
$item[51] = GUICtrlCreateListViewItem("16:45|", $list1)
$item[52] = GUICtrlCreateListViewItem("17:00|", $list1)
$item[53] = GUICtrlCreateListViewItem("17:15|", $list1)
$item[54] = GUICtrlCreateListViewItem("17:30|", $list1)
$item[55] = GUICtrlCreateListViewItem("17:45|", $list1)
$item[56] = GUICtrlCreateListViewItem("18:00|", $list1)
$item[57] = GUICtrlCreateListViewItem("18:15|", $list1)
$item[58] = GUICtrlCreateListViewItem("18:30|", $list1)
$item[59] = GUICtrlCreateListViewItem("18:45|", $list1)
$item[60] = GUICtrlCreateListViewItem("19:00|", $list1)

GuiSetState(@SW_SHOW)

Func _UpdateDateHeader()
    $SetSelectedDateTitle = GUICtrlRead($Date1)
    GUICtrlSetData($Label1, $SetSelectedDateTitle)
EndFunc

Func _ShowSelectedDaySchedule()
    $SelDate = GUICtrlRead($Date1)

    $file = FileOpen("Schedules.csv", 0)

; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

; Read in lines of text until the EOF is reached
    While 1
        
        $l1 = FileReadLine($file)
        If @error = -1 Then ExitLoop
        $l2 = StringSplit($l1, ",")
        
        If $SelDate <> $l2[1] Then
        ;Do Nothing
        Else
        
        $StartTimeindex = _GUICtrlListViewFindItem($List1, $l2[3], -1, BitOR($LVFI_PARTIAL, $LVFI_WRAP))
        $EndTimeindex = _GUICtrlListViewFindItem($List1, $l2[4], -1, BitOR($LVFI_PARTIAL, $LVFI_WRAP))
                
        $i = $StartTimeindex

        Do
            GUICtrlSetBkColor("" & $item[ "" & $i & "" ], 0xff3333)
            $i = $i + 1
        Until $i = $EndTimeindex
        
    ;Else
        EndIf
    Wend

FileClose($file)
    
    
    
    
EndFunc





While 1
    If ($current <> _GUICtrlListViewGetHoverTime ($list1)) Then
        $current = _GUICtrlListViewGetHoverTime ($list1)
    EndIf
    
    
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Date1
            _UpdateDateHeader()
            _ShowSelectedDaySchedule()

    EndSwitch
WEnd

The CSV file

28/10/2007,Demo,09:00,17:00,This is a sample data file,Bill Gates,24/10/2007,Pending Approval
28/10/2007,Demo2, 18:00,18:30,Another test, John Smith, 24/10/2007,Approved

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Not sure about your problem but you can reduce your code by doing this:

Dim $item[49]
$K = 0
;Hour value
For $X = 7 to 19
    ;Minute value
    For $Y = 0 to 3
        ;Pad hour and minute to 2 digits
        ;$item[$K] = StringFormat("%02i",$X) & ":" & StringFormat("%02i",$Y * 15)
        $item[$K] = GUICtrlCreateListViewItem(StringFormat("%02i",$X) & ":" & StringFormat("%02i",$Y * 15) & "|", $List1)
        ;Break at 19:00
        If $K = 48 Then ExitLoop 2
        $K += 1
    Next
Next

Instead of...

$item[0] = GUICtrlCreateListViewItem("07:00|", $List1)

....

$item[60] = GUICtrlCreateListViewItem("19:00|", $List1)

Which has some duplicate entries...

$item[21] = GUICtrlCreateListViewItem("12:15|", $list1)

$item[25] = GUICtrlCreateListViewItem("12:15|", $list1)

$item[29] = GUICtrlCreateListViewItem("12:15|", $list1)

$item[33] = GUICtrlCreateListViewItem("12:15|", $list1)

$item[22] = GUICtrlCreateListViewItem("12:30|", $list1)

$item[26] = GUICtrlCreateListViewItem("12:30|", $list1)

$item[30] = GUICtrlCreateListViewItem("12:30|", $list1)

$item[34] = GUICtrlCreateListViewItem("12:30|", $list1)

$item[23] = GUICtrlCreateListViewItem("12:45|", $list1)

$item[27] = GUICtrlCreateListViewItem("12:45|", $list1)

$item[31] = GUICtrlCreateListViewItem("12:45|", $list1)

$item[35] = GUICtrlCreateListViewItem("12:45|", $list1)

I'm not sure if you inteded it to be this way?

Edited by weaponx

Share this post


Link to post
Share on other sites

Thanks for the tip on the time slots. I think I just had fat fingers when I was copying and pasting the list in. I have got most of the stuff working now. The last thing I am stuck on is that when I select a time slot ie/7:15, I want it to bring up the details from the CSV file into a small text window or even a MSGbox would do. Where I am getting stuck is returning the text in the listview then matching it to the corresponding entry in the CSV file. I was thinking of returning the time and then getting the date from the Date field and using those to find the correcet entry in the file. Any help would be great.

Cheers

Share this post


Link to post
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
Sign in to follow this  
Followers 0