📄 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)
Panel1: TPanel;
BitBtn1: TBitBtn;
Panel2: TPanel;
Panel3: TPanel;
Image1: TImage;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
ListView1: TListView;
Label3: TLabel;
BitBtn2: TBitBtn;
Label4: TLabel;
Label5: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
ImageList1: TImageList;
Label6: TLabel;
Label2: TLabel;
Label1: TLabel;
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
Database1: TDatabase;
procedure BitBtn1Click(Sender: TObject);
procedure Panel1Click(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
{$R *.DFM}
procedure TBackup_Disk.BitBtn1Click(Sender: TObject);
begin
Close;
end;
procedure TBackup_Disk.Panel1Click(Sender: TObject);
begin
ShellExecute(handle,nil,'http://www.MingRiSoft.com',nil,nil,sw_shownormal);
//连接网址
end;
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);
Label4.Caption:=s;
//------------------------------------------------------------------------------
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 WYGL 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 WYGL 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 WYGL 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;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -