diff --git a/MBTest.cfg b/MBTest.cfg new file mode 100644 index 0000000..9e01afb --- /dev/null +++ b/MBTest.cfg @@ -0,0 +1,42 @@ +-$A8 +-$B- +-$C+ +-$D+ +-$E- +-$F- +-$G+ +-$H+ +-$I+ +-$J- +-$K- +-$L+ +-$M- +-$N+ +-$O+ +-$P+ +-$Q- +-$R- +-$S- +-$T- +-$U- +-$V+ +-$W- +-$X+ +-$YD +-$Z1 +-cg +-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +-H+ +-W+ +-M +-$M16384,1048576 +-K$00400000 +-LE"c:\program files (x86)\borland\delphi7\Projects\Bpl" +-LN"c:\program files (x86)\borland\delphi7\Projects\Bpl" +-U"E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\component;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\core;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\dbc;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\parsesql;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\plain" +-O"E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\component;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\core;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\dbc;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\parsesql;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\plain" +-I"E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\component;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\core;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\dbc;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\parsesql;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\plain" +-R"E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\component;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\core;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\dbc;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\parsesql;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\plain" +-w-UNSAFE_TYPE +-w-UNSAFE_CODE +-w-UNSAFE_CAST diff --git a/MBTest.dof b/MBTest.dof new file mode 100644 index 0000000..55e39f2 --- /dev/null +++ b/MBTest.dof @@ -0,0 +1,136 @@ +[FileVersion] +Version=7.0 +[Compiler] +A=8 +B=0 +C=1 +D=1 +E=0 +F=0 +G=1 +H=1 +I=1 +J=0 +K=0 +L=1 +M=0 +N=1 +O=1 +P=1 +Q=0 +R=0 +S=0 +T=0 +U=0 +V=1 +W=0 +X=1 +Y=1 +Z=1 +ShowHints=1 +ShowWarnings=1 +UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +NamespacePrefix= +SymbolDeprecated=1 +SymbolLibrary=1 +SymbolPlatform=1 +UnitLibrary=1 +UnitPlatform=1 +UnitDeprecated=1 +HResultCompat=1 +HidingMember=1 +HiddenVirtual=1 +Garbage=1 +BoundsError=1 +ZeroNilCompat=1 +StringConstTruncated=1 +ForLoopVarVarPar=1 +TypedConstVarPar=1 +AsgToTypedConst=1 +CaseLabelRange=1 +ForVariable=1 +ConstructingAbstract=1 +ComparisonFalse=1 +ComparisonTrue=1 +ComparingSignedUnsigned=1 +CombiningSignedUnsigned=1 +UnsupportedConstruct=1 +FileOpen=1 +FileOpenUnitSrc=1 +BadGlobalSymbol=1 +DuplicateConstructorDestructor=1 +InvalidDirective=1 +PackageNoLink=1 +PackageThreadVar=1 +ImplicitImport=1 +HPPEMITIgnored=1 +NoRetVal=1 +UseBeforeDef=1 +ForLoopVarUndef=1 +UnitNameMismatch=1 +NoCFGFileFound=1 +MessageDirective=1 +ImplicitVariants=1 +UnicodeToLocale=1 +LocaleToUnicode=1 +ImagebaseMultiple=1 +SuspiciousTypecast=1 +PrivatePropAccessor=1 +UnsafeType=0 +UnsafeCode=0 +UnsafeCast=0 +[Linker] +MapFile=0 +OutputObjs=0 +ConsoleApp=1 +DebugInfo=0 +RemoteSymbols=0 +MinStackSize=16384 +MaxStackSize=1048576 +ImageBase=4194304 +ExeDescription= +[Directories] +OutputDir= +UnitOutputDir= +PackageDLLOutputDir= +PackageDCPOutputDir= +SearchPath=E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\component;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\core;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\dbc;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\parsesql;E:\Delphi 7 Projekti\Komponente\zeosdbo-6.1.5-stable\src\plain +Packages=vcl;rtl;vclx;indy;inet;xmlrtl;vclie;inetdbbde;inetdbxpress;dbrtl;dsnap;dsnapcon;vcldb;soaprtl;VclSmp;dbexpress;dbxcds;inetdb;bdertl;vcldbx;webdsnap;websnap;adortl;ibxpress;teeui;teedb;tee;dss;visualclx;visualdbclx;vclactnband;vclshlctrls;IntrawebDB_50_70;Intraweb_50_70;Rave50CLX;Rave50VCL;dclOfficeXP;JVCL200_R70;qrpt;ZCore;ZComponent;ZParseSql;ZDbc;ZPlain;Xi;SerialNGD70;FiskalniPrinter;QRExportFilterD70;O406_r70;RoomD7;GifImageD70;cChangeFocus;FlatStyle_D6;dxPack2D7;DBZRCtrlGridPckg;CurrencyPackage;CryptoPackage;ComboMatchD70;ColorDBGridD70;teeqr;ShockWaveFlash70;vrControlBarD70;KeyboardD70;ExPackD70;SMCmpntD7;BarcodeD7;vlcplugin;DJCL70;VirtualTreesD7 +Conditionals= +DebugSourceDirs= +UsePackages=0 +[Parameters] +RunParams= +HostApplication= +Launcher= +UseLauncher=0 +DebugCWD= +[Language] +ActiveLang= +ProjectLang= +RootDir=C:\Program Files (x86)\Borland\Delphi7\Bin\ +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=9242 +CodePage=1250 +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= diff --git a/MBTest.dpr b/MBTest.dpr new file mode 100644 index 0000000..75345fb --- /dev/null +++ b/MBTest.dpr @@ -0,0 +1,14 @@ +program MBTest; + +uses + Forms, + unMain in 'unMain.pas' {Form1}, + unNBS in 'unNBS.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. diff --git a/MBTest.exe b/MBTest.exe new file mode 100644 index 0000000..84f73cb Binary files /dev/null and b/MBTest.exe differ diff --git a/MBTest.res b/MBTest.res new file mode 100644 index 0000000..6044f58 Binary files /dev/null and b/MBTest.res differ diff --git a/MBTest.~dpr b/MBTest.~dpr new file mode 100644 index 0000000..bc10377 --- /dev/null +++ b/MBTest.~dpr @@ -0,0 +1,13 @@ +program MBTest; + +uses + Forms, + unMain in 'unMain.pas' {Form1}; + +{$R *.res} + +begin + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. diff --git a/unMain.dcu b/unMain.dcu new file mode 100644 index 0000000..98bb85c Binary files /dev/null and b/unMain.dcu differ diff --git a/unMain.dfm b/unMain.dfm new file mode 100644 index 0000000..3deb0fa --- /dev/null +++ b/unMain.dfm @@ -0,0 +1,170 @@ +object Form1: TForm1 + Left = 526 + Top = 157 + Width = 529 + Height = 280 + Caption = 'NBS Pretraga' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -13 + Font.Name = 'Arial' + Font.Style = [] + OldCreateOrder = False + PixelsPerInch = 96 + TextHeight = 16 + object Label1: TLabel + Left = 8 + Top = 36 + Width = 35 + Height = 16 + Caption = 'Naziv:' + end + object Label2: TLabel + Left = 8 + Top = 60 + Width = 45 + Height = 16 + Caption = 'Adresa:' + end + object Label3: TLabel + Left = 8 + Top = 84 + Width = 41 + Height = 16 + Caption = 'Ra'#269'un:' + end + object Label4: TLabel + Left = 8 + Top = 108 + Width = 40 + Height = 16 + Caption = 'Mesto:' + end + object Label5: TLabel + Left = 8 + Top = 132 + Width = 42 + Height = 16 + Caption = 'Status:' + end + object Label6: TLabel + Left = 8 + Top = 156 + Width = 49 + Height = 16 + Caption = 'Op'#353'tina:' + end + object Label7: TLabel + Left = 8 + Top = 180 + Width = 59 + Height = 16 + Caption = 'Delatnost:' + end + object Label8: TLabel + Left = 8 + Top = 204 + Width = 25 + Height = 16 + Caption = 'PIB:' + end + object Label9: TLabel + Left = 8 + Top = 12 + Width = 24 + Height = 16 + Caption = 'MB:' + end + object Button1: TButton + Left = 296 + Top = 8 + Width = 75 + Height = 25 + Caption = 'Tra'#382'i' + Default = True + TabOrder = 0 + OnClick = Button1Click + end + object txtNaziv: TEdit + Left = 80 + Top = 32 + Width = 401 + Height = 24 + TabOrder = 1 + end + object txtAdresa: TEdit + Left = 80 + Top = 56 + Width = 401 + Height = 24 + TabOrder = 2 + end + object txtRacun: TEdit + Left = 80 + Top = 80 + Width = 401 + Height = 24 + TabOrder = 3 + end + object txtMesto: TEdit + Left = 80 + Top = 104 + Width = 401 + Height = 24 + TabOrder = 4 + end + object txtStatus: TEdit + Left = 80 + Top = 128 + Width = 401 + Height = 24 + TabOrder = 5 + end + object txtOpstina: TEdit + Left = 80 + Top = 152 + Width = 401 + Height = 24 + TabOrder = 6 + end + object txtDelatnost: TEdit + Left = 80 + Top = 176 + Width = 401 + Height = 24 + TabOrder = 7 + end + object txtPIB: TEdit + Left = 80 + Top = 200 + Width = 200 + Height = 24 + TabOrder = 8 + end + object txtMB: TEdit + Left = 80 + Top = 8 + Width = 200 + Height = 24 + TabOrder = 9 + Text = '20175095' + end + object IdHTTP1: TIdHTTP + MaxLineAction = maException + ReadTimeout = 0 + AllowCookies = True + ProxyParams.BasicAuthentication = False + ProxyParams.ProxyPort = 0 + Request.ContentLength = -1 + Request.ContentRangeEnd = 0 + Request.ContentRangeStart = 0 + Request.ContentType = 'text/html' + Request.Accept = 'text/html, */*' + Request.BasicAuthentication = False + Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)' + HTTPOptions = [hoForceEncodeParams] + Left = 656 + Top = 48 + end +end diff --git a/unMain.pas b/unMain.pas new file mode 100644 index 0000000..6452bb8 --- /dev/null +++ b/unMain.pas @@ -0,0 +1,214 @@ +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; + 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. diff --git a/unMain.~dfm b/unMain.~dfm new file mode 100644 index 0000000..609288e --- /dev/null +++ b/unMain.~dfm @@ -0,0 +1,180 @@ +object Form1: TForm1 + Left = 526 + Top = 157 + Width = 529 + Height = 716 + Caption = 'NBS Pretraga' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -13 + Font.Name = 'Arial' + Font.Style = [] + OldCreateOrder = False + PixelsPerInch = 96 + TextHeight = 16 + object Label1: TLabel + Left = 8 + Top = 36 + Width = 35 + Height = 16 + Caption = 'Naziv:' + end + object Label2: TLabel + Left = 8 + Top = 60 + Width = 45 + Height = 16 + Caption = 'Adresa:' + end + object Label3: TLabel + Left = 8 + Top = 84 + Width = 41 + Height = 16 + Caption = 'Ra'#269'un:' + end + object Label4: TLabel + Left = 8 + Top = 108 + Width = 40 + Height = 16 + Caption = 'Mesto:' + end + object Label5: TLabel + Left = 8 + Top = 132 + Width = 42 + Height = 16 + Caption = 'Status:' + end + object Label6: TLabel + Left = 8 + Top = 156 + Width = 49 + Height = 16 + Caption = 'Op'#353'tina:' + end + object Label7: TLabel + Left = 8 + Top = 180 + Width = 59 + Height = 16 + Caption = 'Delatnost:' + end + object Label8: TLabel + Left = 8 + Top = 204 + Width = 25 + Height = 16 + Caption = 'PIB:' + end + object Label9: TLabel + Left = 8 + Top = 12 + Width = 24 + Height = 16 + Caption = 'MB:' + end + object Button1: TButton + Left = 296 + Top = 8 + Width = 75 + Height = 25 + Caption = 'Tra'#382'i' + Default = True + TabOrder = 0 + OnClick = Button1Click + end + object Memo1: TMemo + Left = 8 + Top = 232 + Width = 481 + Height = 425 + Lines.Strings = ( + 'Memo1') + ScrollBars = ssBoth + TabOrder = 1 + end + object txtNaziv: TEdit + Left = 80 + Top = 32 + Width = 401 + Height = 24 + TabOrder = 2 + end + object txtAdresa: TEdit + Left = 80 + Top = 56 + Width = 401 + Height = 24 + TabOrder = 3 + end + object txtRacun: TEdit + Left = 80 + Top = 80 + Width = 401 + Height = 24 + TabOrder = 4 + end + object txtMesto: TEdit + Left = 80 + Top = 104 + Width = 401 + Height = 24 + TabOrder = 5 + end + object txtStatus: TEdit + Left = 80 + Top = 128 + Width = 401 + Height = 24 + TabOrder = 6 + end + object txtOpstina: TEdit + Left = 80 + Top = 152 + Width = 401 + Height = 24 + TabOrder = 7 + end + object txtDelatnost: TEdit + Left = 80 + Top = 176 + Width = 401 + Height = 24 + TabOrder = 8 + end + object txtPIB: TEdit + Left = 80 + Top = 200 + Width = 200 + Height = 24 + TabOrder = 9 + end + object txtMB: TEdit + Left = 80 + Top = 8 + Width = 200 + Height = 24 + TabOrder = 10 + Text = '20175095' + end + object IdHTTP1: TIdHTTP + MaxLineAction = maException + ReadTimeout = 0 + AllowCookies = True + ProxyParams.BasicAuthentication = False + ProxyParams.ProxyPort = 0 + Request.ContentLength = -1 + Request.ContentRangeEnd = 0 + Request.ContentRangeStart = 0 + Request.ContentType = 'text/html' + Request.Accept = 'text/html, */*' + Request.BasicAuthentication = False + Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)' + HTTPOptions = [hoForceEncodeParams] + Left = 656 + Top = 48 + end +end diff --git a/unMain.~pas b/unMain.~pas new file mode 100644 index 0000000..d89efb7 --- /dev/null +++ b/unMain.~pas @@ -0,0 +1,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. diff --git a/unNBS.dcu b/unNBS.dcu new file mode 100644 index 0000000..f9bb37a Binary files /dev/null and b/unNBS.dcu differ diff --git a/unNBS.pas b/unNBS.pas new file mode 100644 index 0000000..c831436 --- /dev/null +++ b/unNBS.pas @@ -0,0 +1,149 @@ +unit unNBS; + +interface + +uses Classes, SysUtils, Variants, ActiveX, + MSHTML, IdHTTP; + +type + + TNBSPodaci = record + naziv: String; + adresa: String; + racun: String; + mesto: String; + status: String; + opstina: String; + delatnost: String; + pib: String; + end; + +function NBSPretraga(maticniBroj: String): TNBSPodaci; + +implementation + +function NasaSlova(tekst: String): String; +begin + Result := StringReplace(tekst, 'č', '', [rfReplaceAll]); + Result := StringReplace(Result, ' ', '', [rfReplaceAll]); + Result := StringReplace(Result, 'ž', '', [rfReplaceAll]); + Result := StringReplace(Result, '', '', [rfReplaceAll]); +end; + +function 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; + +procedure 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 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 ExtractMunicipality(htmlTR: IHTMLElement; + var municipality: String); +begin + municipality := (IHtmlElementCollection(htmlTR.children).item(1, EmptyParam) as IHTMLElement).innerHTML; + municipality := NasaSlova(municipality); +end; + +procedure 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; + +function NBSPretraga(maticniBroj: String): TNBSPodaci; +var lParamList: TStringList; + lHTTP: TIdHTTP; + Doc: IHTMLDocument2; + V: OleVariant; + i: Integer; + j: Integer; + htmlElement: IHTMLElement; + htmlForm: IHTMLElement; + htmlA: IHTMLElement; + htmlTableBody: IHTMLElement; +begin + lParamList := TStringList.Create; + lParamList.Add('sifban='); + lParamList.Add('partija='); + lParamList.Add('kontbr='); + lParamList.Add('matbr=' + maticniBroj); + 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 + Doc := coHTMLDocument.Create as IHTMLDocument2; // create IHTMLDocument2 instance + V := VarArrayCreate([0,0], varVariant); + V[0] := lHTTP.Post('http://www.nbs.rs/rir_pn/pn_rir.html.jsp?type=rir_results&lang=SER_CIR&konverzija=yes', lParamList); + 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'); + Result.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, Result.adresa, Result.racun); + if j = 3 then ExtractCityAndStatus(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, Result.mesto, Result.status); + if j = 4 then ExtractMunicipality(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, Result.opstina); + if j = 5 then ExtractDelatnostAndPib(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, Result.delatnost, Result.pib); + end; + end; + end; + finally + lHTTP.Free; + lParamList.Free; + end; +end; + +end. diff --git a/unNBS.~pas b/unNBS.~pas new file mode 100644 index 0000000..2d04d1f --- /dev/null +++ b/unNBS.~pas @@ -0,0 +1,149 @@ +unit unNBS; + +interface + +uses Classes, SysUtils, Variants, ActiveX, + MSHTML, IdHTTP; + +type + + TNBSPodaci = record + naziv: String; + adresa: String; + racun: String; + mesto: String; + status: String; + opstina: String; + delatnost: String; + pib: String; + end; + +function NBSPretraga(maticniBroj: String): TNBSPodaci; + +implementation + +function NasaSlova(tekst: String): String; +begin + Result := StringReplace(tekst, 'č', '', [rfReplaceAll]); + Result := StringReplace(tekst, ' ', '', [rfReplaceAll]); + Result := StringReplace(Result, 'ž', '', [rfReplaceAll]); + Result := StringReplace(Result, '', '', [rfReplaceAll]); +end; + +function 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; + +procedure 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 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 ExtractMunicipality(htmlTR: IHTMLElement; + var municipality: String); +begin + municipality := (IHtmlElementCollection(htmlTR.children).item(1, EmptyParam) as IHTMLElement).innerHTML; + municipality := NasaSlova(municipality); +end; + +procedure 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; + +function NBSPretraga(maticniBroj: String): TNBSPodaci; +var lParamList: TStringList; + lHTTP: TIdHTTP; + Doc: IHTMLDocument2; + V: OleVariant; + i: Integer; + j: Integer; + htmlElement: IHTMLElement; + htmlForm: IHTMLElement; + htmlA: IHTMLElement; + htmlTableBody: IHTMLElement; +begin + lParamList := TStringList.Create; + lParamList.Add('sifban='); + lParamList.Add('partija='); + lParamList.Add('kontbr='); + lParamList.Add('matbr=' + maticniBroj); + 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 + Doc := coHTMLDocument.Create as IHTMLDocument2; // create IHTMLDocument2 instance + V := VarArrayCreate([0,0], varVariant); + V[0] := lHTTP.Post('http://www.nbs.rs/rir_pn/pn_rir.html.jsp?type=rir_results&lang=SER_CIR&konverzija=yes', lParamList); + 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'); + Result.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, Result.adresa, Result.racun); + if j = 3 then ExtractCityAndStatus(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, Result.mesto, Result.status); + if j = 4 then ExtractMunicipality(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, Result.opstina); + if j = 5 then ExtractDelatnostAndPib(IHtmlElementCollection(htmlTableBody.children).item(j, EmptyParam) as IHTMLElement, Result.delatnost, Result.pib); + end; + end; + end; + finally + lHTTP.Free; + lParamList.Free; + end; +end; + +end.