Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP9 GRID MULTIPLE INDEPENDENT COMMAND BUTTONS IN EACH ROW AND COLUMN AS PER NOS OF RECORDS IN CURSO

Status
Not open for further replies.

gsdhani2201

Programmer
Nov 29, 2017
3
IN
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

 
 http://files.engineering.com/getfile.aspx?folder=958a04c1-795d-4db3-9b18-87188457308b&file=PICT1.jpg
Given that you are adding the buttons dynamically, the best approach would be to create a button class, and put the required code in the Click of that class. Then use the column's AddObject method to add the buttons, passing the class name as the second parameter.

If the Click code is different for the different kinds of buttons, then set up one or more custom properties for the class. Use the contents of those properties to vary the behaviour of the buttons.

On another point, I suggest you are doing a lot of stuff in the combo's Valid that would be better placed elsewhere. In particular, you are retrieving data from the back end each time the user moves focus away from the combo. That's a big overhead. It would be better to do it either in the form's Init, or (if the data is particularly volatile) give the user a Refresh button to explicitly fetch the data. (I'd also prefer to use the combo's InteractiveChange rather than the Valid for updating the grid, but that's just my personal preference.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I am very poor in creating class and methods. ALl programs have done programmatically. I don't know how to use class, where to write code, how to link with forms, grids. Also how to tackle click events of dynamic objects. Can you help me with those codes?
Main thing My dashboard must have max 5 columns, height and width of cell will be appxox 120 x 120 to accommodate png's I have created. If nos of rooms exceeds number of columns, then it must show in next row and thereon. Have you seen the attachment of form in my previous thread? It will show you an idea what I need.

I have just stuck here. If I cant, then I will add 100 command buttons in command group, add codes in each click events and hide the command buttons excess of room count in my cursor. This I have done earlier, but it is tedious and want something different.
 
It doesn't help to say you are poor in classes and methods, Forms are only consisting of objects (class instances) with methods. You're already using it.
If you don't want to revert to your command group, you will write a command button class.

In the end, if you refuse to learn how to define and use classes because you think it's beyond you and you only feel safe in ways you already know, you're simply not lazy enough. Classes are about reusing code, once written, used many times. So they are about doing less. If that's not a motivation, I don't know what else can motivate you to learn OOP. Get rid of your mental block. Noone can help you with that, if you're not willing to start.

Bye, Olaf.
 
I am very poor in creating class and methods.

In that case, you must bite the bullet and learn. You are using an object-oriented development tool (VFP) in an event-driven environment (Windows). And you are creating an application with a visual interface. The only way you will succeed is to learn the basics of classes, objects and methods. You don't need to be an expert, but you need to understand the fundamentals.

I suggest you pause your development for a week or two, and devote some time to learning the basics. Then go back to your application. With luck, everything will then fall into place.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I too want to learn more with OOP. Once I get started it is easy for me. Actually I never did any course with VFP9, Decade ago I learnt vfp 2.6 dos.

I have hand in C++ and Java, but I like VFP on top of them.

If somebody just give a start for me, what I need now then from there I can do it from myself Till now what I have learnt is just by try and go without training.

Hope I get a reply what I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top