unit u_op_seae_edi_custom_cosco; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IdFTP,IdFTPCommon, Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB; type Tfrm_op_seae_edi_custom_cosco = 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; bsSkinRadioGroup2: TbsSkinRadioGroup; bsSkinButton4: TbsSkinButton; bsSkinGroupBox1: TbsSkinGroupBox; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Label8: TLabel; Edit8: TEdit; Label9: TLabel; Edit9: TEdit; Label10: TLabel; Edit10: TEdit; Label11: TLabel; Edit11: TEdit; Label12: TLabel; Edit12: TEdit; Label13: TLabel; Label14: TLabel; Edit13: TEdit; Edit14: TEdit; Label15: TLabel; Edit15: TEdit; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; procedure bsSkinButton2Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); 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(str:String;Strlength:integer=0):String; function CreateSIEdiFile_MBL:TStrings; function GetCntrEdi(cntrsize: String):String; function GetpkgsEdi(pkgs:String):String; function GetlineEdi(aline:String):String; function GetvesselEdi(avessel:String):String; function GetLengthword(var s: String; l: Integer;str:String): String; procedure GetLengthTString(var sl:TStringList;l:integer); function IsZhongwen(Str:String):Boolean; function Changestr(str:widestring):string; { Private declarations } public { Public declarations } function GetPortStr(Port:String):String; function GetPPCC(aFree:String):string; function GetCntrSize(code,Cntr:String):string; function Getport(code,port:String):string; function GetCarrCustomNO(sanme:String):string; procedure Edi_ZY; end; var frm_op_seae_edi_custom_cosco: Tfrm_op_seae_edi_custom_cosco; implementation uses u_op_seae_edi_data, u_main, my_sys_function, u_data_share; {$R *.dfm} procedure Tfrm_op_seae_edi_custom_cosco.Edi_ZY; var str,sl,sl1:Tstringlist; i,j,Count,L,M:integer; strsql,strRmain,strtemp,S,mblno:string; rs:Tadoquery; aQuery2:Tadoquery; wide_str:widestring; k:integer; inifile1:Tinifile; strType:string; strDatetime:string; SenderCode,ReciverCode:string; function GetShipperString:String; var TempStr:TStringList; begin TempStr:=TStringList.Create; try TempStr.Text:=FormatEdiString(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人名称').AsString+' '+ frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人地址1').AsString); GetLengthTString(TempStr,35); Result:='16:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetConsigneString:String; var TempStr:TStringList; begin TempStr:=TStringList.Create; try TempStr.Text:=FormatEdiString(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人名称').AsString+' '+ frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人地址1').AsString); GetLengthTString(TempStr,35); Result:='17:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetNOTIFYString:String; var TempStr:TStringList; begin TempStr:=TStringList.Create; try TempStr.Text:=FormatEdiString(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人名称').AsString+' '+ frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人地址1').AsString); GetLengthTString(TempStr,35); Result:='18:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,6,35)+''''; finally FreeAndNil(TempStr); end; end; function GetMARKSString:String; var TempStr:TStringList; begin TempStr:=TStringList.Create; try TempStr.Text:=FormatEdiString(frm_op_seae_edi_data.t_op_seae.fieldbyname('唛头').AsString); GetLengthTString(TempStr,35); Result:='44:'; Result:=Result+FormatListString(TempStr,10,35)+''''; finally FreeAndNil(TempStr); end; end; begin SenderCode:=trim(edit1.Text) ; ReciverCode:=trim(edit2.Text) ; strType:='9'; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; if frm_op_seae_edi_data.dxdbgrid1.SelectedCount<=1 then begin str:=Tstringlist.Create; str.Clear; str.Add('00:IFCSUM:MANIFEST:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+FormatDateTime('YYMMDDHHMM', Now)+#39); Count:=0; str.Add('10::' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('船名').asstring) +':' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('航次').asstring) + '::::' + FormatDateTime('YYYYMMDD',frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asdatetime)+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring)+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring) +#39); //船舶经营人 str.Add('11:' +'SOF'+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('船公司代码').asstring) +#39); //船舶经营人 if frm_data_share.t_code_free.locate('代码',frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring,[]) then begin strtemp:=copy(frm_data_share.t_code_free.fieldbyname('代码').asstring,1,1); end else begin strtemp:='P'; end; if trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring)<>'' then mblno:=trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring) else mblno:=trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('主提单号').asstring); str.Add ('12:'+mblno+':' +':::::' // 收货地 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring)+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring)+':' +'CY-CY'+':' +strtemp+':' +FormatDateTime('YYYYMMDD',frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asdatetime)+#39); str.Add ('13:'+frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货代码').asstring+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货港').asstring)+':' +frm_op_seae_edi_data.t_op_seae.fieldbyname('目的代码').asstring+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('目的地').asstring) +#39); Str.Add(GetShipperString); Str.Add(GetConsigneString); Str.Add(GetNOTIFYString); IF trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring)='' THEN strtemp:='S' else strtemp:=trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring); str.Add ('41:001:'+strtemp+':' // 货物标识 S/R/D/O +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) +'::' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring) +':' //第一层包装说明 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) +'::' // 第一层包装尺码 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('尺码').asstring) // 第一层包装皮重 +#39); IF trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring)='R'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('温度单位').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('设置温度').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('最低温度').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('最高温度').asstring) +#39); END; IF trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring)='D'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品分类').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品编号').asstring) +':' +':' +':' +#39); END; Str.Add(GetMARKSString); // Str.Add(GetCARGODESCRIPTIONString); sl1.Text:=FormatEdiString(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').AsString); GetLengthTString(sl1,70); 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; str.Add ('51:::::::::::::::'+''''); count:=str.count; str.Add ('99:'+ inttostr(count+1)+#39); end else begin str:=Tstringlist.Create; str.Clear; str.Add('00:IFCSUM:MANIFEST:'+trim(strType)+':'+ SenderCode+':'+ ReciverCode +':'+FormatDateTime('YYMMDDHHMM', Now)+#39); str.Add('10::' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('船名').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('航次').asstring) + '::::' + FormatDateTime('YYYYMMDD',frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asdatetime)+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring)+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring) +#39); //船舶经营人 str.Add('11:' +'SOF'+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('船公司代码').asstring) +#39); //船舶经营人 Count:=0; for k:=0 to frm_op_seae_edi_data.dxdbgrid1.SelectedCount-1 do begin frm_op_seae_edi_data.t_op_seae.GotoBookmark(pointer(frm_op_seae_edi_data.dxdbgrid1.selectedrows[k])); if frm_data_share.t_code_free.locate('代码',frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring,[]) then begin strtemp:=copy(frm_data_share.t_code_free.fieldbyname('代码').asstring,1,1); end else begin strtemp:='P'; end; if trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring)<>'' then mblno:=trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring) else mblno:=trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('主提单号').asstring); str.Add ('12:'+mblno+':' +':::::' // 收货地 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring)+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring)+':' +'CY-CY'+':' +strtemp+':' +FormatDateTime('YYYYMMDD',frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asdatetime)+#39); str.Add ('13:'+frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货代码').asstring+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货港').asstring)+':' +frm_op_seae_edi_data.t_op_seae.fieldbyname('目的代码').asstring+':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('目的地').asstring) +#39); Str.Add(GetShipperString); Str.Add(GetConsigneString); Str.Add(GetNOTIFYString); IF trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring)='' THEN strtemp:='S' else strtemp:=trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring); str.Add ('41:001:'+strtemp+':' // 货物标识 S/R/D/O +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) +'::' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring) +':' //第一层包装说明 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) +'::' // 第一层包装尺码 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('尺码').asstring) // 第一层包装皮重 +#39); IF trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring)='R'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('温度单位').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('设置温度').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('最低温度').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('最高温度').asstring) +#39); END; IF trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物标识').asstring)='D'THEN BEGIN str.Add ('43:' // 危险品、冷冻 +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品分类').asstring) +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品编号').asstring) +':' +':' +':' +#39); END; Str.Add(GetMARKSString); // Str.Add(GetCARGODESCRIPTIONString); sl1.Text:=FormatEdiString(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').AsString); GetLengthTString(sl1,70); 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; str.Add ('51:::::::::::::::'+''''); end; count:=str.count; str.Add ('99:'+ inttostr(count+1)+#39); end; freeandnil(sl); freeandnil(sl1); SaveDialog1.FileName:=frm_op_seae_edi_data.t_op_seae.fieldbyname('船名').asstring+frm_op_seae_edi_data.t_op_seae.fieldbyname('航次').asstring; if SaveDialog1.Execute then begin str.SaveToFile(SaveDialog1.FileName+'.txt'); showmessage('文件生成成功!'); end else begin showmessage('文件生成失败!'); exit; end; close; end; function Tfrm_op_seae_edi_custom_cosco.Changestr(str:widestring):string; var i:integer; strC:widestring; begin strC:=''; for i:=1 to length(str) do begin if ((str[i]=#39) or (str[i]=':') or (str[i]='''') or (str[i]='+') or (str[i]='?')) then begin strC:=strC+'?'+str[i]; end else begin strC:=strC+str[i]; end; end; result:=strC; end; function Tfrm_op_seae_edi_custom_cosco.GetCarrCustomNO(sanme:String):string; var aQuery:TADOQuery; begin result:=''; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 客户简称,海关编码 from t_crm_client where 客户简称=:客户简称'); Parameters.ParamByName('客户简称').Value:=sanme; Open; if (not IsEmpty) and (FieldByName('海关编码').AsString<>'') then begin Result:=FieldByName('海关编码').AsString; end; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_custom_cosco.GetPPCC(aFree:String):string; var aQuery:TADOQuery; begin result:=''; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 代码 from t_code_FREE where 付费方式=:FREE'); Parameters.ParamByName('FREE').Value:=aFree; Open; if (not IsEmpty) and (FieldByName('代码').AsString<>'') then begin Result:=FieldByName('代码').AsString; end; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_custom_cosco.GetCntrSize(code,Cntr:String):string; var aQuery:TADOQuery; begin result:=Cntr; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select EDI代码 from t_code_ctn where 代码='''+Code+''''); Open; if (not IsEmpty) and (FieldByName('EDI代码').AsString<>'') then begin Result:=FieldByName('EDI代码').AsString; end; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_custom_cosco.Getport(code,port:String):string; var aQuery:TADOQuery; begin result:=port; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 港口名称 from t_code_edi_port where EDI代码='''+Code+''''); Open; if (not IsEmpty) and (FieldByName('港口名称').AsString<>'') then begin Result:=FieldByName('港口名称').AsString; end; end; if Pos(',',Result)>0 then Result:=Copy(Result,1,Pos(',',Result)-1); finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_custom_cosco.GetPortStr(Port:String):String; begin if Pos(',',Port)>0 then Result:=Copy(Port,1,Pos(',',Port)-1) else Result:=Port; end; function Tfrm_op_seae_edi_custom_cosco.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) then begin if bytetype(Str[i],1)<>mbsinglebyte then begin Result:=True; Exit; end; end; end; function Tfrm_op_seae_edi_custom_cosco.GetLengthword(var s: String; l: Integer;str:String): String; var i:Integer; b:Boolean; begin s:=''; if Length(str)<=l then begin result:=str; end else begin b:=true; s:=Copy(str,l+1,Length(str)-l); str:=Copy(str,1,l); result:=''; for i:=Length(str) downto 1 do begin if ( not (str[i] in [' ',';',',','.',':','/','(',')','?','+','-'])) and b then s:=str[i]+s else begin b:=false; result:=str[i]+Result; end; end; s:=s+' '; end; end; procedure Tfrm_op_seae_edi_custom_cosco.GetLengthTString(var sl: TStringList; l: integer); var i:integer; str_head,S:String; Stemp:TStrings; begin Stemp:=TStringList.Create; try str_head:=''; S:=''; for i:=0 to sl.Count-1 do begin if sl[i]<>'' then stemp.add(GetLengthword(str_head,l,s+sl[i])); S:=Str_head; end; while S<>'' do begin stemp.add(GetLengthword(str_head,l,s)); S:=Str_head; end; SL.Assign(Stemp); finally FreeAndNil(Stemp); end; end; function Tfrm_op_seae_edi_custom_cosco.FormatEdiString(str:String;Strlength:integer=0):String; var i:integer; strC:widestring; begin strC:=''; for i:=1 to length(str) do begin if ((str[i]=#39) or (str[i]=':') or (str[i]='+') or (str[i]='?') or (str[i]=';')) then begin strC:=strC+'?'+str[i]; end else begin strC:=strC+str[i]; end; end; result:=strC; end; function Tfrm_op_seae_edi_custom_cosco.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 i4 then begin result:=false; MessageDlg('危险品编号必须是4位数字',mtWarning,[mbOk],0); exit; end; end; if trim(frm_op_seae_edi_data.t_op_seae.FieldByName('货物标识').asstring)='R' then begin if Trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('设置温度').asstring)='' then begin result:=false; MessageDlg('设置温度不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae_edi_data.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_edi_data.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(t_op_ctn.fieldbyname('箱号').asstring)='' then begin result:=false; MessageDlg('箱号不能为空!',mtWarning,[mbOk],0); exit; end; { if Trim(t_op_ctn.fieldbyname('封号').asstring)='' then begin result:=false; MessageDlg('封号不能为空!',mtWarning,[mbOk],0); exit; end; } t_op_ctn.Next; end; if iszhongwen(dataset.fieldbyname('发货人代码').AsString) then begin result:=false; MessageDlg('发货人不能有中文字符!',mtWarning,[mbOk],0); exit; end; if iszhongwen(dataset.fieldbyname('收货人代码').AsString) then begin result:=false; MessageDlg('收货人不能有中文字符!',mtWarning,[mbOk],0); exit; end; if iszhongwen(dataset.fieldbyname('通知人代码').AsString) then begin result:=false; MessageDlg('通知人不能有中文字符!',mtWarning,[mbOk],0); exit; end; if iszhongwen(dataset.fieldbyname('唛头').AsString) then begin result:=false; MessageDlg('唛头不能有中文字符!',mtWarning,[mbOk],0); exit; end; if iszhongwen(dataset.fieldbyname('货物描述').AsString) then begin result:=false; MessageDlg('货物描述不能有中文字符!',mtWarning,[mbOk],0); exit; end; end; function Tfrm_op_seae_edi_custom_cosco.CreateSIEdiFile_MBL:TStrings; var str:Tstringlist; Tempstr : TStrings; Temprslt : string; i,j,Count:integer; strsql,strRmain:string; rs,aQuery2:Tadoquery; wide_str:widestring; k:integer; inifile1:Tinifile; strType,XType,cntstatus:string; strDatetime:string; SenderCode,ReciverCode:string; aAdoQuery:TAdoQuery; begin if not isEditrue(frm_op_seae_edi_data.t_op_seae) then begin Exit; end; aAdoQuery:=CreateAdoQuery; 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'; // ShowMessage(IntToStr(frm_op_seae_edi_data.dxdbgrid1.SelectedCount)); if frm_op_seae_edi_data.dxdbgrid1.SelectedCount<=1 then begin str:=Tstringlist.Create; str.Clear; str.Add('00:CN2101::'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),4)+':1.0'+#39); // Count:=0; str.Add ('10' +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('船舶IMO').asstring // 2 船舶IMO编号 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('船名').AsString) //3船名 +':' //4舶国籍代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('航次').asstring) //5航次 +':' //6 航线代码 +':' //7 航线 +':' //8预计到达日期 +':'+ GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asstring,4) +'086'//9 离港日期(船舶启运日期和时间) +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring // 10离港地点代码(船舶离境地海关代码) +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring // 11 离港地点 +':' //12 下一挂港代码 +':' //13 下一挂港 +':' //14集装箱箱数 +':1' //15运输方式代码 +#39); str.Add('11' +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('船公司代码').AsString //2 船公司(承运人)代码 +':' //3 船公司(承运人) +':'+SenderCode //4舱单传输人名称 ??? +':' //5船舶代理企业代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货代码').asstring) //6船舶抵达关境内第一个目的港代码 +':'+ GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('预抵日期').asstring,4) +'086'//7船舶抵达关境内第一个目的港的日期和时间 + #39); if pos('FREIGHT PREPAID',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'PO' else if pos('FREIGHT COLLECT',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'CC' else xtype := 'PO'; str.add('12:' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('主提单号').asstring) //2总提运单号 +':' //3 前程运输船名代码 +':' //4 前程运输船名 +':' //5 前程运输航次 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('交货代码').asstring) //6 收货地代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('交货地点').asstring) //7收货地名称 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring) //8装货港代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring) //9装货港 +':' //10运输条款 +':'+ XType //11付款方式(运费支付方法代码) +':'+ GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asstring,4) +'086'//12 离港日期(船舶启运日期和时间) +':' //13检疫代码 +':' //14签发日期 +':' //15币种(金额类型代码) +':' //16 汇率 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring) //17 分提运单号 +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) //18 托运货物总件数 +':'+trim(GetpkgsEdi(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring)) //19 包装种类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) //20 货物总毛重 +':' //21 货物体积 +':' //22 托运货物价值 +':' //23 码头作业指令代码 +':' //24 拆箱人代码 +':' //25 前一海关单证号 +':' //26 前一海关单证类型代码 +':001' //27 货物海关处理状态代码(1~99) +#39); str.add('13:' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货代码').asstring) //2卸货地代码 ??? +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货港').asstring) //3卸货港 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('目的代码').asstring) //4交货地代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('目的地').asstring) //5交货地 + ':' // 6 中转港代码 + ':' // 7 中转港 + ':CN' // 8 提单签发地代码(货物托运地或者国家代码) +':' // 9 +':' // 10 +':' +GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('预抵日期').asstring,0) // 11 +':' // 12 +':' // 13 +#39); str.add('16' +':' //2 发货人代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人名称').AsString) //3发货人名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人地址1').AsString) //4发货人地址(街道,邮箱) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人城市').AsString) //5 城市名称 +':' //6 省份代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人州').AsString) //7 省份名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人邮编').AsString) //8 邮政编码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) //9 国家代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人电话').AsString) //10 发货人电话 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人联系人').AsString) //11 发货人EMAIL +':' ///12 发货人传真 +#39); str.add('17' +':' //2 收货人代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人名称').AsString) //3收货人名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人地址1').AsString) //4收货人地址(街道,邮箱) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人城市').AsString) //5 城市名称 +':' //6 省份代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人州').AsString) //7 省份名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人邮编').AsString) //8 邮政编码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人国家代码').AsString) //9 国家代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人电话').AsString) //10 收货人电话 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人联系人').AsString) //11 收货人EMAIL +':' ///12 收货人传真 +':' ///13 收货人具体联系人名称 +':' ///14 收货人具体联系人电话 +':' ///15 收货人具体联系人EMAIL +':' ///16 收货人具体联系人传真 +#39); str.add('18' +':' //2 通知人代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人名称').AsString) //3通知人名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人地址1').AsString) //4通知人地址(街道,邮箱) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人城市').AsString) //5 城市名称 +':' //6 省份代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人州').AsString) //7 省份名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人邮编').AsString) //8 邮政编码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) //9 国家代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人电话').AsString) //10 通知人电话 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人联系人').AsString) //11 通知人EMAIL +':' ///12 通知人传真 +#39); str.Add ('41:1' //2货物序号 +':' //3货类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) //4 货物件数 +':'+trim(GetpkgsEdi(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring)) //5 包装种类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring) // 6 包装类型 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) // 7货毛重 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) // 8货净重 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('尺码').asstring) // 9货尺码 +':' // 10海关税则编号 +':' // 11海关手续代码 +':' // 12原产地代码 +#39); with aAdoQuery do begin Close;sql.Clear; sql.Add('select 箱号'); sql.Add('from t_op_ctn_edi'); sql.Add('where 编号=:编号'); Parameters.ParamByName('编号').Value:=frm_op_seae_edi_data.t_op_seae.fieldbyname('编号').asstring; Open;First; while not Eof do begin str.Add ('42' +':'+trim(fieldbyname('箱号').asstring) //2 箱号 +#39); Count:=Count+1; Next; end; end; if trim(frm_op_seae_edi_data.t_op_seae.FieldByName('货物标识').asstring)='D' then begin str.Add ('43:'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品分类').asstring) //2危险品分类 +':none' //3危险品页号 +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品编号').asstring) //4联合国危险品编号 +':none' //5危险品标签 +':' //6 危险货物闪点 +':' //7 船运危险品应急措施号 +':' //8 医疗急救指南号 +':' //9 应急联系 +':' //10 温度计量单位 +':' //11 设置温度 +':' //12 冷藏最低温度 +':' //13 冷藏最高温度 +':' //14 危险品联系人姓名 +':' //15 危险品联系人电话 +':' //16 危险品联系人EMAIL +':' //17 危险品联系人传真 +#39); end else if trim(frm_op_seae_edi_data.t_op_seae.FieldByName('货物标识').asstring)='R' then begin str.Add ('43:' //2危险品分类 +':' //3危险品页号 +':' //4联合国危险品编号 +':' //5危险品标签 +':' //6 危险货物闪点 +':' //7 船运危险品应急措施号 +':' //8 医疗急救指南号 +':' //9 应急联系 +':C' //10 温度计量单位 +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('设置温度').asstring //11 设置温度 +':' //12 冷藏最低温度 +':' //13 冷藏最高温度 +':' //14 危险品联系人姓名 +':' //15 危险品联系人电话 +':' //16 危险品联系人EMAIL +':' //17 危险品联系人传真 +#39); end; Temprslt:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('唛头').asstring); Temprslt:=StringReplace(Temprslt,#13#10,' ',[rfReplaceAll]); str.Add ('44:' +Temprslt + #39); Temprslt:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').asstring); Temprslt:=StringReplace(Temprslt,#13#10,' ',[rfReplaceAll]); str.Add ('47:' + Temprslt+ ':' + #39); Count:=Count+10; strsql:='select * from t_op_ctn_edi ' +'WHERE 编号=' +#39+frm_op_seae_edi_data.t_op_seae.fieldbyname('编号').asstring+#39; if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='空' then cntstatus:='4' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='重' then cntstatus:='5' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='满' then cntstatus:='6' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='拼' then cntstatus:='7' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='整' then cntstatus:='8' else cntstatus:='8'; try rs:=Tadoquery.Create(application); rs.Connection := frm_main.db; rs.sql.clear; rs.sql.add(strsql); rs.Open; rs.First; if not rs.IsEmpty then begin rs.First; while not rs.Eof do begin str.Add ('51:001' //2货物序号 +':'+trim(rs.fieldbyname('箱号').asstring) //3箱号 +':'+trim(rs.fieldbyname('封号').asstring) //4主铅封号 +':'+Trim(rs.fieldbyname('尺寸').asstring+rs.fieldbyname('箱型').asstring) //5集装箱尺寸类型 +':'+cntstatus //6箱状态(重箱或者空箱标识代码) +':' +trim(IntToStr(rs.fieldbyname('件数').AsInteger)) //7箱内货物件数 +':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat)) //8箱内货重 +':0' //9箱皮重 +':'+trim(FloatToStr(rs.fieldbyname('尺码').AsFloat)) //10箱内货物尺码 +':' //11 +':' //12 +':' //13 +':' // 14 +':' // 15 +':' // 16 +':2' // 17 +#39); str.Add ('52' +':'+trim(rs.fieldbyname('封号').asstring) //2 封志号 +':M' //3 封志类型 +':CA' //4 施加封志人 +#39); Count:=Count+1; rs.Next; end; end; rs.Close; rs.Destroy; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; { frm_op_seae_edi_data.t_op_seae.Edit; frm_op_seae_edi_data.t_op_seae.FieldByName('EDI状态').AsString:='已发送'; frm_op_seae_edi_data.t_op_seae.Post; } str.Add ('99:'+ inttostr(Count+2)+#39); end else begin str:=Tstringlist.Create; str.Clear; str.Add('00:CN1101::'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),4)+':1.0'+#39); Count:=0; str.Add ('10' +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('船舶IMO').asstring // 2 船舶IMO编号 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('船名').AsString) //3船名 +':' //4舶国籍代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('航次').asstring) //5航次 +':' //6 航线代码 +':' //7 航线 +':' //8预计到达日期 +':'+ GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asstring,4) +'086'//9 离港日期(船舶启运日期和时间) +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring // 10离港地点代码(船舶离境地海关代码) +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring // 11 离港地点 +':' //12 下一挂港代码 +':' //13 下一挂港 +':' //14集装箱箱数 +':1' //15运输方式代码 +#39); str.Add('11' +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('船公司代码').AsString //2 船公司(承运人)代码 +':' //3 船公司(承运人) +':'+SenderCode //4舱单传输人名称 ??? +':' //5船舶代理企业代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货代码').asstring) //6船舶抵达关境内第一个目的港代码 +':'+ GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('预抵日期').asstring,4) +'086'//7船舶抵达关境内第一个目的港的日期和时间 + #39); for k:=0 to frm_op_seae_edi_data.dxdbgrid1.SelectedCount-1 do begin frm_op_seae_edi_data.t_op_seae.GotoBookmark(pointer(frm_op_seae_edi_data.dxdbgrid1.selectedrows[k])); if pos('FREIGHT PREPAID',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'PO' else if pos('FREIGHT COLLECT',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'CC' else xtype := 'PO'; str.add('12:' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('主提单号').asstring) //2总提运单号 +':' //3 前程运输船名代码 +':' //4 前程运输船名 +':' //5 前程运输航次 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('交货代码').asstring) //6 收货地代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('交货地点').asstring) //7收货地名称 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装港代码').asstring) //8装货港代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('装货港').asstring) //9装货港 +':' //10运输条款 +':'+ XType //11付款方式(运费支付方法代码) +':'+ GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('开船日期').asstring,4) +'086'//12 离港日期(船舶启运日期和时间) +':' //13检疫代码 +':' //14签发日期 +':' //15币种(金额类型代码) +':' //16 汇率 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring) //17 分提运单号 +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) //18 托运货物总件数 +':'+trim(GetpkgsEdi(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring)) //19 包装种类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) //20 货物总毛重 +':' //21 货物体积 +':' //22 托运货物价值 +':' //23 码头作业指令代码 +':' //24 拆箱人代码 +':' //25 前一海关单证号 +':' //26 前一海关单证类型代码 +':001' //27 货物海关处理状态代码(1~99) +#39); str.add('13:' + trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货代码').asstring) //2卸货地代码 ??? +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('卸货港').asstring) //3卸货港 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('目的代码').asstring) //4交货地代码 +':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('目的地').asstring) //5交货地 + ':' // 6 中转港代码 + ':' // 7 中转港 + ':CN' // 8 提单签发地代码(货物托运地或者国家代码) +':' // 9 +':' // 10 +':' +GetDatetime(frm_op_seae_edi_data.t_op_seae.fieldbyname('预抵日期').asstring,0) // 11 +':' // 12 +':' // 13 +#39); str.add('16' +':' //2 发货人代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人名称').AsString) //3发货人名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人地址1').AsString) //4发货人地址(街道,邮箱) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人城市').AsString) //5 城市名称 +':' //6 省份代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人州').AsString) //7 省份名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人邮编').AsString) //8 邮政编码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) //9 国家代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人电话').AsString) //10 发货人电话 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人联系人').AsString) //11 发货人EMAIL +':' ///12 发货人传真 +#39); str.add('17' +':' //2 收货人代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人名称').AsString) //3收货人名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人地址1').AsString) //4收货人地址(街道,邮箱) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人城市').AsString) //5 城市名称 +':' //6 省份代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人州').AsString) //7 省份名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人邮编').AsString) //8 邮政编码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人国家代码').AsString) //9 国家代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人电话').AsString) //10 收货人电话 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人联系人').AsString) //11 收货人EMAIL +':' ///12 收货人传真 +':' ///13 收货人具体联系人名称 +':' ///14 收货人具体联系人电话 +':' ///15 收货人具体联系人EMAIL +':' ///16 收货人具体联系人传真 +#39); str.add('18' +':' //2 通知人代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人名称').AsString) //3通知人名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人地址1').AsString) //4通知人地址(街道,邮箱) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人城市').AsString) //5 城市名称 +':' //6 省份代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人州').AsString) //7 省份名称 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人邮编').AsString) //8 邮政编码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) //9 国家代码 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人电话').AsString) //10 通知人电话 +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人联系人').AsString) //11 通知人EMAIL +':' ///12 通知人传真 +#39); str.Add ('41:1' //2货物序号 +':' //3货类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) //4 货物件数 +':'+trim(GetpkgsEdi(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring)) //5 包装种类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('包装').asstring) // 6 包装类型 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) // 7货毛重 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('重量').asstring) // 8货净重 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('尺码').asstring) // 9货尺码 +':' // 10海关税则编号 +':' // 11海关手续代码 +':' // 12原产地代码 +#39); with aAdoQuery do begin Close;sql.Clear; sql.Add('select 箱号'); sql.Add('from t_op_ctn_edi'); sql.Add('where 编号=:编号'); Parameters.ParamByName('编号').Value:=frm_op_seae_edi_data.t_op_seae.fieldbyname('编号').asstring; Open;First; while not Eof do begin str.Add ('42' +':'+trim(fieldbyname('箱号').asstring) //2 箱号 +#39); Count:=Count+1; Next; end; end; if trim(frm_op_seae_edi_data.t_op_seae.FieldByName('货物标识').asstring)='D' then begin str.Add ('43:'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品分类').asstring) //2危险品分类 +':none' //3危险品页号 +':' +trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('危险品编号').asstring) //4联合国危险品编号 +':none' //5危险品标签 +':' //6 危险货物闪点 +':' //7 船运危险品应急措施号 +':' //8 医疗急救指南号 +':' //9 应急联系 +':' //10 温度计量单位 +':' //11 设置温度 +':' //12 冷藏最低温度 +':' //13 冷藏最高温度 +':' //14 危险品联系人姓名 +':' //15 危险品联系人电话 +':' //16 危险品联系人EMAIL +':' //17 危险品联系人传真 +#39); end else if trim(frm_op_seae_edi_data.t_op_seae.FieldByName('货物标识').asstring)='R' then begin str.Add ('43:' //2危险品分类 +':' //3危险品页号 +':' //4联合国危险品编号 +':' //5危险品标签 +':' //6 危险货物闪点 +':' //7 船运危险品应急措施号 +':' //8 医疗急救指南号 +':' //9 应急联系 +':C' //10 温度计量单位 +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('设置温度').asstring //11 设置温度 +':' //12 冷藏最低温度 +':' //13 冷藏最高温度 +':' //14 危险品联系人姓名 +':' //15 危险品联系人电话 +':' //16 危险品联系人EMAIL +':' //17 危险品联系人传真 +#39); end; Temprslt:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('唛头').asstring); Temprslt:=StringReplace(Temprslt,#13#10,' ',[rfReplaceAll]); str.Add ('44:' +Temprslt + #39); Temprslt:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').asstring); Temprslt:=StringReplace(Temprslt,#13#10,' ',[rfReplaceAll]); str.Add ('47:' + Temprslt+ ':' + #39); Count:=Count+10; if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='空' then cntstatus:='4' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='重' then cntstatus:='5' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='满' then cntstatus:='6' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='拼' then cntstatus:='7' else if frm_op_seae_edi_data.t_op_seae.fieldbyname('装运类型').asstring='整' then cntstatus:='8' else cntstatus:='8'; strsql:='select * from t_op_ctn_edi ' +'WHERE 编号=' +#39+frm_op_seae_edi_data.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; if not rs.IsEmpty then begin rs.First; while not rs.Eof do begin str.Add ('51:001' //2货物序号 +':'+trim(rs.fieldbyname('箱号').asstring) //3箱号 +':'+trim(rs.fieldbyname('封号').asstring) //4主铅封号 +':'+Trim(rs.fieldbyname('尺寸').asstring+rs.fieldbyname('箱型').asstring) //5集装箱尺寸类型 +':'+cntstatus //6箱状态(重箱或者空箱标识代码) +':' +trim(IntToStr(rs.fieldbyname('件数').AsInteger)) //7箱内货物件数 +':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat)) //8箱内货重 +':0' //9箱皮重 +':'+trim(FloatToStr(rs.fieldbyname('尺码').AsFloat)) //10箱内货物尺码 +':' //11 +':' //12 +':' //13 +':' // 14 +':' // 15 +':' // 16 +':2' // 17 +#39); str.Add ('52' +':'+trim(rs.fieldbyname('封号').asstring) //2 封志号 +':M' //3 封志类型 +':CA' //4 施加封志人 +#39); Count:=Count+1; rs.Next; end; end; rs.Close; rs.Destroy; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; { frm_op_seae_edi_data.t_op_seae.Edit; frm_op_seae_edi_data.t_op_seae.FieldByName('EDI状态').AsString:='已发送'; frm_op_seae_edi_data.t_op_seae.Post; } end; str.Add ('99:'+ inttostr(Count+2)+#39); end; Result:=str; close; end; function Tfrm_op_seae_edi_custom_cosco.GetCntrEdi(cntrsize: 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 代码='''+cntrsize+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('Edi代码').AsString; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_custom_cosco.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_custom_cosco.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; function Tfrm_op_seae_edi_custom_cosco.GetvesselEdi(avessel: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 船舶呼号 from t_code_vessel where 英文船名='''+avessel+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('船舶呼号').AsString; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_op_seae_edi_custom_cosco.bsSkinButton3Click(Sender: TObject); var IdFTP1:TIdFTP; str:widestring; str_file:widestring; ftpar,ftpname,ftppass,ftppath,ScriptPath:String; StrL:TStrings; inifile1:Tinifile; i:integer; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.WriteString('customCosco','SEND',edit1.text); inifile1.WriteString('customCosco','RECIEVE',edit2.text); inifile1.WriteString('customCosco','SENDNAME',edit3.text); inifile1.WriteString('customCosco','FTPSERVER',edit4.text); inifile1.WriteString('customCosco','FTPPATH',edit5.text); inifile1.WriteString('customCosco','FTPNAME',edit6.text); inifile1.WriteString('customCosco','FTPPASS',edit7.text); inifile1.WriteString('customCosco','SENDDEPT',edit8.text); inifile1.WriteString('customCosco','SENDATTN',edit9.text); inifile1.WriteString('customCosco','SENDTEL',edit10.text); inifile1.WriteString('customCosco','SENDFAX',edit11.text); inifile1.WriteString('customCosco','SENDEMAIL',edit12.text); inifile1.WriteString('customCosco','SINAME',edit13.text); inifile1.WriteString('customCosco','SIPASS',edit14.text); inifile1.free; 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; if bsSkinRadioGroup2.ItemIndex=1 then begin ftpname:=Trim(edit13.Text); if ftpar='' then begin MessageDlg('请设置FTP用户名!',mtWarning,[mbOk],0); exit; end; ftppass:=Trim(edit14.Text); if ftpar='' then begin MessageDlg('请设置FTP密码!',mtWarning,[mbOk],0); exit; end; end else begin 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; end; ftppath:=Trim(edit5.Text); str:=ScriptPath +frm_op_seae_edi_data.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_edi_data.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 StrL:=CreateSIEdiFile_MBL; for i:=0 to StrL.Count-1 do begin if IsZhongwen(StrL[i]) then begin if MessageDlg('此票业务可能含有中文字符或其他不规范字符,确实要继续上传吗!',mtWarning,[mbYes,mbNo],0)=mrNo then exit; end; end; strL.SaveToFile(str); finally FreeAndNil(StrL) 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_custom_cosco.bsSkinButton4Click(Sender: TObject); begin if frm_op_seae_edi_custom_Cosco.Height=349 then frm_op_seae_edi_custom_Cosco.Height:=200 else frm_op_seae_edi_custom_Cosco.Height:=349; end; end.