Page 1 of 2

Login window

Posted: Mon Aug 30, 2010 11:50 am
by cocoking
How do I implement a "login" window in HMG? Well, It's not actually a login but an "enter date" window, but it must be accepted first before going in to the main window.

The "login" will also be an option in the menu in the main window.

I defined a modal window before a Main window but I get a syntax error at compilation.

I also tried this:

Code: Select all

DEFINE WINDOW MainForm ;
	AT 0, 0 ;
	WIDTH 750 ;
	HEIGHT 700 ; 
	MAIN ;
	TITLE 'HMMGC System'
		
	DEFINE WINDOW fmGetDate ;
		OF MainForm ;
		@ 30, 30 ;
		WIDTH 100 ;
		HEIGHT 100 ;
		TITLE "Enter Period End Date" ;
		MODAL

		@ 50, 50 DATEPICKER dpDate ;
		VALUE date()	
		
	END WINDOW
	
	DEFINE MAIN MENU
...
END WINDOW

I also get a syntax error at the second define window.

But I'm afraid with this construct, "login" will always be called after every loop.
My intention is a mandatory call to the login only at program start. After which it will be an option in the menu.

Can't find samples of this sort or maybe I just don't know where to search.

Thanks for any advice on how to implement this.

Re: Login window

Posted: Mon Aug 30, 2010 1:09 pm
by esgici
Hello cocoking

I'm afraid that couldn't understood your problem :(
cocoking wrote:...but it must be accepted first before going in to the main window.
Except message functions everything must go after main window.
cocoking wrote:But I'm afraid with this construct, "login" will always be called after every loop.
Which loop you are talking about on ?
cocoking wrote:My intention is a mandatory call to the login only at program start.
Did you tried calling your login routine at INIT event of main window ?

If you can supply your problem with a SSW (short, simple and working) sample, we can help you more easily.

Regards

--

Esgici

Re: Login window

Posted: Mon Aug 30, 2010 2:07 pm
by Rathinagiri
I accept all your points Esgici except SSW part. Because I like KISS (Keep It Small and Simple) ;)

Re: Login window

Posted: Mon Aug 30, 2010 2:19 pm
by Rathinagiri
I think this one is a sample KISS. :)

Code: Select all

# include "hmg.ch"

DEFINE window sample At 0,0 width 600 height 400 main title "Want to login?" on init loginattempt()
   DEFINE main menu
      popup "&Login"
         item "&Login" action loginattempt()
      End Popup
   End Menu
End window
sample.center
sample.activate
return nil


FUNCTION loginattempt
   DEFINE window login At 0,0 width 200 height 160 title "User Login" modal
      DEFINE label usernamelabel
         Row 10
         Col 10
         width 80
         Value "Username"
      END label
      DEFINE textbox username
         Row 10
         Col 90
         width 100
         value ""
      END textbox
      DEFINE label passwordlabel
         Row 40
         Col 10
         width 80
         Value "Password"
      END label
      DEFINE textbox password
         Row 40
         Col 90
         width 100
         password .t.
         value ""
      END textbox
      DEFINE button login
         Row 80
         Col 40
         width 50
         caption "Login"
         action iif(upper(login.username.value) == "USERNAME" .and. upper(login.password.value) == "PASSWORD", Loginok(),MsgStop("Not Authorized!")) 
      END button
      DEFINE button cancel
         Row 80
         Col 110
         width 50
         caption "Cancel"
         action logincancelled()
      END button
   END window
   login.center
   login.activate
RETURN nil
   
function loginok
MsgInfo("Login Successful")
login.release()
return nil

function logincancelled
If MsgYesNo("Are you sure to cancel?")
   Msginfo("GoodBye!")
   login.release()
   sample.release()
Endif
return nil

Re: Login window

Posted: Mon Aug 30, 2010 2:40 pm
by esgici
Thanks Rathi

SSW and KISS are two different expression of same thing, so no exception required ;)

All right, your sample is SSW, SSE ad KISS 8-)

But there are some obscure points for me yet :(

- Our friend ccoking WANT from user enter date no UserID, Password;
I don't know what relation has between date and login :(

- Also, by means, AFAIK login is an unique process in an application and it occurs only at startup. So, calling a login routine from menu also is meaningless for me.

I hope our friend will clarify that points.

Regards

--

Esgici

Re: Login window

Posted: Mon Aug 30, 2010 3:07 pm
by cocoking
Thank you, Rathi and Esgici,

Please understand that I cannot send a SSW because I have not solved syntax error yet on define of modal window.

But with the KISS sample, I think Rathi got what I wanted to do, that is if ON INIT is executed only once every time the program is ran. If it does run only once, then this problem is solved and only the syntax error remains (I will post sample later).

I actually tried ON INIT earlier but wasn't able to check if ok because it did not compile successfully.

Re: Login window

Posted: Mon Aug 30, 2010 3:46 pm
by cocoking
Attached is the slightly revised code. When compiling, it results in a syntax error in DEFINE WINDOW fmGetDate

Code: Select all

#include "hmg.ch"

function main()

DEFINE WINDOW MainForm ;
	AT 0, 0 ;
	WIDTH 750 ;
	HEIGHT 700 ; 
	MAIN ;
	ON INIT GetEndDate() ;
	TITLE 'HMMGC System'
		
	DEFINE MAIN MENU

		popup "Utilities"
			item "Change Period Ending Date" action GetEndDate()
		popup "Quit"
			item "Quit Program" action MainForm.Release
		end popup
    END MENU
END WINDOW

CENTER WINDOW MainForm
ACTIVATE WINDOW MainForm

return NIL


*****************************************************************************
function GetEndDate()
*****************************************************************************

DEFINE WINDOW fmGetDate ;
	@ 30, 30 ;
	WIDTH 100 ;
	HEIGHT 100 ;
	TITLE "Enter Period End Date" ;
	MODAL

	@ 50, 50 DATEPICKER dpPayDate ;
		VALUE date()	
	
END WINDOW
	
ACTIVATE WINDOW fmGetDate

return NIL
Other questions:

Can I define a modal window before a main window?
Can I open a main window, release it and open another main window?

Re: Login window

Posted: Mon Aug 30, 2010 4:19 pm
by esgici
Hello cocoking

You have use :

Code: Select all

DEFINE WINDOW fmGetDate ;
	AT 30, 30 ; 
instead of :

Code: Select all

DEFINE WINDOW fmGetDate ;
	@ 30, 30 ;
cocoking wrote:Can I define a modal window before a main window?
No. Think your application as a family and main window as parent; it must be unique and came before all.
cocoking wrote:Can I open a main window, release it and open another main window?
No. Releasing main window will terminate the application.

Regards

--

Esgici

Re: Login window

Posted: Mon Aug 30, 2010 5:00 pm
by Rathinagiri
esgici wrote: But there are some obscure points for me yet :(

- Our friend ccoking WANT from user enter date no UserID, Password;
I don't know what relation has between date and login :(

- Also, by means, AFAIK login is an unique process in an application and it occurs only at startup. So, calling a login routine from menu also is meaningless for me.

I hope our friend will clarify that points.
Hi Esgici,

Since I have taken this code from my working project, the login screen was just an example for on init event.

Regarding the login routine called from Menu is also from a working project of one of my clients, where in same system is shared by admin and user. There may be some features available for admin. They can login again using their password (without closing the connection to the MySQL database), and once they finish their work, they can logout and give the system to use by other user.

Re: Login window

Posted: Mon Aug 30, 2010 5:32 pm
by esgici
Understood, thanks Rathi :)

Regards

--

Esgici