gsdhani2201
Programmer
Hello. I am developing software of a hotel. I want my dashboard to show rooms available, booked, cleaning, etc in a form. I have created a form programmatically and added a page then grid. Rooms available will show green picture, booked in red on command button placed in columm of grid as current control.
Say the rooms have categories Elegant, Prince & Deluxe
Say Elegant have 10 room 102, 103, 104 , 105..111 ; Price have 2 rooms 202,203 & Deluxe have 4 rooms 301, 302, 303, 304
I stored the category names and room details in cursor mytariff. The cursor have a row which have data of rooms available or not in form of logic .t. & .f. I have inserted categories in combo box to choose.
The grid must have 5 columns and n number of rows depending on number of rooms in that category.
Now What I need, I want to populate the grid with command buttons either dynamically or programmatically (adding command buttons as current control) and change the picture as desired + the caption of button as room no. If number of rooms exceed 5 which is max limit of grid column, the next room button must show in next row. All other rows/columns must be then not visible. Later I shall hide the header and gridlines. Below is code written in valid of combo box for just to under stand what I did. If I add command buttons dynamically then I don't know how to use click event of same which will have codes to set focus on page2 and get gust information.
I have attached a picture of form in run mode.
LOCAL x
x=1
cntr=1
hrname=ALLTRIM(THIS.Value)
nResult = SQLEXEC(nHandle,"select * from msttariff","Mytariff")
IF nResult < 0
AERROR( laErr )
MESSAGEBOX("mytariff "+laErr[2])
thisform.Release()
ENDIF
*!* rbook=0 means available
*!* rclean=0 means room is clean and ready to book, 1 means under cleaning
*!* rerror=0 means not in error state, 1 means under error
** make sure you cannot book until rclean = 0 & rerror=0 no matter rbook= 0 (available)
** you cannot clean = 1 or error =1 if book = 1
******
SELECT Mytariff
GO top
SELECT COUNT(*) as nroom_t FROM mytariff INTO CURSOR cur1
thisform.t1.Value=cur1.nroom_t
SELECT COUNT(*) as nroom_a FROM mytariff WHERE rbook=0 INTO CURSOR cur1
thisform.R1.Value=cur1.nroom_a
SELECT COUNT(*) as nroom_o FROM mytariff WHERE rbook=1 INTO CURSOR cur1
thisform.R2.Value=cur1.nroom_o
SELECT COUNT(*) as nroom_r FROM mytariff WHERE rerror=1 INTO CURSOR cur1
thisform.R3.Value=cur1.nroom_r
SELECT COUNT(*) as nroom_c FROM mytariff WHERE rclean=1 INTO CURSOR cur1
thisform.R4.Value=cur1.nroom_c
nResult = SQLEXEC(nHandle,"select * from msttariff where TRIM(rrname)=?hrname","Mytariffx")
IF nResult < 0
AERROR( laErr )
MESSAGEBOX("mytariff "+laErr[2])
thisform.Release()
ENDIF
SELECT COUNT(*) as nroom_t FROM mytariffh INTO CURSOR cur1
xcnt=nroom_t
*MESSAGEBOX(xcnt)
SELECT Mytariffx
thisform.pf.p1.grid1.columncount=xcnt
SELECT mygrid
DELETE all
*SELECT * from myglmast WHERE loccode=0 AND cvou_restrict=0 INTO CURSOR xcur2
APPEND BLANK
rowno=1
xfamt=0
SELECT mytariffx
GO TOP&& SCAN
SCAN &&FOR x = xcnt && cntr = 1 to xcnt
xroomno=ALLTRIM(STR(rno))
x=ALLTRIM(STR(cntr))+"."
xbook=rbook
*INSERT INTO mygrid (c1) VALUES (xroomno)
thisform.pf.p1.grid1.column&x.AddObject('Command1','CommandButton')
thisform.pf.p1.grid1.column&x.Sparse = .f.
thisform.pf.p1.grid1.column&x.bound= .f.
thisform.pf.p1.grid1.column&x.Command1.enabled= .t.
thisform.pf.p1.grid1.column&x.CurrentControl = 'Command1'
thisform.pf.p1.grid1.column&x.Command1.visible = .t.
thisform.pf.p1.grid1.column&x.command1.Caption=xroomno
thisform.pf.p1.grid1.column&x.width=101
thisform.pf.p1.grid1.rowheight=101
*thisform.pf.p1.grid1.column&x.command1.picture='d:\.....\image\gallery\png\bed_ava1.png'
DO case
CASE xbook=0
thisform.pf.p1.grid1.column&x.command1.picture='d:\....image\gallery\png\bed_ava1.png'
*!* thisform.pf.p1.gp1.command&x.caption=ALLTRIM(STR(xroomno))+"..booked"
*!* thisform.pf.p1.gp1.command&x.backcolor=RGB(255,255,0)
*!* thisform.pf.p1.gp1.command&x.forecolor=RGB(0,0,0)
*!* thisform.pf.p1.gp1.command&x.tooltiptext=xtool
*!* thisform.pf.p1.gp1.command&x.fontbold=.t.
*!* thisform.pf.p1.gp1.command&x.fontname="verdana"
*!* thisform.pf.p1.gp1.command&x.fontsize=10
*!* xbk=xbk+1
OTHERWISE
thisform.pf.p1.grid1.column&x.command1.picture='d:\....\image\gallery\png\bed_occ1.png'
*!* thisform.pf.p1.gp1.command&x.caption=ALLTRIM(STR(xroomno))
*!* thisform.pf.p1.gp1.command&x.backcolor=RGB(0,128,128)
*!* thisform.pf.p1.gp1.command&x.forecolor=RGB(255,255,255)
*!* thisform.pf.p1.gp1.command&x.fontbold=.t.
*!* thisform.pf.p1.gp1.command&x.fontname="arial"
*!* thisform.pf.p1.gp1.command&x.fontsize=15
*!* thisform.pf.p1.gp1.command&x.tooltiptext=xtool
*!* xva=xva+1
endcase
SELECT mytariffx
cntr=cntr+1
ENDSCAN
thisform.pf.p1.grid1.recordsource=thisform.pf.p1.grid1.recordsource
Say the rooms have categories Elegant, Prince & Deluxe
Say Elegant have 10 room 102, 103, 104 , 105..111 ; Price have 2 rooms 202,203 & Deluxe have 4 rooms 301, 302, 303, 304
I stored the category names and room details in cursor mytariff. The cursor have a row which have data of rooms available or not in form of logic .t. & .f. I have inserted categories in combo box to choose.
The grid must have 5 columns and n number of rows depending on number of rooms in that category.
Now What I need, I want to populate the grid with command buttons either dynamically or programmatically (adding command buttons as current control) and change the picture as desired + the caption of button as room no. If number of rooms exceed 5 which is max limit of grid column, the next room button must show in next row. All other rows/columns must be then not visible. Later I shall hide the header and gridlines. Below is code written in valid of combo box for just to under stand what I did. If I add command buttons dynamically then I don't know how to use click event of same which will have codes to set focus on page2 and get gust information.
I have attached a picture of form in run mode.
LOCAL x
x=1
cntr=1
hrname=ALLTRIM(THIS.Value)
nResult = SQLEXEC(nHandle,"select * from msttariff","Mytariff")
IF nResult < 0
AERROR( laErr )
MESSAGEBOX("mytariff "+laErr[2])
thisform.Release()
ENDIF
*!* rbook=0 means available
*!* rclean=0 means room is clean and ready to book, 1 means under cleaning
*!* rerror=0 means not in error state, 1 means under error
** make sure you cannot book until rclean = 0 & rerror=0 no matter rbook= 0 (available)
** you cannot clean = 1 or error =1 if book = 1
******
SELECT Mytariff
GO top
SELECT COUNT(*) as nroom_t FROM mytariff INTO CURSOR cur1
thisform.t1.Value=cur1.nroom_t
SELECT COUNT(*) as nroom_a FROM mytariff WHERE rbook=0 INTO CURSOR cur1
thisform.R1.Value=cur1.nroom_a
SELECT COUNT(*) as nroom_o FROM mytariff WHERE rbook=1 INTO CURSOR cur1
thisform.R2.Value=cur1.nroom_o
SELECT COUNT(*) as nroom_r FROM mytariff WHERE rerror=1 INTO CURSOR cur1
thisform.R3.Value=cur1.nroom_r
SELECT COUNT(*) as nroom_c FROM mytariff WHERE rclean=1 INTO CURSOR cur1
thisform.R4.Value=cur1.nroom_c
nResult = SQLEXEC(nHandle,"select * from msttariff where TRIM(rrname)=?hrname","Mytariffx")
IF nResult < 0
AERROR( laErr )
MESSAGEBOX("mytariff "+laErr[2])
thisform.Release()
ENDIF
SELECT COUNT(*) as nroom_t FROM mytariffh INTO CURSOR cur1
xcnt=nroom_t
*MESSAGEBOX(xcnt)
SELECT Mytariffx
thisform.pf.p1.grid1.columncount=xcnt
SELECT mygrid
DELETE all
*SELECT * from myglmast WHERE loccode=0 AND cvou_restrict=0 INTO CURSOR xcur2
APPEND BLANK
rowno=1
xfamt=0
SELECT mytariffx
GO TOP&& SCAN
SCAN &&FOR x = xcnt && cntr = 1 to xcnt
xroomno=ALLTRIM(STR(rno))
x=ALLTRIM(STR(cntr))+"."
xbook=rbook
*INSERT INTO mygrid (c1) VALUES (xroomno)
thisform.pf.p1.grid1.column&x.AddObject('Command1','CommandButton')
thisform.pf.p1.grid1.column&x.Sparse = .f.
thisform.pf.p1.grid1.column&x.bound= .f.
thisform.pf.p1.grid1.column&x.Command1.enabled= .t.
thisform.pf.p1.grid1.column&x.CurrentControl = 'Command1'
thisform.pf.p1.grid1.column&x.Command1.visible = .t.
thisform.pf.p1.grid1.column&x.command1.Caption=xroomno
thisform.pf.p1.grid1.column&x.width=101
thisform.pf.p1.grid1.rowheight=101
*thisform.pf.p1.grid1.column&x.command1.picture='d:\.....\image\gallery\png\bed_ava1.png'
DO case
CASE xbook=0
thisform.pf.p1.grid1.column&x.command1.picture='d:\....image\gallery\png\bed_ava1.png'
*!* thisform.pf.p1.gp1.command&x.caption=ALLTRIM(STR(xroomno))+"..booked"
*!* thisform.pf.p1.gp1.command&x.backcolor=RGB(255,255,0)
*!* thisform.pf.p1.gp1.command&x.forecolor=RGB(0,0,0)
*!* thisform.pf.p1.gp1.command&x.tooltiptext=xtool
*!* thisform.pf.p1.gp1.command&x.fontbold=.t.
*!* thisform.pf.p1.gp1.command&x.fontname="verdana"
*!* thisform.pf.p1.gp1.command&x.fontsize=10
*!* xbk=xbk+1
OTHERWISE
thisform.pf.p1.grid1.column&x.command1.picture='d:\....\image\gallery\png\bed_occ1.png'
*!* thisform.pf.p1.gp1.command&x.caption=ALLTRIM(STR(xroomno))
*!* thisform.pf.p1.gp1.command&x.backcolor=RGB(0,128,128)
*!* thisform.pf.p1.gp1.command&x.forecolor=RGB(255,255,255)
*!* thisform.pf.p1.gp1.command&x.fontbold=.t.
*!* thisform.pf.p1.gp1.command&x.fontname="arial"
*!* thisform.pf.p1.gp1.command&x.fontsize=15
*!* thisform.pf.p1.gp1.command&x.tooltiptext=xtool
*!* xva=xva+1
endcase
SELECT mytariffx
cntr=cntr+1
ENDSCAN
thisform.pf.p1.grid1.recordsource=thisform.pf.p1.grid1.recordsource