
Set FORCOM=COMPANY

IF %CD%==E:\_Cloud Goto Error
IF %FORCOM%==COMPANY Goto Error

Rem Create Short Cut Form Bat File
Rem D:\BdPos\Util_Pok 2 0 0

Rem Switch Folder
D:
Cd\BdPos

Rem Data For Work 
Set DATA_FOLDER=D:\BdPos\
REM Set DATA_FOLDER=M:\

Rem Programn For Work 
Set PROG_FOLDER=D:\BdPos\

Rem =========
Set HARD_FOLDER=E:\_Datanet\
Set CLOUD_DRIVE=E:\_Cloud\%FORCOM%\
Set FLASH_DRIVE=E:\


for /f "tokens=1,2,3,4 delims=/ " %%a in ("%date%") do set wday=%%a&set month=%%b&set day=%%c&set year=%%d
echo.Weekday: %wday%
echo.Month  : %month%
echo.Day    : %day%
echo.Year   : %year%

Rem Bug Wday Not Active
Rem Set wday=Week


UtilPok 2 %CLOUD_DRIVE%
UtilPok 2 %CLOUD_DRIVE%Backup
UtilPok 2 %CLOUD_DRIVE%Screen
UtilPok 2 %CLOUD_DRIVE%Screen\History
UtilPok 2 %CLOUD_DRIVE%Txt
UtilPok 2 %CLOUD_DRIVE%Pdf
UtilPok 2 %CLOUD_DRIVE%UyodTeam
UtilPok 2 %HARD_FOLDER%
UtilPok 2 %HARD_FOLDER%System
UtilPok 2 %HARD_FOLDER%System\%wday%
UtilPok 2 %HARD_FOLDER%%day%
UtilPok 2 %CLOUD_DRIVE%Backup\System
UtilPok 2 %CLOUD_DRIVE%Backup\System\Original
UtilPok 2 %CLOUD_DRIVE%Backup\_Update
UtilPok 2 %CLOUD_DRIVE%Backup\Share
UtilPok 2 %CLOUD_DRIVE%Backup\%wday%


If %day%==01 Del %HARD_FOLDER%*.Zp
If %day%==01 Del %HARD_FOLDER%*.Zpp
If %day%==01 Del %HARD_FOLDER%System\*.Zp

@Pkzip -u %HARD_FOLDER%Data.Zp     %DATA_FOLDER%Data\*.Dbf
@Pkzip -u %HARD_FOLDER%Data.Zp     %DATA_FOLDER%Data\*.Cdx
@Pkzip -u %HARD_FOLDER%Transac.Zp  %DATA_FOLDER%Transac\*.Dbf
@Pkzip -u %HARD_FOLDER%Transac.Zp  %DATA_FOLDER%Transac\*.Cdx
@Pkzip -u %HARD_FOLDER%BakData.Zp     %DATA_FOLDER%BakData\*.Dbf
@Pkzip -u %HARD_FOLDER%Error.Zp    %DATA_FOLDER%_Error\*.Err
@Pkzip -u %HARD_FOLDER%Data001.Zp  %DATA_FOLDER%Data\001\*.Dbf
@Pkzip -u %HARD_FOLDER%Room.Zp     %DATA_FOLDER%Transac\rooms\*.Dbf
@Pkzip -u %HARD_FOLDER%BackFood.Zp %DATA_FOLDER%backup\FOOD\*.dbf
@Pkzip -u %HARD_FOLDER%Test.Zp     %DATA_FOLDER%Test\*.Dbf
@Pkzip -u %HARD_FOLDER%DataLan.Zp  Backup\Datalan\*.dbf

@Pkzip -u %HARD_FOLDER%Source.Zp  %PROG_FOLDER%Selemenu.*
@Pkzip -u %HARD_FOLDER%Source.Zp  %PROG_FOLDER%Seleprin.*
@Pkzip -u %HARD_FOLDER%Source.Zp  %PROG_FOLDER%Sele_prn.*
@Pkzip -u %HARD_FOLDER%Source.Zp  %PROG_FOLDER%.prg
@Pkzip -u %HARD_FOLDER%Source.Zp  %PROG_FOLDER%.sc*


@Copy %HARD_FOLDER%*.* %HARD_FOLDER%%day%\.

@Pkzip -u %HARD_FOLDER%%FORCOM%.Zpp     %DATA_FOLDER%Data\*.Dbf
@Pkzip -u %HARD_FOLDER%%FORCOM%.Zpp     %DATA_FOLDER%Data\*.Cdx
@Pkzip -u %HARD_FOLDER%%FORCOM%.Zpp     %DATA_FOLDER%Transac\*.Dbf
@Pkzip -u %HARD_FOLDER%%FORCOM%.Zpp     %DATA_FOLDER%Transac\*.Cdx


@Pkzip -u %HARD_FOLDER%System\Master.Zp   %PROG_FOLDER%Master.Exe
@Pkzip -u %HARD_FOLDER%System\Poswin.Zp   %PROG_FOLDER%Poswin.exe
@Pkzip -u %HARD_FOLDER%System\Gl.Zp       %PROG_FOLDER%Gl.exe
@Pkzip -u %HARD_FOLDER%System\Al.Zp       %PROG_FOLDER%Al.exe
@Pkzip -u %HARD_FOLDER%System\Cl.Zp       %PROG_FOLDER%Cl.exe
@Pkzip -u %HARD_FOLDER%System\Bat.Zp      %PROG_FOLDER%*.bat
@Pkzip -u %HARD_FOLDER%System\txt.Zp      %PROG_FOLDER%*.txt
@Pkzip -u %HARD_FOLDER%System\prg.Zp      %PROG_FOLDER%*.prg
@Pkzip -u %HARD_FOLDER%System\prg.Zp      %PROG_FOLDER%*.fxp
@Pkzip -u %HARD_FOLDER%System\dbf.Zp      %PROG_FOLDER%*.dbf
@Pkzip -u %HARD_FOLDER%System\dbf.Zp      %PROG_FOLDER%*.cdx

@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.bat
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.dbf
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.cdx
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.Sc?
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.Sp?
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.prg
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.fxp
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.mn?
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.mp?
@Pkzip -u %HARD_FOLDER%System\Report.Zp   %PROG_FOLDER%*.fr?
@Pkzip -u %HARD_FOLDER%System\Report.Zp   %PROG_FOLDER%*.Bmp
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.txt

@Pkzip -u %HARD_FOLDER%System\Setup.Zp    %PROG_FOLDER%Setup\BdPos\*.*
@Pkzip -u %HARD_FOLDER%System\Dbfrun.Zp   %PROG_FOLDER%Dbfrun\*.Dbf
@Pkzip -u %HARD_FOLDER%System\Dbfrun.Zp   %PROG_FOLDER%Dbfrun\*.Cdx
@Pkzip -u %HARD_FOLDER%System\DirData.Zp  %PROG_FOLDER%DirData\*.Dbf
@Pkzip -u %HARD_FOLDER%System\DirData.Zp  %PROG_FOLDER%DirData\*.Cdx
@Pkzip -u %HARD_FOLDER%System\BmpHo7.Zp  %PROG_FOLDER%BmpHo7\*.bmp
@Pkzip -u %HARD_FOLDER%System\BmpHo4U.Zp  %PROG_FOLDER%BmpHo4U\*.bmp

@Pkzip -u %HARD_FOLDER%System\ReportM.Zp  %DATA_FOLDER%*.fr?
@Pkzip -u %HARD_FOLDER%System\ReportM.Zp  %DATA_FOLDER%*.Bmp
@Pkzip -u %HARD_FOLDER%System\Data2Sc.Zp  %DATA_FOLDER%Data2Sc\*.Dbf
@Pkzip -u %HARD_FOLDER%System\Data2Sc.Zp  %DATA_FOLDER%Data2Sc\*.Cdx
@Pkzip -u %HARD_FOLDER%System\Sc2Pos.Zp   %DATA_FOLDER%Sc2Pos\*.Dbf
@Pkzip -u %HARD_FOLDER%System\Sc2Pos.Zp   %DATA_FOLDER%Sc2Pos\*.Cdx
@Pkzip -u %HARD_FOLDER%System\DataCdx.Zp  %DATA_FOLDER%Data\*.Cdx
@Pkzip -u %HARD_FOLDER%System\TranCdx.Zp  %DATA_FOLDER%Transac\*.Cdx
Copy %PROG_FOLDER%Backup2c.bat   %CLOUD_DRIVE%Backup\System\.
Copy %PROG_FOLDER%Pipop.bat  %CLOUD_DRIVE%Backup\System\.
Copy %HARD_FOLDER%System\*.Zp %HARD_FOLDER%System\%wday%\.

@Pkzip -u Backup\%wday%\Data.Zp     %DATA_FOLDER%Data\*.*
@Pkzip -u Backup\%wday%\Tran.Zp  	%DATA_FOLDER%Transac\*.*
@Pkzip -u Backup\%wday%\Tran.Zp  	%DATA_FOLDER%Transac\*.*
@Pkzip -u Backup\%wday%\Room.Zp 	%DATA_FOLDER%Transac\Rooms\*.*
@Pkzip -u Backup\%wday%\Test.Zp     %DATA_FOLDER%Test\*.*
@Pkzip -u Backup\%wday%\001.Zp	    %DATA_FOLDER%Data\001\*.*


Rem Backup SourceCode
@Pkzip -u Backup\Bdpos.Zp  %PROG_FOLDER%*.Prg
@Pkzip -u Backup\Bdpos.Zp  %PROG_FOLDER%*.fxp
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Scx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Sct
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Spr
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Spx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mnx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mnt
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mpr
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mpx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Dbf
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Cdx


Rem Backup Report File
@Pkzip -u Backup\BdPos.Zp  %DATA_FOLDER%*.Fr?
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Bmp
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Exe
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Bat

Rem For Environment
@Copy D:\BdPos\repoPOK*.txt %CLOUD_DRIVE%UyodTeam\.
@Copy D:\BdPos\Spec4you.prg %CLOUD_DRIVE%UyodTeam\.
@Dir %CLOUD_DRIVE%Backup\*.*  >%CLOUD_DRIVE%UyodTeam\backup.txt


If Not Exist c:\windows\pkzip.exe     Copy \BdPos\Pk*.Exe  c:\windows\.
If Not Exist c:\windows\Foxw2600.esl  Copy \BdPos\*.es?    c:\windows\.
If Not Exist %windir%\pkzip.exe       Copy R:\BdPos\Pk*.Exe  %windir%\.
If Not Exist %windir%\Foxw2600.esl    Copy R:\BdPos\*.es?    %windir%\.


Rem Temp From M: To C:
Rem @If Exist M:\Data\FileHave.Dir Pkunzip -o Backup\%wday%\Data.Zp     Datatemp
Rem @If Exist M:\Data\FileHave.Dir Pkunzip -o Backup\%wday%\Transac.Zp  Trantemp
Rem @If Exist M:\Data\FileHave.Dir Pkunzip -o Backup\%wday%\DataRoom.Zp Trantemp\Rooms


Rem For Flash Drive 
UtilPok 2  %FLASH_DRIVE%_datanet
UtilPok 2  %FLASH_DRIVE%_datanet\%wday%
UtilPok 2  %FLASH_DRIVE%System
Copy %HARD_FOLDER%System\Dbfrun.Zp %FLASH_DRIVE%_datanet\.
Copy %HARD_FOLDER%Data.Zp %FLASH_DRIVE%_datanet\.    
Copy %HARD_FOLDER%Transac.Zp %FLASH_DRIVE%_datanet\.
Copy %HARD_FOLDER%_error15.zp %FLASH_DRIVE%_datanet\.
Copy %HARD_FOLDER%System\Report.Zp %FLASH_DRIVE%System\.
Copy %HARD_FOLDER%System\Dirdata.Zp %FLASH_DRIVE%System\.
Copy %HARD_FOLDER%Data.Zp 	%FLASH_DRIVE%_datanet\%wday%\.
Copy %HARD_FOLDER%Transac.Zp 	%FLASH_DRIVE%_datanet\%wday%\.


Rem Copy Data From Harddisk To Flash-Drive 
Rem @If Exist %FLASH_DRIVE%BdPos\Data\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%Data.Zp %FLASH_DRIVE%BdPos\Data
Rem @If Exist %FLASH_DRIVE%BdPos\Transac\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%Transac.Zp %FLASH_DRIVE%BdPos\Transac
Rem @If Exist %FLASH_DRIVE%BdPos\Dbfrun\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%Dbfrun.Zp %FLASH_DRIVE%BdPos\Dbfrun
Rem @If Exist %FLASH_DRIVE%BdPos\Data2Sc\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%System\Data2Sc.Zp %FLASH_DRIVE%BdPos\Data2Sc
Rem @If Exist %FLASH_DRIVE%BdPos\Sc2Pos\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%System\Sc2Pos.Zp %FLASH_DRIVE%BdPos\Sc2Pos
@Cls



Rem Copy To G-drive Or DropBOX
Copy %HARD_FOLDER%*.*	 %CLOUD_DRIVE%Backup\.	
Copy %HARD_FOLDER%System\*.*    %CLOUD_DRIVE%Backup\System\.	
Copy %HARD_FOLDER%*.*    	 %CLOUD_DRIVE%Backup\%wday%\.
Copy %HARD_FOLDER%System\*.*   %CLOUD_DRIVE%Backup\%wday%\.

Rem Copy Any File 
@Pkzip -u %DATA_FOLDER%_update\BdPos \BdPos\Master.exe
@Pkzip -u %DATA_FOLDER%_update\BdPos \BdPos\*.Fr?
@Pkzip -u %DATA_FOLDER%_update\BdPos \BdPos\*.Bmp

Rem Update From update.zip
@If Exist  %CLOUD_DRIVE%Backup\update.zip  Pkunzip -o %CLOUD_DRIVE%Backup\update.zip \BdPos
@If Exist  %CLOUD_DRIVE%Backup\Dbfrun.zip  Pkunzip -o %CLOUD_DRIVE%Backup\Dbfrun.zip \BdPos\Dbfrun
@If Exist  %CLOUD_DRIVE%Backup\Temp.zip  Pkunzip -o %CLOUD_DRIVE%Backup\Temp.zip \BdPos\Temp
@If Exist  %CLOUD_DRIVE%Backup\Backup.zip  Pkunzip -o %CLOUD_DRIVE%Backup\Backup.zip Backup

@If Exist  %CLOUD_DRIVE%Backup\update.zip  Copy %CLOUD_DRIVE%Backup\update.zip _Update\update.zip
@If Exist  %CLOUD_DRIVE%Backup\update.zip  Copy %CLOUD_DRIVE%Backup\update.zip M:\_Update\update.zip

@If Exist  %CLOUD_DRIVE%Backup\update.zip  Pkunzip -o %CLOUD_DRIVE%Backup\update.zip M:\
@If Exist  %CLOUD_DRIVE%Backup\update.zip  Rename %CLOUD_DRIVE%Backup\update.zip    Up"%day%_%month%_%year%".zip
@If Exist  %CLOUD_DRIVE%Backup\Dbfrun.zip  Rename %CLOUD_DRIVE%Backup\Dbfrun.zip Db"%day%_%month%_%year%".zip
@If Exist  %CLOUD_DRIVE%Backup\Temp.zip  Rename  %CLOUD_DRIVE%Backup\Temp.zip Te"%day%_%month%_%year%".zip
@If Exist  %CLOUD_DRIVE%Backup\Backup.zip  Rename  %CLOUD_DRIVE%Backup\Backup.zip Ba"%day%_%month%_%year%".zip

Rem Update From update.prg
@If Exist  %CLOUD_DRIVE%Backup\update.prg Foxprox.exe %CLOUD_DRIVE%Backup\update.prg
@If Exist  %CLOUD_DRIVE%Backup\update.prg Rename %CLOUD_DRIVE%Backup\update.prg   Up"%day%_%month%_%year%".prg
@If Exist  %CLOUD_DRIVE%Backup\update.fxp Rename %CLOUD_DRIVE%Backup\update.fxp    Up"%day%_%month%_%year%".fxp

Rem Del All File *.zip
@If Exist  %CLOUD_DRIVE%Backup\upda*.zip Del %CLOUD_DRIVE%Backup\upda*.zip
@If Exist  %CLOUD_DRIVE%Backup\dbfr*.zip Del %CLOUD_DRIVE%Backup\dbfr*.zip
@If Exist  %CLOUD_DRIVE%Backup\tem*.zip Del %CLOUD_DRIVE%Backup\tem*.zip
@If Exist  %CLOUD_DRIVE%Backup\ba*.zip Del %CLOUD_DRIVE%Backup\ba*.zip
@If Exist  %CLOUD_DRIVE%Backup\upda*.prg Del %CLOUD_DRIVE%Backup\upda*.prg
@If Exist  %CLOUD_DRIVE%Backup\upda*.fxp Del %CLOUD_DRIVE%Backup\upda*.fxp

Rem Backup With Date
UtilPok2 6 %CLOUD_DRIVE%Backup\%wday%

Rem Backup Finish 
Rem set _my_datetime=%date%_%time%
Rem set _my_datetime=%_my_datetime: =_%
Rem set _my_datetime=%_my_datetime::=%
Rem set _my_datetime=%_my_datetime:/=_%
Rem set _my_datetime=%_my_datetime:.=_%
Rem UtilPok 2 %CLOUD_DRIVE%Backup\%_my_datetime%
Rem Copy %HARD_FOLDER%Data.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\.    
Rem Copy %HARD_FOLDER%Transac.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\. 
Rem Copy %HARD_FOLDER%Room.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\.    
Rem Copy %HARD_FOLDER%System\Dbfrun.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\. 

Set ShutDownTime=60
Rem Backup All Folder To Original
Rem If not Exist %CLOUD_DRIVE%Backup\System\Original\Original.zp Goto Original
Rem if %day%==15 Goto Original
goto End


:Original
Set ShutDownTime=180
Del Temp\*.dbf
Del Temp\*.Cdx
Del Temp\*.Txt
Del Temp\*.Tmp
Del Error\*.Dbf
Del Error\*.Cdx
Del Error\*.Err
Del _Error\*.Dbf
Del _Error\*.Cdx
Del _Error\*.Err
Del DayInOut\*.Dbf
Del DayInOut\*.Cdx
Del *.Tmp
Del *.Bak
UtilPok2 8 %PROG_FOLDER% %CLOUD_DRIVE%Backup\System\Original\Original.zp 
goto End


:End
Rem Update Speed File In 32 Bit 
Rem UtilPok4 4 0 0
Rem Delete Junk File 
UtilPok4 6 0 0
C:
Cd\Program 32BIT\WIN32BIT
@Copy formPOK.exe %CLOUD_DRIVE%UyodTeam\.
@Copy *.txt %CLOUD_DRIVE%UyodTeam\.
@Copy *.log %CLOUD_DRIVE%UyodTeam\.
@Copy %DATA_FOLDER%Spec4You.prg %CLOUD_DRIVE%UyodTeam\Spec4You.txt
@Copy %DATA_FOLDER%Amphan.prg %CLOUD_DRIVE%UyodTeam\Amphan.txt
@Dir  *.*  >%CLOUD_DRIVE%UyodTeam\prog32.txt
@Dir  %CLOUD_DRIVE%Backup\*.zip  >%CLOUD_DRIVE%UyodTeam\BackupZipFile.txt
@If Exist  D:\BdPos\Transac.zp Copy %HARD_FOLDER%Transac.Zp D:\BdPos\Transac.zp
Rem Pause      Press 'Enter' For Restart Windows
Rem @Shutdown.exe -r -c "<<< Upload File Backup To Cloud In %ShutDownTime% Second Please Wait...  >>>" -t %ShutDownTime%
Rem @Shutdown.exe -r -c "<<< กรุณารอประมาณ %ShutDownTime% วินาที เพื่อให้ข้อมูลสำรองขึ้นคลาวด์...  >>>" -t  %ShutDownTime%
Rem @Shutdown.exe -s -c "<<< Upload File Backup To Cloud In %ShutDownTime% Second Please Wait...  >>>" -t %ShutDownTime%
Rem Backup Complete
Rem UtilPok 6 
*** For Windows 10
Rem utilpok2 4 cmd
@Exit



:Error
@Cls
Rem Set FORCOM In Backup2c.bat .. Please
Rem Backup2c.bat Run In E:\_Cloud


