Re: Multiple form instances being created with log on/off routine
Try this.
I like keeping if-endif tight so sometimes it's best to use does not equal versus equal. And I always have a cancel button on a dialog.
Try this.
I like keeping if-endif tight so sometimes it's best to use does not equal versus equal. And I always have a cancel button on a dialog.
Code:
DIM GLOBAL gvModuleName as C DIM GLOBAL gvuser as C DIM GLOBAL gvEmpName as C DIM GLOBAL gvEmpid as C DIM GLOBAL gvLogOnOff as C DIM SHARED vuserpass as C DIM SHARED varC_result as C DIM SHARED vCenterForm as C DIM vuserfound as C 'Change Title to "Log On As" and refresh parent layout gvModuleName = "Log On As" 'Blank the Username and Password gvuser="" vuserpass="" 'Change the Employee Name to "No Employee" gvEmpName="No Employee" 'Set Log_On_Off button text to "Log On" gvLogOnOff = "Log On" Log_On_Off.text = gvLogOnOff 'Refresh Main Menu topparent.Repaint() '--------------- Retry_here: '--------------- ok_button_label = "&Log On" 'cancel_button_label = "&Cancel" varC_result = ui_dlg_box("EIM Track",<<%dlg% {font=Arial,10} {frame=1,1:Enter your Username and Password:} {region} {lf}; Username:| [.40gvuser]; Password:| [%p%.40vuserpass]; {lf}; {endregion}; {lf}; {region} {justify=right} <*15=ok_button_label!Log On*?> <Cancel> {endregion}; %dlg%) If varC_result="Cancel" end end if IF varC_result = "Log On" ' Get data from Employee Master file to verify password - make one text string that has both values and then parse it out below ' Lookup the records for the matching username and password lres = lookupc("F",alltrim(gvuser),"alltrim(emplognid)+' -- '+alltrim(emppass)",a5.Get_Path()+"\emp.dbf","_emplognid") vuserfound = word(lres,1," -- ") vpassfound = word(lres,2," -- ") 'Compare user name entered to that in the Employee Master file (found with lookupc above) 'Test User Name IF alltrim(lower(gvuser)) <> alltrim(lower(vuserfound)) 'Name does not matches - try again ui_msg_box("User Name Not Found","The User Name you entered could not be found",UI_STOP_SYMBOL) gvuser = "" vuserpass = "" GOTO Retry_here END IF ' Test Password IF alltrim(lower(vuserpass)) <> alltrim(lower(vpassfound)) ' Password matches too 'Password does not match - try again ui_msg_box("Password Error!","Password entered is incorrect.",UI_STOP_SYMBOL) 'Clear vuserpass variable vuserpass = "" GOTO retry_here END IF 'SUCCESS: User name and Password match gvuser = alltrim(lower(gvuser)) 'Clear vuserpass variable vuserpass = "" 'Set a Global Variable containing the Employees full name gvEmpName = lookupc("F", gvuser, "alltrim(Empfname)+' '+ alltrim(Emplname)", "emp","_Emplognid") 'Set a Global Variable containing the Employees ID Number gvEmpid = lookupc("F", gvuser, "alltrim(Empid)", "emp","_Emplognid") 'Set a Global Variable containing the current module name gvModuleName = "Main Menu" 'Form Name to Center when opening vCenterForm = "Main_Menu" 'Set Log_On_Off button text to "Log Off" gvLogOnOff = "Log Off" Log_On_Off.text = gvLogOnOff if a_form_current<>"Main_Menu" 'Close the current form parentform.close(.f.) 'Loads the Main Menu form.view(vCenterForm, "", "", "center", "center") end if 'Refresh Main Menu ' refresh screen topparent.resynch() topparent.refresh_layout() topparent.Repaint() END IF
Comment