unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls, DB, ADODB;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
PB: TProgressBar;
StatusBar1: TStatusBar;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
dir:string;
id:DWORD;
pd:THandle;
implementation
{$R *.dfm}
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Close;
end;
function pro:Boolean;
begin
if Form1.PB.position<100 then
Form1.PB.Position:=Form1.PB.Position+1;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
if SaveDialog1.Execute then
begin
dir:=SaveDialog1.FileName+'.bak';
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Text:='backup database db_ems to disk='''+dir+'''';
ExecSQL;
end;
pd:=createthread(nil,0,@pro,nil,0,id);
PB.Position:=PB.Max;
ShowMessage('备份OK!');
PB.Position:=PB.Min;
end;
except
begin
ShowMessage('备份失败!');
PB.Position:=PB.Min;
end;
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
try
if OpenDialog1.Execute then
begin
dir:=OpenDialog1.FileName;
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Text:='use master restore database db_EMS from disk='''+dir+'''';
ExecSQL;
end;
pd:=CreateThread(nil,0,@pro,nil,0,id);
PB.Position:=PB.Max;
ShowMessage('还原OK!');
PB.Position:=PB.Min;
end;
except
showmessage('还原失败!');
pb.Position:=PB.Min;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
postmessage(Pb.Handle,$0409,0,clLime);
end;
end.
这样还简单点,呵呵