?? backup_form.pas
字號:
unit BackUp_Form;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TFlatGaugeUnit, StdCtrls, TFlatEditUnit, ExtCtrls,FileCtrl;
type
TBackup_F = class(TForm)
Label1: TLabel;
Label2: TLabel;
ZT_FE: TFlatEdit;
JD_FG: TFlatGauge;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Backup_F: TBackup_F;
implementation
{$R *.dfm}
Uses
ExtIniFiles,StrUtils;
function GetFileNum(dir:string):integer; //取得文件夾下的文件個數
var
sr:Tsearchrec;
begin
result:=0;
if FindFirst(dir,faanyfile,sr)=0 then
repeat
if(sr.Attr<>fadirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
result:=result+1;
until FindNext(sr)<>0;
FindClose(sr);
end;
//***********************************************************************************
procedure Wait(second:Longint); //等待
var
FirstTickCount:longint;
begin
FirstTickCount:=GetTickCount;
repeat
Application.ProcessMessages;
until ((GetTickCount-FirstTickCount) >=second);
end;
//***********************************************************************************
procedure TBackup_F.Timer1Timer(Sender: TObject); //進行備份或還原操作
var
myini:TExtIniFile;
cz,dbnum,num:integer;
spath,dpath,SJD,BackPath,NowPath:string;
sr:Tsearchrec;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
Timer1.Enabled:=false;
myini:=TExtIniFile.Create(ExtractFilePath(Application.ExeName)+'set.ini');
cz:=myini.ReadInteger('bakup','CZ',0);
if cz=0 then //0為備份操作
begin
spath:=ExtractFilePath(Application.ExeName)+'DB';
dpath:=myini.ReadString('bakup','BakPath','');
SJD:=DateTimeToStr(now);
dpath:=dpath+'\'+AnsiReplaceStr(SJD,':','');
ForceDirectories(dpath);
dbnum:=GetFileNum(spath+'\*.*');
JD_FG.MaxValue:=dbnum+2;
ZT_FE.Text:='正在檢查原目錄......';
if DirectoryExists(spath) then JD_FG.Progress:=JD_FG.Progress+1;
Wait(100);
ZT_FE.Text:='正在檢查備份目錄......';
if DirectoryExists(dpath) then JD_FG.Progress:=JD_FG.Progress+1;
Wait(100);
ZT_FE.Text:='開始備份數據庫......';
if FindFirst(spath+'\*.*',faanyfile,sr)=0 then
repeat
if(sr.Attr<>fadirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
begin
CopyFile(pchar(spath+'\'+sr.Name),pchar(dpath+'\'+sr.Name),false);
JD_FG.Progress:=JD_FG.Progress+1;
end;
Wait(100);
until FindNext(sr)<>0;
FindClose(sr);
ZT_FE.Text:='數據庫備份成功';
num:=myini.ReadInteger('bakup','num',0);
num:=num+1;
BackPath:=myini.ReadString('bakup','BakPath','');;
myini.WriteInteger('bakup','CZ',0);
myini.WriteInteger('bakup','num',num);
myini.WriteString('bakupdian','bak'+IntToStr(num),SJD);
myini.WriteString('bakupdian',SJD,BackPath);
FreeAndNil(myini);
MessageBox(handle,'恭喜你:數據庫備份成功!','祝賀你',MB_OK or MB_ICONINFORMATION);
end
else begin
SJD:=myini.ReadString('bakup','RQ','');
spath:=myini.ReadString('bakupdian',SJD,'');
spath:=spath+'\'+AnsiReplaceStr(SJD,':','');
dpath:=ExtractFilePath(Application.ExeName);
dpath:=dpath+'DB';
dbnum:=GetFileNum(spath+'\*.*');
JD_FG.MaxValue:=dbnum+2;
ZT_FE.Text:='正在檢查備份目錄......';
if DirectoryExists(spath) then JD_FG.Progress:=JD_FG.Progress+1;
Wait(100);
ZT_FE.Text:='正在檢查原目錄......';
if DirectoryExists(dpath) then JD_FG.Progress:=JD_FG.Progress+1;
Wait(100);
ZT_FE.Text:='正在還原數據庫......';
if FindFirst(spath+'\*.*',faanyfile,sr)=0 then
repeat
if(sr.Attr<>fadirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
begin
CopyFile(pchar(spath+'\'+sr.Name),pchar(dpath+'\'+sr.Name),false);
JD_FG.Progress:=JD_FG.Progress+1;
end;
Wait(100);
until FindNext(sr)<>0;
FindClose(sr);
ZT_FE.Text:='數據庫還原成功';
MessageBox(handle,'恭喜你:數據庫還原成功!','祝賀你',MB_OK or MB_ICONINFORMATION);
end;
StartupInfo.cb:=sizeof(StartupInfo);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
NowPath:=ExtractFilePath(Application.ExeName);
chdir(NowPath);
CreateProcess(pchar(NowPath+'BYSJ.exe'),nil,nil,nil,false,0,nil,nil,StartupInfo,ProcessInfo);
close;
end;
//****************************************************************************************
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -