# include "fivewin.ch" // 0x4L |
# include "btnget.ch"
# include "eagle1.ch"
# include "Splitter.ch"
# include "report.ch"
static oWnd, oDlg // objeto ventana principal
STATIC oAppW, oTray, oIcon
//---------------------------------------------------------------------------------------------------
Function Main()
local cTitle, lOk, iLogo, _msn_n
local oCursor, oSalir, lSalir, oConec, oEscon
local cHost, cUser, cPass, cDbNa, cDDes
local oHost, oUser, oPass, oDbNa, oDDes
local oMySQL, oDataBase, oTimba
local oDias, aDias, oHora, cHora, oTray, oMenu, oIcon1, lUno, aFile, cFile
local eConec, lYa, oBoton
IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) ) // evita el doble arranque
RETURN NIL
ENDIF
ServiceProcess(1)
oDias := ARRAY(7)
aDias := ARRAY(7)
aFile := {}
AFill(aDias, .f.)
lSalir := .t.
lYa := .t.
cHora := SPACE(5)
cHost := SPACE(40)
cPass := "contraseña" // contraseña de la base de datos
cDbNa := SPACE(40)
cDDes := SPACE(75)
cFile := "SVBACKUP.CFG"
If File(cFile)
aFile := LeerTxt(cFile)
cHost := aFile[1]
cUser := aFile[2]
cDbNa := aFile[3]
aDias[1] := IF(aFile[4] = "1", .t.,.f.)
aDias[2] := IF(aFile[5] = "1", .t.,.f.)
aDias[3] := IF(aFile[6] = "1", .t.,.f.)
aDias[4] := IF(aFile[7] = "1", .t.,.f.)
aDias[5] := IF(aFile[8] = "1", .t.,.f.)
aDias[6] := IF(aFile[9] = "1", .t.,.f.)
aDias[7] := IF(aFile[10] = "1", .t.,.f.)
cHora := aFile[11]
EndIF
eConec := {||CConectar(oMySQL, oDataBase, cHost, cUser, cPass, cDbNa, aDias, cHora, oTimBa, oBoton) }
DEFINE ICON oIcon RESOURCE "ABACKUP"
DEFINE ICON oIcon1 RESOURCE "ABACKUP2"
DEFINE CURSOR oCursor HAND
DEFINE DIALOG oAppW RESOURCE "ABACKUP2" ICON oIcon TITLE "SVBACKUP V1-0"
REDEFINE BTNGET oHost ;
VAR cHost ;
ID 110 OF oAppW
REDEFINE BTNGET oUser ;
VAR cUser ;
ID 111 OF oAppW
REDEFINE BTNGET oDbNa ;
VAR cDbNa ;
ID 113 OF oAppW
REDEFINE BTNGET oDDes ;
VAR cDDes ;
ID 114 OF oAppW
REDEFINE CHECKBOX oDias[1] ;
VAR aDias[1] ;
ID 101 OF oAppW
REDEFINE CHECKBOX oDias[2] ;
VAR aDias[2] ;
ID 102 OF oAppW
REDEFINE CHECKBOX oDias[3] ;
VAR aDias[3] ;
ID 103 OF oAppW
REDEFINE CHECKBOX oDias[4] ;
VAR aDias[4] ;
ID 104 OF oAppW
REDEFINE CHECKBOX oDias[5] ;
VAR aDias[5] ;
ID 105 OF oAppW
REDEFINE CHECKBOX oDias[6] ;
VAR aDias[6] ;
ID 106 OF oAppW
REDEFINE CHECKBOX oDias[7] ;
VAR aDias[7] ;
ID 107 OF oAppW
REDEFINE BTNGET oHora ;
VAR cHora ;
VALID OkHora(cHora) ;
PICTURE "99:99" ;
ID 115 OF oAppW
REDEFINE BUTTON oEscon ;
ACTION oAppW:Hide() ;
PROMPT "&Esconder" ;
ID 121 OF oAppW
REDEFINE BUTTON oConec ;
ACTION CConectar(oMySQL, oDataBase, cHost, cUser, cPass, cDbNa, aDias, cHora, oTimBa, oBoton) ;
PROMPT "&Conectar" ;
ID 122 OF oAppW
REDEFINE BUTTON oSalir ;
ACTION (If(MsgNoYes("Cerrar la Aplicación?","Confirme"),(lSalir := .t., oAppW:End()), ) ) ;
PROMPT "&Salir" ;
ID 123 OF oAppW
REDEFINE BITMAP oBoton ;
RESOURCE "BVERDE" TRANSPARENT ;
ID 120 OF oAppW
aEval(oAppW:aControls,{|oC|iif(oC:ClassName()="TBUTTON",oC:oCursor:=oCursor,)})
ACTIVATE DIALOG oAppW CENTER ; //
ON INIT (oTray := TTrayIcon():New(oAppW,oIcon,"SVBACKUP",{||oAppW:Show()},{|nRow,nCol|MenuTray(nRow,nCol,oTray)}), ;
oTimBa:=ATimer(oAppW, oTimBa, eConec) ) ;
ON PAINT (If(lYa, (oAppW:Hide(), lYa:=.f.), Nil) ) ;
ON RIGHT CLICK oTray:SetIcon( oIcon1, "Another" ) ;
VALID (lSalir) // oTray:End() ;
SysRefresh()
Return(Nil)
//------------------------------------------------------------------------------------------------------
Function ATimer(oAppW, oTimBa, eConec)
DEFINE TIMER oTimBA OF oAppW INTERVAL 60000 ACTION EVAL (eConec)
ACTIVATE TIMER oTimBa
oAppW:Hide()
oAppW:Minimize()
Return(oTimBa)
//---------------------------------------------------------------------------------------------------------
FUNCTION MenuTray( nRow, nCol, oTray )
LOCAL oMenu
MENU oMenu POPUP
MENUITEM "Mostrar" ACTION oAppW:Show(), oAppW:SetFocus()
// MENUITEM "Esconder" ACTION oAppW:Hide()
ENDMENU
ACTIVATE POPUP oMenu AT nRow, nCol OF oTray:oWnd
RETURN NIL
//----------------------------------------------------------------------------------------------------
Function CConectar(oMySQL, oDataBase, cHost, cUser, cPass, cDbNa, aDias, cHora, oTimBa, oBoton)
local oWndBack, oBack, cBack, fBack, lOk, cTime, cSufijo, cRuta, aTablas, nLen, nCont, cRZip, cLinea, aFiles
local oApp, oMeter1, oMeter2, nPer1, nPer2, lNo
local oAcepta, oCursor, lProcede, oSay, cFilZip, oFont1
local cDiskExe, oHand, cFile, qDia, qHora, qMinu, nSec1, nSec2
oBoton:SETBMP("BVERDE")
If EMPTY(cHost) .OR. EMPTY(cUser) .OR. EMPTY(cDbNa)
Return(.f.)
EndIF
cFile := "SVBACKUP.CFG"
cLinea := cHost + CHR(13) + CHR(10) + ;
cUser + CHR(13) + CHR(10) + ;
cDbNa + CHR(13) + CHR(10) + ;
If(aDias[1],"1","0") + CHR(13) + CHR(10) + ;
If(aDias[2],"1","0") + CHR(13) + CHR(10) + ;
If(aDias[3],"1","0") + CHR(13) + CHR(10) + ;
If(aDias[4],"1","0") + CHR(13) + CHR(10) + ;
If(aDias[5],"1","0") + CHR(13) + CHR(10) + ;
If(aDias[6],"1","0") + CHR(13) + CHR(10) + ;
If(aDias[7],"1","0") + CHR(13) + CHR(10) + ;
cHora + CHR(13) + CHR(10)
oHand := FCreate( cFile )
FWRITE(oHand, cLinea)
FCLose(oHand)
lOK := .f.
qDia := DOW(DATE()) // se en ordinal de la semana de la fecha del sistema.
qHora := TIME() // se toma la hora del sistema
If aDias[qDia]
lOk := .t.
EndIf
If !lOK
Return(lOk)
EndIf
nSec1 := ( VAL(SUBSTR(qHora,1,2)) * 3600 ) + (VAL(SUBSTR(qHora,4,2)) * 60 )
nSec2 := ( VAL(SUBSTR(cHora,1,2)) * 3600 ) + (VAL(SUBSTR(cHora,4,2)) * 60 )
If nSec1 < nSec2
Return(.f.)
EndIf
cDiskExe := CURDRIVE() + ":"
cRuta := cRZip := "BACKUP_SVITE"
lMKDir("\" + cRuta) // almacena archivos de la tabla
cRuta := cDiskExe + "/" + cRuta + "/"
cRZip := cDiskExe + "\" + cRZip + "\"
cFilZip := cDbNa + cRZip
If FILE(ALLTRIM(cRZip) + ALLTRIM(cDbNa) + ".ZIP")
Return(.f.)
EndIF
cHost := ALLTRIM(cHost)
cUser := ALLTRIM(cUser)
cDbNa := ALLTRIm(cDbNa)
WHILE .t.
oMySql := TMSConnect():New()
If oMySql:Connect( cHost, cUser, cPass )
EXIT
Else
Return(.f.)
EndIF
ENDDO
Sonido("reminder.wav")
If !oMySQL:ExistDb( cDbNa ) // si no existe la base de datos,,,
Return( .f. )
EndIf
//--------creamos el objeto contenedor de la base de datos
USE DATABASE oDataBase NAME cDbNa OF oMySQL
If !oDataBase:Used() //
Return( .f. )
Endif
lOK := .f.
lNo := .f.
nPer1 := nPer2 := 0
aTablas := oDataBase:ListTables()
nLen := LEN(aTablas)
IF nLen = 0
Return(lOk)
EndIF
cFilZip := ""
oAppW:Show()
oTimBa:DeActivate()
oBoton:SETBMP("BROJO")
oBoton:Refresh()
lOK := ZipTablas(oMySQL, oDataBase, cRuta, cRZip, aTablas, @cFilZip, cPass, cDbNa)
oTimBa:Activate()
oBoton:SETBMP("BVERDE")
oBoton:Refresh()
oAppW:Hide()
Return(lOk)
//---------------------------------------------------------------------------------------------------
Function ZipTablas(oMySQL, oDataBase, cRuta, cRZip, aTablas, cFilZip, cPass, cDbNa )
local nCont, nLen, aFiles, lOK, cTime, cSufijo, fBack, cBack, nRow
CURSORWAIT()
aFiles := {}
lOK := .f.
nRow := 1
cPass := ALLTRIM(cPass)
cTime := TIME()
cSufijo := DTOS(Date()) //+ SUBSTR(cTime,1,2) + SUBSTR(cTime,4,2) + SUBSTR(cTime,7,2)
nLen := LEN(aTablas)
cFilZip := cRZip + cDbNa + cSufijo + ".ZIP"
If FILE(cFilZip)
Return(.f.)
EndIf
FOR nCont := 1 TO nLen
Tone(1000,1)
fBack := cSufijo + ALLTRIM(aTablas[nCont])
cBack := "SELECT * INTO OUTFILE '" + cRuta + fBack + "' FROM " + ALLTRIM(aTablas[nCont])
lOk := oDatabase:ExecSQL( cBack )
If !lOK
EXIT
ENDIF
AaDd(aFiles, cRZip + AllTrim( fBack ) )
Tone(500,1)
NEXT nCont
If !lOk
Return(lOk)
EndIF
lOk := HB_ZipFile( cFilZip, aFiles, 9,,.T., cPass, .F., .F. )
FOR nCont := 1 TO nLen
FERASE(aFiles[nCont])
NEXT nCont
Sonido("reminder.wav")
Return(lOk)
//---------------------------------------------------------------------------------------------------
Function Sonido(cWav)
local cWav1
cWav1 := cWav
cWav := GetWinDir()+ "\Media\" + cWav + ".WAV"
If File(cWav)
SndPlaySound(cWav)
Else
cWav1 := "SND\" + cWav1
If File(cWav1)
SndPlaySound(cWav1)
Else
Tone(1000,1)
EndIf
EndIf
Return(Nil)
//---------------------------------------------------------------------------------------------------
Function LeerTxt(cFile,nModo)
local oFile,cLinea := "", aLinea := {}
DEFAULT cFile := ""
DEFAULT nModo := 0
If Empty(cFile) .OR. !File(cFile)
Return({})
EndIf
oFile := TTxtFile():New( cFile )
Do while !oFile:lEof()
AaDd(aLinea,oFile:cLine)
oFile:Skip()
EndDo
oFile:End()
Return(aLinea)
//--------------------------------------------------------------------------------------------------
Function OkHora(cHora)
local lOK
lOk := .f.
If VAL(SUBSTR(cHora,1,2)) >= 0 .AND. VAL(SUBSTR(cHora,1,2)) <=23
lOk := .t.
Endif
If VAL(SUBSTR(cHora,3,2)) >= 0 .AND. VAL(SUBSTR(cHora,3,2)) <=59
lOk := .t.
Else
lOk := .f.
EndIf
Return(lOk)
//---------------------------------------------------------------------------------------------------
Function ServiceProcess( mode )
//------------------------------
Local nProcessId := 0
Default mode := 0
nProcessId := GCP( )
If Abs( nProcessId ) > 0
RSProcess( nProcessId, mode )
Endif
RETURN Nil
//----------------------------------------------------
DLL32 FUNCTION RSProcess(npID AS LONG ,;
nMode AS LONG ) AS LONG ;
FROM "RegisterServiceProcess" LIB "kernel32.DLL"
//----------------------------------------------------
DLL32 FUNCTION GCP() AS LONG;
FROM "GetCurrentProcessId" LIB "kernel32.dll"