ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/examples/services/BackupDlgUnit.pas
Revision: 209
Committed: Wed Mar 14 12:48:51 2018 UTC (6 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 3828 byte(s)
Log Message:
Fixes Merged

File Contents

# Content
1 (*
2 * IBX For Lazarus (Firebird Express)
3 *
4 * The contents of this file are subject to the Initial Developer's
5 * Public License Version 1.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy
7 * of the License here:
8 *
9 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 *
11 * Software distributed under the License is distributed on an "AS
12 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 * implied. See the License for the specific language governing rights
14 * and limitations under the License.
15 *
16 * The Initial Developer of the Original Code is Tony Whyman.
17 *
18 * The Original Code is (C) 2015 Tony Whyman, MWA Software
19 * (http://www.mwasoftware.co.uk).
20 *
21 * All Rights Reserved.
22 *
23 * Contributor(s): ______________________________________.
24 *
25 *)
26
27 unit BackupDlgUnit;
28
29 {$mode objfpc}{$H+}
30
31 interface
32
33 uses
34 Classes, SysUtils, FileUtil, IBXServices, Forms, Controls, Graphics, Dialogs, ExtCtrls,
35 StdCtrls, Buttons;
36
37 type
38
39 { TBackupDlg }
40
41 TBackupDlg = class(TForm)
42 Bevel1: TBevel;
43 Button1: TButton;
44 Button2: TButton;
45 CSBackupService1: TIBXClientSideBackupService;
46 SSBackupService1: TIBXServerSideBackupService;
47 ServerName: TEdit;
48 DBName: TEdit;
49 BackupFilename: TEdit;
50 Label1: TLabel;
51 Label2: TLabel;
52 Label3: TLabel;
53 ServerSideBtn: TRadioButton;
54 ClientSideBtn: TRadioButton;
55 SaveDialog1: TSaveDialog;
56 SpeedButton1: TSpeedButton;
57 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
58 procedure FormShow(Sender: TObject);
59 procedure SpeedButton1Click(Sender: TObject);
60 procedure SSBackupService1GetNextLine(Sender: TObject; var Line: string);
61 private
62 { private declarations }
63 FOutputLog: TStrings;
64 procedure RunBackup;
65 public
66 { public declarations }
67 function ShowModal(var aDBName: string; OutputLog: TStrings): TModalResult;
68 end;
69
70 var
71 BackupDlg: TBackupDlg;
72
73 implementation
74
75 {$R *.lfm}
76
77 { TBackupDlg }
78
79 procedure TBackupDlg.SpeedButton1Click(Sender: TObject);
80 begin
81 if SaveDialog1.Execute then
82 BackupFilename.Text := SaveDialog1.Filename;
83 end;
84
85 procedure TBackupDlg.SSBackupService1GetNextLine(Sender: TObject;
86 var Line: string);
87 begin
88 Application.ProcessMessages;
89 end;
90
91 function TBackupDlg.ShowModal(var aDBName: string; OutputLog: TStrings): TModalResult;
92 begin
93 DBName.Text := aDBName;
94 FOutputLog := OutputLog;
95 Result := inherited ShowModal;
96 if Result = mrOK then
97 begin
98 RunBackup;
99 aDBName := DBName.Text;
100 end;
101 end;
102
103 procedure TBackupDlg.RunBackup;
104 var BackupCount: integer;
105 begin
106 FOutputLog.Add('Starting Backup');
107 if ClientSideBtn.Checked then
108 begin
109 CSBackupService1.BackupToFile(BackupFilename.Text,BackupCount);
110 FOutputLog.Add(Format('Backup Completed - File Size = %d bytes',[BackupCount]));
111 MessageDlg(Format('Backup Completed - File Size = %d bytes',[BackupCount]),mtInformation,[mbOK],0);
112 end
113 else
114 begin
115 SSBackupService1.Execute(FOutputLog);
116 FOutputLog.Add('Backup Completed');
117 MessageDlg('Backup Completed',mtInformation,[mbOK],0);
118 end;
119 end;
120
121 procedure TBackupDlg.FormShow(Sender: TObject);
122 begin
123 ServerName.Text := CSBackupService1.ServicesConnection.ServerName;
124 SSBackupService1.BackupFiles.Clear;
125 end;
126
127 procedure TBackupDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
128 begin
129 if ModalResult <> mrOK then Exit;
130 if DBName.Text = '' then
131 raise Exception.Create('A Database Name must be given');
132 if BackupFilename.Text = '' then
133 raise Exception.Create('A Backup File Name must be given');
134 CSBackupService1.DatabaseName := DBName.Text;
135 SSBackupService1.DatabaseName := DBName.Text;
136 if ServerSideBtn.Checked then
137 SSBackupService1.BackupFiles.Add(BackupFilename.Text);
138 end;
139
140 end.
141