Search This Blog

Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Release Block User Code

In any login code, aside from status login, logout, I also made use of block. A user has a status of block if his username and password dis not match thrice in a row. This will help in the security of accessing the program.

PUBLIC pBlockUser
IF !EMPTY(THISFORM.Text2.Value)
IF THISFORM.Text4.Value = "BLOCK"
pBlockUser = THISFORM.Text3.Value
lAnswer = MESSAGEBOX("Do you want to release "+ALLTRIM(pBlockUser)+"?", 4, "Confirmation")
IF lAnswer = 6
SELECT SviewAccess
LOCATE FOR IdNum = THISFORM.Text2.Value
IF FOUND()
REPLACE AccessStatus WITH "LOGOUT"
=MESSAGEBOX("Successfully release "+ALLTRIM(pBlockUser)+" .", "Confirmation")
THISFORM.Grid1.REFRESH
ENDIF
ENDIF
ELSE
=MESSAGEBOX("Select a Block User.", "Confirmation")
ENDIF
ELSE
=MESSAGEBOX("Select User.", "Confirmation")
ENDIF

Table Update Code

Sample of table update implemented in replace:

SELECT SviewAccountList
lBranches = pBranchName
=REQUERY("SviewAccountList")
LOCATE FOR (IdNum) = (THISFORM.Text34.Value)
IF FOUND()
REPLACE TotalDebit WITH THISFORM.TEXT15.Value
REPLACE TotalCredit WITH THISFORM.TEXT18.Value
REPLACE EndingBalance WITH THISFORM.TEXT26.Value
REPLACE Lines WITH "POST"
REPLACE LDate WITH DATE()
=TABLEUPDATE(.T.)
ENDIF

Activity Log Code

This is the first time I will be using Activity Log on my program. Where the User or Admin can view the activity of a certain user such as adding or editing. You can also add certain specific information such as amount and account chart of journal entries.

SELECT SviewActivityLog
APPEND BLANK
REPLACE UserName WITH pCurrUser
REPLACE ActivityDate WITH DATE()
REPLACE ActivityLog WITH "Add Journal Entries in "+ALLTRIM(pBranchName)+".."

SELECT SviewActivityLog
APPEND BLANK
REPLACE UserName WITH pCurrUser
REPLACE ActivityDate WITH DATE()
REPLACE ActivityLog WITH "Edit Journal Entries in "+ALLTRIM(pBranchName)+".."

Login Code

Login Code

SELECT SviewAccess
=REQUERY("SviewAccess")
PUBLIC pCurrUser, pBranchName
LOCATE FOR ALLTRIM(LOWER(Username)) = ALLTRIM(LOWER(THISFORM.Text1.Value))
IF FOUND()
IF ALLTRIM(AccessStatus) = "LOGOUT"
IF THISFORM.Text3.Value = 3
WAIT WINDOW "Three (3) incorrect attempts." NOWAIT
REPLACE SviewAccess.AccessStatus WITH "BLOCK"
THISFORM.Release()
QUIT
ELSE
IF EMPTY(ALLTRIM(THISFORM.Text2.Value))
WAIT WINDOW "Cannot continue without password." NOWAIT
ELSE
IF EMPTY(ALLTRIM(THISFORM.Combo1.Value))
WAIT WINDOW "Cannot continue without Branch Office." NOWAIT
ELSE
IF LOWER(ALLTRIM(Password)) == LOWER(ALLTRIM(THISFORM.Text2.Value))
WAIT WINDOW "Welcome " + Username NOWAIT
pDept = ALLTRIM(sviewaccess.AccessDepartment)
pCurrUser = ALLTRIM(Username)
pFullName = ALLTRIM(FullName)
pPassword = ALLTRIM(sViewAccess.Password)
pBranchName = ALLTRIM(THISFORM.Combo1.Value)
IF (ALLTRIM(THISFORM.Text1.Value)) = "MUFFIE"
ELSE
REPLACE SviewAccess.AccessStatus WITH "LOGIN"
ENDIF
THISFORM.ActivityLogin()
SELECT SviewAccess
=TABLEUPDATE(.T.)
THISFORM.Release()
=REQUERY("SviewAccess")
ELSE
WAIT WINDOW "Incorrect Password." NOWAIT
THISFORM.Text3.Value = THISFORM.Text3.Value + 1
THISFORM.Text2.SetFocus()
ENDIF
ENDIF
ENDIF
ENDIF
ELSE
=MESSAGEBOX("User currently Logged In : "+ ALLTRIM(SviewAccess.FullName)+" station.", "MultiUser: Block")
ENDIF
ENDIF

Local View and Remote View

Samples of Local View and Remote View with different filter using like, between and =.

SELECT SviewAccountChart
lAccountCode = ALLTRIM(THISFORM.Text16.Value)+"%"
=REQUERY("SviewAccountChart")

SELECT SviewJvHeader
lJvNo = ALLTRIM(THISFORM.Text20.Value)+"%"
lJvBranch = ALLTRIM(THISFORM.Text21.Value)+"%"
=REQUERY("SviewJvHeader")

SELECT SviewCheckIssueReg
lCheckNum = ALLTRIM(THISFORM.Text20.Value)+"%"
lCheckType = ALLTRIM(THISFORM.Combo3.Value)+"%"
StartDate = THISFORM.Text14.Value
EndDate = THISFORM.Text15.Value
=REQUERY("SviewCheckIssueReg")

Edit Save Code

Microsoft Visual FoxPro programming language has a lot of code to edit, insert, replace or save. Using select, append, insert or replace is some of the ways to save data. I always use the select and replace because it is easy to troubleshoot when your code has a problem.

SELECT InfoNumber
LOCATE FOR IdNum = THISFORM.txtIdNum.VALUE
IF FOUND()
SELECT InfoNumber
REPLACE LastName WITH ALLTRIM(THISFORM.txtLastName.VALUE)
REPLACE FirstName WITH ALLTRIM(THISFORM.txtFirstName.VALUE)
REPLACE MiddleName WITH ALLTRIM(THISFORM.txtMiddleName.VALUE)

Edit Save Code


Most of the time neophyte VFP Programmers know how to add, edit and save data on the table. But how can we improve the form design? This is a sample I usually used, to ask or confirm if the User want to edit dat. A confirmation message box will appear with a 'Yes' or 'No'. From that the User can choose which will be the next function.

lAnswer = MESSAGEBOX("Save and update Counter Dispatch?", 4, "Confirmation")
IF lAnswer = 6
SELECT sviewbranch
LOCATE FOR IdNum = THISFORM.Text12.Value
IF FOUND()
REPLACE beginbal WITH THISFORM.TEXT1.Value
REPLACE branchname WITH THISFORM.TEXT2.Value
REPLACE branchaddress WITH THISFORM.TEXT3.Value
REPLACE branchdesc WITH THISFORM.TEXT4.Value
REPLACE debit WITH THISFORM.TEXT5.Value
REPLACE credit WITH THISFORM.TEXT6.Value
REPLACE netchange WITH THISFORM.TEXT7.Value
REPLACE ending WITH THISFORM.TEXT8.Value
REPLACE branchdescnum WITH THISFORM.TEXT9.Value
THISFORM.REFRESH
ENDIF