backupdata_unit.pas

来自「delphi毕业设计02学校班级教学管理系统.ZIP」· PAS 代码 · 共 81 行

PAS
81
字号
unit BackUpData_Unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Base_Unit, Gauges, StdCtrls, Buttons, Menus, StdActns, ActnList,
  ComCtrls;

type
  TfrmBackupData = class(TfrmBase)
    btnBackup: TBitBtn;
    btnRestore: TBitBtn;
    SaveDialog: TSaveDialog;
    OpenDialog: TOpenDialog;
    Animate1: TAnimate;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnBackupClick(Sender: TObject);
    procedure btnRestoreClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmBackupData: TfrmBackupData;
  DataBaseFile: string;
implementation

uses DM_Unit, Common_Unit;

{$R *.dfm}

procedure TfrmBackupData.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  frmBackUpData := nil;
end;

procedure TfrmBackupData.btnBackupClick(Sender: TObject);
begin
  inherited;
//读取配置文件中的数据连接路径
  DataBaseFile := DBConFileName(FileName);
//判断是否存在相同的备份
  if SaveDialog.Execute then
  begin
    if FileExists(SaveDialog.FileName+'.mdb') then
      if Application.MessageBox('文件名重复,是否覆盖!','提示',68)=IDNo then
         Exit;
    Animate1.Active := True;
//复制出来进行备份
    if CopyFile(PChar(DataBaseFile),PChar(SaveDialog.FileName+'.mdb'),True) then
    begin
      Animate1.Active := False;
      Application.MessageBox('备份成功!','提示',64);
    end;
  end;
end;

procedure TfrmBackupData.btnRestoreClick(Sender: TObject);
begin
  inherited;
  DataBaseFile := DBConFileName(FileName);

  if OpenDialog.Execute then
  begin
    Animate1.Active := True;
//复制文件到另一个目录
    if CopyFile(PChar(OpenDialog.FileName),PChar(DataBaseFile), False) then
    begin
      Animate1.Active := False;
      Application.MessageBox('还原成功!','提示',64);
    end;
  end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?