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
|
unit frmsqldbrestselectconn;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, ExtCtrls,
StdCtrls, sqldbrestschema, sqldbrestbridge;
type
{ TSelectRestConnectionForm }
TSelectRestConnectionForm = class(TForm)
BPSelect: TButtonPanel;
CGFieldOPtions: TCheckGroup;
CBAllTables: TCheckBox;
RGConnection: TRadioGroup;
private
FShowOptions: Boolean;
procedure SetShowOptions(AValue: Boolean);
public
Procedure Init(aList : TSQLDBRestConnectionList); overload;
Procedure Init(aList : TStrings); overload;
Property ShowOptions : Boolean Read FShowOptions Write SetShowOptions;
Function SelectedConnection : TSQLDBRestConnection;
Function SelectedOptions : TRestFieldOptions;
Function AllTables : Boolean;
end;
Function SelectRestConnection(aList : TSQLDBRestConnectionList) : TSQLDBRestConnection;
Function SelectRestConnection(aList : TStrings; out aOptions: TRestFieldOptions; Out aAllTables : Boolean) : TSQLDBRestConnection;
Function SelectRestConnection(aList : TSQLDBRestConnectionList; out aOptions: TRestFieldOptions; Out aAllTables : Boolean) : TSQLDBRestConnection;
var
SelectRestConnectionForm: TSelectRestConnectionForm;
implementation
{$R *.lfm}
Function SelectRestConnection(aList : TStrings; out aOptions: TRestFieldOptions; Out aAllTables : Boolean) : TSQLDBRestConnection;
begin
Result:=Nil;
if Alist.Count<>0 then
With TSelectRestConnectionForm.Create(Application) do
try
Init(aList);
ShowOptions:=True;
if ShowModal=mrOK then
begin
Result:=SelectedConnection;
aOptions:=SelectedOptions;
aAllTables:=AllTables;
end;
finally
Free;
end;
end;
Function DoSelectRestConnection(aList : TSQLDBRestConnectionList; withOpts : Boolean; out aOptions: TRestFieldOptions; Out aAllTables : Boolean) : TSQLDBRestConnection;
begin
Result:=Nil;
if Alist.Count<>0 then
With TSelectRestConnectionForm.Create(Application) do
try
Init(aList);
ShowOptions:=WithOpts;
if ShowModal=mrOK then
begin
Result:=SelectedConnection;
if WithOpts then
aOptions:=SelectedOptions;
aAllTables:=AllTables;
end;
finally
Free;
end;
end;
Function SelectRestConnection(aList : TSQLDBRestConnectionList; out aOptions: TRestFieldOptions; Out aAllTables : Boolean) : TSQLDBRestConnection;
begin
Result:=DoSelectRestConnection(alIst,True,aOptions,aAllTables);
end;
Function SelectRestConnection(aList : TSQLDBRestConnectionList) : TSQLDBRestConnection;
Var
aOptions: TRestFieldOptions;
B : Boolean;
begin
Result:=DoSelectRestConnection(alIst,False,aOptions,B);
end;
{ TSelectRestConnectionForm }
procedure TSelectRestConnectionForm.SetShowOptions(AValue: Boolean);
begin
if FShowOptions=AValue then Exit;
FShowOptions:=AValue;
if Not FShowOptions then
begin
CGFieldOptions.Visible:=False;
RGConnection.Width:=CGFieldOptions.Left+CGFieldOptions.Width;
end;
end;
procedure TSelectRestConnectionForm.Init(aList: TSQLDBRestConnectionList);
Var
I : integer;
begin
For I:=0 to aList.Count-1 do
RGConnection.Items.AddObject(aList[I].Name,aList[i]);
end;
procedure TSelectRestConnectionForm.Init(aList: TStrings);
begin
RGConnection.Items.Assign(aList);
end;
function TSelectRestConnectionForm.SelectedConnection: TSQLDBRestConnection;
begin
With RGConnection do
if ItemIndex=-1 then
Result:=Nil
else
Result:=TSQLDBRestConnection(Items.Objects[ItemIndex]);
end;
function TSelectRestConnectionForm.SelectedOptions: TRestFieldOptions;
Procedure Add(I : integer; V : TRestFieldOption);
begin
if CGFieldOPtions.Checked[I] then
Include(Result,V);
end;
begin
Result:=[];
Add(0,foFilter);
Add(1,foOrderBy);
Add(2,foOrderByDesc);
Add(3,foInInsert);
Add(4,foInUpdate);
Add(5,foRequired);
end;
function TSelectRestConnectionForm.AllTables: Boolean;
begin
Result:=CBAllTables.Checked;
end;
end.
|