📄 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;
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,num:integer;
spath,dpath,name,RQ: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
begin
spath:=ExtractFilePath(Application.ExeName)+'Data';
dpath:=myini.ReadString('bakup','BakPath','');
dpath:=dpath+'\'+AnsiReplaceStr(DateTimeToStr(now),':','');
ForceDirectories(dpath);
num:=GetFileNum(spath+'\*.*');
ZT_FE.Text:='正在备份数据库......';
JD_FG.MaxValue:=num;
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;
ZT_FE.Text:='数据库备份成功';
MessageBox(handle,'恭喜你:数据库备份成功!','祝贺你',MB_OK or MB_ICONINFORMATION);
end
else begin
RQ:=myini.ReadString('bakup','RQ','');
spath:=myini.ReadString('bakupdian',RQ,'');
spath:=spath+'\'+RQ;
dpath:=ExtractFilePath(Application.ExeName);
dpath:=dpath+'Data';
num:=GetFileNum(spath+'\*.*');
ZT_FE.Text:='正在还原数据库......';
JD_FG.MaxValue:=num;
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;
ZT_FE.Text:='数据库还原成功';
MessageBox(handle,'恭喜你:数据库还原成功!','祝贺你',MB_OK or MB_ICONINFORMATION);
end;
StartupInfo.cb:=sizeof(StartupInfo);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
CreateProcess(pchar(ExtractFilePath(Application.ExeName)+'TSGL.exe'),nil,nil,nil,false,0,nil,nil,StartupInfo,ProcessInfo);
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -