📄 resthread.pas
字号:
unit resthread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
type
TResThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
Procedure RestoreDatabase;
end;
implementation
uses Datamodal,sjhy,bfsb;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TResThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TResThread }
procedure TResThread.Execute;
begin
while f_sjhy.ProBar1.Position < f_sjhy.ProBar1.Width do
f_sjhy.ProBar1.Position := f_sjhy.ProBar1.Position+1;
end;
procedure TResThread.RestoreDatabase;
var
timeNow, TimeTo: String;
Num: Integer;//记录备份设备在备份媒体中的位置
begin
if Trim(f_sjhy.lj.Text)<>'' then
begin
Try
f_sjhy.Probar1.Position := 0;
TimeNow := FormatDatetime('yyyy-mm-dd',f_sjhy.sj.Date);
TimeTo := FormatDatetime('yyyy-mm-dd',f_sjhy.sj.Date+1);
Data.Database.Close;
with Data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add(' Restore Headeronly from disk = '+''''+Trim(f_sjhy.lj.Text)+'''');
Open;
end;
Data.Query2.Filter := 'BackupFinishDate ' + '>= ' + TimeNow + ' and '+' BackupFinishDate ' +' < '+ TimeTo;
Data.Query2.Filtered := True;
if Data.Query2.RecordCount>0 then
begin
if Data.Query2.RecordCount>1 then
begin
Self.Suspend;
Application.CreateForm(Tf_bfsb,f_bfsb);
f_bfsb.DataSource1.DataSet:=Data.Query2;
f_bfsb.ShowModal;
f_bfsb.Free;
Self.Resume;
end;
Num := Data.Query2.FieldByName('Position').AsInteger;
end
else
begin
Application.MessageBox('该天没有备份数据.','提示',64);
Exit;
end;
with Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('use master restore Database qygl from disk =' +''''+ f_sjhy.lj.Text +'''' + ' with File = '+ IntToStr(Num) );
ExecSQL;
end;
with Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('use qygl ');
ExecSQL;
end;
Application.MessageBox('还原成功.','提示',64);
f_sjhy.ProBar1.Position := 0;
self.Terminate;
f_sjhy.Close;
Except
Data.Query2.filtered := False;
with Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('use qygl ');
ExecSQL;
end;
Data.Query2.Filter := '';
Application.MessageBox('系统出错.','提示',64);
self.Terminate;
f_sjhy.Close;
end;
Data.Query2.filtered := False;
Data.Query2.Filter := '';
end
else
Application.MessageBox('请设置还原路径.','提示',64);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -