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

📄 u_backup_db.~pas

📁 学员管理的软件
💻 ~PAS
字号:
unit U_backup_db;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, ADODB,inifiles,shellapi;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    OpenDialog1: TOpenDialog;
    Label3: TLabel;
    ADOCom_backup: TADOCommand;
    procedure Button1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Edit1Enter(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.InitialDir:=extractfilepath(application.ExeName)+'backup_DB\';
opendialog1.FileName:='exam_data';
if opendialog1.Execute then
   edit2.Text:=opendialog1.FileName;
while application.MessageBox('保存路径中不应该含有中文字符,'+chr(10)+chr(13)+
                             '否则数据库恢复时会报错,'+chr(10)+chr(13)+
                             '请确认你保存路径中是否含有中文字符,'+chr(10)+chr(13)+
                             '如确定没有,请点选[是],'+chr(10)+chr(13)+
                             '否则点选[否],重新选择保存路径','系统提示',MB_YESNO+MB_ICONQUESTION)= IDNO  do
begin
   edit2.Text:='';
   button1click(sender);
   exit;
end;
end;

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

procedure TForm1.BitBtn1Click(Sender: TObject);
var
myfile:Tinifile;
strip,strinitcat,strname,strpass:string;
begin
   if trim(edit2.Text)='' then
   begin
     Application.MessageBox(Pchar('请选择有效的文件路径!'),'错误信息提示',MB_OK+MB_ICONERROR);
     edit2.SetFocus;
     exit;
   end;
   myfile:=Tinifile.Create(extractfilepath(application.ExeName)+'myfile.ini');
   strip:=myfile.ReadString('db_set','ipaddress','127.0.0.1');
   strinitcat:=myfile.ReadString('db_set','db_name','exam');
   strname:=myfile.ReadString('db_set','name','sa');
   strpass:=myfile.ReadString('db_set','pass','');
   myfile.Free;
   try
   adocom_backup.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;';
   adocom_backup.ConnectionString:=adocom_backup.ConnectionString+'User ID='+strname+';password='+strpass+';Initial Catalog='+strinitcat+';Data Source='+strip;
   except
       Application.MessageBox(Pchar('数据库连接错误,请重新配置数据库后再进行备份工作'),'错误信息提示',MB_OK+MB_ICONERROR);
       label3.Visible:=false;
       screen.Cursor := crDefault;
       if (Application.MessageBox(Pchar('是否现在进行数据库的配置工作?'+chr(10)+chr(13)+'配置完后请重新进行备份工作!'),
      '信息询问',MB_YESNO+MB_ICONQUESTION))=ID_Yes then
       ShellExecute(handle,'open',pchar(extractfilepath(application.ExeName)+'P_db_set.exe'),nil,nil,SW_SHOWNORMAL);
       exit;
   end;
   screen.Cursor := crHourGlass;
   label3.Visible := true;
   label3.Update;

   try
   with ADOCom_backup do
   begin
       CommandText := '';
       CommandText := 'backup database '+trim(edit1.Text)+' to DISK = :path with init';
       Parameters.ParamByName('path').value := trim(edit2.text);
       Execute;
   end;
   except
       Application.MessageBox(Pchar('数据库连接错误,请重新配置数据库后再进行备份工作'),'错误信息提示',MB_OK+MB_ICONERROR);
       label3.Visible:=false;
       screen.Cursor := crDefault;
       if (Application.MessageBox(Pchar('是否现在进行数据库的配置工作?'+chr(10)+chr(13)+'配置完后请重新进行备份工作!'),
      '信息询问',MB_YESNO+MB_ICONQUESTION))=ID_Yes then
       ShellExecute(handle,'open',pchar(extractfilepath(application.ExeName)+'P_db_set.exe'),nil,nil,SW_SHOWNORMAL);
       exit;
   end;
   label3.Visible := false;
   label3.Update;
   Application.MessageBox(Pchar('恭喜您,备份成功!'+chr(10)+chr(13)+'备份路径:'+edit2.Text+chr(10)+chr(13)+'请核对!'),
   '信息提示',MB_OK+MB_ICONINFORMATION);
   screen.Cursor := crDefault;
   if (Application.MessageBox(Pchar('是否关闭现有备份窗口?'),
   '信息询问',MB_YESNO+MB_ICONQUESTION))=ID_Yes then
    close;
end;

procedure TForm1.Edit1Enter(Sender: TObject);
begin
if (sender is Tedit) then
(sender as Tedit).Color:=clInactiveCaptionText;
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
if (sender is Tedit) then
(sender as Tedit).Color:=clwindow;
end;

end.

⌨️ 快捷键说明

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