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

📄 backup_form.pas

📁 软件实现了以下主要功能:1.手动生成试卷;2.自动生成试卷;3.抽取现有试卷;4.用户管理;5.数据库管理。
💻 PAS
字号:
unit BackUp_Form;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TFlatGaugeUnit, StdCtrls, TFlatEditUnit, ExtCtrls,FileCtrl;

type
  TBackup_F = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    ZT_FE: TFlatEdit;
    JD_FG: TFlatGauge;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Backup_F: TBackup_F;

implementation

{$R *.dfm}

Uses
  ExtIniFiles,StrUtils;

function GetFileNum(dir:string):integer;          //取得文件夹下的文件个数
var
  sr:Tsearchrec;
begin
  result:=0;
  if FindFirst(dir,faanyfile,sr)=0 then
    repeat
      if(sr.Attr<>fadirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
        result:=result+1;
    until FindNext(sr)<>0;
  FindClose(sr);
end;
//***********************************************************************************
procedure Wait(second:Longint);                        //等待
var
  FirstTickCount:longint;
begin
  FirstTickCount:=GetTickCount;
  repeat
    Application.ProcessMessages;
  until ((GetTickCount-FirstTickCount) >=second);
end;
//***********************************************************************************
procedure TBackup_F.Timer1Timer(Sender: TObject);             //进行备份或还原操作 
var
  myini:TExtIniFile;
  cz,dbnum,num:integer;
  spath,dpath,SJD,BackPath,NowPath:string;
  sr:Tsearchrec;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  Timer1.Enabled:=false;
  myini:=TExtIniFile.Create(ExtractFilePath(Application.ExeName)+'set.ini');
  cz:=myini.ReadInteger('bakup','CZ',0);
  if cz=0 then      //0为备份操作
    begin
      spath:=ExtractFilePath(Application.ExeName)+'DB';
      dpath:=myini.ReadString('bakup','BakPath','');
      SJD:=DateTimeToStr(now);
      dpath:=dpath+'\'+AnsiReplaceStr(SJD,':','');
      ForceDirectories(dpath);
      dbnum:=GetFileNum(spath+'\*.*');
      JD_FG.MaxValue:=dbnum+2;
      ZT_FE.Text:='正在检查原目录......';
      if DirectoryExists(spath) then JD_FG.Progress:=JD_FG.Progress+1;
      Wait(100);
      ZT_FE.Text:='正在检查备份目录......';
      if DirectoryExists(dpath) then JD_FG.Progress:=JD_FG.Progress+1;
      Wait(100);
      ZT_FE.Text:='开始备份数据库......';
      if FindFirst(spath+'\*.*',faanyfile,sr)=0 then
        repeat
          if(sr.Attr<>fadirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
            begin
              CopyFile(pchar(spath+'\'+sr.Name),pchar(dpath+'\'+sr.Name),false);
              JD_FG.Progress:=JD_FG.Progress+1;
            end;
          Wait(100);
        until FindNext(sr)<>0;
      FindClose(sr);
      ZT_FE.Text:='数据库备份成功';

      num:=myini.ReadInteger('bakup','num',0);
      num:=num+1;
      BackPath:=myini.ReadString('bakup','BakPath','');;
      myini.WriteInteger('bakup','CZ',0);
      myini.WriteInteger('bakup','num',num);
      myini.WriteString('bakupdian','bak'+IntToStr(num),SJD);
      myini.WriteString('bakupdian',SJD,BackPath);
      FreeAndNil(myini);
      MessageBox(handle,'恭喜你:数据库备份成功!','祝贺你',MB_OK or MB_ICONINFORMATION);
    end
    else begin
      SJD:=myini.ReadString('bakup','RQ','');
      spath:=myini.ReadString('bakupdian',SJD,'');
      spath:=spath+'\'+AnsiReplaceStr(SJD,':','');
      dpath:=ExtractFilePath(Application.ExeName);
      dpath:=dpath+'DB';
      dbnum:=GetFileNum(spath+'\*.*');
      JD_FG.MaxValue:=dbnum+2;
      ZT_FE.Text:='正在检查备份目录......';
      if DirectoryExists(spath) then JD_FG.Progress:=JD_FG.Progress+1;
      Wait(100);
      ZT_FE.Text:='正在检查原目录......';
      if DirectoryExists(dpath) then JD_FG.Progress:=JD_FG.Progress+1;
      Wait(100);
      ZT_FE.Text:='正在还原数据库......';
      if FindFirst(spath+'\*.*',faanyfile,sr)=0 then
        repeat
          if(sr.Attr<>fadirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
            begin
              CopyFile(pchar(spath+'\'+sr.Name),pchar(dpath+'\'+sr.Name),false);
              JD_FG.Progress:=JD_FG.Progress+1;
            end;
          Wait(100);
        until FindNext(sr)<>0;
      FindClose(sr);
      ZT_FE.Text:='数据库还原成功';
      MessageBox(handle,'恭喜你:数据库还原成功!','祝贺你',MB_OK or MB_ICONINFORMATION);
    end;
  StartupInfo.cb:=sizeof(StartupInfo);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  NowPath:=ExtractFilePath(Application.ExeName);
  chdir(NowPath);
  CreateProcess(pchar(NowPath+'BYSJ.exe'),nil,nil,nil,false,0,nil,nil,StartupInfo,ProcessInfo);
  close;
end;
//****************************************************************************************
end.

⌨️ 快捷键说明

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