|
|
unit u_op_seae_edi_CSSA;
|
|
|
|
|
|
interface
|
|
|
|
|
|
uses
|
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
|
Dialogs, bsSkinCtrls, StdCtrls, ExtCtrls, DB, ADODB,XMLDoc, XMLIntf,
|
|
|
xmldom, msxmldom, IdBaseComponent, IdComponent, IdTCPConnection,
|
|
|
IdTCPClient, IdHTTP, IdCoder, IdCoder3to4, IdCoderMIME,DateUtils,EncdDecd,Httpapp,
|
|
|
IdHashMessageDigest,IdGlobal, IdHash,U_md5;
|
|
|
|
|
|
type
|
|
|
TFrm_op_seae_edi_CSSA = class(TForm)
|
|
|
Label1: TLabel;
|
|
|
Edit1: TEdit;
|
|
|
RadioGroup1: TRadioGroup;
|
|
|
bsSkinButton2: TbsSkinButton;
|
|
|
bsSkinButton1: TbsSkinButton;
|
|
|
bsSkinButton4: TbsSkinButton;
|
|
|
t_op_ctn: TADOQuery;
|
|
|
t_sys_company: TADOQuery;
|
|
|
XMLDocument1: TXMLDocument;
|
|
|
SaveDialog1: TSaveDialog;
|
|
|
IdHTTP1: TIdHTTP;
|
|
|
IdEncoderMIME1: TIdEncoderMIME;
|
|
|
Label2: TLabel;
|
|
|
Edit2: TEdit;
|
|
|
CheckBox1: TCheckBox;
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
procedure bsSkinButton1Click(Sender: TObject);
|
|
|
procedure bsSkinButton2Click(Sender: TObject);
|
|
|
procedure bsSkinButton4Click(Sender: TObject);
|
|
|
|
|
|
private
|
|
|
{ Private declarations }
|
|
|
function CheckParaExist(para:string):Boolean;
|
|
|
function CheckSendorCode:Boolean;
|
|
|
function IsZhongwen(Str: String): Boolean;
|
|
|
function SeparateEC(Str: String): string;
|
|
|
procedure MakeVGM;
|
|
|
function GetShipVGM(Ship:String): String;
|
|
|
function GetShipFTP(Ship:String): String;
|
|
|
function Changestr(str:widestring):string;
|
|
|
procedure SendFile;
|
|
|
public
|
|
|
{ Public declarations }
|
|
|
end;
|
|
|
|
|
|
var
|
|
|
Frm_op_seae_edi_CSSA: TFrm_op_seae_edi_CSSA;
|
|
|
|
|
|
implementation
|
|
|
uses u_op_seae, my_sys_function, u_main, u_data_share, u_op_seae_assistant;
|
|
|
{$R *.dfm}
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.CheckParaExist(para:string):Boolean;
|
|
|
begin
|
|
|
Result:=False;
|
|
|
if Trim(para)<>'' then Result:=True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
//获取时间戳 java里的时间是从1970年1月1日0点到当前的间隔
|
|
|
function GetJavaTime( d: TDateTime ): Int64;
|
|
|
var
|
|
|
dJavaStart: TDateTime;
|
|
|
begin
|
|
|
dJavaStart := EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 );
|
|
|
Result := MilliSecondsBetween( d, dJavaStart );
|
|
|
end;
|
|
|
|
|
|
//读取XML文件节点信息 不加任何回车换行
|
|
|
function ReadXml(node: IXMLNode): string;
|
|
|
var
|
|
|
nodeList,attrList: IXMLNodeList;
|
|
|
str,strName,strValue: string;
|
|
|
i: Integer;
|
|
|
|
|
|
begin
|
|
|
Result := '';
|
|
|
if not node.HasChildNodes then Exit;
|
|
|
|
|
|
attrList := node.AttributeNodes; {根节点的属性清单}
|
|
|
nodeList := node.ChildNodes; {根节点下的子节点列表}
|
|
|
|
|
|
str := '<' + node.NodeName;
|
|
|
|
|
|
//先读取属性
|
|
|
for i := 0 to attrList.Count - 1 do
|
|
|
begin
|
|
|
strName := attrList[i].NodeName;
|
|
|
strValue := attrList[i].NodeValue;
|
|
|
str := str + ' ' + strName + '=' + AnsiQuotedStr(strValue, '"');
|
|
|
end;
|
|
|
str := str + '>';// + sLineBreak; {sLineBreak 是常量, 相当于 #13#10 此处不加,网站自动解析}
|
|
|
|
|
|
//读取子节点
|
|
|
for i := 0 to nodeList.Count - 1 do
|
|
|
begin
|
|
|
strName := nodeList[i].NodeName;
|
|
|
if nodeList[i].IsTextElement then
|
|
|
begin
|
|
|
strValue := nodeList[i].NodeValue;
|
|
|
str := str + '<' + strName + '>' + strValue + '</' + strName + '>' ;//+ sLineBreak; //此处不加,网站自动解析
|
|
|
end else if nodeList[i].HasChildNodes then
|
|
|
begin
|
|
|
str := str + ReadXml(nodeList[i]); {递归}
|
|
|
str := str + '</' + strName + '>' ;//+ sLineBreak; {封口} //此处不加,网站自动解析
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
str := str + '</' + node.NodeName + '>'; {封口}
|
|
|
|
|
|
Result := str;
|
|
|
end;
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.CheckSendorCode:Boolean;
|
|
|
begin
|
|
|
Result:=False;
|
|
|
with t_sys_company do
|
|
|
begin
|
|
|
Close;
|
|
|
SQL.Clear;
|
|
|
SQL.Add('select top 1 * from t_sys_company ');
|
|
|
Open;
|
|
|
end;
|
|
|
if Trim(Edit1.Text)=Trim(t_sys_company.fieldbyname('VGM发送代码').AsString) then Result:=True;
|
|
|
|
|
|
end;
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.IsZhongwen(Str: String): Boolean;
|
|
|
var
|
|
|
i:Integer;
|
|
|
begin
|
|
|
Result:=false;
|
|
|
if Str='' then Exit;
|
|
|
for i:=1 to Length(Str) do begin
|
|
|
if (Str[i]>Chr(127)) or (Str[i]=Chr(9)) then begin
|
|
|
Result:=True;
|
|
|
Exit;
|
|
|
end;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.SeparateEC(Str: String): string;
|
|
|
var
|
|
|
i:Integer;
|
|
|
begin
|
|
|
if Str='' then Exit;
|
|
|
for i:=1 to Length(Str) do
|
|
|
begin
|
|
|
if (Str[i]<=Chr(127)) then Result:=Result+Str[i] else Break;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.GetShipVGM(Ship:String): String;
|
|
|
var
|
|
|
aQuery:TADOQuery;
|
|
|
begin
|
|
|
aQuery:=CreateAdoQuery;
|
|
|
try
|
|
|
with aQuery do begin
|
|
|
Close;SQL.Clear;
|
|
|
SQL.Add('Select 代码,VGM代码,FTP接收代码,客户简称,客户全称,揽货人,录入人,录入日期 from t_crm_client');
|
|
|
SQL.Add('where 客户性质<>''目标'' and 船公司=1 and 客户简称='''+Ship+'''');
|
|
|
SQL.Add('order by 代码');
|
|
|
Open;
|
|
|
if not IsEmpty then
|
|
|
Result:=Trim(FieldByName('VGM代码').asstring)
|
|
|
else
|
|
|
Result:='';
|
|
|
end;
|
|
|
finally
|
|
|
FreeAndNil(aQuery);
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.GetShipFTP(Ship:String): String;
|
|
|
var
|
|
|
aQuery:TADOQuery;
|
|
|
begin
|
|
|
aQuery:=CreateAdoQuery;
|
|
|
try
|
|
|
with aQuery do begin
|
|
|
Close;SQL.Clear;
|
|
|
SQL.Add('Select 代码,VGM代码,FTP接收代码,客户简称,客户全称,揽货人,录入人,录入日期 from t_crm_client');
|
|
|
SQL.Add('where 客户性质<>''目标'' and 船公司=1 and 客户简称='''+Ship+'''');
|
|
|
SQL.Add('order by 代码');
|
|
|
Open;
|
|
|
if not IsEmpty then
|
|
|
Result:=Trim(FieldByName('FTP接收代码').asstring)
|
|
|
else
|
|
|
Result:='';
|
|
|
end;
|
|
|
finally
|
|
|
FreeAndNil(aQuery);
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
procedure TFrm_op_seae_edi_CSSA.FormShow(Sender: TObject);
|
|
|
begin
|
|
|
with t_sys_company do
|
|
|
begin
|
|
|
Close;
|
|
|
SQL.Clear;
|
|
|
SQL.Add('select top 1 * from t_sys_company ');
|
|
|
Open;
|
|
|
end;
|
|
|
Edit1.Text:= t_sys_company.fieldbyname('VGM发送代码').AsString;
|
|
|
Edit2.Text:=GetShipVGM(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString);
|
|
|
end;
|
|
|
|
|
|
function TFrm_op_seae_edi_CSSA.Changestr(str:widestring):string;
|
|
|
var
|
|
|
i:integer;
|
|
|
strC:widestring;
|
|
|
begin
|
|
|
strC:=str;
|
|
|
strC:=StringReplace(strC,'''''','"',[rfReplaceAll]);
|
|
|
strC:=StringReplace(strC,'''',''',[rfReplaceAll]);
|
|
|
strC:=StringReplace(strC,'&','&',[rfReplaceAll]);
|
|
|
strC:=StringReplace(strC,'>','>',[rfReplaceAll]);
|
|
|
strC:=StringReplace(strC,'<','<',[rfReplaceAll]);
|
|
|
|
|
|
result:=strC;
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TFrm_op_seae_edi_CSSA.MakeVGM;
|
|
|
var
|
|
|
fNode,pNode,mNode,cNode,dNode,eNode,gNode: IXMLNode; {定义7层节点}
|
|
|
sl:TStringList;
|
|
|
i,Elength,Wlength,Clength:Integer;
|
|
|
begin
|
|
|
XMLDocument1.XML.Clear;
|
|
|
XMLDocument1.Active := True;
|
|
|
XMLDocument1.Version := '1.0';
|
|
|
XMLDocument1.Encoding := 'GB2312';
|
|
|
|
|
|
//添加根节点 edi
|
|
|
fNode := XMLDocument1.AddChild('edi');
|
|
|
|
|
|
// 为根节点添加子节点:HEAD
|
|
|
pNode := fNode.AddChild('head');
|
|
|
|
|
|
cNode := pNode.AddChild('sndcom'); //*
|
|
|
if (IsZhongwen(t_sys_company.fieldbyname('VGM发送代码').AsString)) or (not CheckParaExist(t_sys_company.fieldbyname('VGM发送代码').AsString)) then
|
|
|
begin
|
|
|
ShowMessage('发送方代码未配置或不能包含中文!请检查!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text := t_sys_company.fieldbyname('VGM发送代码').AsString;
|
|
|
cNode := pNode.AddChild('sender');
|
|
|
if (IsZhongwen(department)) or (not CheckParaExist(department)) then
|
|
|
begin
|
|
|
ShowMessage('发送方部门不存在或不能包含中文!请检查!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text := department;
|
|
|
|
|
|
cNode := pNode.AddChild('fromop'); //*
|
|
|
if IsZhongwen(employee) then
|
|
|
begin
|
|
|
ShowMessage('发送方操作员不能包含中文!请检查!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text := employee;
|
|
|
|
|
|
cNode := pNode.AddChild('fromtele'); //*
|
|
|
if not CheckParaExist(emptel) then
|
|
|
begin
|
|
|
ShowMessage('操作员联系电话未配置!请检查!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text := emptel;
|
|
|
cNode := pNode.AddChild('fromfax');
|
|
|
|
|
|
cNode := pNode.AddChild('frommail'); //*
|
|
|
cNode.Text := 'dongshengsoft@dongshengsoft.com';
|
|
|
cNode := pNode.AddChild('fromopc');
|
|
|
cNode.Text := empmobil;
|
|
|
cNode := pNode.AddChild('fromope');
|
|
|
cNode.Text := employee;
|
|
|
cNode := pNode.AddChild('accom'); //*
|
|
|
if Trim(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString)='' then
|
|
|
begin
|
|
|
ShowMessage('接收方公司为空!船公司不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text :=frm_op_seae.t_op_seae.fieldbyname('船公司').AsString;
|
|
|
cNode := pNode.AddChild('accepter');
|
|
|
cNode := pNode.AddChild('toop');
|
|
|
cNode := pNode.AddChild('sendtime'); //*
|
|
|
cNode.Text:=FormatDateTime('yyyy-mm-dd hh:mm:ss',Now);
|
|
|
cNode := pNode.AddChild('editype'); //*
|
|
|
cNode.Text:='VERMAS';
|
|
|
cNode := pNode.AddChild('EdiID'); //*
|
|
|
cNode := pNode.AddChild('EdiName');
|
|
|
cNode := pNode.AddChild('EdiMode'); //*
|
|
|
cNode.Text:='HYXML';
|
|
|
cNode := pNode.AddChild('EdiReceiver'); //*
|
|
|
if Trim(GetShipVGM(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString))='' then
|
|
|
begin
|
|
|
ShowMessage('接收方公司VGM为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text := GetShipVGM(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString);
|
|
|
cNode := pNode.AddChild('EdiSender'); //*
|
|
|
cNode.Text := t_sys_company.fieldbyname('VGM发送代码').AsString;
|
|
|
|
|
|
// 为根节点添加子节点:Forward
|
|
|
pNode := fNode.AddChild('Forward');
|
|
|
cNode := pNode.AddChild('EdiForwardFMT');
|
|
|
cNode := pNode.AddChild('EdiForwardType');
|
|
|
cNode := pNode.AddChild('EdiForwardURL');
|
|
|
cNode := pNode.AddChild('EdiForwardId');
|
|
|
cNode := pNode.AddChild('EdiForwardPass');
|
|
|
cNode := pNode.AddChild('EdiForwardREFE1');
|
|
|
cNode := pNode.AddChild('EdiForwardREFE2');
|
|
|
cNode := pNode.AddChild('EdiForwardREFE3');
|
|
|
cNode := pNode.AddChild('EdiForwardREFE4');
|
|
|
cNode := pNode.AddChild('EdiForwardREFE5');
|
|
|
|
|
|
// 为根节点添加子节点:reference
|
|
|
pNode := fNode.AddChild('reference');
|
|
|
cNode := pNode.AddChild('blfreight'); //*
|
|
|
if RadioGroup1.ItemIndex=0 then cNode.Text:='9';
|
|
|
if RadioGroup1.ItemIndex=1 then cNode.Text:='5';
|
|
|
if RadioGroup1.ItemIndex=2 then cNode.Text:='1';
|
|
|
cNode := pNode.AddChild('refid');
|
|
|
cNode := pNode.AddChild('freid');
|
|
|
cNode := pNode.AddChild('referenceno');
|
|
|
cNode := pNode.AddChild('bookingno'); //*
|
|
|
cNode.Text:= frm_op_seae.t_op_seae.fieldbyname('订舱单号').AsString;
|
|
|
cNode := pNode.AddChild('workno'); //*
|
|
|
cNode.Text:=frm_op_seae.t_op_seae.fieldbyname('业务编号').AsString;
|
|
|
cNode := pNode.AddChild('sale');
|
|
|
cNode.Text:='gu';//frm_op_seae.t_op_seae.fieldbyname('揽货人').AsString;
|
|
|
cNode := pNode.AddChild('billofladingno'); //*
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('主提单号').AsString) then
|
|
|
begin
|
|
|
ShowMessage('主提单号不存在!不能生成XML!请检查!');
|
|
|
Exit;
|
|
|
end;
|
|
|
cNode.Text:=frm_op_seae.t_op_seae.fieldbyname('主提单号').AsString;
|
|
|
|
|
|
// 为根节点添加子节点:detail
|
|
|
pNode := fNode.AddChild('detail');
|
|
|
//增加二级子节点 baseinfo
|
|
|
mNode:= pNode.AddChild('baseinfo');
|
|
|
cNode := mNode.AddChild('orderman'); //* 订舱单位 如果录了,就取订舱代理,如果没录就取company里的shortname
|
|
|
cNode.Text := frm_op_seae.t_op_seae.fieldbyname('船公司').AsString;
|
|
|
cNode := mNode.AddChild('source');
|
|
|
cNode := mNode.AddChild('usdaccountshipper');
|
|
|
cNode := mNode.AddChild('customshipper');
|
|
|
cNode := mNode.AddChild('rmbaccountshipper');
|
|
|
cNode := mNode.AddChild('paymenttermcode'); //* 付款方式代码(P/C/E)
|
|
|
cNode := mNode.AddChild('paymentterm'); //*
|
|
|
cNode := mNode.AddChild('payableat');
|
|
|
cNode := mNode.AddChild('shippingitem'); //*
|
|
|
cNode.Text := frm_op_seae.t_op_seae.fieldbyname('运输条款').AsString;
|
|
|
cNode := mNode.AddChild('billofladingtype'); //*
|
|
|
|
|
|
cNode := mNode.AddChild('shipper'); //*
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('发货人代码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('发货人不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=frm_op_seae.t_op_seae.fieldbyname('发货人代码').AsString;
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
|
|
|
cNode := mNode.AddChild('consignee'); //*
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('收货人代码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('收货人不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=frm_op_seae.t_op_seae.fieldbyname('收货人代码').AsString;
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
|
|
|
cNode := mNode.AddChild('notifyparty'); //*
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('通知人代码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('通知人代码不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=frm_op_seae.t_op_seae.fieldbyname('通知人代码').AsString;
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
|
|
|
cNode := mNode.AddChild('notifyparty2');
|
|
|
if Trim(frm_op_seae.t_op_seae.fieldbyname('第二通知人').AsString)<>'' then
|
|
|
begin
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=frm_op_seae.t_op_seae.fieldbyname('第二通知人').AsString;
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
end;
|
|
|
|
|
|
cNode := mNode.AddChild('ordermemo');
|
|
|
cNode := mNode.AddChild('numberoforiginals'); //*
|
|
|
cNode := mNode.AddChild('numberofcopys');
|
|
|
cNode := mNode.AddChild('placeofissuecode'); //*
|
|
|
cNode := mNode.AddChild('placeofissue'); //*
|
|
|
cNode := mNode.AddChild('timeofissue'); //*
|
|
|
|
|
|
//增加二级子节点 cargo
|
|
|
mNode:= pNode.AddChild('cargo');
|
|
|
cNode := mNode.AddChild('APPLICANT');
|
|
|
cNode := mNode.AddChild('BOKKINGPARTY');
|
|
|
cNode := mNode.AddChild('FOBPARTY');
|
|
|
cNode := mNode.AddChild('SCNO');
|
|
|
cNode := mNode.AddChild('QUARANTINECODING');
|
|
|
cNode := mNode.AddChild('SCACCODE');
|
|
|
cNode := mNode.AddChild('QUOTATIONNO');
|
|
|
cNode := mNode.AddChild('CHARGETYPE');
|
|
|
cNode := mNode.AddChild('NVOCCHBLNO');
|
|
|
|
|
|
cNode := mNode.AddChild('realshipper');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
cNode := mNode.AddChild('realconsignee');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
cNode := mNode.AddChild('realnotifyparty');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
cNode := mNode.AddChild('realnotifyparty2');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
//增加二级子节点 booking
|
|
|
mNode:= pNode.AddChild('booking');
|
|
|
cNode := mNode.AddChild('shipmentdate');
|
|
|
cNode := mNode.AddChild('expirydate');
|
|
|
cNode := mNode.AddChild('tranship');
|
|
|
cNode := mNode.AddChild('batch');
|
|
|
cNode := mNode.AddChild('quotationno');
|
|
|
|
|
|
//增加二级子节点 freight
|
|
|
mNode:= pNode.AddChild('freight');
|
|
|
cNode := mNode.AddChild('fl');
|
|
|
cNode := mNode.AddChild('masterlclno');
|
|
|
cNode := mNode.AddChild('requestdate');
|
|
|
cNode := mNode.AddChild('lastdate');
|
|
|
cNode := mNode.AddChild('arrivedate');
|
|
|
//增加三级子节点 port
|
|
|
cNode := mNode.AddChild('port');
|
|
|
dNode := cNode.AddChild('placeofreceipt');
|
|
|
dNode := cNode.AddChild('portofloading'); //* 装货港
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('装货港').AsString) then
|
|
|
begin
|
|
|
ShowMessage('装货港不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('装货港').AsString;
|
|
|
dNode := cNode.AddChild('portoftranship');
|
|
|
dNode := cNode.AddChild('portofdischarge'); //* 卸货港
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('卸货港').AsString) then
|
|
|
begin
|
|
|
ShowMessage('卸货港不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('卸货港').AsString;
|
|
|
dNode := cNode.AddChild('placeofdelivery'); //* 目的港
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('目的地').AsString) then
|
|
|
begin
|
|
|
ShowMessage('目的地不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('目的地').AsString;
|
|
|
dNode := cNode.AddChild('finaldestination');
|
|
|
dNode := cNode.AddChild('co_placeofreceipt');
|
|
|
dNode := cNode.AddChild('co_portofloading'); //* 装货港代码
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('装港代码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('装港代码不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('装港代码').AsString;
|
|
|
dNode := cNode.AddChild('co_portoftranship');
|
|
|
dNode := cNode.AddChild('co_portofdischarge'); //* 卸货港代码
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('卸货代码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('卸货港代码不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('卸货代码').AsString;
|
|
|
dNode := cNode.AddChild('co_placeofdelivery'); //* 目的港代码
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('目的地代码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('目的地代码不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('目的地代码').AsString;
|
|
|
dNode := cNode.AddChild('co_finaldestination');
|
|
|
//增加三级子节点vessel
|
|
|
cNode := mNode.AddChild('vessel');
|
|
|
dNode := cNode.AddChild('carrier'); //* 船公司
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('船公司').AsString;
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('船名').AsString) then
|
|
|
begin
|
|
|
ShowMessage('船名不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode := cNode.AddChild('oceanvessel'); //* 船名
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('船名').AsString;
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('航次').AsString) then
|
|
|
begin
|
|
|
ShowMessage('航次不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode := cNode.AddChild('voyno'); //* 航次
|
|
|
dNode.Text:=frm_op_seae.t_op_seae.fieldbyname('航次').AsString;
|
|
|
dNode := cNode.AddChild('etd'); //* 开航日期
|
|
|
if not CheckParaExist(frm_op_seae.t_op_seae.fieldbyname('开船日期').AsString) then
|
|
|
begin
|
|
|
ShowMessage('开船日期不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
dNode.Text:= FormatDateTime('yyyy-mm-dd',frm_op_seae.t_op_seae.fieldbyname('开船日期').AsDateTime);
|
|
|
dNode := cNode.AddChild('deliverymode');
|
|
|
|
|
|
//增加三级子节点info2nd
|
|
|
cNode := mNode.AddChild('info2nd');
|
|
|
dNode := cNode.AddChild('carrier');
|
|
|
dNode := cNode.AddChild('oceanvessel');
|
|
|
dNode := cNode.AddChild('voyno');
|
|
|
dNode := cNode.AddChild('etd');
|
|
|
dNode := cNode.AddChild('eta');
|
|
|
dNode := cNode.AddChild('remarks');
|
|
|
eNode := dNode.AddChild('text');
|
|
|
|
|
|
//增加三级子节点container
|
|
|
cNode := mNode.AddChild('container'); //若集装箱没录,提示:集装箱信息不能为空
|
|
|
with t_op_ctn do
|
|
|
begin
|
|
|
Close;
|
|
|
SQL.Clear;
|
|
|
sql.Add('select * from t_op_ctn where 编号='+quotedstr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString)+' order by 代码' );
|
|
|
Open;
|
|
|
end;
|
|
|
if t_op_ctn.RecordCount=0 then
|
|
|
begin
|
|
|
ShowMessage('集装箱信息不存在!不能生成VGM文件!请检查!');
|
|
|
Exit;
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
t_op_ctn.First;
|
|
|
while not t_op_ctn.Eof do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('containers'); //可无限循环
|
|
|
eNode := dNode.AddChild('containertype'); //* 箱型 箱型不能为空
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('箱型').AsString;
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('箱型').AsString) then
|
|
|
begin
|
|
|
ShowMessage('箱型不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode := dNode.AddChild('containerno'); //* 箱号 箱型不能为空
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('箱号').AsString) then
|
|
|
begin
|
|
|
ShowMessage('箱号不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('箱号').AsString;
|
|
|
eNode := dNode.AddChild('sealno'); //* 封号 不能为空
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('封号').AsString) then
|
|
|
begin
|
|
|
ShowMessage('封号不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('封号').AsString;
|
|
|
eNode := dNode.AddChild('containernoofpkgs'); //* 件数 不能为空
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('件数').AsString) then
|
|
|
begin
|
|
|
ShowMessage('件数不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('件数').AsString;
|
|
|
eNode := dNode.AddChild('containergrossweight'); //* 毛重 不能为空
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('重量').AsString) then
|
|
|
begin
|
|
|
ShowMessage('毛重不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('重量').AsString;
|
|
|
eNode := dNode.AddChild('containercbm'); //* 体积 不能为空
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('尺码').AsString) then
|
|
|
begin
|
|
|
ShowMessage('体积不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('尺码').AsString;
|
|
|
eNode := dNode.AddChild('containerpackagingcode'); //* 箱货物包装类型代码 包装类型代码未配置
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('包装').AsString) then
|
|
|
begin
|
|
|
ShowMessage('包装类型未配置!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('包装').AsString;
|
|
|
eNode := dNode.AddChild('containerpackaging'); //* 箱货物包装类型 包装不能为空
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('包装').AsString;
|
|
|
eNode := dNode.AddChild('containerdescription');
|
|
|
gNode := eNode.AddChild('text');
|
|
|
|
|
|
eNode := dNode.AddChild('containermarksandnumbers');
|
|
|
eNode := dNode.AddChild('vgmgrossmassweight'); //VGM总重量 不能为空
|
|
|
if not CheckParaExist(t_op_ctn.fieldbyname('称重重量').AsString) then
|
|
|
begin
|
|
|
ShowMessage('VGM重量不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
eNode.Text:=t_op_ctn.fieldbyname('称重重量').AsString;
|
|
|
eNode := dNode.AddChild('vgmweighingmethod'); //VGM称重方式 不能为空
|
|
|
if (Trim(t_op_ctn.fieldbyname('称重方式').AsString)='') or (Trim(t_op_ctn.fieldbyname('称重方式').AsString)='累加') then eNode.Text:='SM2'
|
|
|
else eNode.Text:='SM1';
|
|
|
|
|
|
eNode := dNode.AddChild('vgmweighingtime'); //VGM称重时间 不能为空 空则取开船前三天
|
|
|
if Trim(t_op_ctn.fieldbyname('VGM称重日期').AsString)='' then eNode.Text:=FormatDateTime('yyyy-mm-dd',frm_op_seae.t_op_seae.fieldbyname('开船日期').AsDateTime-3)
|
|
|
else eNode.Text:=t_op_ctn.fieldbyname('VGM称重日期').AsString;
|
|
|
eNode := dNode.AddChild('vgmresponsibleparty'); //VGM联系单位
|
|
|
eNode.Text:=department;
|
|
|
eNode := dNode.AddChild('vgmauthorizedperson'); //VGM授权联系人
|
|
|
eNode.Text:=employee;
|
|
|
eNode := dNode.AddChild('vgmauthorizedpersontele'); //VGM授权联系人电话
|
|
|
eNode.Text:=emptel;
|
|
|
eNode := dNode.AddChild('vgmauthorizedpersonmail'); //VGM授权联系人邮件
|
|
|
eNode := dNode.AddChild('vgmremark'); //VGM其他备注内容
|
|
|
t_op_ctn.Next;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
//增加二级子节点 goods
|
|
|
mNode:= pNode.AddChild('goods');
|
|
|
cNode := mNode.AddChild('marksandnumbers'); //* 唛头
|
|
|
if frm_op_seae.t_op_seae.fieldbyname('唛头').AsString='' then
|
|
|
begin
|
|
|
ShowMessage('唛头不能为空!');
|
|
|
Exit;
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=frm_op_seae.t_op_seae.fieldbyname('唛头').AsString;
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
end;
|
|
|
cNode := mNode.AddChild('noofpkgs'); //* 包装件数
|
|
|
cNode.Text:=frm_op_seae.t_op_seae.fieldbyname('件数包装').AsString;
|
|
|
cNode := mNode.AddChild('packagingcode'); //* 包装类型代码
|
|
|
cNode.Text:=frm_op_seae.t_op_seae.fieldbyname('包装').AsString;
|
|
|
cNode := mNode.AddChild('packaging'); //* 包装类型
|
|
|
cNode.Text:=frm_op_seae.t_op_seae.fieldbyname('包装').AsString;
|
|
|
cNode := mNode.AddChild('cargoid'); //* 货物类型(GC/RF/DR)
|
|
|
cNode.Text:=frm_op_seae.t_op_seae.fieldbyname('货物标识').AsString;
|
|
|
cNode := mNode.AddChild('hscode'); //海关编码
|
|
|
|
|
|
cNode := mNode.AddChild('description'); //货物描述(英文货名)
|
|
|
if Trim(frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString)='' then
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=SeparateEC(frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString);
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
end;
|
|
|
cNode := mNode.AddChild('dcdescription'); //货物描述(中文货名)
|
|
|
Wlength:= Length(frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString);
|
|
|
Elength:= Length(SeparateEC(frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString));
|
|
|
if Trim(Copy(frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString,Elength,WLength-Elength-1) )=''
|
|
|
then
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
sl:=TStringList.Create;
|
|
|
sl.Text:=Copy(frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString,Elength,WLength-Elength-1);
|
|
|
for i:=0 to sl.Count-1 do
|
|
|
begin
|
|
|
dNode := cNode.AddChild('text');
|
|
|
dNode.Text:=sl[i];
|
|
|
end;
|
|
|
sl.Free;
|
|
|
end;
|
|
|
|
|
|
cNode := mNode.AddChild('grossweight'); //* 毛重
|
|
|
cNode.Text:= frm_op_seae.t_op_seae.fieldbyname('重量').AsString;
|
|
|
cNode := mNode.AddChild('cbm'); //* 体积
|
|
|
cNode.Text:= frm_op_seae.t_op_seae.fieldbyname('尺码').AsString;
|
|
|
|
|
|
cNode := mNode.AddChild('specialgoods'); //特殊货物说明
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
//增加二级子节点 dr
|
|
|
mNode := pNode.AddChild('dr');
|
|
|
|
|
|
cNode := mNode.AddChild('CLASS');
|
|
|
cNode := mNode.AddChild('PAGE');
|
|
|
cNode := mNode.AddChild('UNDGNO');
|
|
|
cNode := mNode.AddChild('TECNAME');
|
|
|
cNode := mNode.AddChild('PACKGROUP');
|
|
|
|
|
|
cNode := mNode.AddChild('LABEL');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
cNode := mNode.AddChild('FLASHPOINT');
|
|
|
cNode := mNode.AddChild('FLASHUNIT');
|
|
|
cNode := mNode.AddChild('EMSNO');
|
|
|
cNode := mNode.AddChild('MFAGNO');
|
|
|
cNode := mNode.AddChild('MPT');
|
|
|
cNode := mNode.AddChild('Elinkman');
|
|
|
|
|
|
cNode := mNode.AddChild('DANGEROUS');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
cNode := mNode.AddChild('TEMPERATURE');
|
|
|
cNode := mNode.AddChild('TEMPERATUREUNIT');
|
|
|
cNode := mNode.AddChild('MINTEMPERATURE');
|
|
|
cNode := mNode.AddChild('MAXTEMPERATURE');
|
|
|
cNode := mNode.AddChild('ALLCOLDTORAGE');
|
|
|
cNode := mNode.AddChild('VENTI');
|
|
|
|
|
|
cNode := mNode.AddChild('REEFER');
|
|
|
dNode := cNode.AddChild('text');
|
|
|
|
|
|
//增加二级子节点 loadplan
|
|
|
mNode := pNode.AddChild('loadplan');
|
|
|
cNode := mNode.AddChild('entryno');
|
|
|
cNode := mNode.AddChild('warehouse');
|
|
|
cNode := mNode.AddChild('landcarrier');
|
|
|
cNode := mNode.AddChild('stuffdate');
|
|
|
cNode := mNode.AddChild('stuffmode');
|
|
|
cNode := mNode.AddChild('stuffaddress');
|
|
|
cNode := mNode.AddChild('stuffmemo');
|
|
|
|
|
|
//增加二级子节点 announce
|
|
|
mNode := pNode.AddChild('announce');
|
|
|
cNode := mNode.AddChild('text');
|
|
|
|
|
|
//增加二级子节点 remarks
|
|
|
mNode := pNode.AddChild('remarks');
|
|
|
|
|
|
end;
|
|
|
|
|
|
procedure TFrm_op_seae_edi_CSSA.bsSkinButton1Click(Sender: TObject);
|
|
|
begin
|
|
|
MakeVGM;
|
|
|
SaveDialog1.FileName:=frm_op_seae.t_op_seae.fieldbyname('船名').asstring+frm_op_seae.t_op_seae.fieldbyname('航次').asstring;
|
|
|
if SaveDialog1.Execute then
|
|
|
begin
|
|
|
XMLDocument1.SaveToFile(SaveDialog1.FileName+'.XML');
|
|
|
XMLDocument1.Active:=False;
|
|
|
showmessage('文件生成成功!');
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
showmessage('文件生成失败!');
|
|
|
exit;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
procedure TFrm_op_seae_edi_CSSA.bsSkinButton2Click(Sender: TObject);
|
|
|
begin
|
|
|
XMLDocument1.Active:=False;
|
|
|
close;
|
|
|
end;
|
|
|
|
|
|
function FormatEncodeDate(s:string):string;
|
|
|
begin
|
|
|
Result:=StringReplace(s,' ','+',[rfreplaceall]);
|
|
|
Result:=StringReplace(Result,':','%3a',[rfreplaceall]);
|
|
|
end;
|
|
|
|
|
|
procedure TFrm_op_seae_edi_CSSA.SendFile;
|
|
|
var
|
|
|
s1,s2: string;
|
|
|
IdHttp : TIdHTTP;
|
|
|
Url : string;//请求地址
|
|
|
//返回信息
|
|
|
ResponseStream : TStringStream;
|
|
|
ResponseStr: string;
|
|
|
//请求信息
|
|
|
RequestStr : string;
|
|
|
RequestStream : TStringStream;
|
|
|
//请求参数
|
|
|
Realdate:TDateTime;
|
|
|
Requestdate,RequestOrg,RequestSign:string;
|
|
|
RequestFile,RequestContent,RequestDateSTamp:string;
|
|
|
|
|
|
begin
|
|
|
if GetShipVGM(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString)='' then
|
|
|
begin
|
|
|
ShowMessage('船公司VGM不能为空!');
|
|
|
Exit;
|
|
|
end;
|
|
|
MakeVGM;
|
|
|
|
|
|
IdHttp := TIdHTTP.Create(nil);
|
|
|
idhttp.Request.ContentType:='application/x-www-form-urlencoded';
|
|
|
//TStringStream对象用于保存响应信息
|
|
|
ResponseStream := TStringStream.Create('');
|
|
|
RequestStream := TStringStream.Create('');
|
|
|
Realdate:=Now;
|
|
|
//初始化各参数
|
|
|
Requestdate:=FormatDateTime('yyyy-mm-dd hh:mm:ss',Realdate);
|
|
|
RequestDateSTamp:=FormatEncodeDate(Requestdate);
|
|
|
RequestOrg:='dssoft' + 'ced93003-1577-4ff4-9fcf-73a52408eb36' + Requestdate;
|
|
|
RequestSign:=UpperCase(MD5Print(MD5String(RequestOrg)));
|
|
|
RequestFile:=IntToStr(GetJavaTime(Realdate))+'.XML';
|
|
|
XMLDocument1.SaveToFile(RequestFile);
|
|
|
XMLDocument1.Active:=False;
|
|
|
XMLDocument1.LoadFromFile(RequestFile);
|
|
|
{读取文件头}
|
|
|
s1 := AnsiQuotedStr(XMLDocument1.Version, '"'); {读出版本,加双引号}
|
|
|
s2 := AnsiQuotedStr(XMLDocument1.Encoding, '"'); {读出字元集, 加双引号}
|
|
|
RequestContent := Format('<?xml version=%s encoding=%s?>',[s1,s2]); {头}
|
|
|
RequestContent := RequestContent + ReadXml(XMLDocument1.DocumentElement);
|
|
|
RequestContent:=EncodeString(RequestContent);
|
|
|
try
|
|
|
if not CheckBox1.Checked then url := 'http://api.nbeport.com/router/rest' else url := 'http://api.trainer.nbeport.com/router/rest';
|
|
|
try
|
|
|
//以流的方式提交参数
|
|
|
RequestStr:='user_id=dssoft&format=json×tamp='+RequestDateSTamp+'&sign='+RequestSign
|
|
|
+'&method=cargoedi.demessage.msgrec.post&deaId='+GetShipVGM(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString)
|
|
|
+'&userId=dssoft&docName='+RequestFile+'&docType=VERMAS&docLength='+IntToStr(Length(RequestContent))
|
|
|
+'&docContent='+RequestContent+'&channel=WSTOM&destDeaId='+t_sys_company.fieldbyname('VGM发送代码').AsString
|
|
|
+'&port=Qingdao';
|
|
|
RequestStream.WriteString(RequestStr);
|
|
|
IdHttp.Post(Url,RequestStream,ResponseStream);
|
|
|
except
|
|
|
on e : Exception do
|
|
|
begin
|
|
|
ShowMessage(e.Message);
|
|
|
end;
|
|
|
end;
|
|
|
//获取网页返回的信息
|
|
|
ResponseStr := ResponseStream.DataString;
|
|
|
//网页中的存在中文时,需要进行UTF8解码
|
|
|
ResponseStr := UTF8Decode(ResponseStr);
|
|
|
if Pos('T',ResponseStr)>0 then ShowMessage('提交成功!') else ShowMessage(ResponseStr);
|
|
|
|
|
|
finally
|
|
|
IdHttp.Free;
|
|
|
RequestStream.Free;
|
|
|
ResponseStream.Free;
|
|
|
end;
|
|
|
DeleteFile(RequestFile);
|
|
|
end;
|
|
|
|
|
|
procedure TFrm_op_seae_edi_CSSA.bsSkinButton4Click(Sender: TObject);
|
|
|
begin
|
|
|
SendFile;
|
|
|
end;
|
|
|
|
|
|
end.
|