procedure TfrmDbBackup.BtnOKClick(Sender: TObject);
var
sfile: string;
begin
if trim(EditPath.Text) = '' then
begin
application.messagebox('请选择备份文件路径!', '系统提示', MB_ICONINFORMATION);
exit;
end;
sfile:=EditPath.Text;
if FileExists(sfile) then
begin
if application.messagebox(' 文件已存在是否覆盖? ','提示',MB_YESNO )=IDNo then
exit
else Deletefile(sfile);
end;
ProgressBar1.Visible:= true;
ProgressBar1.Max:=80;
ProgressBar1.Min:=0;
ProgressBar1.Position:=0;
ProgressBar1.Step:=20;
frmDataModule.ADOConnection.Connected:= false;
try
with ADOQuery1 do
begin
//制作操作日志
ProgressBar1.StepIt;
SQL.Clear;
SQL.Add('use Master');
ExecSQL;
ProgressBar1.StepIt;
SQL.Clear;
SQL.Add('execute sp_helpdevice');
ExecSQL;
ProgressBar1.StepIt;
SQL.Clear;
SQL.Add('backup database erp_0 to disk=:disk with init');
Parameters.ParamByName('disk').Value:= sfile;
ExecSQL;
ProgressBar1.StepIt;
//-------2008 02 26-----------
SQL.Clear;
SQL.Add('use erp_0');
ExecSQL;
end;
if FileExists(sfile) then
begin
application.messagebox(' 备份成功! ', '提示', MB_ok);
try
frmDataModule.ADOConnection.Connected:=true;
except
application.messagebox('无法重新连接数据库,请重新登入软件!', '提示', MB_ok);
//退出程序,自动释放相关的资源
application.Terminate;
end;
close;
end
else begin
with ADOQuery1 do
begin
try
SQL.Clear;
SQL.Add('use Master');
ExecSQL;
SQL.Clear;
SQL.Add('exec master..xp_cmdshell '+'''del disk=:disk''');
Parameters.ParamByName('disk').Value:= sfile;
ExecSQL;
except
end;
application.messagebox(' 备份失败! ', '提示', MB_ok);
end;
end;
except
on exception do
begin
application.messagebox(' 备份失败! ', '提示', MB_ok);
end;
end;//try
ProgressBar1.Visible:= false;
end;