**************************************************
*** Class Browser Exported Form Code 
**************************************************
*-- Form:         frmguest (c:\wwapps\wc2\wwdemo\guest.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*
DEFINE CLASS frmguest AS form


	Top = 15
	Left = 87
	Height = 373
	Width = 684
	DoCreate = .T.
	Caption = "Guest Book Browser"
	Name = "FRMGUEST"
	lnewrecord = .F.


	ADD OBJECT container1 AS container WITH ;
		Top = 12, ;
		Left = 180, ;
		Width = 493, ;
		Height = 289, ;
		SpecialEffect = 0, ;
		BackColor = RGB(254,255,225), ;
		Name = "Container1"


	ADD OBJECT txtname AS textbox WITH ;
		ControlSource = "guest.name", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 292, ;
		MaxLength = 40, ;
		TabIndex = 2, ;
		Top = 23, ;
		Width = 288, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtName"


	ADD OBJECT txtcompany AS textbox WITH ;
		FontBold = .T., ;
		ControlSource = "guest.company", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 292, ;
		MaxLength = 40, ;
		TabIndex = 4, ;
		Top = 50, ;
		Width = 288, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtCompany"


	ADD OBJECT txtentered AS textbox WITH ;
		ControlSource = "guest.entered", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 512, ;
		MaxLength = 8, ;
		TabIndex = 8, ;
		Top = 269, ;
		Width = 127, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtEntered"


	ADD OBJECT edtmessage AS editbox WITH ;
		Enabled = .F., ;
		Height = 120, ;
		Left = 292, ;
		TabIndex = 10, ;
		Top = 143, ;
		Width = 348, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		ControlSource = "guest.message", ;
		Name = "edtMessage"


	ADD OBJECT txtlocation AS textbox WITH ;
		ControlSource = "guest.location", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 292, ;
		MaxLength = 40, ;
		TabIndex = 12, ;
		Top = 111, ;
		Width = 288, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtLocation"


	ADD OBJECT txtpassword AS textbox WITH ;
		ControlSource = "guest.password", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 292, ;
		MaxLength = 8, ;
		TabIndex = 14, ;
		Top = 271, ;
		Width = 66, ;
		Comment = "", ;
		PasswordChar = "*", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtPassword"


	ADD OBJECT lblname AS label WITH ;
		FontBold = .T., ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Name:", ;
		Left = 249, ;
		Top = 26, ;
		Visible = .T., ;
		Width = 39, ;
		ForeColor = RGB(128,0,64), ;
		Name = "lblName"


	ADD OBJECT lblcompany AS label WITH ;
		FontBold = .T., ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Company:", ;
		Left = 228, ;
		Top = 53, ;
		Visible = .T., ;
		Width = 61, ;
		ForeColor = RGB(128,0,64), ;
		Name = "lblCompany"


	ADD OBJECT lblemail AS label WITH ;
		FontBold = .T., ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Email:", ;
		Left = 251, ;
		Top = 85, ;
		Visible = .T., ;
		Width = 37, ;
		ForeColor = RGB(128,0,64), ;
		Name = "lblEmail"


	ADD OBJECT lblmessage AS label WITH ;
		FontBold = .T., ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Message:", ;
		Left = 229, ;
		Top = 146, ;
		Visible = .T., ;
		Width = 60, ;
		ForeColor = RGB(128,0,64), ;
		Name = "lblMessage"


	ADD OBJECT lbllocation AS label WITH ;
		FontBold = .T., ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Checking in from:", ;
		Height = 17, ;
		Left = 187, ;
		Top = 114, ;
		Visible = .T., ;
		Width = 101, ;
		ForeColor = RGB(128,0,64), ;
		Name = "lblLocation"


	ADD OBJECT lblpassword AS label WITH ;
		FontBold = .T., ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Password:", ;
		Left = 222, ;
		Top = 274, ;
		Visible = .T., ;
		Width = 67, ;
		ForeColor = RGB(128,0,64), ;
		Name = "lblPassword"


	ADD OBJECT shape1 AS shape WITH ;
		Top = 311, ;
		Left = 180, ;
		Height = 51, ;
		Width = 493, ;
		SpecialEffect = 0, ;
		BackColor = RGB(64,128,128), ;
		Name = "Shape1"


	ADD OBJECT btnnew AS commandbutton WITH ;
		Top = 323, ;
		Left = 270, ;
		Height = 27, ;
		Width = 62, ;
		Caption = "\<New", ;
		Name = "btnNew"


	ADD OBJECT btndelete AS commandbutton WITH ;
		Top = 323, ;
		Left = 332, ;
		Height = 27, ;
		Width = 62, ;
		Caption = "\<Delete", ;
		Name = "btnDelete"


	ADD OBJECT btntop AS commandbutton WITH ;
		Top = 325, ;
		Left = 425, ;
		Height = 22, ;
		Width = 35, ;
		FontBold = .T., ;
		Caption = "|<<", ;
		Name = "btnTop"


	ADD OBJECT btnprevious AS commandbutton WITH ;
		Top = 325, ;
		Left = 460, ;
		Height = 22, ;
		Width = 35, ;
		FontBold = .T., ;
		Caption = "<<", ;
		Name = "btnPrevious"


	ADD OBJECT btnnext AS commandbutton WITH ;
		Top = 325, ;
		Left = 496, ;
		Height = 22, ;
		Width = 35, ;
		FontBold = .T., ;
		Caption = ">>", ;
		Name = "btnNext"


	ADD OBJECT btnbottom AS commandbutton WITH ;
		Top = 325, ;
		Left = 531, ;
		Height = 22, ;
		Width = 35, ;
		FontBold = .T., ;
		Caption = ">>|", ;
		Name = "btnBottom"


	ADD OBJECT btnexit AS commandbutton WITH ;
		Top = 323, ;
		Left = 575, ;
		Height = 27, ;
		Width = 62, ;
		Caption = "E\<xit", ;
		Name = "btnExit"


	ADD OBJECT btnrefresh AS commandbutton WITH ;
		Top = 338, ;
		Left = 10, ;
		Height = 24, ;
		Width = 157, ;
		Caption = "\<Refresh", ;
		Name = "btnRefresh"


	ADD OBJECT lstguests AS listbox WITH ;
		FontSize = 9, ;
		RowSourceType = 6, ;
		RowSource = ['guest.name +replicate(chr(160),40)+"|" + custid'], ;
		Height = 297, ;
		Left = 9, ;
		Top = 36, ;
		Width = 158, ;
		Name = "lstGuests"


	ADD OBJECT txtcustid AS textbox WITH ;
		ControlSource = "guest.custid", ;
		Height = 23, ;
		Left = 592, ;
		MaxLength = 8, ;
		TabIndex = 31, ;
		Top = 23, ;
		Width = 66, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtCustid"


	ADD OBJECT btnedit AS commandbutton WITH ;
		Top = 323, ;
		Left = 208, ;
		Height = 27, ;
		Width = 62, ;
		Caption = "\<Edit", ;
		Name = "btnEdit"


	ADD OBJECT lblentered AS label WITH ;
		Alignment = 1, ;
		BackStyle = 0, ;
		Caption = "Entered on:", ;
		Left = 437, ;
		Top = 274, ;
		Visible = .T., ;
		Width = 70, ;
		Name = "lblEntered"


	ADD OBJECT optlistorder AS optiongroup WITH ;
		ButtonCount = 2, ;
		Value = 1, ;
		Height = 26, ;
		Left = 12, ;
		Top = 5, ;
		Width = 156, ;
		Name = "optListOrder", ;
		Option1.Caption = "Entry Date", ;
		Option1.Value = 1, ;
		Option1.Height = 17, ;
		Option1.Left = 5, ;
		Option1.Top = 6, ;
		Option1.Width = 85, ;
		Option1.Name = "optDate", ;
		Option2.Caption = "Name", ;
		Option2.Height = 16, ;
		Option2.Left = 95, ;
		Option2.Top = 6, ;
		Option2.Width = 55, ;
		Option2.Name = "optName"


	ADD OBJECT txtemail AS textbox WITH ;
		ControlSource = "guest.email", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 292, ;
		MaxLength = 65, ;
		TabIndex = 6, ;
		Top = 80, ;
		Width = 348, ;
		Comment = "", ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(128,128,128), ;
		Name = "txtEmail"

	PROCEDURE Init
		SET TALK OFF
		SET DELETED ON

        SELE Guest
		SET ORDER TO Date
		LOCATE
		
		*** Force list to show first entry
		THISFORM.lstGuests.Value=EVAL(THISFORM.lstGuest.RowSource)
	ENDPROC


	*-- Displays the form based on a Customer Id parameter passed.
	PROCEDURE showform
		* lnStatus   -    0  - Normal editing
		*                 1  - Disabled
		*                 2  - Empty editing
		*                 3  - Empty disabled
		LPARAMETER lcCustId, lnStatus

		lnStatus=IIF(type("lnStatus")="N",lnStatus,0)

		SELE GUEST
		IF THISFORM.optListOrder.value=1
		  SET ORDER TO DATE
		ELSE
		  SET ORDER TO NAME
		ENDIF

		THISFORM.lstGuests.Requery()

		IF EMPTY(lcCustId)
		   lcCustId=Guest.custid
		ELSE
		   LOCATE FOR CustId = lcCustId
		   IF !FOUND()
		      LOCATE
		   ENDIF 
		ENDIF

		IF lnStatus=2
		  GO BOTTOM
		  SKIP
		  THISFORM.Refresh()
		ENDIF  

		IF lnStatus = 1 
		   THISFORM.Setall("enabled",.F.)
		   THISFORM.Setall("enabled",.T.,"Label")
		   THISFORM.lstGuests.enabled=.t.
		   THISFORM.btnNew.enabled=.t.
		   THISFORM.btnDelete.enabled=.f.
		   THISFORM.btnRefresh.enabled=.T.
		   THISFORM.lstGuests.enabled=.T.
		   THISFORM.txtCustid.visible=.T.
		   THISFORM.txtEntered.visible=.T.
		   THISFORM.lblEntered.visible=.T.
		   THISFORM.optListorder.enabled=.T.
		   THISFORM.optListorder.setall('enabled',.T.)
		ELSE
		   THISFORM.Setall("enabled",.T.)
		   THISFORM.lstGuests.enabled=.F.
		   THISFORM.btnNew.enabled=.F.
		   THISFORM.btnDelete.enabled=.T.
		   THISFORM.btnExit.enabled=.F.
		   THISFORM.btnRefresh.enabled=.F.
		   THISFORM.lstGuests.enabled=.F.
		   THISFORM.txtCustid.visible=.F.
		   THISFORM.txtEntered.visible=.F.
		   THISFORM.lblEntered.visible=.F.
		   THISFORM.optListorder.enabled=.F.
		   THISFORM.optListorder.setall('enabled',.F.)
		ENDIF   

		THISFORM.btnEdit.enabled=.T.
		THISFORM.btnExit.enabled=.T.

		*** Set the button status
		IF lnStatus # 2
		  THISFORM.Navigate()
		ENDIf  
	ENDPROC


	PROCEDURE deleterecord
		LPARAMETER lcCustId

		SELE Guest
		LOCATE FOR Custid = PADR(lcCustID,8)
		IF FOUND()
		   DELETE
		ENDIF   
	ENDPROC


	PROCEDURE setlistorder
		LPARAMETER lnOrder

		THISFORM.optListOrder.value=lnOrder
	ENDPROC


	PROCEDURE checkpassword
		*** Checks to see whether a password matches the password on the form
		LPARAMETER lcPassword

		IF EMPTY(lcPassword) or UPPER(lcPassWord) # TRIM(UPPER(THISFORM.txtPassword.value)) 
		   RETURN .f.
		ENDIF

		RETURN .t.
	ENDPROC


	PROCEDURE navigate
		LPARAMETER lcAction
		lcAction=IIF(type("lcAction")="C",lcAction,"")

		llSuccess=.T.

		THISFORM.btnTop.enabled=.T.
		THISFORM.btnPrevious.enabled=.T.
		THISFORM.btnNext.enabled=.T.
		THISFORM.btnBottom.enabled=.T.

		DO CASE
		  CASE lcAction = "NEXT"
		    IF !EOF()
		       SKIP
		    ELSE
		       THISFORM.btnNext.enabled=.F.
		       THISFORM.btnBottom.enabled=.F.
			ENDIF
		  CASE lcAction="PREV"
		    IF !BOF()
		       SKIP -1
		       IF BOF()
		         THISFORM.btnPrevious.enabled=.F.
		         THISFORM.btnTop.enabled=.F.
		       ENDIF       
		    ELSE 
		       THISFORM.btnPrevious.enabled=.F.
		       THISFORM.btnTop.enabled=.F.
		    ENDIF
		  CASE lcAction="TOP"
		    LOCATE
		    THISFORM.btnPrevious.enabled=.F.
		    THISFORM.btnTop.enabled=.F.
		  CASE lcAction="BOTTOM"
		    LOCATE FOR .F.
		ENDCASE

		IF EOF()
		  SKIP -1
		  THISFORM.btnNext.enabled=.F.
		  THISFORM.btnBottom.enabled=.F.
		ENDIF
		IF BOF()
		   THISFORM.btnPrevious.enabled=.F.
		   THISFORM.btnTop.enabled=.F.
		ENDIF  

		THISFORM.lstGuests.Value=guest.name +replicate(chr(160),40)+"|" + guest.custid

		*IF !EMPTY(lcAction)
		*   THISFORM.ShowForm(guest.custId,1)
		*ENDIF

		THISFORM.Refresh

		RETURN .T.
	ENDPROC


	*-- Displays the updated Saved form
	PROCEDURE save
		LOCAL loButton

		*** Listbox contains the name + "|" + custid in hidden space
		*** Retrieve the "|" to show.
		loButton=THISFORM.btnEdit

		*** Do nothing. In HTML we have to show the form
		*** locate on the appropriate record, then wwForm::SetValues
		loButton.Caption="\<Edit"

		*** Show Form in View Mode
		THISFORM.ShowForm(Guest.custid,1)
	ENDPROC


	*-- Shows the form in Edit mode
	PROCEDURE edit
		LPARAMETER lnType
		LOCAL loButton

		lnType=IIF(type("lnType")="N",lnType,0)

		*** Listbox contains the name + "|" + custid in hidden space
		*** Retrieve the "|" to show.
		loButton=THISFORM.btnEdit

		*** Do nothing. In HTML we have to show the form
		*** locate on the appropriate record, then wwForm::SetValues
		loButton.Caption="\<Save"

		*** Show Form in View Mode
		THISFORM.ShowForm(Guest.custid,lnType)
	ENDPROC


	PROCEDURE btnnew.Click
		* HTML would do this
		* THISFORM.ShowForm(,2)

		*** Ok, so this is very hokey 
		*** Hey, it's a demo! <bg>

		INSERT INTO GUEST (Custid,entered) VALUES (SYS(3),DATETIME())
		THISFORM.ShowForm(Guest.CustId,0)
		THISFORM.btnEdit.Caption="\<Save"
	ENDPROC


	PROCEDURE btndelete.Click
		THISFORM.DeleteRecord(guest.custid)

		THISFORM.ShowForm(,1)
		THISFORM.btnEdit.Caption="\<Edit"
	ENDPROC


	PROCEDURE btntop.Click
		THISFORM.Navigate("TOP")
	ENDPROC


	PROCEDURE btnprevious.Click
		THISFORM.Navigate("PREV")
	ENDPROC


	PROCEDURE btnnext.Click
		THISFORM.NaviGate("NEXT")
	ENDPROC


	PROCEDURE btnbottom.Click
		THISFORM.Navigate("BOTTOM")
	ENDPROC


	PROCEDURE btnexit.Click
		THISFORM.Release
	ENDPROC


	PROCEDURE btnrefresh.Click
		*** Test Web Operation of 'REFRESH'

		*** Listbox contains the name + "|" + custid in hidden space
		*** Retrieve the "|" to show.
		lcValue=THISFORM.lstGuests.DisplayValue
		lcCustId=SUBSTR(lcValue,AT("|",lcValue)+1)

		SELE GUEST
		THISFORM.ShowForm(Guest.custid,1)

		      
	ENDPROC

	PROCEDURE btnedit.Click
		IF THIS.Caption="\<Edit"
		  THISFORM.Edit()
		ELSE
		  THISFORM.Save()
		ENDIF    
	ENDPROC


ENDDEFINE
*
*-- EndDefine: frmguest
**************************************************
