Retail POS

www.pcland.com.pk

Monday 16 November 2015

USING SMS API in VISUAL FOXPRO

[Visual fox pro SMS using API]

Visual fox pro uses two method of  programming for SMS sending from VFP build applications.

1. Direct Comport Interface with Local or Network server logging tables/database.

Following two method can be used for this type of communication.
a.) From VFP custom build application, directly open the local Comport, & push the SMS to your mobile operator SMS gateway in real time.

b.) Dedicated VFP build SMS pooling (Push) application is hosted on local or network server.
In this way of sending SMS, a log database (tables) is created & used to Que the messages to Push on SMS gateway on FIFO based algorithm. Pooling application can be configured as "service" or "Startup/Scheduled application" on local or server based machine
Multiple applications can send SMS using this shared way.

VFP  good SMS pooler example with source code to modify according to your needs :

Vivek Deodhar shows you how to send SMS text messages with VFP. smspooler.zip - Download ID: 225



2. WEB-SMS  (Using SMS Gateway on internet via SMS PUSH method) 
In this method , all message is composed locally in VFP application (using variables, properties, or textbox etc.) and merged, validated before Pushing to server according to calling Syntax of every Web Gateway server. (for proper syntax refer to documentation of every service provider)


[WEB SMS] 

1. UFONE API CODE Example:

Local lcUrl, lcresult
lcUrl="http://bsms.ufone.com/bsms_app4/sendapi.jsp?id=011111111&message=&lcTempTxtFile&shortcode=fox&lang=English&mobilenum=&ccnum&password=12345&groupname=groupname"

**-----------------------*
** Red high lighted variable values will be replaced  provided by Ufone against your account.

lcresult = Sms_Push(lcUrl)

wait wind lcresult
RETURN

*------------------------------*
FUNCTION Sms_Push
*-----------------------------*
Lparameters lcurl
Local lcRetstatus, XmlHttpobj As Microsoft.XMLHTTP
lcRetstatus = ""

Try
        XmlHttpobj = Createobject("Microsoft.XMLHTTP")
        XmlHttpobj.Open("GET", lcurl, .F.)
        XmlHttpobj.setRequestHeader("Content-Type", "text/urlencoded")
        XmlHttpobj.Send()
   
    If (XmlHttpobj.Status = 404)
        lcRetstatus = "Error#: 404"
    Else
        lcRetstatus = XmlHttpobj.ResponseText
    endif
   
        XmlHttpobj = Null
Catch To oErr
        lcRetstatus = "Following Error Occurs:"+oErr.Message
endtry

        Return lcRetstatus

endfunc



**************----------------------------------------------*******************************

2. SmsGatewayhub.com  API CODE Example:


Local lcuser,lcPassword,lcUrl, lcresult
lcUrl="http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user="+lcuser+"&pwd="+lcPassword+"&to="+lcNumber+"&sid="+lcuser+"&msg="+lcMsg+"&fl=0&gwid=2"
**-----------------------*
** Red high lighted variable values will be replaced  provided by service provider against your
** account.


 lcresult = Sms_Push(lcUrl)
wait wind lcresult
RETURN


*------------------------------*
FUNCTION Sms_Push
*-----------------------------*
Lparameters lcurl
Local lcRetstatus, XmlHttpobj As Microsoft.XMLHTTP
lcRetstatus = ""

Try
        XmlHttpobj = Createobject("Microsoft.XMLHTTP")
        XmlHttpobj.Open("GET", lcurl, .F.)
        XmlHttpobj.setRequestHeader("Content-Type", "text/urlencoded")
        XmlHttpobj.Send()
   
    If (XmlHttpobj.Status = 404)
        lcRetstatus = "Error#: 404"
    Else
        lcRetstatus = XmlHttpobj.ResponseText
    endif
   
        XmlHttpobj = Null
Catch To oErr
        lcRetstatus = "Following Error Occurs:"+oErr.Message
endtry

        Return lcRetstatus

endfunc

******************************** Code end *******************

Cheers!


Hope this will help you to choose according to your Requirement of SMS for your VFP Application development !

Tuesday 20 January 2015

VFP Scanning using WIA.Common Dialog


Visual Foxpro & Scanning :


Visual Foxpro is having great feature to connect any hardware device  via windows class libraries, it may be  Dynamic link Library (.dll), Object Linking and Embedding OCX, Foxpro Link Library (.Fll) or Window API calls.

These all above need's proper syntax & calling method parameters to use in programming. Passing parameter type and function /procedure returning value type.

Now coming toward our scanning project.Here we will use a easy & common way of scanning a document in vfp using windows API  library call of "WIA.CommonDialog".

This library interacts with scanning or capturing device's driver provided by manufacturer of this device,  stores basic properties and relevant data as windows API interface.

Well different manufacture uses different methods & properties of their dll/ocx declaration. That is not our headace because we are not interacting their .dlls or ocx to get directly data from driver libraries.

We will use WIA.CommonDialog to get any device's list of  properties, names &  values  with VFP. This list of properties will help us to manage our desired out put format & relevent size of scanned document as our requirement.

Note:

* For adjusting properties of any device we have to communicate directly with device by calling functions of dll/ocx. WIA.CommonDialog will not allow to adjust properties values in some cases.


*********************************************
* Programe :   ReadScanner.prg
* Author :     witten by Zia Mughal

* CopyRight :  Pcland Software Inc. Pakistan
* http://www.pcland.com.pk
**********************************

#DEFINE WIA_FORMAT_JPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
#DEFINE DPI = 150  && or what you want

LOCAL cdg As Object
cdg = CREATEOBJECT("Wia.CommonDialog")
DevMgr = CREATEOBJECT ("WIA.DeviceManager")

 dev = cdg.ShowSelectDevice
clear

set printer to fullpath(sys(2003))+"\Property.txt"
set printer on
set device to printer

**  May your loop vary according to device properties
for i=1 to 33 step 1
a= dev.Properties(i).name
b= dev.Properties(i).value
? alltrim(str(i)) + " : "
??  alltrim(a) + " = "
?? b
endfor
set device to screen
set printer off
set printer to

modify file fullpath(sys(2003))+'\Property.txt' noedit
********assume example of HP scanjet g4050
*dev.properties(24).value = 2  && 'Access Rights
*dev.properties(25).value = 300  && 'DPI horizontal
*dev.properties(26).value = 300  && 'DPI horizontal

*dev.properties(6149).value = 0 && 'x point to start scan
*dev.properties(6150).value = 0 && 'y point to start scan
*dev.properties(6151).value = 8.5 * DPI && 'Horizontal Extent
*dev.properties(6152).value = 11# * DPI && 'Vertical Extent for letter

Img = cdg.ShowAcquireImage
IF ISNULL(Img)
WAIT WINDOW TIMEOUT 1 "User Cancelled"
RETURN .F.
ENDIF
*dev.Transfer(WIA_FORMAT_JPEG)
Img.SaveFile(FULLPATH(sys(2003))+"\test.jpg")

************************************************

Enjoy the COFFEE!
My Respects!

Monday 12 May 2014

How to Hide Black RUN window in VFP

Visual Fox pro RUN | ! command runs any external program using cmd.exe. But it shows Black window running in background of called Program by RUN command and it remains open till called program is active.





As alternative of RUN wscript.shell script can be run but it has dependencies for windows scripting to be installed & enabled to run Client/server system.

[Recomended Solution]
I prefer to use myself & recommend Windows API Call shellExecute(), which works as alternative to above both methods. It does not shows any Black window in your developed application to make it UGLY for user dis-appointment.

Why not Shellexec() Alone to use.?


I used windows Sleep() function  & CMD with Shellexec() in my runfile() function.

Trick implement in runfile() function is that Shellexec() calls  'CMD' to run the passed parameter in string variable. Shellexec() executes 'CMD'  as silent application, Finally we get Rid of UGLY Black windows to display on screen.

CMD can run all  windows application as well as DOS internal commands are supported .
Hence we can run all DOS supported commands in runfile() which can not be executed alone in Shellexec().

see bellow image running Notepad.exe with no-background Black window.



Bellow is my function Code which is replacement of all you required to hide Black window.
*********************************************
* Author :     witten by Zia Mughal
* CopyRight :  Pcland Software Inc. Pakistan
* http://www.pcland.com.pk
**********************************
=runfile("notepad.exe", "untitled.txt" )

**********************
FUNCTION runfile
PARAMETERS rfile, lcmdpara
**********************************
DECLARE INTEGER ShellExecute IN shell32.dll ; 
INTEGER hndWin, ; 
STRING cAction, ; 
STRING cFileName, ; 
STRING cParams, ;  
STRING cDir, ; 
INTEGER nShowWin
local lcCMD, lcParas
DECLARE Sleep IN Win32API INTEGER
lcCmd = rfile   && command to Execute 
lcParas = lcmdpara   && Extra parameter to pass your command 
 * --- Execute the command.
****   shellExecute last parameter 0  will hide DOS window
***  If you want to show DOS window change it to value  1 

ShellExecute(0,'open','cmd', '/C'+lcCmd+' '+lcParas, '',0)
sleep(2000)  && delay time to come  back
 *** sleep value  can be reduced according to your need
CLEAR DLLS ShellExecute
* --- Return to caller.
RETURN
ENDFUNC
 ***********************************


 Hi Folks!

This is all what i did, now its upon your will to adopt the way to complete your task!

Regards!

Zia Mughal

Running Applications with full Access on WIndows 7/8

Microsoft Changed it Security with better Security Policy  for Windows 7, Windows 8 & onward Releases.
They introduced  UAC (User Authentication Control), comparatively  is best feature then Xp or Previous OS released by Microsoft. By default on New OS installation it becomes effective.

Many users did not know UAC features & benefits because there already installed/ running applications on XP becomes effected  under UAC control, which needs setting to be done on Windows 7, Windows 8 or later version.

Some of default restricted UAC locations are as follows
Main root C:\ , C:\windows & all sub folders  (including all exe, dll, etc)
c:\Program files\  etc.
in these above areas we can not create/delete  manualy or Programmatically any file  without 'Administrator Rights'

To run effected applications user needs to adjust his applications as per his needs, because default setting for all applications become in tight position.

[RUN as Administrator Settings]

Setting & Running a application as 'Administrator' does not effect the whole UAC (user Authentication Control) of OS. we can use Windows 7/8 compatibility mode for running your applications.

1. Right click on your application Program (Exe,App)  then click ->Properties
2. click on "Compatibility" tab.
3. "Check mark" the option "Run this program as an administrator"  and Click "Apply"





[Backward Compatibility Settings]


Microsoft provided this feature  for those application which were designed for windows XP or All backward OS. To run those Old Applications we need to set this feature for every application we want to RUN on Windows 7, Windows 8.

Setting this feature does not effect all  OS applications behavior as backward. It will assign compatability environment to only application whom you are setting.

1. Right click on your application then click ->Properties

2. click on "Compatibility" tab.

3. "Check mark"  both options and Click "Apply"

  i) "Run this Program in Compatible Mode"
     ->select Windows XP (service Pack 3)  or any other OS you required from list.
 ii) "Run this program as an administrator" This  is optional if you required it.






Cheers!


Hope this will RUN your effected application till Next Release of Windows by Microsoft !


Zia Mughal










Saturday 3 May 2014

How to Enable VFP9 Help under WINDOW 8

VF9 help is written in dv_foxhelp.chm file. When any user Upgrades his operating system from Windows 7 to windows 8 or installs new copy of window 8 directly. Suddenly he experiences that in VFP help stops working.

All this happens due to Microsoft is increasing its UAC & security of its new OS  or might be a guess not confirmed its new policy to make harder day by day related to Old application to retire permanently.

Any how thanks again Microsoft that there was a manual driven  way was left for Programmers/Developer to do, & switch on the blocked Applications to RUN on Windows 8 & 8.1.

Many website site & blogs are full off Question  regarding 'How to enable VFP9 help to run on window 8'.
This driven me to write this post on Blog for all who are in search for this answer.


1. Open your Directory/Folder of VFP9, find file dv_foxhelp.chm  Right click & see Properties figure 1.1.

Figure 1.1


2. See its default properties will be as bellow shown in figure 1.2.

Figure 1.2

 3. Select by click on your windows user from you logged in or if you want to assign it to all 'Authenticated user'.   finally click on EDIT button
You will find only two permission are by default assigned 'Read & execute' , 'Read'  but not effective to execute in VFP,  So Check mark 'Allow' the all controls  which were not assigned  (indicated in picture as RED Arrow)  & Click on "Apply" button.

Figure 1.3

4. After 'Apply' you will be back into dv_foxHelp.chm Properties window. Now you can see 'Green Arrow' indication changes made to properties of dv_foxHelp.chm file.


This was all Story for that, we were facing problem to run VFP9 Help with in remaining Visual foxpro by hitting F1 key.

Hope it will help you & make you easier to enjoy!

Cheers!

Zia Mughal

Monday 21 April 2014

VFP connect to Any DataBase Server

Visual Fox pro is having great feature to connect to All Other Database Servers  for  Back-end Data.
There are many features for using Database Server with VFP but a few major reasons for using Other Databases are as follows:-

1.Due to some limitation in VFP DBC/table goes corrupted at some point when accidentally shutdown occurs of PC/OS due to failure of Electricity of some Hardware Problem.

2. In Multi user Environment, Programmer has to manage much more with many precautions when using  VFP native DBC/tables. i.e, Record Locking, File Locking, Exclusive use of tables, etc.

I seen many Question for searching method/procedure How to Connect VFp to Database server  (i.e. SQLserver,Oracle,MYSQL, Postgress,Maria DB etc.).

Here is bellow code which will help you for your own coding & connecting to Any of above mentioned server.

NOTE: Mostly Connect Strings are listed here, you can choose or UN-comment line which you required.

*********************************************
* Author :     witten by Zia Mughal
* CopyRight :  Pcland Software Inc. Pakistan
* http://www.pcland.com.pk
**********************************
public MB_OKBUTTON,MB_STOPSIGNICON, gnconnhandle
LOCAL lcserver,lcusername,lcpassword,lcdatabase , lcok

store 0 to MB_OKBUTTON
store 16 to MB_STOPSIGNICON
STORE .f. TO lcok

lcserver = 'localhost'
lcusername = 'abc'
lcpassword = 'abc12345'
lcdatabase = 'data1'

lcok=CONNECTSERVER(lcserver,lcusername,lcpassword,lcdatabase)
******gnconnhandle= SQLCONNECT("ospos")   &&& 
*** for odbc DNS direct connection use your own odbc name
IF lcok = .t.
MESSAGEBOX('Connect Successfully to Server',0+64,'http://www.Pclandpk.Blogspot.com')
=disconnectserver()
ENDIF
RETURN

**********************************
PROCEDURE CONNECTSERVER 
param mserver,muid,mpass,mdatabase
***********************************
LOCAL tmpresult
*gnConnHandle =  && define it Public from calling routine
tmpresult = SQLSetProp(0, 'DISPLOGIN', 3)

********** Sql Server Connection
***gnConnHandle= SQLStringConnect("Driver=SQL Server;Server=&mserver;
    UID=&muid;PWD=&mpass;Database=&mdatabase")  
**  On Tcp/IP:
*gnConnHandle = SQLStringConnect("Driver=SQL Server;Server=192.168.0.205;
   UID=&logname;PWD=&mypass;Database=global")

************ Dsn Connect string
*STORE SQLSTRINGCONNECT("DSN=FOXSQL;uid=&muid;pwd=&mpass;database=&mdatabase")
   TO gnConnHandle
*STORE SQLSTRINGCONNECT("DSN=LocalServer;UID=&muid;PWD=&mpass;Database=&mdatabase") 
  TO gnConnHandle

**************Oracle string
 **gnConnHandle= SQLStringConnect( "Driver={Microsoft ODBC for Oracle};Server=
 &mserverr;Uid=&muide;Pwd=&mpass;")
 **gnConnHandle= SQLStringConnect("DRIVER=SQL Server Native Client 11.0;
Trusted_Connection=No;DATABASE=&mdatabase;SERVER=&mserver;UID=&muid;PWD=&mpass") 
 ************MYSQL String
** gnConnHandle= SQLStringConnect("DRIVER=MySQL ODBC 3.51 Driver;Server=&mserver;
UID=&muid;PWD=&mpass;Database=&mdatabase;Port=3306;Option=16899;")
** gnConnHandle= SQLStringConnect("DRIVER=MySQL ODBC 5.1 Driver;Server=&mserver;
UID=&muid;PWD=&mpass;Database=&mdatabase;OPTION=11;")

***Postgress String
* gnConnHandle= SQLStringConnect("DRIVER={PostgreSQL odbc driver(unicode)};server=&mserver
;Port=5432;Database=&mdatabase; Uid=&muid;Pwd=&mpass;" )
 gnConnHandle= SQLStringConnect("DRIVER={PostgreSQL odbc driver(ANSI)};server=&mserver;
Port=5432;Database=&mdatabase; Uid=&muid;Pwd=&mpass;" )


***PSQL SERVER 2012 & SQLlocaldb string
*gnConnHandle= SQLStringConnect("Driver={SQL Server Native Client 11.0}; 
Server=&mserver\SQLEXPRESS;Database=&mDataBase;UID=&muid;
PWD=&mpass;Trusted_Connection=yes;")

***Ms Access string
*gnConnHandle=  sqlstringconnect("Driver={Microsoft Access Driver ;(*.mdb)};Dbq=&mDatabase;Uid=&muid;Pwd=&mpass")

***SQLLITE3 ***

**** Specify location in Database parameter called i.e c:\my.db
*gnConnHandle =SQLStringConnect("DRIVER=SQLite3 ODBCDriver; Database=&mDatabase
LongNames=0; Timeout=1000;NoTXN=0; SyncPragma=NORMAL;StepAPI=0;")


IF gnConnHandle < 0
LOCAL ARRAY laError[1]
AERROR(laError)
************ Display output of error
MESSAGEBOX( laError[2],MB_OKBUTTON + MB_STOPSIGNICON,"Error " ;
+ TRANSFORM(laError[5]))
   RETURN .F.
ENDIF
RETURN  .T.
endproc
***---------------------------- end of Connect server

PROCEDURE alive 
parameter handle
if handle < 0
return .f.
endif
return .t.
endproc

PROCEDURE RUNSQL
PARAMETERS pcSQL, Viewname
LOCAL lnRetVal

IF LEN(ALLTRIM(viewname)) = 0
 lnRetVal = SQLEXEC(gnConnHandle, pcSQL)
ELSE
  lnRetVal = SQLEXEC(gnConnHandle, pcSQL, viewname) 
  ****lnResult = SQLExec(gnConnHandle, lcSQL, View_Name)
ENDIF

IF lnRetVal < 0
LOCAL ARRAY laError[1]
AERROR(laError)
MESSAGEBOX( ;
laError[2], ;
MB_OKBUTTON + MB_STOPSIGNICON, ;
"Error " + TRANSFORM(laError[5]))
RETURN .F.
ELSE
RETURN .t.
ENDIF
RETURN 
endproc
********

**********************
procedure disconnectserver
**********************
if gnConnHandle >= 0
= SQLDISCONNECT(gnConnHandle)
close database
return .t.
endif
return .f.
endproc
******************************

Enjoy the life!
My Respects!

Tuesday 8 April 2014

Reset Bulk/specific VFP FORM Dataenvironment to NULL

VFP developers faces problem when  he had to make structure change in his source project regarding Data-environment. Then he had to make a lot  manual efforts to change every form or  any specific form.

Bellow is example code with function fmb_DenvNull which can help to remove Data environment cursors references in one one call.
 
*********************************************
*  Reset Form Dataenvironment to NULL
*  form_dataen.prg
*  Author:    Zia Mughal (2013)
*  Copy right (R) Pcland Software inc. Pakistan
*********************************************

SET SAFETY off
SET CONFIRM OFF
CLOSE DATABASES 

=adir(scxlist,"*.scx")
create table scxname ( fname c(30))
index on fname tag fname
USE
IF ! USED("scxname.dbf")
USE scxname ALIAS scxname again IN 11
ENDIF

SELECT scxname
append from array scxlist
IF ! BOF()
GO top
ENDIF

SCAN
SELECT scxname
if fmb_DenvNull(fname)= .f.
MESSAGEBOX('Error Restting Dataenvironment to NULL in Form: ' +;
scxname.fname,0+16,"Pcland.com.pk")
ENDIF
ENDSCAN
USE

MESSAGEBOX('All files Successfulyy cleared Dataenvironment: ',0+64,;
"Pcland.com.pk")
RETURN


**************************
FUNCTION fmb_DenvNull
PARAMETERS lcfile
***************************
LOCAL llresult, lcstring
STORE .f. TO llresult
lcstring = "Top = 0" + CHR(13)+ "Left = 0" + CHR(13) + "Width = 0"+ CHR(13)+;
"Height = 0" + CHR(13) + "DataSource = .NULL." + CHR(13) +;
"Name = 'Dataenvironment'"

IF !FILE(lcfile)
 RETURN .f.
ENDIF

USE &lcfile ALIAS prs IN 1

SELECT  prs
IF ! BOF()
GO top
ENDIF

LOCATE FOR objname='Dataenvironment'  AND class='dataenvironment'

IF FOUND()
replace [properties] WITH lcstring
replace [reserved2] WITH '1'
replace [reserved4] WITH '1'
DELETE ALL FOR class='cursor'
pack
STORE .t. TO llresult
ENDIF

USE
RETURN llresult
ENDFUNC
***********************

Cheers!