1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
{
This file is part of the Free Component Library.
Copyright (c) 2017 Michael Van Canneyt, member of the Free Pascal development team
Form to edit a SQLDB data connection, used in data management.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit dlgsqldbrestconnection;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel, Buttons, sqldb, sqldbrestbridge;
type
{ TSQLDBRestConnectionEditorForm }
TSQLDBRestConnectionEditorForm = class(TForm)
BPConnection: TButtonPanel;
CBType: TComboBox;
ECharset: TEdit;
EName: TEdit;
ERole: TEdit;
EUserName: TEdit;
EPassword: TEdit;
EHostName: TEdit;
EDatabaseName: TEdit;
Label2: TLabel;
LEHostName1: TLabel;
LEUserName: TLabel;
LCBType: TLabel;
LEHostName: TLabel;
LEDatabaseName: TLabel;
LEPassword: TLabel;
LERole: TLabel;
LMParams: TLabel;
MParams: TMemo;
SBTest: TSpeedButton;
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SBTestClick(Sender: TObject);
private
FConnection: TSQLDBRestConnection;
Function TestConnection : String;
procedure FormToConnection;
procedure ConnectionToForm;
procedure SetConnection(AValue: TSQLDBRestConnection);
public
Property Connection : TSQLDBRestConnection Read FConnection Write SetConnection;
end;
Function EditSQLDBRestConnection(aConnection : TSQLDBRestConnection) : Boolean;
Resourcestring
SConnectionSuccesful = 'Connection to the database was succesfully made.';
SErrConnectionNotOK = 'Error connecting to the database';
SSuccess = 'Succesfully connected.';
implementation
{$R *.lfm}
Function EditSQLDBRestConnection(aConnection : TSQLDBRestConnection) : Boolean;
begin
With TSQLDBRestConnectionEditorForm.Create(Application) do
try
Connection:=aConnection;
result:= (ShowModal=mrOK);
if Result then
aConnection.Assign(Connection);
finally
end;
end;
procedure TSQLDBRestConnectionEditorForm.FormCreate(Sender: TObject);
begin
FConnection:=TSQLDBRestConnection.Create(Nil);
GetConnectionList(CBType.Items);
end;
procedure TSQLDBRestConnectionEditorForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
Var
S : String;
begin
if ModalResult=mrOK then
begin
FormToConnection;
S:=TestConnection;
if (S<>'') then
if MessageDlg(SErrConnectionNotOK,S,mtError,[mbIgnore,mbCancel],0)=mrIgnore then
S:='';
end;
CanClose:=(S='');
end;
procedure TSQLDBRestConnectionEditorForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(FConnection);
end;
procedure TSQLDBRestConnectionEditorForm.SBTestClick(Sender: TObject);
Var
S : String;
begin
FormToConnection;
S:=TestConnection;
if (S<>'') then
MessageDlg(SErrConnectionNotOK,S,mtError,[mbOK],0)
else
MessageDlg(SSuccess,SConnectionSuccesful,mtInformation,[mbOK],0);
end;
function TSQLDBRestConnectionEditorForm.TestConnection: String;
Var
Conn : TSQLConnector;
TR : TSQLTransaction;
begin
Conn:=TSQLConnector.Create(Self);
try
TR:=TSQLTransaction.Create(Conn);
Conn.Transaction:=TR;
FConnection.ConfigConnection(Conn);
try
Conn.Connected:=true;
except
On E: Exception do
Result:=E.Message;
end;
finally
Conn.Free;
end;
end;
procedure TSQLDBRestConnectionEditorForm.SetConnection(AValue: TSQLDBRestConnection);
begin
if FConnection=AValue then Exit;
FConnection.Assign(AValue);
ConnectionToForm;
end;
procedure TSQLDBRestConnectionEditorForm.FormToConnection;
begin
With FConnection do
begin
Name:=EName.Text;
ConnectionType:=CBType.Text;
HostName:=EHostName.Text;
DatabaseName:=EDatabaseName.Text;
Params:=MParams.Lines;
UserName:=EUserName.Text;
Password:=EPassword.Text;
Role:=ERole.Text;
Charset:=ECharset.Text;
end;
end;
procedure TSQLDBRestConnectionEditorForm.ConnectionToForm;
begin
With FConnection do
begin
EName.Text:=Name;
CBType.Text:=ConnectionType;
EHostName.Text:=HostName;
EDatabaseName.Text:=DatabaseName;
MParams.Lines:=Params;
EUserName.Text:=UserName;
EPassword.Text:=Password;
ERole.Text:=Role;
ECharset.Text:=Charset;
end;
end;
end.
|