⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitcommrestore.pas

📁 此代码为企业原料管理代码
💻 PAS
字号:
unit UnitCommRestore;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, FileCtrl, ShellApi;

type
  TfrmCommRestore = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    Edit1: TEdit;
    BitBtn2: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    Bevel1: TBevel;
    procedure BitBtn1Click(Sender: TObject);
    procedure DirectoryListBox1Change(Sender: TObject);
    procedure DriveComboBox1Change(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);

    private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCommRestore: TfrmCommRestore;
implementation

{$R *.DFM}

procedure TfrmCommRestore.BitBtn1Click(Sender: TObject);
  var
   lpFileOp: TSHFileOpStruct;
   sSourcePath,sTargetPath:string;
begin
  sSourcePath:=edit1.text;
  sTargetPath:=ExtractFilePath(Application.Exename)+'db';
    //showmessage(sSourcePath+'    ');
//=======================================================================
// 判读是否是本系统的备份目录  依据是  是否有 JL2001.txt 这个文件
//=======================================================================
  if not FileExists(sSourcePath+'\JL2001.txt') then
  begin
    messagedlg('您所选择的目录不是本系统的备份目录,请选择有 XX年XX月XX日备份 字样的目录!',mtError,[mbok],0);
    exit;
  end; //if

  if messagedlg('您确定要恢复  '+sSourcePath+ '  目录下的进度吗?',mtinformation,[mbyes,mbno],0) <> mryes then
  begin
   // showmessage('您已经取消了数据还原操作!');
    exit;
  end; //if

  if MessageDlg('本操作会清除目前所有记录,恢复上次备份的记录,您确定要继续吗?',mtwarning,[mbyes,mbno],0) = mryes then
  begin

//=====================
// 删除原来的目录
//=====================
    with lpFileOp do
    begin
      Wnd := Self.Handle;
      pFrom := pchar(sTargetPath);
      pTo := pchar(sTargetPath);
       wFunc := FO_DELETE;
      fFlags := FOF_ALLOWUNDO;
      hNameMappings := nil;
      lpszProgressTitle := nil;
      fAnyOperationsAborted := true;
    end; //with

   if SHFileOperation(lpFileOp)<> 0 then
     begin
      ShowMessage('数据恢复失败!');
      exit;
     end;
//==============
// 下一句不能删除!!
//===============
    sSourcePath:=edit1.text;

    sTargetPath:=ExtractFilePath(Application.Exename)+'db';
//   showmessage(sSourcePath+#13+#13+sTargetPath+'  '+inttostr(strlen(Pchar(sSourcePath))));

//==============
// 还原DB目录
//==============
     with lpFileOp do
       begin
       Wnd := Self.Handle;
       pFrom := pchar(sSourcePath);
       pTo := pchar(sTargetPath);
       wFunc := FO_COPY;
       fFlags := FOF_ALLOWUNDO;
       hNameMappings := nil;
       lpszProgressTitle := nil;
       fAnyOperationsAborted := True;
     end; //with
     if SHFileOperation(lpFileOp) <> 0 then
     begin
     ShowMessage('数据还原失败');
     exit;
     end;

     messagedlg('数据还原完成!',mtinformation,[mbok],0);
     exit;
     end
  else
   // showmessage('您已经取消了数据还原操作!');

  end;

procedure TfrmCommRestore.DirectoryListBox1Change(Sender: TObject);
begin
    edit1.text:=DirectoryListBox1.Directory;
  end;

procedure TfrmCommRestore.DriveComboBox1Change(Sender: TObject);
begin
     edit1.text:=DirectoryListBox1.Directory;
   end;

procedure TfrmCommRestore.BitBtn2Click(Sender: TObject);
begin
  close;
end;

end.

⌨️ 快捷键说明

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