unit u_op_seae_edi_custom_ld; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IdFTP,IdFTPCommon, Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, IdBaseComponent, IdMessage,IdAttachmentFile; type Tfrm_op_seae_edi_custom_ld = 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; t_op_ams: TADOQuery; t_op_ams1: TDataSource; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; t_op_seae_assistant: TADOQuery; Label8: TLabel; Edit8: TEdit; Label9: TLabel; Edit9: TEdit; Label10: TLabel; Edit10: TEdit; Label11: TLabel; Edit11: TEdit; Label12: TLabel; Edit12: TEdit; t_op_edictn: TADOQuery; Label13: TLabel; Label14: TLabel; Edit13: TEdit; Edit14: TEdit; Label15: TLabel; Edit15: TEdit; IdMsg: TIdMessage; SMTP1: TIdSMTP; 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; end; var frm_op_seae_edi_custom_ld: Tfrm_op_seae_edi_custom_ld; implementation uses u_op_seae_edi_data, u_main, my_sys_function, u_data_share; {$R *.dfm} function Tfrm_op_seae_edi_custom_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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_ld.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:string; strDatetime:string; SenderCode,ReciverCode,TransType:string; begin if not isEditrue(frm_op_seae_edi_data.t_op_seae) then begin Exit; end; 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'; 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+':'+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航次 +#39); str.Add('11' +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('船公司代码').AsString //2 船公司(承运人)代码 +':' //3 船公司(承运人) + #39); if pos('PREPAID',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'P' else if pos('COLLECT',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'C' else xtype := 'P'; if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='CY-CY' then TransType:='10' else if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='DOOR-DOOR' then TransType:='27' else if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='DOOR-PIER' then TransType:='28' else if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='PIER-DOOR' then TransType:='29' else TransType:='10'; // PIER TO PIER 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装货港 +':'+TransType //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 分提运单号 +#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 中转港 + ':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('签单地点').asstring) // 8 提单签发地代码(货物托运地或者国家代码) +':' // 9 +':' // 10 +#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发货人地址(街道,邮箱) +#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收货人地址(街道,邮箱) +#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通知人地址(街道,邮箱) +#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) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人州').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人邮编').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人电话').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人邮箱').AsString) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) +#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) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人州').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人邮编').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人国家代码').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人电话').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人邮箱').AsString) +':::::' +#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) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人州').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人邮编').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人国家代码').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人电话').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人邮箱').AsString) +':' +#39); str.Add ('41:1' //2货物序号 +':' //3货类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) //4 货物件数 +':'+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货尺码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输方式').asstring) // 10海关税则编号 +':' // 11海关手续代码 +':' // 12原产地代码 +#39); 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; try Tempstr:=TStringList.Create; Tempstr.Clear; Tempstr.Text:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('唛头').asstring); str.Add ('44:' //+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').asstring)+ ':' + FormatListString(Tempstr,5,300)+ ':' +'::::' + #39); finally Tempstr.Free; end; try Tempstr:=TStringList.Create; Tempstr.Clear; Tempstr.Text:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').asstring); str.Add ('47:' //+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').asstring)+ ':' + FormatListString(Tempstr,5,300)+ ':' + #39); finally Tempstr.Free; end; Count:=Count+10; XType := 'F'; strsql:='select t_op_ctn_edi.编号,t_op_ctn_edi.代码,t_op_ctn_edi.箱号,t_op_ctn_edi.封号,t_op_ctn_edi.尺寸,t_op_ctn_edi.箱型,t_op_ctn_edi.件数,t_op_ctn_edi.重量,t_op_ctn_edi.包装,t_op_ctn_edi.尺码,t_code_ctn.EDI代码 from t_op_ctn_edi ' +'left join t_code_ctn on t_code_ctn.代码=t_op_ctn_edi.代码 WHERE t_op_ctn_edi.编号=' +#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集装箱尺寸类型 +':8' //6箱状态(重箱或者空箱标识代码) +':' +trim(IntToStr(rs.fieldbyname('件数').AsInteger)) //7箱内货物件数 +':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat)) //8箱内货重 +':' //9箱皮重 +':' //10箱内货物尺码 +':' //11 +':' //12 +':' //13 +':' // 14 +':' // 15 +':' // 16 +':' // 17 +#39); 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:IFCSUM:MANIFEST:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),4)+':1.0'+#39); Count:=0; for k:=0 to frm_op_seae_edi_data.dxdbgrid1.SelectedCount-1 do begin 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航次 +#39); str.Add('11' +':'+frm_op_seae_edi_data.t_op_seae.fieldbyname('船公司代码').AsString //2 船公司(承运人)代码 +':' //3 船公司(承运人) + #39); if pos('PREPAID',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'P' else if pos('COLLECT',trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('付费方式').asstring)) >0 then xtype := 'C' else xtype := 'P'; if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='CY-CY' then TransType:='10' else if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='DOOR-DOOR' then TransType:='27' else if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='DOOR-PIER' then TransType:='28' else if uppercase(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输条款').asstring)='PIER-DOOR' then TransType:='29' else TransType:='10'; // PIER TO PIER 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装货港 +':'+TransType //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 分提运单号 +#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 中转港 + ':'+ trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('签单地点').asstring) // 8 提单签发地代码(货物托运地或者国家代码) +':' // 9 +':' // 10 +#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发货人地址(街道,邮箱) +#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收货人地址(街道,邮箱) +#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通知人地址(街道,邮箱) +#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) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人州').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人邮编').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人电话').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人邮箱').AsString) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('发货人国家代码').AsString) +#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) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人州').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人邮编').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人国家代码').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人电话').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('收货人邮箱').AsString) +':::::' +#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) +'::'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人州').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人邮编').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人国家代码').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人电话').AsString) +':'+ Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('通知人邮箱').AsString) +':' +#39); str.Add ('41:1' //2货物序号 +':' //3货类代码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('件数').asstring) //4 货物件数 +':'+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货尺码 +':'+trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('运输方式').asstring) // 10海关税则编号 +':' // 11海关手续代码 +':' // 12原产地代码 +#39); 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; try Tempstr:=TStringList.Create; Tempstr.Clear; Tempstr.Text:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('唛头').asstring); str.Add ('44:' + FormatListString(Tempstr,5,300)+ ':' + #39); finally Tempstr.Free; end; try Tempstr:=TStringList.Create; Tempstr.Clear; Tempstr.Text:=Changestr(frm_op_seae_edi_data.t_op_seae.fieldbyname('货物描述').asstring); str.Add ('47:' + FormatListString(Tempstr,5,300)+ ':' + #39); finally Tempstr.Free; end; Count:=Count+10; XType := 'F'; XType := 'F'; strsql:='select t_op_ctn_edi.编号,t_op_ctn_edi.代码,t_op_ctn_edi.箱号,t_op_ctn_edi.封号,t_op_ctn_edi.尺寸,t_op_ctn_edi.箱型,t_op_ctn_edi.件数,t_op_ctn_edi.重量,t_op_ctn_edi.包装,t_op_ctn_edi.尺码,t_code_ctn.EDI代码 from t_op_ctn_edi ' +'left join t_code_ctn on t_code_ctn.代码=t_op_ctn_edi.代码 WHERE t_op_ctn_edi.编号=' +#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集装箱尺寸类型 +':8' //6箱状态(重箱或者空箱标识代码) +':' +trim(IntToStr(rs.fieldbyname('件数').AsInteger)) //7箱内货物件数 +':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat)) //8箱内货重 +':' //9箱皮重 +':' //10箱内货物尺码 +':' //11 +':' //12 +':' //13 +':' // 14 +':' // 15 +':' // 16 +':' // 17 +#39); 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_ld.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_ld.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_ld.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_ld.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_ld.bsSkinButton3Click(Sender: TObject); var str:widestring; StrL:TStrings; i:integer; str_memo:Tmemo; ScriptPath:string; begin ScriptPath:=ExtractFilePath(ParamStr(0))+'CUSTOMFILE\'; if not DirectoryExists(ScriptPath) then CreateDir(ScriptPath); if Trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring)<>'' then begin 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'; end else begin 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'; end; 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); str_memo:=Tmemo.create(application); str_memo.visible:=false; str_memo.Parent:=frm_op_seae_edi_custom_ld; str_memo.Lines.Add('公司名称:海尔舱单-联代'); str_memo.Lines.Add('发送人:'+Employee); try if Trim(str_memo.lines.Text)<>'' then begin SMTP1.AuthType := satDefault; //(satNone, satDefault, satSASL); SMTP1.username:=MailAddress; SMTP1.Password :=MailPw; SMTP1.Host:='mail.sdsmartlogistics.com'; SMTP1.Port:=25; try SMTP1.Connect; except on e : Exception do begin ShowMessage('连接邮箱出错:'+E.Message); end; end; if not SMTP1.Connected then begin Sleep(1000); SMTP1.Connect; end; try with IdMsg do begin body.Clear; Body.Text :=str_memo.lines.Text; From.address :=MailAddress; Recipients.EMailAddresses :=MailAddress; if Trim(frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring)<>'' then Subject:='海尔舱单 主提单号:'+frm_op_seae_edi_data.t_op_seae.fieldbyname('主提单号').asstring+' 分提单号:'+frm_op_seae_edi_data.t_op_seae.fieldbyname('分提单号').asstring else Subject:='海尔舱单 主提单号:'+frm_op_seae_edi_data.t_op_seae.fieldbyname('主提单号').asstring; TIdAttachmentFile.Create(MessageParts,str); end; if not SMTP1.Connected then begin Sleep(1000); SMTP1.Connect; end; SMTP1.Send(IdMsg); MessageDlg('发送成功!',mtConfirmation,[mbOK],0) finally SMTP1.Disconnect; end; end; except MessageDlg('发送失败!',mtError,[mbOK],0); end; str_memo.free; finally FreeAndNil(StrL) end; end; procedure Tfrm_op_seae_edi_custom_ld.bsSkinButton4Click(Sender: TObject); begin if frm_op_seae_edi_custom_ld.Height=349 then frm_op_seae_edi_custom_ld.Height:=200 else frm_op_seae_edi_custom_ld.Height:=349; end; end.