unit u_op_seae_edi_ym; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IdFTP,IdFTPCommon, Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB, ExtCtrls; type Tfrm_op_seae_edi_ym = class(TForm) bsBusinessSkinForm1: TbsBusinessSkinForm; Label2: TLabel; Edit2: TEdit; Edit1: TEdit; Label1: TLabel; SaveDialog1: TSaveDialog; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton3: TbsSkinButton; t_op_ctn: TADOQuery; t_op_ctn1: TDataSource; bsSkinRadioGroup1: TbsSkinRadioGroup; Label3: TLabel; Edit3: TEdit; bsSkinGroupBox1: TbsSkinGroupBox; bsSkinButton4: TbsSkinButton; Label4: TLabel; Edit4: TEdit; Edit5: TEdit; Label5: TLabel; Label6: TLabel; Edit6: TEdit; Label7: TLabel; Edit7: TEdit; bsSkinRadioGroup2: TbsSkinRadioGroup; procedure bsSkinButton2Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure bsSkinButton4Click(Sender: TObject); private function isEditrue(DataSet:TDataSet): boolean; function GetStrNum(str:String):integer; function FormatListString(Old:TStrings;mCount,Strlength:integer):String; function FormatEdiString(old:String;Strlength:integer):String; function CreateEdiFile:TStrings; function CreateSIEdiFile:TStrings; function CreateZHUEdiFile:TStrings; function GetCntrEdi(cntrID:String):String; function GetpkgsEdi(pkgs:String):String; function GetlineEdi(aline:String):String; { Private declarations } public { Public declarations } end; var frm_op_seae_edi_ym: Tfrm_op_seae_edi_ym; implementation uses u_op_seae, u_main, my_sys_function, u_data_share; {$R *.dfm} function Tfrm_op_seae_edi_ym.FormatEdiString(old:String;Strlength:integer):String; var i:integer; begin Result:=Trim(Old); Result:=StringReplace(Result,'?','??',[rfReplaceAll]); Result:=StringReplace(Result,':','?:',[rfReplaceAll]); Result:=StringReplace(Result,'''','?''',[rfReplaceAll]); Result:=StringReplace(Result,'+','?+',[rfReplaceAll]); if Strlength<>0 then if length(Result)>Strlength then Result:=Copy(Result,1,Strlength); end; function Tfrm_op_seae_edi_ym.FormatListString(Old:TStrings;mCount,Strlength:integer):String; var i:integer; NewStrs:TStrings; mStr:String; begin Result:=''; NewStrs:=TStringList.Create; for i:=0 to old.Count-1 do begin if Length(old.Strings[i])<=Strlength then begin NewStrs.Add(old.Strings[i]); end else begin mStr:=old.Strings[i]; while length(mStr)>Strlength do begin newStrs.Add(copy(mStr,1,Strlength)); system.Delete(mStr,1,Strlength); end; newStrs.Add(mStr); end; end; try for i:=0 to mCount-1 do begin if i0 then Str:=CreateZHUEdiFile else begin Exit; end; SaveDialog1.FileName:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring; if SaveDialog1.Execute then begin str.SaveToFile(SaveDialog1.FileName+'.txt'); showmessage('文件生成成功!'); end else begin showmessage('文件生成失败!'); exit; end; end else begin if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then Str:=CreateSIEdiFile; SaveDialog1.FileName:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring; if SaveDialog1.Execute then begin str.SaveToFile(SaveDialog1.FileName+'.edi'); showmessage('文件生成成功!'); end else begin showmessage('文件生成失败!'); exit; end; end; finally FreeAndNil(Str) end; close; end; function Tfrm_op_seae_edi_ym.isEditrue(DataSet:TDataSet): boolean; var cntrs:String; begin result:=true; if trim(DataSet.fieldbyname('主提单号').asstring)='' then begin result:=false; MessageDlg('提单号不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('付费方式').asstring)='' then begin result:=false; MessageDlg('付费方式不能为空',mtWarning,[mbOk],0); exit; end; { if trim(DataSet.fieldbyname('船名').asstring)='' then begin result:=false; MessageDlg('船名不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('航次').asstring)='' then begin result:=false; MessageDlg('航次不能为空',mtWarning,[mbOk],0); exit; end; } if trim(DataSet.fieldbyname('装港代码').asstring)='' then begin result:=false; MessageDlg('装港代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('装货港').asstring)='' then begin result:=false; MessageDlg('装货港不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('总价').asstring)='' then begin result:=false; MessageDlg('第一层包装皮重不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('开船日期').asstring)='' then begin result:=false; MessageDlg('开船日期不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('交货代码').asstring)='' then begin result:=false; MessageDlg('交货代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('卸货代码').asstring)='' then begin result:=false; MessageDlg('卸货代码不能为空',mtWarning,[mbOk],0); exit; end; { if trim(DataSet.fieldbyname('交货地点').asstring)='' then begin result:=false; MessageDlg('交货地点不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('目的地').asstring)='' then begin result:=false; MessageDlg('目的地不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring)='' then begin result:=false; MessageDlg('运费协议号不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.fieldbyname('发货人编号').asstring)='' then begin result:=false; MessageDlg('船舶服务号不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.fieldbyname('EDI备注').asstring)='' then begin result:=false; MessageDlg('EDI备注不能为空',mtWarning,[mbOk],0); exit; end; } if trim(DataSet.fieldbyname('签单地点').asstring)='' then begin result:=false; MessageDlg('签单地点不能为空',mtWarning,[mbOk],0); exit; end; if trim(GetpkgsEdi(DataSet.fieldbyname('包装').asstring))='' then begin result:=false; MessageDlg('包装EDI代码不存在!',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('货物描述').asstring)='' then begin result:=false; MessageDlg('货物描述不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('唛头').asstring)='' then begin result:=false; MessageDlg('唛头不能为空',mtWarning,[mbOk],0); exit; end; if DataSet.fieldbyname('件数').asinteger=0 then begin result:=false; MessageDlg('件数不能为空',mtWarning,[mbOk],0); exit; end; if DataSet.fieldbyname('重量').asFloat=0 then begin result:=false; MessageDlg('总重量不能为空',mtWarning,[mbOk],0); exit; end; if DataSet.fieldbyname('尺码').asFloat=0 then begin result:=false; MessageDlg('总尺码不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='' then begin result:=false; MessageDlg('货物标识不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.FieldByName('货物标识').asstring)='D' then begin if Trim(frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring)='' then begin result:=false; MessageDlg('危险品等级不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring)='' then begin result:=false; MessageDlg('危险品编号不能为空',mtWarning,[mbOk],0); exit; end; if GetStrNum(Trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring))<>4 then begin result:=false; MessageDlg('危险品编号必须是4位数字',mtWarning,[mbOk],0); exit; end; end; if trim(frm_op_seae.t_op_seae.FieldByName('货物标识').asstring)='R' then begin if Trim(frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring)='' then begin result:=false; MessageDlg('设置温度不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('冷藏通风量').asstring)='' then begin result:=false; MessageDlg('冷藏通风量不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('最低温度').asstring)='' then begin result:=false; MessageDlg('最低温度不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring)='' then begin result:=false; MessageDlg('最高温度不能为空',mtWarning,[mbOk],0); exit; end; end; t_op_ctn.close; t_op_ctn.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring; t_op_ctn.open; if t_op_ctn.IsEmpty then begin result:=false; MessageDlg('集装箱不能为空',mtWarning,[mbOk],0); exit; end; t_op_ctn.First; while not t_op_ctn.Eof do begin if Trim(GetCntrEdi(t_op_ctn.fieldbyname('代码').asstring))='' then begin result:=false; MessageDlg('集装箱EDI代码不存在!',mtWarning,[mbOk],0); exit; end; t_op_ctn.Next; end; end; function Tfrm_op_seae_edi_ym.CreateEdiFile:TStrings; var str:Tstringlist; sl,sl1:TStrings; i,j,Count,l,M:integer; strsql,strRmain,strtemp,S:string; rs:Tadoquery; wide_str:widestring; k:integer; strType:string; strDatetime:string; SenderCode,ReciverCode:string; function GetRemarksString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('EDI备注').AsString; Result:='17:'; Result:=Result+FormatListString(TempStr,5,35)+''''; finally FreeAndNil(TempStr); end; end; function GetShipperString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('发货人代码').AsString; Result:='20:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetConsigneString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('收货人代码').AsString; Result:='21:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetNOTIFYString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('通知人代码').AsString; Result:='22:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetMARKSString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('唛头').AsString; Result:='44:'; Result:=Result+FormatListString(TempStr,10,35)+''''; finally FreeAndNil(TempStr); end; end; { function GetCARGODESCRIPTIONString:String; var TempStr:TStrings; i:integer; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString; for i:=0 to TempStr.Count-1 do begin if i=0 then Result:='47:'+FormatEdiString(TempStr.Strings[i],70) else Result:=Result+':'+FormatEdiString(TempStr.Strings[i],70); end; Result:=Result+''''; finally FreeAndNil(TempStr); end; end; } begin if not isEditrue(frm_op_seae.t_op_seae) then exit; SenderCode:=trim(edit1.Text) ; ReciverCode:=trim(edit2.Text) ; if bsSkinRadioGroup1.ItemIndex=0 then strType:='9' else if bsSkinRadioGroup1.ItemIndex=1 then strType:='2' else if bsSkinRadioGroup1.ItemIndex=2 then strType:='3' else if bsSkinRadioGroup1.ItemIndex=3 then strType:='4' else strType:='9'; str:=Tstringlist.Create; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; str.Clear; str.Add('00:IFTMBF:BOOKING:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+#39); Count:=0; str.Add ('02:'+ trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring) +':' + trim(Edit3.Text) +':' + ReciverCode+':' + ':::::::' + '::' + trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring)+':' +':'+ #39); if trim(frm_op_seae.t_op_seae.fieldbyname('签单方式').asstring)='正本' then strtemp:='ORI' else strtemp:='EXP'; str.add('03:'+strtemp+':' +':' + trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring) +':' + GetDatetime(trim(frm_op_seae.t_op_seae.fieldbyname('签单日期').asstring),0)+':' + get_fenshu(trim(frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring))+':' + trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring) +#39); str.Add('11:' + trim(frm_op_seae.t_op_seae.fieldbyname('发货人编号').asstring)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('船名').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('航次').asstring)+':' +'::' + ReciverCode +'::' + GetDatetime(trim(frm_op_seae.t_op_seae.fieldbyname('开船日期').asstring),0)+':' + '::::' +#39); //船舶经营人 str.Add ('12:'+trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring)+':' +trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring)+':' +trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring)+':' +trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring)+':' +trim(frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring)+':' +':' +':' +trim(frm_op_seae.t_op_seae.fieldbyname('交货代码').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('交货地点').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('目的地代码').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('目的地').asstring) +#39); if frm_data_share.t_code_free.locate('付费方式',frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring,[]) then begin str.Add ('14:'+frm_data_share.t_code_free.fieldbyname('代码').asstring+':' +trim(frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring)+#39); str.Add('15:' +'::' +trim(frm_data_share.t_code_free.fieldbyname('代码').asstring)+':' +'::' + '::::' +#39); //船舶经营人 end else begin str.Add ('14:'+'P'+':' +trim(frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring)+#39); str.Add('15:' +'::' +'P:' +'::' + '::::' +#39); //船舶经营人 end; if trim(frm_op_seae.t_op_seae.fieldbyname('EDI备注').asstring)<>'' then Str.Add(GetRemarksString); Str.Add(GetShipperString); Str.Add(GetConsigneString); Str.Add(GetNOTIFYString); { str.Add ('20:'+':' +Changestr(frm_op_seae.t_op_seae.fieldbyname('发货人代码').asstring) +#39); str.Add ('21:'+':' +Changestr(frm_op_seae.t_op_seae.fieldbyname('收货人代码').asstring) +#39); str.Add ('22:'+':' +Changestr(frm_op_seae.t_op_seae.fieldbyname('通知人代码').asstring) +#39); } str.Add ('41:1::'+trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)+':' // 货物标识 S/R/D/O +trim(frm_op_seae.t_op_seae.fieldbyname('件数').asstring) +':' +trim(GetpkgsEdi(frm_op_seae.t_op_seae.fieldbyname('包装').asstring))+':' +trim(frm_op_seae.t_op_seae.fieldbyname('包装').asstring) +':' //第一层包装说明 +trim(frm_op_seae.t_op_seae.fieldbyname('总价').asstring) +':' //第一层包装说明 +trim(frm_op_seae.t_op_seae.fieldbyname('尺码').asstring) +'::::::' // 第一层包装皮重 +trim(frm_op_seae.t_op_seae.fieldbyname('重量').asstring) +':::' // 第一层包装尺码 +#39); IF trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='R' THEN BEGIN str.Add ('43:' // 危险品、冷冻 +':' +':' +':' +':' +':' +':' +':' +'::' +trim(frm_op_seae.t_op_seae.fieldbyname('冷藏通风量').asstring) +':' +'C:' +trim(frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('最低温度').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring) +':' +'::::' +#39); END; IF trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='D'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +trim(frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring) +':' +':' +trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring) +':' +':' +':' +':' +':' +'::' +':' +':' +':' +':' +':::::' +#39); END; Str.Add(GetMARKSString); sl1.Text:=frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString; sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then sl.Add(sl1.Strings[L]); end; M:=1; for L:=0 to sl.Count-1 do begin if M<=5 then begin if M=1 then begin s:='47:'+FormatEdiString(sl.Strings[L],0)+':'; end else begin if M=5 then s:=s+FormatEdiString(sl.Strings[L],0) else s:=s+FormatEdiString(sl.Strings[L],0)+':'; end; end else begin S:=S+''''; Str.Add(S); M:=1; s:='47:'+FormatEdiString(sl.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); // Str.Add(GetCARGODESCRIPTIONString); Count:=Count+11; strRmain:=''; if trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then begin if frm_data_share.t_crm_client_changzhan.locate('客户简称',frm_op_seae.t_op_seae.fieldbyname('场站').asstring,[])then begin if frm_op_seae.t_op_seae.fieldbyname('是否自有箱').asboolean then strRmain:=strRmain+'F:'+':'+':'+frm_data_share.t_crm_client_changzhan.fieldbyname('EDI代码').asstring+':'+':'+'Y'+#39 else strRmain:=strRmain+'F:'+':'+':'+frm_data_share.t_crm_client_changzhan.fieldbyname('EDI代码').asstring+':'+':'+'N'+#39 end else begin if frm_op_seae.t_op_seae.fieldbyname('是否自有箱').asboolean then strRmain:=strRmain+'F:'+':'+':'+':'+':'+'Y'+#39 else strRmain:=strRmain+'F:'+':'+':'+':'+':'+'N'+#39; end; strsql:='select 代码,编号,尺寸,箱型,sum(数量) as 数量 from t_op_ctn group by 代码,编号,尺寸,箱型 having 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; try rs:=Tadoquery.Create(application); rs.Connection := frm_main.db; rs.sql.clear; rs.sql.add(strsql); rs.Open; rs.First; while not rs.Eof do begin str.Add ('48:'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring))+':'+ trim(rs.fieldbyname('数量').asstring)+':'+ strRmain); Count:=Count+1; rs.Next; end; { strsql:='select * from t_op_ctn where 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; rs.Close; rs.sql.clear; rs.sql.add(strsql); rs.Open; if not rs.IsEmpty then begin if rs.FieldByName('件数').AsInteger>0 then begin rs.First; while not rs.Eof do begin str.Add ('51:'+trim(rs.fieldbyname('箱号').asstring)+':'+Trim(GetCntrEdi(rs.fieldbyname('尺寸').asstring,rs.fieldbyname('箱型').asstring))+':'+ trim(rs.fieldbyname('封号').asstring)+':'+trim(IntToStr(rs.fieldbyname('件数').AsInteger))+':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat))+':'+'''' ); rs.Next; end; end; end; } rs.Close; rs.Destroy; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; end else begin if frm_data_share.t_crm_client_changzhan.locate('客户简称',frm_op_seae.t_op_seae.fieldbyname('场站').asstring,[])then begin strRmain:=strRmain+'L:'+':'+':'+frm_data_share.t_crm_client_changzhan.fieldbyname('EDI代码').asstring+':'+':'+'N'+#39; end else begin strRmain:=strRmain+'L:'+':'+':'+':'+':'+'N'+#39; end; str.Add('48:'+':'+':'+strRmain); Count:=Count+1; end; I:=str.Count; str.Add('99:'+intToStr(i+1)+''''); Result:=str; end; function Tfrm_op_seae_edi_ym.CreateZHUEdiFile:TStrings; var str:Tstringlist; sl,sl1:TStrings; i,j,Count,l,M:integer; first:Boolean; strsql,strRmain,strtemp:string; rs,aQuery:Tadoquery; wide_str:widestring; k:integer; strType,s:string; strDatetime:string; SenderCode,ReciverCode:string; function GetRemarksString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('EDI备注').AsString; Result:='17:'; Result:=Result+FormatListString(TempStr,5,35)+''''; finally FreeAndNil(TempStr); end; end; function GetShipperString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=aQuery.fieldbyname('发货人代码').AsString; Result:='20:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetConsigneString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=aQuery.fieldbyname('收货人代码').AsString; Result:='21:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetNOTIFYString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=aQuery.fieldbyname('通知人代码').AsString; Result:='22:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetMARKSString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=aQuery.fieldbyname('唛头').AsString; Result:='44:'; Result:=Result+FormatListString(TempStr,10,35)+''''; finally FreeAndNil(TempStr); end; end; function GetCARGODESCRIPTIONString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=aQuery.fieldbyname('货物描述').AsString; Result:='47:'; Result:=Result+FormatListString(TempStr,5,70)+''''; finally FreeAndNil(TempStr); end; end; begin SenderCode:=trim(edit1.Text) ; ReciverCode:=trim(edit2.Text) ; if bsSkinRadioGroup1.ItemIndex=0 then strType:='9' else if bsSkinRadioGroup1.ItemIndex=1 then strType:='2' else if bsSkinRadioGroup1.ItemIndex=2 then strType:='3' else if bsSkinRadioGroup1.ItemIndex=3 then strType:='4' else strType:='9'; str:=Tstringlist.Create; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; str.Clear; str.Add('00:IFTMBF:BOOKING:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+#39); Count:=0; aQuery:=CreateAdoQuery; try aQuery.Close;aQuery.sql.Clear; aQuery.SQL.Add('select * from t_op_seae where 主编号=:编号 and 主编号<>编号'); aQuery.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring; aQuery.Open; if not aQuery.IsEmpty then begin if not isEditrue(aQuery) then exit; aQuery.first; first:=true; while not aQuery.eof do begin if first then begin str.Add ('02:'+ trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring) +':' + trim(aQuery.fieldbyname('运输条款').asstring) +'::' + ReciverCode+':' + ':::::::' + '::' + trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring)+':' +':'+ #39); end else begin str.Add ('02:'+ trim(aQuery.fieldbyname('业务编号').asstring)+':' + trim(aQuery.fieldbyname('主提单号').asstring) +':' + trim(aQuery.fieldbyname('运输条款').asstring) +':' + trim(Edit3.Text) +':' + ReciverCode+':' + ':::::::' + '::' + trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring)+':' +':'+ #39); { str.Add ('02:'+ trim(aQuery.fieldbyname('业务编号').asstring)+':' + trim(aQuery.fieldbyname('主提单号').asstring) +':' + trim(aQuery.fieldbyname('运输条款').asstring) +'::' + ReciverCode +':' + ':::::::' + trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring)+':' +':::'+ #39); } end; if trim(aQuery.fieldbyname('签单方式').asstring)='正本' then strtemp:='ORI' else strtemp:='EXP'; str.add('03:'+strtemp+':' +':' + trim(aQuery.fieldbyname('签单地点').asstring) +':' + GetDatetime(trim(aQuery.fieldbyname('签单日期').asstring),0)+':' + get_fenshu(trim(aQuery.fieldbyname('提单份数').asstring))+':' + trim(aQuery.fieldbyname('预付地点').asstring) +':' + trim(aQuery.fieldbyname('预付地点').asstring) +#39); str.Add('11:' + trim(frm_op_seae.t_op_seae.fieldbyname('发货人编号').asstring)+':' + trim(aQuery.fieldbyname('船名').asstring) +':' + trim(aQuery.fieldbyname('航次').asstring)+':' +'::' + ReciverCode +':' + '::::::' +#39); //船舶经营人 str.Add ('12:'+trim(aQuery.fieldbyname('装港代码').asstring)+':' +trim(aQuery.fieldbyname('装货港').asstring)+':' +trim(aQuery.fieldbyname('装港代码').asstring)+':' +trim(aQuery.fieldbyname('装货港').asstring)+':' +trim(aQuery.fieldbyname('卸货代码').asstring) +':' +trim(aQuery.fieldbyname('卸货港').asstring)+':' +':' +':' +trim(aQuery.fieldbyname('交货代码').asstring) +':' +trim(aQuery.fieldbyname('交货地点').asstring) +':' +trim(aQuery.fieldbyname('目的地代码').asstring) +':' +trim(aQuery.fieldbyname('目的地').asstring) +#39); if frm_data_share.t_code_free.locate('付费方式',aQuery.fieldbyname('付费方式').asstring,[]) then begin str.Add ('14:'+frm_data_share.t_code_free.fieldbyname('代码').asstring+':' +trim(aQuery.fieldbyname('付费方式').asstring)+#39); str.Add('15:' +'::' +trim(frm_data_share.t_code_free.fieldbyname('代码').asstring)+':' +'::' + '::::' +#39); //船舶经营人 end else begin str.Add ('14:'+'P'+':' +trim(aQuery.fieldbyname('付费方式').asstring)+#39); str.Add('15:' +'::' +'P:' +'::' + '::::' +#39); //船舶经营人 end; if trim(aQuery.fieldbyname('EDI备注').asstring)<>'' then Str.Add(GetRemarksString); Str.Add(GetShipperString); Str.Add(GetConsigneString); Str.Add(GetNOTIFYString); str.Add ('41:1::'+trim(aQuery.fieldbyname('货物标识').asstring)+':' // 货物标识 S/R/D/O +trim(aQuery.fieldbyname('件数').asstring) +':' +trim(GetpkgsEdi(aQuery.fieldbyname('包装').asstring))+':' +trim(aQuery.fieldbyname('包装').asstring) +':' //第一层包装说明 +trim(aQuery.fieldbyname('总价').asstring) +':' //第一层包装说明 +trim(aQuery.fieldbyname('尺码').asstring) +'::::::' // 第一层包装皮重 +trim(aQuery.fieldbyname('重量').asstring) +':::' // 第一层包装尺码 +#39); IF trim(aQuery.fieldbyname('货物标识').asstring)='R'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +':' +':' +':' +':' +':' +':' +':' +'::' +trim(aQuery.fieldbyname('冷藏通风量').asstring) +':' +'C:' +trim(aQuery.fieldbyname('设置温度').asstring) +':' +trim(aQuery.fieldbyname('最低温度').asstring) +':' +trim(aQuery.fieldbyname('最高温度').asstring) +':' +'::::' +#39); END; IF trim(aQuery.fieldbyname('货物标识').asstring)='D'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +trim(aQuery.fieldbyname('危险品分类').asstring) +':' +':' +trim(aQuery.fieldbyname('危险品编号').asstring) +':' +':' +':' +':' +':' +'::' +':' +':' +':' +':' +':::::' +#39); END; Str.Add(GetMARKSString); // Str.Add(GetCARGODESCRIPTIONString); sl1.Text:=frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString; sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then sl.Add(sl1.Strings[L]); end; M:=1; for L:=0 to sl.Count-1 do begin if M<=5 then begin if M=1 then begin s:='47:'+FormatEdiString(sl.Strings[L],0)+':'; end else begin if M=5 then s:=s+FormatEdiString(sl.Strings[L],0) else s:=s+FormatEdiString(sl.Strings[L],0)+':'; end; end else begin S:=S+''''; Str.Add(S); M:=1; s:='47:'+FormatEdiString(sl.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); Count:=Count+11; strRmain:=''; if first then strRmain:=strRmain+'L:'+':'+':'+':'+':'+'N'+#39 else strRmain:=strRmain+'L:'+trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring)+':'+':'+':'+':'+'N'+#39; strsql:='select 代码,编号,尺寸,箱型,sum(数量) as 数量 from t_op_ctn group by 代码,编号,尺寸,箱型 having 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; try rs:=Tadoquery.Create(application); rs.Connection := frm_main.db; rs.sql.clear; rs.sql.add(strsql); rs.Open; rs.First; while not rs.Eof do begin str.Add ('48:'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring))+':'+ trim(rs.fieldbyname('数量').asstring)+':'+ strRmain); Count:=Count+1; rs.Next; end; { strsql:='select * from t_op_ctn where 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; rs.Close; rs.sql.clear; rs.sql.add(strsql); rs.Open; if not rs.IsEmpty then begin if rs.FieldByName('件数').AsInteger>0 then begin rs.First; while not rs.Eof do begin str.Add ('51:'+trim(rs.fieldbyname('箱号').asstring)+':'+Trim(GetCntrEdi(rs.fieldbyname('尺寸').asstring,rs.fieldbyname('箱型').asstring))+':'+ trim(rs.fieldbyname('封号').asstring)+':'+trim(IntToStr(rs.fieldbyname('件数').AsInteger))+':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat))+':'+'''' ); rs.Next; end; end; end; } rs.Close; rs.Destroy; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; aQuery.Next; first:=False; end; end; finally FreeAndNil(aQuery); end; I:=str.Count; str.Add('99:'+intToStr(i+1)+''''); Result:=str; end; function Tfrm_op_seae_edi_ym.GetCntrEdi(cntrID: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select Edi代码 from t_code_ctn where 代码='''+cntrID+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('Edi代码').AsString; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_ym.GetpkgsEdi(pkgs: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select Edi代码 from t_code_package where 代码='''+pkgs+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('Edi代码').AsString; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_ym.GetlineEdi(aline: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select Edi代码 from t_code_trade where 航线='''+aline+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('Edi代码').AsString; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_op_seae_edi_ym.bsSkinButton3Click(Sender: TObject); var IdFTP1:TIdFTP; str:widestring; str_file:widestring; ftpar,ftpname,ftppass,ftppath,ScriptPath:String; StrL:TStrings; begin ScriptPath:=ExtractFilePath(ParamStr(0))+'EDIFILE\'; if not DirectoryExists(ScriptPath) then CreateDir(ScriptPath); ftpar:=Trim(edit4.Text); if ftpar='' then begin MessageDlg('请设置FTP地址!',mtWarning,[mbOk],0); exit; end; ftpname:=Trim(edit6.Text); if ftpar='' then begin MessageDlg('请设置FTP用户名!',mtWarning,[mbOk],0); exit; end; ftppass:=Trim(edit7.Text); if ftpar='' then begin MessageDlg('请设置FTP密码!',mtWarning,[mbOk],0); exit; end; ftppath:=Trim(edit5.Text); if bsSkinRadioGroup2.ItemIndex=0 then begin str:=ScriptPath +frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.txt'; str_file:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.txt'; strL:=Tstringlist.Create; try if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then StrL:=CreateEdiFile else if Pos('主票',(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring))>0 then StrL:=CreateZHUEdiFile else begin Exit; end; strL.SaveToFile(str); finally FreeAndNil(StrL) end; end else begin str:=ScriptPath +frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.edi'; str_file:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.edi'; strL:=Tstringlist.Create; try if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then begin StrL:=CreateSIEdiFile; strL.SaveToFile(str); end else begin Exit; end; finally FreeAndNil(StrL) end; end; try IdFTP1:=TIdFTP.Create(application); with idftp1 do begin Username:=ftpname; Password:=ftppass; Host:=ftpar; Connect; end; idftp1.ChangeDir(ftppath); idftp1.TransferType:=ftBinary; idftp1.Put(str,str_file); idftp1.Disconnect; showmessage('文件上传成功!'); except deletefile(str); showmessage('文件上传错误!'); end; idftp1.Free; end; procedure Tfrm_op_seae_edi_ym.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var inifile1:Tinifile; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.WriteString('YMEDI','SEND',edit1.text); inifile1.WriteString('YMEDI','RECIEVE',edit2.text); inifile1.WriteString('YMEDI','SENDNAME',edit3.text); inifile1.WriteString('YMEDI','FTPSERVER',edit4.text); inifile1.WriteString('YMEDI','FTPPATH',edit5.text); inifile1.WriteString('YMEDI','FTPNAME',edit6.text); inifile1.WriteString('YMEDI','FTPPASS',edit7.text); inifile1.free; end; procedure Tfrm_op_seae_edi_ym.bsSkinButton4Click(Sender: TObject); begin if frm_op_seae_edi_ym.Height=301 then frm_op_seae_edi_ym.Height:=162 else frm_op_seae_edi_ym.Height:=301; end; function Tfrm_op_seae_edi_ym.CreateSIEdiFile: TStrings; var str:Tstringlist; sl,sl1:TStrings; i,j,Count,l,M:integer; strsql,strRmain,strtemp,S:string; rs,pkQuery:Tadoquery; wide_str,shipperstr,consigneestr,notipartystr:widestring; k:integer; strType:string; strDatetime:string; SenderCode,ReciverCode:string; function GetShipperString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('发货人代码').AsString; Result:='NAD+CZ++'; Result:=Result+FormatListString(TempStr,16,35)+''''; finally FreeAndNil(TempStr); end; end; function GetConsigneString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('收货人代码').AsString; Result:='NAD+CN++'; Result:=Result+FormatListString(TempStr,16,35)+''''; finally FreeAndNil(TempStr); end; end; function GetNOTIFYString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('通知人代码').AsString; Result:='NAD+N1++'; Result:=Result+FormatListString(TempStr,16,35)+''''; finally FreeAndNil(TempStr); end; end; begin if not isEditrue(frm_op_seae.t_op_seae) then exit; SenderCode:=trim(edit1.Text) ; ReciverCode:=trim(edit2.Text) ; if bsSkinRadioGroup1.ItemIndex=0 then strType:='9' else if bsSkinRadioGroup1.ItemIndex=1 then strType:='2' else if bsSkinRadioGroup1.ItemIndex=2 then strType:='3' else if bsSkinRadioGroup1.ItemIndex=3 then strType:='5' else strType:='9'; str:=Tstringlist.Create; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; str.Clear; str.Add('UNB+UNOC:2+'+ SenderCode+':ZZZ+'+'INTTRA:ZZZ+'+formatdatetime('YYMMDD:HHMM',NOW)+'+'+trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+'++IFTMIN'+#39); str.Add('UNH+'+trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+'+IFTMIN:D:99B:UN'+#39); Count:=0; str.Add ('BGM+340+'+trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring)+'@'+ trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+'+' +strType+ #39); str.Add('DTM+137:'+formatdatetime('YYYYMMDD',now)+':203'+#39); if trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring)='CY TO DOOR' then begin str.Add('TSR+29+2'+#39); end else if trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring)='DOOR TO DOOR' then begin str.Add('TSR+27+2'+#39); end else if trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring)='DOOR TO CY' then begin str.Add('TSR+28+2'+#39); end else begin str.Add('TSR+30+2'+#39); end; IF frm_op_seae.t_op_seae.fieldbyname('EDI备注').asstring<>'' THEN str.Add('FTX+DOC+++'+frm_op_seae.t_op_seae.fieldbyname('EDI备注').asstring+#39); // str.Add('FTX+AAI+++'+#39); str.Add('CNT+7:'+trim(frm_op_seae.t_op_seae.fieldbyname('重量').asstring)+':KGM'+#39); str.Add('CNT+11:'+trim(frm_op_seae.t_op_seae.fieldbyname('件数').asstring)+#39); str.Add('CNT+15:'+trim(frm_op_seae.t_op_seae.fieldbyname('尺码').asstring)+':MTQ'+#39); pkQuery:=CreateAdoQuery; try with pkQuery do begin Close; SQL.text:='select sum(数量) as 数量 from t_op_ctn where 编号='''+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+''''; open; if not IsEmpty then str.Add('CNT+16:'+trim(pkQuery.fieldbyname('数量').asstring)+#39); end; finally FreeAndNil(pkQuery); end; if frm_data_share.t_code_disport.Locate('英文名',trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring+frm_op_seae.t_op_seae.fieldbyname('到付地点').asstring),[]) then str.Add('LOC+57+'+frm_data_share.t_code_disport.fieldbyname('EDI代码').AsString+'::6:'+trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring+frm_op_seae.t_op_seae.fieldbyname('到付地点').asstring)+#39) else str.Add('LOC+57+'+'::6:'+trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring+frm_op_seae.t_op_seae.fieldbyname('到付地点').asstring)+#39); if frm_data_share.t_code_disport.Locate('英文名',frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring,[]) then str.Add('LOC+73+'+frm_data_share.t_code_disport.fieldbyname('EDI代码').AsString+'::6:'+trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring)+#39) else str.Add('LOC+73+'+'::6:'+trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring)+#39); str.Add('RFF+AFG:MLCC'+#39); str.Add('RFF+BM:'+trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring)+#39); str.Add('RFF+BN:'+trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring)+#39); if frm_data_share.t_code_free.locate('付费方式',frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring,[]) then begin str.Add('CPI+4++'+frm_data_share.t_code_free.fieldbyname('代码').asstring+#39); end; str.Add('TDT+20+'+trim(frm_op_seae.t_op_seae.fieldbyname('航次').asstring)+'+1+++++:::'+trim(frm_op_seae.t_op_seae.fieldbyname('船名').asstring)+#39); str.Add('LOC+88+'+trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring)+':::'+trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring)+#39); str.Add('LOC+9+'+trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring)+':::'+trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring)+#39); str.Add('LOC+11+'+trim(frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring)+':::'+trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring)+#39); str.Add('LOC+7+'+trim(frm_op_seae.t_op_seae.fieldbyname('交货代码').asstring)+':::'+trim(frm_op_seae.t_op_seae.fieldbyname('交货地点').asstring)+#39); str.Add('DTM+133:'+formatdatetime('YYYYMMDD',frm_op_seae.t_op_seae.fieldbyname('开船日期').AsDateTime)+':102'+#39); str.Add('NAD+CA+YMLU:160:86++YMLU'+#39); str.Add('NAD+ZZZ+'+SenderCode+':160:86++'+SenderCode+#39); str.Add('NAD+FW+'+SenderCode+':160:86++'+SenderCode+#39); Str.Add(GetShipperString); Str.Add(GetConsigneString); Str.Add(GetNOTIFYString); if trim(frm_op_seae.t_op_seae.fieldbyname('签单方式').asstring)='海运单' then str.Add('DOC+710+++3+3'+#39) else if trim(frm_op_seae.t_op_seae.fieldbyname('签单方式').asstring)='正本' then str.Add('DOC+706+++3+3'+#39); str.Add('GID+1+'+trim(frm_op_seae.t_op_seae.fieldbyname('件数').asstring)+':'+trim(GetpkgsEdi(frm_op_seae.t_op_seae.fieldbyname('包装').asstring))+'::6:'+trim(frm_op_seae.t_op_seae.fieldbyname('包装').asstring)+#39); str.Add('TMD+3'+#39); sl1.Text:=frm_op_seae.t_op_seae.fieldbyname('货物描述').AsString; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then str.Add('FTX+AAA+++'+sl1.Strings[L]+#39); end; str.Add('MEA+AAE+G+KGM:'+trim(frm_op_seae.t_op_seae.fieldbyname('重量').asstring)+#39); str.Add('MEA+AAE+AAW+MTQ:'+trim(frm_op_seae.t_op_seae.fieldbyname('尺码').asstring)+#39); sl1.Text:=frm_op_seae.t_op_seae.fieldbyname('唛头').AsString; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then str.Add('PCI+23+'+sl1.Strings[L]+#39); end; rs:=CreateAdoQuery; try rs.sql.text:='select * from t_op_ctn where 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; rs.Open; if not rs.IsEmpty then begin if rs.FieldByName('件数').AsInteger>0 then begin rs.First; while not rs.Eof do begin str.Add ('SGP+'+trim(rs.fieldbyname('箱号').asstring)+'+'+trim(IntToStr(rs.fieldbyname('件数').AsInteger))+#39); str.Add ('MEA+AAE+G+KGM:'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat))+#39); str.Add ('MEA+AAE+AAW+MTQ:'+trim(FloatToStr(rs.fieldbyname('尺码').AsFloat))+#39); rs.Next; end; end; end; IF trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='D'THEN BEGIN str.Add ('DGS+IMD+' // 危险品、冷冻 +trim(frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring) +':' +'+' +trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring) +'+' +':' +'+' +'+' +#39); END; if not rs.IsEmpty then begin if rs.FieldByName('件数').AsInteger>0 then begin rs.First; while not rs.Eof do begin str.Add ('EQD+CN+'+trim(rs.fieldbyname('箱号').asstring)+'+'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring))+#39); str.Add ('SEL+'+trim(rs.fieldbyname('封号').asstring)+'+CA'+#39); IF trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='R'THEN BEGIN str.Add ('TMP+2+' // 危险品、冷冻 +trim(frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring) +':' +':' +'CEL'+#39); END; rs.Next; end; end; end; finally FreeAndNil(rs); end; I:=str.Count; str.Add('UNT+'+intToStr(i+1)+'+'+trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+''''); str.Add('UNZ+1+'+trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring)+''''); Result:=str; end; end.