-
Notifications
You must be signed in to change notification settings - Fork 0
/
unMain.~pas
215 lines (192 loc) · 6.97 KB
/
unMain.~pas
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
unit unMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, xmldom, XMLIntf, msxmldom, XMLDoc,
MSHTML, ActiveX;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
txtNaziv: TEdit;
Label1: TLabel;
txtAdresa: TEdit;
txtRacun: TEdit;
txtMesto: TEdit;
txtStatus: TEdit;
txtOpstina: TEdit;
txtDelatnost: TEdit;
txtPIB: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
txtMB: TEdit;
Label9: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function findChildByTagName(node: IHTMLElement; tagName: String): IHTMLElement;
procedure ExtractAddressAndAccount(htmlTR: IHTMLElement; var address: String; var account: String);
procedure ExtractCityAndStatus(htmlTR: IHTMLElement; var city: String; var status: String);
procedure ExtractMunicipality(htmlTR: IHTMLElement; var municipality: String);
procedure ExtractDelatnostAndPib(htmlTR: IHTMLElement; var delatnost: String; var pib: String);
function NasaSlova(tekst: String): String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unNBS;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
lHTTP: TIdHTTP;
lParamList: TStringList;
Cache: string;
V: OleVariant;
Doc: IHTMLDocument2;
htmlElement: IHTMLElement;
htmlTableBody: IHTMLElement;
htmlForm: IHTMLElement;
htmlA: IHTMLElement;
i: Integer;
j: Integer;
naziv: String;
adresa: String;
racun: String;
mesto: String;
status: String;
opstina: String;
delatnost: String;
pib: String;
NBSPodaci: TNBSPodaci;
begin
NBSPodaci := NBSPretraga(txtMB.Text);
txtNaziv.Text := NBSPodaci.naziv;
txtAdresa.Text := NBSPodaci.adresa;
txtRacun.Text := NBSPodaci.racun;
txtMesto.Text := NBSPodaci.mesto;
txtStatus.Text := NBSPodaci.status;
txtOpstina.Text := NBSPodaci.opstina;
txtDelatnost.Text := NBSPodaci.delatnost;
txtPIB.Text := NBSPodaci.pib;
{
lParamList := TStringList.Create;
lParamList.Add('sifban=');
lParamList.Add('partija=');
lParamList.Add('kontbr=');
lParamList.Add('matbr=' + txtMB.Text);
lParamList.Add('pib=');
lParamList.Add('korisnik=');
lParamList.Add('mesto=');
lParamList.Add('tip_racuna=1');
lParamList.Add('rezident=1');
lParamList.Add('Submit=Pretra%C5%BEi');
lHTTP := TIdHTTP.Create(nil);
lHTTP.Request.CustomHeaders.Add('Content-Type=application/x-www-form-urlencoded');
try
Memo1.Text := lHTTP.Post('http://www.nbs.rs/rir_pn/pn_rir.html.jsp?type=rir_results&lang=SER_CIR&konverzija=yes', lParamList);
Doc := coHTMLDocument.Create as IHTMLDocument2; // create IHTMLDocument2 instance
V := VarArrayCreate([0,0], varVariant);
V[0] := Memo1.Text;
Doc.Write(PSafeArray(TVarData(v).VArray)); // write data from IdHTTP
for i := 0 to Doc.all.length - 1 do
begin
htmlElement := Doc.all.item(i, EmptyParam) as IHTMLElement;
if htmlElement.getAttribute('id',0) = 'result' then
begin
htmlForm := findChildByTagName(htmlElement, 'form');
if htmlForm <> nil then
begin
htmlA := findChildByTagName(htmlForm, 'a');
naziv := NasaSlova(htmlA.innerHTML);
end;
htmlTableBody := IHtmlElementCollection(htmlElement.children).item(0, EmptyParam) as IHTMLElement;
for j := 0 to IHtmlElementCollection(htmlTableBody.children).length - 1 do
begin
if j = 2 then ExtractAddressAndAccount(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, adresa, racun);
if j = 3 then ExtractCityAndStatus(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, mesto, status);
if j = 4 then ExtractMunicipality(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, opstina);
if j = 5 then ExtractDelatnostAndPib(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, delatnost, pib);
end;
end;
end;
txtNaziv.Text := naziv;
txtAdresa.Text := adresa;
txtRacun.Text := racun;
txtMesto.Text := mesto;
txtStatus.Text := status;
txtOpstina.Text := opstina;
txtDelatnost.Text := StringReplace(delatnost, 'Ä', 'è', [rfReplaceAll]);
txtPIB.Text := pib;
finally
lHTTP.Free;
lParamList.Free;
end;
}
end;
procedure TForm1.ExtractAddressAndAccount(htmlTR: IHTMLElement;
var address, account: String);
begin
address := (IHtmlElementCollection(htmlTR.children).item(1, EmptyParam) as IHTMLElement).innerHTML;
account := (IHtmlElementCollection( (IHtmlElementCollection(htmlTR.children).item(3, EmptyParam) as IHTMLElement).children).item(0, EmptyParam) as IHTMLElement).innerHTML;
address := NasaSlova(address);
account := NasaSlova(account);
end;
procedure TForm1.ExtractCityAndStatus(htmlTR: IHTMLElement; var city,
status: String);
begin
city := (IHtmlElementCollection(htmlTR.children).item(1, EmptyParam) as IHTMLElement).innerHTML;
status := (IHtmlElementCollection((IHtmlElementCollection((IHtmlElementCollection(htmlTR.children).item(3, EmptyParam) as IHTMLElement).children).item(1, EmptyParam) as IHTMLElement).children).item(0, EmptyParam) as IHTMLElement).innerHTML;
city := NasaSlova(city);
status := NasaSlova(status);
end;
procedure TForm1.ExtractDelatnostAndPib(htmlTR: IHTMLElement;
var delatnost, pib: String);
begin
delatnost := (IHtmlElementCollection(htmlTR.children).item(1, EmptyParam) as IHTMLElement).innerHTML;
pib := (IHtmlElementCollection(htmlTR.children).item(3, EmptyParam) as IHTMLElement).innerHTML;
delatnost := NasaSlova(delatnost);
pib := NasaSlova(pib);
end;
procedure TForm1.ExtractMunicipality(htmlTR: IHTMLElement;
var municipality: String);
begin
municipality := (IHtmlElementCollection(htmlTR.children).item(1, EmptyParam) as IHTMLElement).innerHTML;
municipality := NasaSlova(municipality);
end;
function TForm1.findChildByTagName(node: IHTMLElement; tagName: String): IHTMLElement;
var i: Integer;
htmlElement: IHTMLElement;
begin
if node = nil then
Result := nil
else
begin
if node.tagName = UpperCase(tagName) then
Result := node
else
for i := 0 to IHtmlElementCollection(node.children).length - 1 do
begin
htmlElement := IHtmlElementCollection(node.children).item(i, EmptyParam) as IHTMLElement;
Result := findChildByTagName(htmlElement, tagName);
if Result <> nil then
Exit;
end;
end;
end;
function TForm1.NasaSlova(tekst: String): String;
begin
Result := StringReplace(tekst, 'Ä', 'è', [rfReplaceAll]);
Result := StringReplace(tekst, ' ', '', [rfReplaceAll]);
Result := StringReplace(Result, 'ž', 'ž', [rfReplaceAll]);
Result := StringReplace(Result, 'Å', 'Š', [rfReplaceAll]);
end;
end.