File: frafpreportsqldbdata.pp

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (147 lines) | stat: -rw-r--r-- 3,670 bytes parent folder | download | duplicates (6)
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
{
    This file is part of the Free Component Library.
    Copyright (c) 2017 Michael Van Canneyt, member of the Free Pascal development team

    Frame to configure a SQL report data loop.

    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 frafpreportsqldbdata;


interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, EditBtn, StdCtrls, Buttons, ActnList, SynEdit, SynHighlighterSQL,
  fpreportdesignreportdata, fpjson, sqldb, fpreportdatasqldb, dialogs;

type
  TFrame = TReportDataConfigFrame;

  { TSQLReportDataConfigFrame }

  TSQLReportDataConfigFrame = class(TFrame)
    ATest: TAction;
    ALJSON: TActionList;
    AConstruct: TAction;
    EConnection: TEditButton;
    ILJSON: TImageList;
    Label1: TLabel;
    LSQl: TLabel;
    SpeedButton1: TSpeedButton;
    SESQL: TSynEdit;
    SynSQLSyn1: TSynSQLSyn;
    procedure ATestExecute(Sender: TObject);
    procedure EConnectionButtonClick(Sender: TObject);
  private
    FConnectionData: TJSONObject;

  public
    Constructor Create(AOwner : TComponent); override;
    Destructor Destroy; override;
    Procedure GetConfig(aConfig : TJSONObject); override;
    Procedure SetConfig(aConfig : TJSONObject); override;
    Function SaveNotOKMessage : string; override;
    Property ConnectionData : TJSONObject Read FConnectionData;
  end;

  { TSQLDBReportDataHandler }


implementation

uses  frmfpreportdataconnectioneditor;



{$R *.lfm}

{ TSQLReportDataConfigFrame }

procedure TSQLReportDataConfigFrame.EConnectionButtonClick(Sender: TObject);

Var
  F : TReportConnectionEditorForm;

begin
  F:=TReportConnectionEditorForm.Create(Self);
  try
    F.Params:=FConnectionData;
    if F.ShowModal=mrOK then
      begin
      FreeAndNil(FConnectionData);
      FConnectionData:=F.Params.Clone as TJSONObject;
      EConnection.Text:=FConnectionData.AsJSON;
      end;
  finally
    F.Free;
  end;
end;

procedure TSQLReportDataConfigFrame.ATestExecute(Sender: TObject);

Var
  S : String;

begin
  S:=TFPReportConnector.TestConnection(FConnectionData);
  if (S<>'') then
    MessageDlg(SErrConnectionNotOK,S,mtError,[mbOK],0)
  else
    MessageDlg(SSuccess,SConnectionSuccesful,mtInformation,[mbOK],0)
end;

constructor TSQLReportDataConfigFrame.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FConnectionData:=TJSONObject.Create;
end;

destructor TSQLReportDataConfigFrame.Destroy;
begin
  FreeAndNil(FConnectionData);
  inherited Destroy;
end;

procedure TSQLReportDataConfigFrame.GetConfig(aConfig: TJSONObject);

begin
  aConfig.Objects[keyConnection]:=FConnectionData.CLone as TJSONObject;
  aConfig.strings[keySQL]:=SESQL.Text;
end;

procedure TSQLReportDataConfigFrame.SetConfig(aConfig: TJSONObject);

Var
  O : TJSONObject;
begin
  O:=aConfig.Get(keyConnection,TJSONObject(Nil));
  if Assigned(O) then
    begin
    FreeAndNil(FConnectionData);
    FConnectionData:=O.Clone as TJSONObject;
    EConnection.Text:=FConnectionData.asJSON;
    end;
  SESQL.Text:=aConfig.get(keySQL,'');
end;

function TSQLReportDataConfigFrame.SaveNotOKMessage: string;
begin
  if (FConnectionData.Count=0) then
    Result:=SErrNoConnectionData
  else if Trim(SESQL.Text)='' then
    Result:=SErrNoSQL
  else
    Result:=TFPReportConnector.TestConnection(FConnectionData);
end;

initialization
  TSQLDBReportDataHandler.RegisterConfigClass(TSQLReportDataConfigFrame);
end.