uses
System.Variants, XMLDoc, XMLIntf,
ActiveX;
procedure TThreadAutoimport.LoadXmlFile(Datei:
String);
var
XmlDocument: IXMLDocument;
NodeList: IXMLNodeList;
MyNode: IXMLNode;
i: Integer;
s:
String;
d: double;
Auftragsnummer, Abgabemenge: Integer;
FS: TFormatSettings;
begin
CoInitialize(
nil);
FS.DecimalSeparator := '
.';
XmlDocument := XMLDoc.LoadXMLDocument(Datei);
try
XmlDocument.Options := [doNodeAutoIndent];
XmlDocument.Encoding := '
UTF-8';
XmlDocument.Active := true;
NodeList := XmlDocument.DocumentElement.ChildNodes;
for i := 0
to NodeList.Count - 1
do
begin
if NodeList.Nodes[i].NodeName = '
Orderlist'
then
begin
if NodeList.Nodes[i].ChildValues['
Ordernumber'] <> NULL
then
begin
s := NodeList.Nodes[i].ChildValues['
Ordernumber'];
Auftragsnummer := StrToIntDef(s, -1);
if Auftragsnummer <> -1
then
begin
d := 0;
// default
MyNode := NodeList.Nodes[i].ChildNodes.FindNode('
Product');
if MyNode <>
nil then
begin
if MyNode.ChildValues['
Quantity'] <> NULL
then
begin
s := MyNode.ChildValues['
Quantity'];
d := StrToFloatDef(s, 0, FS) * 1000;
end;
end;
Abgabemenge := trunc(d);
SaveOrderData(Auftragsnummer, '
', 0, 0, 0, Abgabemenge, 0);
end;
end;
end;
end;
except
on E:
Exception do
TextMessage := E.
Message;
end;
CoUninitialize;
end;
function Fill(Value:
string; NewLenght: Integer; Character: Char):
string;
begin
result := StringOfChar(Character, NewLenght - length(Value)) + Value;
end;
procedure TThreadAutoimport.SaveOrderData(Auftragsnummer: Int64;
Registration:
String; Position, Workshop, Produkt, Abgabemenge,
Abgegeben: Integer);
var
KeyValue:
String;
q: Uni.TUniQuery;
begin
KeyValue := Fill(IntToStr(Auftragsnummer), 20, '
0') +
Fill(IntToStr(Position), 5, '
0');
q := TUniQuery.Create(
nil);
try
q.Connection := Datenmodul.UniConnection;
q.Transaction := Datenmodul.UniTransaction;
q.SQL.Clear;
q.SQL.Add('
INSERT INTO orderdata');
q.SQL.Add(
'
(order_id, ordernumber, orderposition, registration_number, workshop, productquality, order_volume, delivery_volume, date_time)');
q.SQL.Add(
'
VALUES (:order_id, :ordernumber, :orderposition, :registration_number, :workshop, :productquality, :order_volume, :delivery_volume, :date_time)');
q.SQL.Add('
ON DUPLICATE KEY UPDATE');
q.SQL.Add('
order_id = :order_id,');
q.SQL.Add('
ordernumber = :ordernumber,');
q.SQL.Add('
orderposition = :orderposition,');
q.SQL.Add('
registration_number = :registration_number,');
q.SQL.Add('
workshop = :workshop,');
q.SQL.Add('
productquality = :productquality,');
q.SQL.Add('
order_volume = :order_volume,');
q.SQL.Add('
delivery_volume = :delivery_volume,');
q.SQL.Add('
date_time = :date_time');
q.ParamByName('
order_id').AsString := KeyValue;
q.ParamByName('
ordernumber').AsString := IntToStr(Auftragsnummer);
q.ParamByName('
orderposition').AsInteger := Position;
q.ParamByName('
registration_number').AsString := Registration;
q.ParamByName('
workshop').AsInteger := Workshop;
q.ParamByName('
productquality').AsInteger := Produkt;
q.ParamByName('
order_volume').AsFloat := Abgabemenge;
q.ParamByName('
delivery_volume').AsFloat := Abgegeben;
q.ParamByName('
date_time').AsDateTime := now;
q.ExecSQL;
q.Close;
finally
q.Free;
end;
sleep(100);
// ???
end;