diff --git a/ALoader/ALib/MainFRM.dfm b/ALoader/ALib/MainFRM.dfm index 0c9117d..0e42a15 100644 --- a/ALoader/ALib/MainFRM.dfm +++ b/ALoader/ALib/MainFRM.dfm @@ -77,7 +77,7 @@ object frmMain: TfrmMain Height = 21 Anchors = [akTop, akRight] TabOrder = 0 - Text = 'LT0000' + Text = 'LT000005816835' end object btnSubmit: TButton Left = 677 diff --git a/ALoader/ALib/MainFRM.pas b/ALoader/ALib/MainFRM.pas index fcaa606..7223ae8 100644 --- a/ALoader/ALib/MainFRM.pas +++ b/ALoader/ALib/MainFRM.pas @@ -51,6 +51,7 @@ TfrmMain = class(TForm) procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); procedure WB1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant); + function NavigateDetail2(AHTML: String): Boolean; private { Private declarations } @@ -61,10 +62,18 @@ TfrmMain = class(TForm) Function GetData(AUser, APassword, ACompany, ASearchNumber: PChar): Boolean; Export; Procedure Debug(); Export; Function Test(a: PChar): Boolean; Export; -Function ParseHeader(AHTML: String): Boolean; -Function ParseValue(AName, AString: String): String; +Function ParseHeader2(AHTML: String): Boolean; +Function ParseValue2(AName, AString: String): String; function StripHTML(S: string): string; +Const + + URL1 = 'https://www.vic.lt:8102/pls/gris/kl_main.pirmas#'; + URL2 = 'https://www.vic.lt:8102/pls/gris/ataskaitos.gyvulio_judejimo_forma'; + + URLCompare1 = 'https://www.vic.lt:8102/pls/gris/kl_main.pirmas'; + URLCompare2 = 'https://www.vic.lt:8102/pls/gris/ataskaitos'; + var frmMain: TfrmMain; gloUser: String = 'VG0344'; @@ -72,22 +81,25 @@ function StripHTML(S: string): string; gloLivestock: TAnimal; gloHTML: String = ''; gloCount: Integer; + gloCompany: String; + gloSearchNumber: String; implementation Function Test(a: PChar): Boolean; begin Result := True; - //ShowMessage('Test'); + // ShowMessage('Test'); end; Function GetData(AUser, APassword, ACompany, ASearchNumber: PChar): Boolean; begin gloCount := 0; - AUser := StrAlloc(MAX_PATH); - APassword := StrAlloc(MAX_PATH); + // AUser := StrAlloc(MAX_PATH); + // APassword := StrAlloc(MAX_PATH); + // ACompany := StrAlloc(MAX_PATH); + // ASearchNumber := StrAlloc(MAX_PATH); - //ShowMessage('GetData start ' + IntToStr(Length(AUser))); Result := False; if Trim(AUser) <> '' then @@ -96,14 +108,22 @@ implementation if Trim(APassword) <> '' then gloPsw := APassword; + if Trim(ACompany) <> '' then + gloCompany := ACompany; + + if Trim(ASearchNumber) <> '' then + gloSearchNumber := ASearchNumber; + if not assigned(frmMain) then Exit; - frmMain.Get1('LT000005816831'); + // frmMain.Get1('LT000005816831'); + Result := frmMain.Get2(gloSearchNumber); - //ShowMessage('GetData end'); - StrDispose(AUser); - StrDispose(APassword); + // StrDispose(AUser); + // StrDispose(APassword); + // StrDispose(ACompany); + // StrDispose(ASearchNumber); end; Procedure Debug(); @@ -118,35 +138,9 @@ implementation {$R *.dfm} procedure TfrmMain.btnSubmitClick(Sender: TObject); -var - doc: IHTMLDocument2; - ElementCollection: IHTMLElementCollection; - iall: IHTMLElement; - - i: Integer; begin - Get2('LT000006042643'); - - // ShowMessage('before parse'); - -// doc := WB1.Document as IHTMLDocument2; -// -// iall := doc.body; -// -// while iall.parentElement <> nil do -// begin -// iall := iall.parentElement; -// end; - - //ParseHeader(iall.outerHTML); - - // memResult.Lines.Add(iall.outerHTML); - - // // Memo1.Text := iall.outerHTML; - // // - // // ParseHeader(Memo1.Lines); - // - // memResult.Lines.Add(gloLivestock.Number); + if not GetData(PChar(txtUser.Text), PChar(txtpassword.Text), PChar(txtCompany.Text), PChar(txtAnimalNo.Text)) then + MessageDlg('An error occurs ...', mtError, [mbOK], 0); end; procedure TfrmMain.Button1Click(Sender: TObject); @@ -201,7 +195,7 @@ procedure TfrmMain.CheckBox1Click(Sender: TObject); procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction); begin - //ShowMessage('Close'); + // ShowMessage('Close'); end; function TfrmMain.Get1(ANumber: String): Boolean; @@ -283,27 +277,117 @@ function TfrmMain.Get1(ANumber: String): Boolean; function TfrmMain.Get2(ANumber: String): Boolean; begin Result := False; - WB1.Stop; - WB1.GoAboutBlank; - while WB1.ReadyState < READYSTATE_INTERACTIVE do - Application.ProcessMessages; + try - { Open page and wait } - WB1.Navigate('https://www.vic.lt:8102/pls/gris/ataskaitos.gyvulio_judejimo_forma'); - while WB1.ReadyState < READYSTATE_COMPLETE do - Application.ProcessMessages; + WB1.Stop; + WB1.GoAboutBlank; + while WB1.ReadyState < READYSTATE_INTERACTIVE do + Application.ProcessMessages; - { Fill edit with value } - WB1.OleObject.Document.Forms.item(0).elements.item(0).value := ANumber; + { Open page and wait } + WB1.Navigate(URL2); + while WB1.ReadyState < READYSTATE_COMPLETE do + Application.ProcessMessages; + + { Fill edit with value } + WB1.OleObject.Document.Forms.item(0).elements.item(0).value := ANumber; + + { Execute Java Script to submit data } + WB1.ExecScript('document.forma.submit()', 'JavaScript'); + while WB1.ReadyState < READYSTATE_COMPLETE do + Application.ProcessMessages; + + Result := True; + except + + end; +end; + +function TfrmMain.NavigateDetail2(AHTML: String): Boolean; +var + ATableStart, ATableEnd, ATR1, ATR2, AString: String; + APosition, APosition2: Integer; + ATable: TStringList; +begin + Result := False; + + try + + ATable := TStringList.Create; + + if Trim(AHTML) = '' then + Exit; + + ATableStart := ' 0 do + begin + APosition2:= Pos (ATR2, AHTML);//Search } - APosition := POS(b1, AString); + APosition := Pos(b1, AString); if APosition = 0 then Exit; Delete(AString, 1, APosition + Length(b1) - 1); { Find last } - APosition := POS(b2, AString); + APosition := Pos(b2, AString); if APosition = 0 then Exit; @@ -379,34 +463,52 @@ procedure TfrmMain.WB1DocumentComplete(ASender: TObject; const pDisp: IDispatch; Inc(gloCount); if gloCount = 3 then begin - LStream := TStringStream.Create(''); - try - LPersistStreamInit := WB1.Document as IPersistStreamInit; - Stream := TStreamAdapter.Create(LStream, soReference); - LPersistStreamInit.Save(Stream, True); - memResult.Lines.Text := LStream.DataString; - ParseHeader(LStream.DataString); - memResult.Lines.Add(gloLivestock.Number); - finally - LStream.Free(); + { WAY 1 } + if Pos(URLCompare1, ShortString(WB1.LocationURL)) > 0 then + begin + // Not implemented end; + { WAY 2 } + if Pos(URLCompare2, ShortString(WB1.LocationURL)) > 0 then + begin + LStream := TStringStream.Create(''); + try + LPersistStreamInit := WB1.Document as IPersistStreamInit; + Stream := TStreamAdapter.Create(LStream, soReference); + LPersistStreamInit.Save(Stream, True); + memResult.Lines.Text := LStream.DataString; + ParseHeader2(LStream.DataString); + + memResult.Lines.Add(gloLivestock.Number); + memResult.Lines.Add(gloLivestock.Species); + memResult.Lines.Add(gloLivestock.Gender); + memResult.Lines.Add(gloLivestock.Breed); + memResult.Lines.Add(gloLivestock.DateOfBirth); + memResult.Lines.Add(gloLivestock.MotherNumber); + memResult.Lines.Add(gloLivestock.Passport); + + NavigateDetail2(LStream.DataString); + + finally + LStream.Free(); + end; + end; end; - end; function StripHTML(S: string): string; var TagBegin, TagEnd, TagLength: Integer; begin - TagBegin := POS('<', S); // search position of first < + TagBegin := Pos('<', S); // search position of first < while (TagBegin > 0) do begin // while there is a < in S - TagEnd := POS('>', S); // find the matching > + TagEnd := Pos('>', S); // find the matching > TagLength := TagEnd - TagBegin + 1; Delete(S, TagBegin, TagLength); // delete the tag - TagBegin := POS('<', S); // search for next < + TagBegin := Pos('<', S); // search for next < end; Result := S; // give the result diff --git a/ALoader/ALib/Win32/Debug/ALib.dll b/ALoader/ALib/Win32/Debug/ALib.dll index 8c0fdb6..744c620 100644 Binary files a/ALoader/ALib/Win32/Debug/ALib.dll and b/ALoader/ALib/Win32/Debug/ALib.dll differ diff --git a/ALoader/ALib/Win32/Debug/MainFRM.dcu b/ALoader/ALib/Win32/Debug/MainFRM.dcu index 34daf49..c47d49f 100644 Binary files a/ALoader/ALib/Win32/Debug/MainFRM.dcu and b/ALoader/ALib/Win32/Debug/MainFRM.dcu differ diff --git a/ALoader/ALib/Win32/Debug/Veikia/ALib.dll b/ALoader/ALib/Win32/Debug/Veikia/ALib.dll new file mode 100644 index 0000000..0c98441 Binary files /dev/null and b/ALoader/ALib/Win32/Debug/Veikia/ALib.dll differ diff --git a/ALoader/ALib/Win32/Debug/Veikia2/ALib.dll b/ALoader/ALib/Win32/Debug/Veikia2/ALib.dll new file mode 100644 index 0000000..026c03e Binary files /dev/null and b/ALoader/ALib/Win32/Debug/Veikia2/ALib.dll differ diff --git a/ALoader/ALib/Win32/Debug/Veikia3/ALib.dll b/ALoader/ALib/Win32/Debug/Veikia3/ALib.dll new file mode 100644 index 0000000..8c0fdb6 Binary files /dev/null and b/ALoader/ALib/Win32/Debug/Veikia3/ALib.dll differ