سلام
ببخشید آخر سال همه گرفتارند:
************************************************** ************************************************
* Procedure Make backup on midnight
* Last Update : 03/08/2006
* By : M.R.TAVAKOL
* Parameters:
* TableName : table name that you chack it
* Path : path for filename destention
* Attention*************Attention*************Attent ion
* ***** Warning: if you use timer in other part of program
* it can be slow or siop your codes!
* ***********************
************************************************** ************************************************
LPARAMETERS tcTableName, tcPath
#DEFINE MESSAGEUSERBYANOTHER "ÈÇä˜ ÑÇ ˜Óí ÏíÑ ÈÇÒ ˜ÑÏå ÇÓÊ"
#DEFINE MESSAGEFILENOTFOUND "ÝÇíáí Èå Çíä ÇÓã æÌæÏ äÏÇÑÏ"
_SCREEN.AddObject("tmrBackup","tmrMyTimer")
_SCREEN.tmrBackup.cPathBackup = tcPath
_SCREEN.tmrBackup.cTableName = tcTableName
DEFINE CLASS tmrMyTimer as Timer
Interval = 1000 && On a minute.
cTableName = '' && Table Name that you want to create backup
cToday = ''
cBackUpname = ''
cPathBackup = ''
PROCEDURE INIT &&Initial Properties
LOCAL o
o = THIS
o.cToday = o.ToDay()
o.cBackupName = o.cToDay+".DBF"
ENDPROC
************************************************** ************************************************
* Procedure Make backup on midnight
* Last Update : 03/08/2006
* By : M.R.TAVAKOL
* Parameters:
* None
* Return: Today
*
*
************************************************** ************************************************
FUNCTION ToDay
LOCAL lcPreDateSet, lcPreCenturySet, lcToDay
lcPreDateSet = SET("Date")
lcPreCenturySet = SET("Century")
SET CENTURY ON
SET DATE YMD
lcToDay = STRTRAN(DTOC(DATE()),"/","")
SET CENTURY &lcPreCenturySet
SET DATE &lcPreDateSet
RETURN lcToday
ENDFUNC
************************************************** ************************************************
* THIS Procedure check for midnight and if occure create backup
* Last Update : 03/08/2006
* By : M.R.TAVAKOL
* Parameters:
* none
*
* Return Values:
* none
*
************************************************** ************************************************
PROCEDURE timer
WITH THIS
LOCAL lcToday
lcToDay = THIS.Today()
IF lcToday > THIS.cToday
.Makebackup(.cTableName, .cPathBackup+"\"+.cBackUpname )
.cToday = lcToday
.cBackUpname = .cToday +".dbf"
ENDIF
ENDWITH
ENDPROC
************************************************** ************************************************
* THIS Function Make backup
* Last Update : 03/08/2006
* By : M.R.TAVAKOL
* Parameters:
* TableName : table name that you chack it
* FileName : path and filename destention
* Return Values:
* -1: Table Open By Another
* -2: Table Dose not exist?!
* 0: Successful!
*
************************************************** ************************************************
FUNCTION MakeBackup
LPARAMETERS tcTablename, tcDestFile
LOCAL lnUseByAnother, lnPreSelect, lnSelectUse
lnUseByAnother = UseByAnother(tcTablename)
lnPreSelect = SELECT(0)
DO CASE
CASE INLIST(lnUseByAnother,1,3)
MESSAGEBOX(MESSAGEUSERBYANOTHER,16)
RETURN -1
CASE lnUseByAnother=2
lnSelectUse = USEDBF(tcTablename)
COPY TO (tcDestFile)
IF lnSelectUse = 2
USE
ELSE
SELECT (lnPreSelect)
ENDIF
RETURN 0
MESSAGEBOX("Ok")
CASE lnUseByAnother=4
MESSAGEBOX(MESSAGEFILENOTFOUND,16)
RETURN -2
ENDCASE
ENDFUNC
ENDDEFINE
************************************************** ************************************************
* THIS Function determin Table use by another
* Last Update : 02/16/2004
* By : M.R.TAVAKOL
* Parameters:
* TableName : table name that you chack it
* Return Values:
* 1: File Open By Another share
* 2: File Not Open By Another
* 3: File Open Exclusive
* 4: File Dose not exist!
************************************************** ************************************************
FUNCTION UseByAnother
LPARAMETERS lcTableName &&TableName And Path and Extention Must Be Entered
LOCAL lnFileHandle1
lnFileHandle1=FOPEN(lcTableName,0)
IF lnFileHandle1>0 THEN
=FCLOSE(lnFileHandle1)
lnFileHandle1=FOPEN(lcTableName,2)
IF lnFileHandle1<0
RETURN 1 && File Open By Another Share
ELSE
=FCLOSE(lnFileHandle1)
RETURN 2 && File not Open By Another
ENDIF
ELSE
IF FILE(lcTableName)
RETURN 3 && File Open Exclusive
ELSE
RETURN 4 && File Dose not exist!
ENDIF
ENDIF
ENDFUNC
************************************************** ************************************************
* THIS Function use or select table
* Last Update : 02/16/2004
* By : M.R.TAVAKOL
* Patameters:
* table name that select or use
* Return Values:
* 1: select only
* 2: select new area and use
*
* Remeber: it work on this datasession
*
************************************************** ************************************************
FUNCTION USEDBF
LPARAMETERS tcTableName
IF USED(tcTableName)
SELECT (tcTableName)
RETURN 1
ELSE
SELECT 0
USE (tcTableName)
RETURN 2
ENDIF
ENDFUNC
البته چیزی که هست اینه که با سرعت نوشتم و مشکل حتما داره خودتون روش تست کنید.
روش صدا زدن:
CreateBackup("table.dbf","c:\")