#include "fivewin.ch"
#include 'Ads.ch'
#include 'Splitter.ch'
#define ADS_ABORT .T.
#define ADS_CONTINUE .F.
external AdsKeyCount, AdsGetRelKeyPos, AdsSetRelKeyPos
// REQUEST DBFCDX, DBFFPT
static oWnd, oTimer, cRDD, cFOPath, objSMS, cSendPort, lRun
*----------------------*
FUNCTION main()
local oIni, cPort, cBaudRate, cParity, cDataBits, cStopBits, nRDDType, cThaiFont, cCharacter
local oFont, oFnt2, objLicense
local cIMEI, cModel, cManu, cNet, cNum, cThai
SET EPOCH TO 1940
SET DATE FORMAT TO 'DD/MM/YY'
SET DATE BRITISH
SET(_SET_DELETED,.T.)
SetHandleCount(200)
if !file(".\SMS.INI")
PortSetup()
end
INI oIni FILE ".\SMS.INI"
GET cRDD SECTION "RDD" ENTRY "RDDTYPE" OF oIni DEFAULT "LOCAL"
GET cFoPath SECTION "RDD" ENTRY "RDDPATH" OF oIni DEFAULT ".\"
GET cPort SECTION "SMS" ENTRY "PORT" OF oIni DEFAULT "COM5"
GET cBaudRate SECTION "SMS" ENTRY "BAUDRATE" OF oIni DEFAULT "19200 "
GET cParity SECTION "SMS" ENTRY "PARITY" OF oIni DEFAULT "N"
GET cDataBits SECTION "SMS" ENTRY "DATABITS" OF oIni DEFAULT "8"
GET cStopBits SECTION "SMS" ENTRY "STOPBITSP" OF oIni DEFAULT "1"
GET cCharacter SECTION "SMS" ENTRY "CHARACTER" OF oIni DEFAULT "0"
ENDINI
do case
case cRDD = 'LOCAL'
nRDDType := 1
case cRDD = 'REMOTE'
nRDDType := 2
case cRDD = 'INTERNET'
nRDDType := 4
otherwise
nRDDType := 7
end
if right(cFoPath,1) <> '' .and. !empty(cFoPath)
cFoPath := cFoPath+''
end
REQUEST ADS
RddRegister( "ADS", 1 )
Rddsetdefault( "ADS" )
AdsSetDeleted(.T.)
AdsSetServerType( nRDDType ) // 1,2,4,7
AdsSetFileType( ADS_CDX ) // 2
AdsRightsCheck(.F.)
REQUEST ADSKeyCount, ADSKeyNo, OrdKeyCount, OrdKeyNo, ADSKEYCOUNT, ADSGETRELKEYPOS, ADSSETRELKEYPOS
SET OPTIMIZE ON
objSMS := CreateObject("mCore.SMS")
objSMS:Port := rtrim(cPort)
objSMS:BaudRate := val(cBaudRate)
objSMS:Parity := rtrim(cParity)
objSMS:DataBits := val(cDataBits)
objSMS:StopBits := rtrim(cStopBits)
objSMS:Character := val(cCharacter)
objSMS:LongMessage:= 3 // Send as Single Truncated Message when exceeded 160 chars in both types *objSMS:LongMessage := 1 // Send as multiple Messages But show as Individual un-formated messages with out Page Nos. to Receipient (160 + Remainig of Each Message)
cIMEI := objSMS:IMEI
cManu := objSMS:Manufacturer
cModel:= objSMS:Model
cNet := ltrim(str(objSMS:SignalStrength,3))+'%'
cThai := iif(cCharacter='0','No ','Yes')
lRun := .F.
DEFINE FONT oFont NAME "Tahoma" SIZE 0, -12
DEFINE WINDOW oWnd TITLE 'SMS program' PIXEL ;
MENU BuildMenu()
oWnd:oFont := oFont
SET MESSAGE OF oWnd ;
TO '[IMEI : '+rtrim(cIMEI)+']'+;
' - [Manufacturer : '+rtrim(cManu)+']'+;
' - [Model : '+rtrim(cModel)+']'+;
' - [Thai Font : '+rtrim(cThai)+']'+;
' - [Signal : '+cNet+']' ;
NOINSET DATE TIME KEYBOARD 2007
/*
@ 10, 10 SAY 'IMEI' OF oWnd SIZE 80,18 TRANSPARENT PIXEL COLOR CLR_WHITE
@ 35, 10 SAY 'Manufacturer' OF oWnd SIZE 80,18 TRANSPARENT PIXEL COLOR CLR_WHITE
@ 60, 10 SAY 'Model' OF oWnd SIZE 80,18 TRANSPARENT PIXEL COLOR CLR_WHITE
@ 85, 10 SAY 'Thai Font' OF oWnd SIZE 80,18 TRANSPARENT PIXEL COLOR CLR_WHITE
@ 110, 10 SAY 'Signal' OF oWnd SIZE 80,18 TRANSPARENT PIXEL COLOR CLR_WHITE
@ 10,100 SAY cIMEI OF oWnd SIZE 150,18 TRANSPARENT PIXEL COLOR CLR_YELLOW, CLR_WHITE
@ 35,100 SAY cManu OF oWnd SIZE 150,18 TRANSPARENT PIXEL COLOR CLR_YELLOW, CLR_WHITE
@ 60,100 SAY cModel OF oWnd SIZE 150,18 TRANSPARENT PIXEL COLOR CLR_YELLOW, CLR_WHITE
@ 85,100 SAY cThai OF oWnd SIZE 150,18 TRANSPARENT PIXEL COLOR CLR_YELLOW, CLR_WHITE
@ 110,100 SAY cNet OF oWnd SIZE 150,18 TRANSPARENT PIXEL COLOR CLR_YELLOW, CLR_WHITE
*/
ACTIVATE WINDOW oWnd ;
ON INIT (Timers()) ;
ON PAINT GradientFill( hDC, 0, 0, oWnd:nHeight, oWnd:nWidth, { { 0.50, 16054371, 8388608 } } ) ;
VALID (oTimer:DeActivate(), .T. )
oFont:End()
objSMS:DisConnect()
objSMS := NIL
return nil
*-------------------*
Function Timers()
if oTimer = nil .and. file( cFoPath+'EZSMSRD.DBF' )
DEFINE TIMER oTimer OF oWnd INTERVAL 3000 ACTION (FindNew())
oTimer:Activate()
end
return nil
*---------------*
Function FindNew
local FileName, cAlias, cFileName, cFile
local nCount
if !lRun
lRun := !lRun
if SELECT('SNT') = 0
FileName := 'EZSMSRD'
cAlias := 'SNT'
cFileName := cFoPath+alltrim(FileName+'.DBF')
cFile := cFoPath+alltrim(FileName)
USE (cFile) INDEX (cFile) ALIAS (cAlias) SHARE NEW
SNT->(DbSetOrder(1))
SNT->(OrdScope( 0 , 'A'))
SNT->(OrdScope( 1 , 'Y'))
end
SNT->(DbGoTop())
if SELECT('SND') = 0
FileName := 'EZSMSRD'
cAlias := 'SND'
cFileName := cFoPath+alltrim(FileName+'.DBF')
cFile := cFoPath+alltrim(FileName)
USE (cFile) INDEX (cFile) ALIAS (cAlias) SHARE NEW
SNT->(DbSetOrder(1))
SND->(OrdScope( 0 , ' '))
SND->(OrdScope( 1 , ' '))
// SND->(DbSetFilter( {|| SND->SRD_SEND=' ' }, "SND->SRD_SEND=' '" ))
end
SND->(DbGoTop())
if SND->(DbSeek(' '))
do while empty(SND->SRD_SEND) .and. !SND->(eof())
if !empty(SND->SRD_MOBL) .and. ;
!empty(SND->SRD_TEXT)
if SendSms(rtrim(SND->SRD_MOBL), AnsiToOem(rtrim(SND->SRD_TEXT)) )
if SND->(Rlock())
SND->SRD_SEND := 'Y'
end
SND->(DbCommit())
SND->(DbUnlock())
else
if SND->(Rlock())
SND->SRD_SEND := 'N'
end
SND->(DbCommit())
SND->(DbUnlock())
end
end
SND->(DbSkip())
SND->(DbGoTop())
end
end
lRun := !lRun
end
return nil
*-----------------*
Function BuildMenu
local oMenu
MENU oMenu 2007
MENUITEM 'SMS Records' ACTION SMSBrow()
MENUITEM 'Send SMS' ACTION SMSText()
MENUITEM 'Set Up' ACTION PortSetup()
MENUITEM 'Exit' ACTION oWnd:End()
ENDMENU
return oMenu
*-----------------*
Procedure SMSText
local oDlg, oGet[2], oFont, oFnt2
local cText := space(160)
local cPhone:= space(15)
local lAlert:= .F.
DEFINE FONT oFnt2 NAME "AngsanaUPC" SIZE 0, -14
DEFINE FONT oFont NAME "Tahoma" SIZE 0, -12
DEFINE DIALOG oDlg FROM 0, 0 TO 310, 300 TITLE 'SMS Text' PIXEL FONT oFont
@ 5, 5 SAY 'Mobile# ' SIZE 30,11 PIXEL OF oDlg
@ 20, 5 SAY 'Message ' SIZE 30,11 PIXEL OF oDlg
@ 125, 5 SAY 'Alert' SIZE 30, 11 PIXEL OF oDlg
@ 3, 35 GET oGet[1] VAR cPhone SIZE 100, 11 PIXEL OF oDlg
@ 18, 35 GET oGet[2] VAR cText SIZE 100,100 PIXEL OF oDlg TEXT FONT oFnt2
@ 122, 35 CHECKBOX lAlert PROMPT '' SIZE 12,11 PIXEL OF oDlg
@ 135, 35 BUTTON 'Send SMS' SIZE 40, 15 OF oDlg PIXEL ACTION (SendSms(cPhone,cText,lAlert), oDlg:end())
@ 135, 90 BUTTON 'Cancel' SIZE 40, 15 OF oDlg PIXEL ACTION (oDlg:End())
ACTIVATE DIALOG oDlg CENTER
oFont:End()
oFnt2:End()
return
*---------------------------------------------*
Function SendSms( cPhone, cText, lAlert )
LOCAL objLicense, objInbox, n
local cStart := time()
local cEnd, lNotSent
Default lAlert := .F.
if subs(cPhone,1,1) ='0'
cPhone := "+66"+right(rtrim(cPhone),len(rtrim(cPhone))-1)
elseif subs(cPhone,1,1) <> '+'
cPhone := "+"+right(rtrim(cPhone),len(rtrim(cPhone))-1)
end
objSMS:SendSMS(rtrim(cPhone), rtrim(cText), lAlert)
IF (lNotSent := objSMS:IsError(.F.))
MsgInfo("Error " + CStr(objSMS:ErrorCode) + ;
": " + objSMS:ErrorDescription)
ENDIF
/*
cEnd := time()
Msginfo('Time : '+cStart+' - '+cEnd )
*/
/*
* This code to Receive the SMS
objInbox := objSMS:Inbox()
objInbox:Concatenate := .T.
objSMS:MessageMemory := "SM"
objInbox:Refresh()
If objInbox:HasMessages
MsgInfo("Total "+ LTRIM(STR(objInbox:Count))+ " messages are there in inbox!")
For n = 1 TO objInbox:Count
?ObjInbox:Message(n):TimeStampRFC + CHR(13)+CHR(10) + "From: " + ;
ObjInbox:Message(n):Phone + CHR(13)+CHR(10) + ObjInbox:Message(n):Text
Next
EndIf
*/
RETURN !lNotSent
*------------------*
Procedure PortSetup
local oDlg, oGet, oCbx, oSay, oBtn, oFont, oSplit, oIni
local cRddType, cIpAdd, cPort, cBaudRate, cParity, cDataBits, cStopBits, cThaiFont, cCharacter, nLoop, lSave, n
local aRddType := {'LOCAL ', 'REMOTE ', 'INTERNET'}
local aPort, aBaudRate, aParity, aDataBits, aStopBits, aThaiFont
aPort := {}
for n := 1 to 32
aadd( aPort, "COM"+ltrim(str(n,2)) )
next
aBaudRate := {'1200 ','2400 ','4800 ','9600 ','19200 ','38400 ','57600 ','115200','230400','460800'}
aParity := {'N','E'}
aDataBits := {'7','8'}
aStopBits := {'1','2'}
aThaiFont := {'Yes','No '}
cRddType := 'LOCAL '
cIpAdd := '.'+space(48)
lSave := .F.
INI oIni FILE ".\SMS.INI"
GET cRddType SECTION "RDD" ENTRY "RDDTYPE" OF oIni DEFAULT cRddType
GET cIpAdd SECTION "RDD" ENTRY "RDDPATH" OF oIni DEFAULT cIpAdd
GET cPort SECTION "SMS" ENTRY "PORT" OF oIni DEFAULT "COM3"
GET cBaudRate SECTION "SMS" ENTRY "BAUDRATE" OF oIni DEFAULT "19200 "
GET cParity SECTION "SMS" ENTRY "PARITY" OF oIni DEFAULT "N"
GET cDataBits SECTION "SMS" ENTRY "DATABITS" OF oIni DEFAULT "8"
GET cStopBits SECTION "SMS" ENTRY "STOPBITS" OF oIni DEFAULT "1"
GET cCharacter SECTION "SMS" ENTRY "CHARACTER" OF oIni DEFAULT "0"
cThaiFont := iif(cCharacter='2','Yes','No ')
DEFINE FONT oFont NAME "Tahoma" SIZE 0, -12
DEFINE DIALOG oDlg FROM 0, 0 TO 300, 400 TITLE 'Server Setup' PIXEL FONT oFont
oDlg:lHelpIcon := .F.
@ 10, 10 SAY oSay PROMPT 'Server Type' SIZE 50,12 OF oDlg PIXEL
@ 24, 10 SAY oSay PROMPT 'Address' SIZE 50,12 OF oDlg PIXEL
@ 38, 10 SAY oSay PROMPT 'Port' SIZE 50,12 OF oDlg PIXEL
@ 52, 10 SAY oSay PROMPT 'BaudRate' SIZE 50,12 OF oDlg PIXEL
@ 66, 10 SAY oSay PROMPT 'Parity' SIZE 50,12 OF oDlg PIXEL
@ 80, 10 SAY oSay PROMPT 'DataBits' SIZE 50,12 OF oDlg PIXEL
@ 94, 10 SAY oSay PROMPT 'StopBits' SIZE 50,12 OF oDlg PIXEL
@ 108, 10 SAY oSay PROMPT 'Thai Font' SIZE 50,12 OF oDlg PIXEL
@ 7, 50 COMBOBOX oCbx VAR cRddType ITEMS aRddType OF oDlg PIXEL
@ 21, 50 GET oGet VAR cIpAdd OF oDlg PIXEL SIZE 130,12 ;
VALID !empty(cIpAdd) ;
ACTION (cIpAdd := cGetDir('Select Folder'), oGet:Refresh(), oBtn:SetFocus())
@ 35, 50 COMBOBOX oCbx VAR cPort ITEMS aPort OF oDlg PIXEL // SIZE 130,12
@ 49, 50 COMBOBOX oCbx VAR cBaudRate ITEMS aBaudRate OF oDlg PIXEL // SIZE 130,12
@ 63, 50 COMBOBOX oCbx VAR cParity ITEMS aParity OF oDlg PIXEL // SIZE 130,12
@ 77, 50 COMBOBOX oCbx VAR cDataBits ITEMS aDataBits OF oDlg PIXEL // SIZE 130,12
@ 91, 50 COMBOBOX oCbx VAR cStopBits ITEMS aStopBits OF oDlg PIXEL // SIZE 130,12
@ 105, 50 COMBOBOX oCbx VAR cThaiFont ITEMS aThaiFont OF oDlg PIXEL // SIZE 130,12
@ 130, 80 BUTTON oBtn PROMPT 'OK' OF oDlg SIZE 50,15 PIXEL ;
WHEN (!empty(cRddType).and.;
!empty(cIpAdd) .and.;
!empty(cPort) .and.;
!empty(cParity) .and.;
!empty(cDataBits) .and.;
!empty(cStopBits) .and.;
!empty(cBaudRate)) ;
ACTION (lSave := .T., oDlg:End())
@ 125, 0 SPLITTER oSplit ;
HORIZONTAL ;
PREVIOUS CONTROLS oBtn ;
HINDS CONTROLS oCbx ; // LEFT MARGIN 100 ; RIGHT MARGIN 140 ;
SIZE 380, 1 PIXEL ;
OF oDlg ;
3DLOOK
ACTIVATE DIALOG oDlg CENTERED
oFont:End()
cCharacter := iif(cThaiFont='Yes','2','0')
if lSave
SET SECTION "RDD" ENTRY "RDDTYPE" TO rtrim(cRddType) OF oIni
SET SECTION "RDD" ENTRY "RDDPATH" TO rtrim(cIpAdd) OF oIni
SET SECTION "SMS" ENTRY "PORT" TO rtrim(cPort) OF oIni
SET SECTION "SMS" ENTRY "BAUDRATE" TO rtrim(cBaudRate) OF oIni
SET SECTION "SMS" ENTRY "PARITY" TO cParity OF oIni
SET SECTION "SMS" ENTRY "DATABITS" TO cDataBits OF oIni
SET SECTION "SMS" ENTRY "STOPBITS" TO cStopBits OF oIni
SET SECTION "SMS" ENTRY "CHARACTER" TO cCharacter OF oIni
end
ENDINI
return
*----------------*
Procedure SMSBrow
MsgInfo('Add Browse for SMS record')
return