📄 mc_backup_disk.pas
字号:
unit MC_Backup_Disk;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, ShellAPI, jpeg, ImgList, ComCtrls, FileCtrl,
Db, DBTables;
type
TBackup_Disk = class(TForm)
BitBtn1: TBitBtn;
Panel2: TPanel;
Panel3: TPanel;
Image1: TImage;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
ListView1: TListView;
Label5: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
ImageList1: TImageList;
Label6: TLabel;
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
Database1: TDatabase;
BitBtn2: TBitBtn;
Bevel1: TBevel;
Label1: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DirectoryListBox1Change(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure ListView1Click(Sender: TObject);
private
Files:String;
{ Private declarations }
public
{ Public declarations }
end;
var
Backup_Disk: TBackup_Disk;
implementation
uses MC_TLCYGLXT;
{$R *.DFM}
procedure TBackup_Disk.FormShow(Sender: TObject); //系统初始化设置
var List_View:array[0..1]of TListItem; a:integer; s:String;
begin
Label6.Caption:=DateToStr(Now)+'.MC'; //显示当天的备份卡名称
GetDir(3,s);
TLCYGLXT.CYDATE.Connected:=False;
ListView1.Items.Clear;
If FileListBox1.Items.Count <> 0 Then
begin //显示当前路径下的备份卡
For a:=0 to FileListBox1.Items.Count-1 do
begin
List_View[0]:=ListView1.Items.Add;
List_View[0].Caption:=FileListBox1.Items.Strings[a];
List_View[0].ImageIndex:=0;
end;
end;
end;
procedure TBackup_Disk.DirectoryListBox1Change(Sender: TObject); //选择备份卡位置
var List_View:array[0..1]of TListItem; a:integer;
begin
ListView1.Items.Clear; //清空备份卡列表
If FileListBox1.Items.Count <> 0 Then
begin
For a:=0 to FileListBox1.Items.Count-1 do
begin
List_View[0]:=ListView1.Items.Add; //添加备份卡
List_View[0].Caption:=FileListBox1.Items.Strings[a];
List_View[0].ImageIndex:=0;
end;
end;
end;
procedure TBackup_Disk.BitBtn2Click(Sender: TObject); //备份或恢复文件
var BF,HF:TQuery; List:TListItem; a,b:integer;
begin
if RadioButton1.Checked=True then //备份数据
begin
if MessageDlg('您确认要备份数据吗?',mtCustom,[mbYes,mbNo],0)=mrYes then
begin
if ListView1.Items.Count<>0 then //存在记录卡
begin
For a:=0 to ListView1.Items.Count-1 do
begin
if ListView1.Items.Item[a].Caption=Label6.Caption then //已备份,则退出备份
begin
ShowMessage('本路径下已有今天做的备份卡.');
Exit;
end;
end;//结束For循环
Database1.Connected:=True;
BF:=TQuery.Create(Self);
BF.DatabaseName:='BBB';
BF.Close;
BF.SQL.Clear;
BF.SQL.Add('Backup database TLJDGLXT To Disk=:A');
if Copy(DirectoryListBox1.Directory,Length(DirectoryListBox1.Directory),1)='\' then
BF.ParamByName('A').AsString:=DirectoryListBox1.Directory+Label6.Caption
Else
BF.ParamByName('A').AsString:=DirectoryListBox1.Directory+'\'+Label6.Caption;
BF.ExecSQL;
BF.Free;
Database1.Connected:=True;
List:=ListView1.Items.Add;
List.ImageIndex:=0;
List.Caption:=Label6.Caption;
ShowMessage('备份完闭!!');
End
else //如果为空没有记录卡
begin
Database1.Connected:=True;
BF:=TQuery.Create(Self);
BF.DatabaseName:='BBB';
BF.Close;
BF.SQL.Clear;
BF.SQL.Add('Backup database TLJDGLXT To Disk=:A');
if Copy(DirectoryListBox1.Directory,Length(DirectoryListBox1.Directory),1)='\' then
BF.ParamByName('A').AsString:=DirectoryListBox1.Directory+Label6.Caption
Else
BF.ParamByName('A').AsString:=DirectoryListBox1.Directory+'\'+Label6.Caption;
BF.ExecSQL;
BF.Free;
Database1.Connected:=False;
List:=ListView1.Items.Add;
List.ImageIndex:=0;
List.Caption:=Label6.Caption;
ShowMessage('备份完闭!!');
end;
end;
end;
if RadioButton2.Checked=True then //选择恢复数据
begin
if MessageDlg('您确认要恢复数据吗?',mtCustom,[mbYes,mbNo],0)=mrYes then
begin
if ListView1.Items.Count=0 then //如果为空没有记录卡
begin
ShowMessage('对不起没有发现备份卡,无法恢复数据.');
Exit;
End
else //如果存在记录卡
begin
if Files='Nil' then //没有选择恢复文件
begin
ShowMessage('对不起,请重新选择要恢复的备份.');
Exit;
End
Else
begin //开始恢复
Database1.Connected:=True;
BF:=TQuery.Create(Self);
BF.DatabaseName:='BBB';
BF.Close;
BF.SQL.Clear;
BF.SQL.Add('Restore Database TLJDGLXT From Disk=:A');
if Copy(DirectoryListBox1.Directory,Length(DirectoryListBox1.Directory),1)='\' then
BF.ParamByName('A').AsString:=DirectoryListBox1.Directory+Files
Else
BF.ParamByName('A').AsString:=DirectoryListBox1.Directory+'\'+Files;
BF.ExecSQL;
BF.Free;
Database1.Connected:=False;
ShowMessage('恢复完闭!!');
end;
end;
end;
end;
end;
procedure TBackup_Disk.ListView1Click(Sender: TObject); //选择要恢复的备份卡
var Lists:TListItem;
begin
Lists:=ListView1.Selected;
if Lists<>nil then //选择了备份卡
begin
Files:=Lists.Caption;
End
else Files:='Nil';
end;
procedure TBackup_Disk.FormClose(Sender: TObject;var Action: TCloseAction);
begin
TLCYGLXT.CYDATE.Connected:=True;
Backup_Disk.Release; //释放窗体资源
Backup_Disk:=Nil;
end;
procedure TBackup_Disk.BitBtn1Click(Sender: TObject);
begin
Close; //退出数据备份
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -