unit u_op_seae_edi_waiyun; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IdFTP,IdFTPCommon, Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,IdGlobal, FtpCli, IdExplicitTLSClientServerBase; type Tfrm_op_seae_edi_WAIYUN = 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; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; FtpClient1: TFtpClient; bsSkinButton5: TbsSkinButton; IdFTP1: TIdFTP; CheckBox1: TCheckBox; Memo1: TMemo; Label8: TLabel; 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); procedure FtpClient1Error(Sender: TObject; var Msg: String); procedure bsSkinButton5Click(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 GetCntrEdi(cntrsize: String):String; function GetpkgsEdi(pkgs:String):String; function GetDELIVERYTERMEdiNo(names:String):String; function GetlineEdi(aline:String):String; procedure GetLengthTString(var sl: TStringList; l: integer); function GetLengthword(var s: String; l: Integer;str:String): String; function GetcustEdi(cust: String): String; function GetvesselEdi(avessel: String): String; function GetShipEdiNO(Ship:String): String; function GetShipEName(Ship:String): String; function SCNVaild(cust: String): boolean; { Private declarations } public { Public declarations } end; var frm_op_seae_edi_WAIYUN: Tfrm_op_seae_edi_WAIYUN; implementation uses u_op_seae, u_main, my_sys_function, u_data_share, u_op_seae_assistant; {$R *.dfm} function Tfrm_op_seae_edi_WAIYUN.GetShipEdiNO(Ship:String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 代码,EDI代码,外运代码,客户简称,客户全称,揽货人,录入人,录入日期 from t_crm_client'); SQL.Add('where 客户简称='''+Ship+''''); SQL.Add('order by 代码'); Open; if not IsEmpty then Result:=Trim(FieldByName('外运代码').asstring) else Result:=''; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_WAIYUN.GetShipEName(Ship:String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 英文全称 from t_crm_client'); SQL.Add('where 客户简称='''+Ship+''''); SQL.Add('order by 代码'); Open; if not IsEmpty then Result:=Trim(FieldByName('英文全称').asstring) else Result:=''; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_WAIYUN.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:='a' else Result:=FieldByName('呼号').AsString; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_op_seae_edi_WAIYUN.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_WAIYUN.GetLengthword(var s: String; l: Integer;str:String): String; var i:Integer; b:Boolean; begin s:=''; if Length(str)'') and (Trim(old.Strings[i])<>#10) then 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 i1 then begin for i:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do begin frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[i])); if not isEditrue(frm_op_seae.t_op_seae) then exit; end; end else begin if not isEditrue(frm_op_seae.t_op_seae) then exit; end; str:=Tstringlist.Create; try 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 bsSkinCheckRadioBox1.Checked then str.Add('00:IFTMBF:SI:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+':2.1'+#39) else str.Add('00:IFTMBF:BK:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+':2.1'+#39); if frm_op_seae.dxdbgrid1.SelectedCount>1 then begin for i:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do begin frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[i])); if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then Str.AddStrings(CreateEdiFile) else Exit; end; end else begin if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then Str.AddStrings(CreateEdiFile) else Exit; end; I:=str.Count; str.Add('99:'+intToStr(i+1)+''''); for i:=0 to Str.Count-1 do begin if IsZhongwen(Str[i]) then begin MessageDlg('此票业务有中文字符或TAB等不规范字符'+Str[i]+',请去除字符后重试!',mtWarning,[mbYes],0); exit; end; end; if bsSkinCheckRadioBox1.Checked then FileType:='SI_' else FileType:='BK_'; SaveDialog1.FileName:=FileType+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; finally FreeAndNil(Str); end; close; end; function Tfrm_op_seae_edi_WAIYUN.isEditrue(DataSet:TDataSet): boolean; var cntrs:String; begin result:=true; if SCNVaild('发货人代码') then begin result:=false; exit; end; if SCNVaild('收货人代码') then begin result:=false; exit; end; if SCNVaild('通知人代码') then begin result:=false; exit; end; if trim(DataSet.fieldbyname('船公司').asstring)='中远' then begin if not bsSkinCheckRadioBox2.Checked then begin if trim(DataSet.fieldbyname('主提单号').asstring)='' then begin result:=false; MessageDlg('提单号不能为空',mtWarning,[mbOk],0); exit; end; end else begin if trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('主提单号').asstring)='' then begin result:=false; MessageDlg('提单号不能为空',mtWarning,[mbOk],0); exit; end; end; 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 if (GetvesselEdi(trim(DataSet.fieldbyname('船名').asstring)))='' then begin result:=false; MessageDlg('船舶呼号不能为空',mtWarning,[mbOk],0); exit; end; 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 not bsSkinCheckRadioBox2.Checked then begin 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; end else begin if trim(GetpkgsEdi(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('包装').asstring))='' then begin result:=false; MessageDlg('包装EDI代码不存在!',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('货物描述').asstring)='' then begin result:=false; MessageDlg('货物描述不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('唛头').asstring)='' then begin result:=false; MessageDlg('唛头不能为空',mtWarning,[mbOk],0); exit; end; if frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('件数').asinteger=0 then begin result:=false; MessageDlg('件数不能为空',mtWarning,[mbOk],0); exit; end; if frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('重量').asFloat=0 then begin result:=false; MessageDlg('总重量不能为空',mtWarning,[mbOk],0); exit; end; if frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('尺码').asFloat=0 then begin result:=false; MessageDlg('总尺码不能为空',mtWarning,[mbOk],0); exit; end; 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 else begin 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; if not bsSkinCheckRadioBox2.Checked then begin t_op_ctn.Close;t_op_ctn.SQL.Clear; t_op_ctn.SQL.Add('select * from t_op_ctn'); t_op_ctn.SQL.Add('where 编号=:编号'); t_op_ctn.SQL.Add('order by 代码'); t_op_ctn.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring; end else begin t_op_ctn.Close;t_op_ctn.SQL.Clear; t_op_ctn.SQL.Add('select * from t_op_ctn_fendan'); t_op_ctn.SQL.Add('where AS_ID=:AS_ID'); t_op_ctn.SQL.Add('order by 代码'); t_op_ctn.Parameters.ParamByName('AS_ID').Value:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('AS_ID').AsInteger; end; 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_WAIYUN.CreateEdiFile:TStrings; var str,sl1:Tstringlist; sl:TStrings; i,j,Count,l,M:integer; strsql,strRmain,strtemp,S,tmpDate:string; rs,aQuery2:Tadoquery; wide_str:widestring; k:integer; strType,strorderno,ctnsource:string; strDatetime:string; SenderCode,ReciverCode,shipname,shipaddr,SM:string; function GetRemarksString:String; var TempStr:TStrings; begin TempStr:=TStringList.Create; try if not bsSkinCheckRadioBox2.Checked then TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('EDI备注').AsString else TempStr.Text:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('EDI备注').AsString; Result:='17:'; Result:=Result+FormatListString(TempStr,5,35)+''''; finally FreeAndNil(TempStr); end; end; function GetShipperString:String; var TempStr:TStringlist; aQuery:TADOQuery; M,L:integer; S:String; begin TempStr:=TStringList.Create; aQuery:=CreateAdoQuery; try if bsSkinCheckRadioBox2.Checked then TempStr.Text:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('发货人代码').AsString else TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('发货人代码').AsString; GetLengthTString(TempStr,35); if Tempstr.Count<=9 then begin Result:='18:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,9,35)+''''; end else begin M:=1; for L:=0 to Tempstr.Count-1 do begin if M<=9 then begin if M=1 then begin s:='20:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end else begin if M=9 then s:=s+FormatEdiString(Tempstr.Strings[L],0) else s:=s+FormatEdiString(Tempstr.Strings[L],0)+':'; end; end else begin S:=S+''''; Str.Add(S); M:=1; s:='20:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); result:=''; end; finally FreeAndNil(TempStr); end; end; function GetConsigneString:String; var TempStr:TStringlist; M,L:integer; S:String; begin TempStr:=TStringList.Create; try if bsSkinCheckRadioBox2.Checked then begin TempStr.Text:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('收货人代码').AsString; end else TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('收货人代码').AsString; GetLengthTString(TempStr,35); if Tempstr.Count<=9 then begin Result:='19:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,9,35)+''''; end else begin M:=1; for L:=0 to Tempstr.Count-1 do begin if M<=9 then begin if M=1 then begin s:='21:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end else begin if M=9 then s:=s+FormatEdiString(Tempstr.Strings[L],0) else s:=s+FormatEdiString(Tempstr.Strings[L],0)+':'; end; end else begin S:=S+''''; Str.Add(S); M:=1; s:='21:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); result:=''; end; finally FreeAndNil(TempStr); end; end; function GetNOTIFYString:String; var TempStr:TStringlist; M,L:integer; S:String; begin TempStr:=TStringList.Create; try if bsSkinCheckRadioBox2.Checked then begin TempStr.Text:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('通知人代码').AsString; end else TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('通知人代码').AsString; GetLengthTString(TempStr,35); if Tempstr.Count<=9 then begin Result:='20:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,9,35)+''''; end else begin M:=1; for L:=0 to Tempstr.Count-1 do begin if M<=9 then begin if M=1 then begin s:='22:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end else begin if M=9 then s:=s+FormatEdiString(Tempstr.Strings[L],0) else s:=s+FormatEdiString(Tempstr.Strings[L],0)+':'; end; end else begin S:=S+''''; Str.Add(S); M:=1; s:='22:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); result:=''; end; finally FreeAndNil(TempStr); end; end; // function GetNOTIFYTwoString:String; var TempStr:TStringlist; aQuery:TADOQuery; M,L:integer; S:String; begin TempStr:=TStringList.Create; aQuery:=CreateAdoQuery; try if trim(frm_op_seae.t_op_seae.fieldbyname('第二通知人').AsString)='' then Exit; TempStr.Text:=frm_op_seae.t_op_seae.fieldbyname('第二通知人').AsString; GetLengthTString(TempStr,35); if Tempstr.Count<=6 then begin Result:='23:'; Result:=Result+':'; Result:=Result+FormatListString(TempStr,9,35)+''''; end else begin M:=1; for L:=0 to Tempstr.Count-1 do begin if M<=6 then begin if M=1 then begin s:='21:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end else begin if M=6 then s:=s+FormatEdiString(Tempstr.Strings[L],0) else s:=s+FormatEdiString(Tempstr.Strings[L],0)+':'; end; end else begin S:=S+''''; Str.Add(S); M:=1; s:='23:'+FormatEdiString(Tempstr.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); result:=''; end; 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; Count:=0; strorderno:=''; if frm_op_seae.t_op_seae.fieldbyname('委托编号').asstring<>'' then strorderno:=Trim(frm_op_seae.t_op_seae.fieldbyname('委托编号').asstring) else strorderno:=Trim(frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring); if not bsSkinCheckRadioBox2.Checked then //主单 begin str.Add ('02:'+ strorderno //2 运编号 +':'+ trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring) //3 提单号 +':'+ GetDELIVERYTERMEdiNo(trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring)) //4 交货条款 +':'+ trim(Edit3.Text) //5 订舱人说明 货代方企业名称 +':'+ ReciverCode //6 即接受订舱的人的代码 +'::::::::::'+trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring) //16 +':::' //17 18 19 +':' //20 +#39); end else begin str.Add ('02:'+ strorderno //2 运编号 +':'+ trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('主提单号').asstring) //3 提单号 +':'+ GetDELIVERYTERMEdiNo(trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('运输条款').asstring)) //4 交货条款 +':'+ trim(Edit3.Text) //5 订舱人说明 货代方企业名称 +':'+ ReciverCode //6 即接受订舱的人的代码 +'::::::::::'+trim(frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring) //16 +':::' // 17 18 19 +':' //20 +#39); end; if not bsSkinCheckRadioBox2.Checked then //主单 begin if trim(frm_op_seae.t_op_seae.fieldbyname('签单方式').asstring)='正本' then strtemp:='ORI' else strtemp:='EXP'; end else begin if trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('签单方式').asstring)='正本' then strtemp:='ORI' else strtemp:='EXP'; end; str.add('03:'+strtemp //2 提单类型 +':' //3 提单签发地代码 +':'+ trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring) //4提单签发地 +':'+ GetDatetime(trim(frm_op_seae.t_op_seae.fieldbyname('签单日期').asstring),0) //5签发日期 +':'+ get_fenshu(trim(frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring)) //6正本提单份数 +':'+ trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring) //7预付地点 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring) //8到付地点 +':' +frm_op_seae.t_op_seae.fieldbyname('订舱人说明').asstring +#39); if (trim(frm_op_seae.t_op_seae.fieldbyname('船名').asstring)='') and (trim(frm_op_seae.t_op_seae.fieldbyname('航次').asstring)='') then tmpDate:=GetDatetime(trim(frm_op_seae.t_op_seae.fieldbyname('开船日期').asstring),0) else tmpDate:=''; str.Add('11:' + trim(GetvesselEdi(frm_op_seae.t_op_seae.fieldbyname('船名').asstring)) //2 船舶呼号 +':'+ trim(frm_op_seae.t_op_seae.fieldbyname('船名').asstring) //3 船名 +':'+ trim(frm_op_seae.t_op_seae.fieldbyname('航次').asstring) //4航次 +':' // +':' // +':'+GetShipEdiNO(frm_op_seae.t_op_seae.fieldbyname('船公司').asstring) //5船公司(承运人)代码 +':' +GetShipEName(frm_op_seae.t_op_seae.fieldbyname('船公司').asstring)//6 +':'+tmpDate //9 +':::::' //6-14 船公司(承运人)名称 +#39); //船舶经营人 str.Add ('12:'+trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring) // 2收货地代码 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring) //3 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring) //4 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring) //5 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring) //6 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring) //7 +':' //8 +':' //9 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('交货代码').asstring) //10 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('交货地点').asstring) //11 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('目的地代码').asstring) //12 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('目的地').asstring) //13 +':'+trim(GetcustEdi(frm_op_seae.t_op_seae.fieldbyname('场站').asstring)) //14 +'::' // 15 16 +#39); if not bsSkinCheckRadioBox2.Checked then //主单 begin 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:' //2 +':' //3 +':'+trim(frm_data_share.t_code_free.fieldbyname('外运代码').asstring) //4 PREPAID OR COLLECT 付款方式 P/C/F/R/E/L +':::::::' +#39); //船舶经营人 end; end else begin if frm_data_share.t_code_free.locate('付费方式',frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('付费方式').asstring,[]) then begin str.Add ('14:'+frm_data_share.t_code_free.fieldbyname('外运代码').asstring +':'+trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('付费方式').asstring)+#39); str.Add('15:' //2 +':' //3 +':'+trim(frm_data_share.t_code_free.fieldbyname('外运代码').asstring) //4 PREPAID OR COLLECT 付款方式 P/C/F/R/E/L +':::::::' //6-11 +#39); //船舶经营人 end; end; if not bsSkinCheckRadioBox2.Checked then //主单 begin if trim(frm_op_seae.t_op_seae.fieldbyname('EDI备注').asstring)<>'' then Str.Add(GetRemarksString); end else begin if trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('EDI备注').asstring)<>'' then Str.Add(GetRemarksString); end; strtemp:=GetShipperString; if strtemp<>'' then Str.Add(strtemp); strtemp:=GetConsigneString; if strtemp<>'' then Str.Add(strtemp); strtemp:=GetNOTIFYString; if strtemp<>'' then Str.Add(strtemp); { strtemp:=GetNOTIFYTwoString; if strtemp<>'' then Str.Add(strtemp); } 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 not bsSkinCheckRadioBox2.Checked then strRmain:=strRmain+'F:'+':'+':'+frm_data_share.t_crm_client_changzhan.fieldbyname('EDI代码').asstring+':'+':'+ctnsource+#39 // 5 6 7 8 9 else strRmain:=strRmain+'L:'+trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring)+':'+':'+frm_data_share.t_crm_client_changzhan.fieldbyname('EDI代码').asstring+':'+':'+ctnsource+#39; end else begin if not bsSkinCheckRadioBox2.Checked then strRmain:=strRmain+'F:'+':'+':'+':'+':'+ctnsource+#39 else strRmain:=strRmain+'L:'+trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring)+':'+':'+':'+':'+ctnsource+#39; end; strsql:=''; if not bsSkinCheckRadioBox2.Checked then begin strsql:='select 编号,代码,sum(数量) as 数量 from t_op_ctn group by 编号,代码 having 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; //4 end else begin strsql:='select 代码,sum(数量) as 数量 from t_op_ctn_fendan where AS_ID=' +frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('AS_ID').AsString +' group by 代码'; end; try rs:=CreateAdoQuery; rs.Close; rs.sql.clear; rs.sql.add(strsql); rs.Open;rs.First; while not rs.Eof do begin str.Add ('40:'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring)) //2 CTN. SIZE & TYPE 集装箱尺寸类型 +':'+trim(rs.fieldbyname('数量').asstring) //3 CTN. NUMBERS 集装箱箱数 +':'+strRmain); Count:=Count+1; rs.Next; end; rs.Close; rs.Free; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; end; if not bsSkinCheckRadioBox2.Checked then begin str.Add ('41' +':1' // 2 +':' // 3 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring) // 4 货物标识 S/R/D/O +':'+trim(frm_op_seae.t_op_seae.fieldbyname('件数').asstring) // 5 +':'+trim(GetpkgsEdi(frm_op_seae.t_op_seae.fieldbyname('包装').asstring)) // 6 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('包装').asstring) // 7 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('重量').asstring) //第一层包装说明 8 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('尺码').asstring) //第一层包装说明 9 +':' // 10 +':' // 11 +':' // 12 +':' // 13 +':' // 14 +':' // 15 +':' // 16 +':' // 17 +':' // 第一层包装尺码 // 18 +':' // 第一层包装尺码 // 19 +':' // 第一层包装尺码 // 20 +':' // 第一层包装尺码 // 21 +#39); end else begin //2 3 str.Add ('41' +':1' // 2 +':' // 3 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring) // 4 货物标识 S/R/D/O +':'+trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('件数').asstring) // 5 +':'+trim(GetpkgsEdi(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('包装').asstring)) // 6 +':'+trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('包装').asstring) // 7 +':'+trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('重量').asstring) //第一层包装说明 8 +':'+trim(frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('尺码').asstring) //第一层包装说明 9 +':' // 10 +':' // 11 +':' // 12 +':' // 13 +':' // 14 +':' // 15 +':' // 16 +':' // 17 +':' // 第一层包装尺码 // 18 +':' // 第一层包装尺码 // 19 +':' // 第一层包装尺码 // 20 +':' // 第一层包装尺码 // 21 +#39); end; IF trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='R' THEN BEGIN str.Add ('43:' // 2 危险品、冷冻 +':' //3 +':' //4 +':' //5 +':' //6 +':' //7 +':' //8 +':' //9 +':' //10 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('冷藏通风量').asstring) //11 +':' +'C' //12 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring) //13 +':' //14 +':' //15 +':' //16 +'::::::::' // 17 18 19 20--24 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('湿度').asstring) //25 // +#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) //2 +':' //3 +':'+trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring) //4 +':' //5 +':' //6 +':' //7 +':' //8 +':' //9 +'::' //10 +':' //11 +':' // 12 +':' // 13 +':' // 14 +'::::::::::' // 15---24 +#39); END; if bsSkinCheckRadioBox2.Checked then sl1.Text:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('唛头').AsString else sl1.Text:=frm_op_seae.t_op_seae.fieldbyname('唛头').AsString; GetLengthTString(sl1,35); 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<=10 then begin if M=1 then begin s:='44:'+FormatEdiString(sl.Strings[L],0)+':'; end else begin if M=10 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:='44:'+FormatEdiString(sl.Strings[L],0)+':'; end; M:=M+1; end; S:=S+''''; Str.Add(S); if bsSkinCheckRadioBox2.Checked then sl1.Text:=frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('货物描述').AsString else sl1.Text:=frm_op_seae.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); // Str.Add(GetCARGODESCRIPTIONString); ctnsource:='N'; if frm_op_seae.t_op_seae.fieldbyname('是否自有箱').AsBoolean then ctnsource:='Y'; strsql:=''; Count:=Count+11; if trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then begin if bsSkinCheckRadioBox1.Checked then begin if not bsSkinCheckRadioBox2.Checked then begin strsql:='select * from t_op_ctn where 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; end else begin strsql:='select * from t_op_ctn_fendan where AS_ID=' +frm_op_seae_assistant.t_op_seae_assistant.fieldbyname('AS_ID').AsString; end; end; if trim(strsql)<>'' then try rs:=CreateAdoQuery; 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 if bsSkinCheckRadioBox1.Checked then begin if Trim(rs.fieldbyname('称重方式').asstring)='累加' then SM:='SM2' else if Trim(rs.fieldbyname('称重方式').asstring)='总重' then SM:='SM1'; sl1.Text:=frm_op_seae.t_op_seae.fieldbyname('发货人代码').asstring; GetLengthTString(sl1,35); shipname:=''; if sl1.Count>=1 then shipname:=Copy(sl1[0],1,20); shipaddr:=''; if sl1.Count>=2 then shipaddr:=sl1[1]; str.Add ('51:'+trim(rs.fieldbyname('箱号').asstring) //2箱号 +':'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring)) //3箱型尺寸 +':'+trim(rs.fieldbyname('封号').asstring) //4铅封号 +':'+'M' //5 封志类型 +':'+'CA' //6 施加封志人 +':'+'F' //7 箱状态 +':'+trim(IntToStr(rs.fieldbyname('件数').AsInteger)) //8 箱内货物件数 +':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat)) //9 箱内货重 +':' //10 +':'+trim(FloatToStr(rs.fieldbyname('尺码').AsFloat)) //11箱内货物尺码 +':' +':'+rs.fieldbyname('称重重量').asstring //15 +':'+GetDatetime(rs.fieldbyname('VGM称重日期').asString,1) //16 +':'+SM //17 +'::'+rs.fieldbyname('称重地点').asString //18 //12 集装箱来源代 +'''' ); str.Add ('58:'+shipname //2 +':'+shipaddr //3 +':'+rs.fieldbyname('VGM联系人').asString // 4 +':'+'' //5 +':'+rs.fieldbyname('VGM联系联系方式').asString //6 +':'+'' //7 +':' +rs.fieldbyname('签名').asString //8 +''''); end else str.Add ('51:'+trim(rs.fieldbyname('箱号').asstring) //2箱号 +':'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring)) //3箱型尺寸 +':'+trim(rs.fieldbyname('封号').asstring) //4铅封号 +':'+'M' //5 封志类型 +':'+'CA' //6 施加封志人 +':'+'F' //7 箱状态 +':'+trim(IntToStr(rs.fieldbyname('件数').AsInteger)) //8 箱内货物件数 +':'+trim(FloatToStr(rs.fieldbyname('重量').AsFloat)) //9 箱内货重 +':' //10 +':'+trim(FloatToStr(rs.fieldbyname('尺码').AsFloat)) //11箱内货物尺码 +':' //12 集装箱来源代 +'''' ); rs.Next; end; end; end; rs.Close; rs.Free; 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; Result:=str; end; function Tfrm_op_seae_edi_WAIYUN.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_WAIYUN.GetpkgsEdi(pkgs: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 外运代码 from t_code_package where 代码='''+pkgs+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('外运代码').AsString; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_WAIYUN.GetDELIVERYTERMEdiNo(names:String):String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 外运代码 from t_code_items where 代码='''+names+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('外运代码').AsString; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_WAIYUN.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_WAIYUN.bsSkinButton3Click(Sender: TObject); var str:widestring; str_file:widestring; ftpar,ftpname,ftppass,ftppath,ScriptPath:String; StrL:TStrings; i:integer; SenderCode,ReciverCode,strType:String; begin 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); FtpClient1.UserName:=ftpname; FtpClient1.PassWord:=ftppass; FtpClient1.HostName:=ftpar; FtpClient1.Passive:=CheckBox1.Checked; FtpClient1.MultiThreaded:=True; FtpClient1.Port:='21'; FtpClient1.DisplayFileFlag:=True; FtpClient1.Timeout:=5; try if (FtpClient1.Open) and (FtpClient1.User) and (FtpClient1.Pass) then begin //连接失败 frm_op_seae_edi_waiyun.Caption:='用户连接成功!'; FtpClient1.HostDirName:=ftppath; if FtpClient1.Cwd then end else begin showmessage('用户连接失败!'); end; except on e:exception do begin FtpClient1.Abort; frm_op_seae_edi_waiyun.Caption:='用户连接失败!'; end; end; { with idftp1 do begin Username:=ftpname; Password:=ftppass; Host:=ftpar; Passive:=CheckBox1.Checked; try finally Connect; end; if Connected then begin showmessage('Ftp连接成功!'); ChangeDir(ftppath); TransferType:=ftBinary; end else showmessage('Ftp连接失败,请重新连接!'); end; } end; procedure Tfrm_op_seae_edi_WAIYUN.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var inifile1:Tinifile; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.WriteString('waiyunEDI','SEND',edit1.text); inifile1.WriteString('waiyunEDI','RECIEVE',edit2.text); inifile1.WriteString('waiyunEDI','SENDNAME',edit3.text); inifile1.WriteString('waiyunEDI','FTPSERVER',edit4.text); inifile1.WriteString('waiyunEDI','FTPPATH',edit5.text); inifile1.WriteString('waiyunEDI','FTPNAME',edit6.text); inifile1.WriteString('waiyunEDI','FTPPASS',edit7.text); inifile1.free; Memo1.Lines.SaveToFile(ExtractFilePath(application.ExeName)+'carriercode.ini'); end; procedure Tfrm_op_seae_edi_WAIYUN.bsSkinButton4Click(Sender: TObject); begin if frm_op_seae_edi_waiyun.Height=301 then frm_op_seae_edi_waiyun.Height:=162 else frm_op_seae_edi_waiyun.Height:=301; end; function Tfrm_op_seae_edi_WAIYUN.GetcustEdi(cust: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.CLEAR; SQL.Add('Select 外运代码 from t_crm_client where 客户简称='''+Cust+''''); Open; if not IsEmpty then result:=fieldbyname('外运代码').AsString; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_op_seae_edi_WAIYUN.FtpClient1Error(Sender: TObject; var Msg: String); begin ShowMessage(Msg); end; procedure Tfrm_op_seae_edi_WAIYUN.bsSkinButton5Click(Sender: TObject); var str:widestring; str_file:widestring; ftpar,ftpname,ftppass,ftppath,ScriptPath:String; StrL:TStrings; i,i_soi:integer; SenderCode,ReciverCode,strType,filetype:String; begin i_soi:=0; if bsSkinCheckRadioBox2.Checked then begin if frm_op_seae_assistant=nil then begin ShowMessage('请在(委托和提单)界面发送分单Edi'); exit; end end; if frm_op_seae.dxdbgrid1.SelectedCount>1 then begin for i:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do begin frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[i])); if not isEditrue(frm_op_seae.t_op_seae) then exit; end; end else begin if not isEditrue(frm_op_seae.t_op_seae) then exit; end; 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 bsSkinCheckRadioBox1.Checked then FileType:='SI_' else FileType:='BK_'; str:=ScriptPath +FileType+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:=FileType+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 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 bsSkinCheckRadioBox1.Checked then strL.Add('00:IFTMBF:SI:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+':2.1'+#39) else strL.Add('00:IFTMBF:BK:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+':2.1'+#39); if frm_op_seae.dxdbgrid1.SelectedCount>1 then begin for i:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do begin frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[i])); if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then StrL.AddStrings(CreateEdiFile) else Exit; end; end else begin if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then StrL.AddStrings(CreateEdiFile) else Exit; end; I:=strL.Count; strL.Add('99:'+intToStr(i+1)+''''); for i:=0 to StrL.Count-1 do begin if IsZhongwen(StrL[i]) then begin MessageDlg('此票业务有中文字符或TAB等不规范字符'+StrL[i]+',请去除字符后重试!',mtWarning,[mbYes],0); exit; end; end; strL.SaveToFile(str); finally FreeAndNil(StrL) end; if FtpClient1.Connected then begin try FtpClient1.TransferMode := ftpTransModeStream; FtpClient1.LocalFileName:=str; // showmessage(FtpClient1.LocalFileName); FtpClient1.HostFileName:= str_file; // showmessage(FtpClient1.HostFileName); // Exit; try if FtpClient1.Put then begin ShowMessage('上传成功'); frm_op_seae_edi_waiyun.Caption:='上传成功!'; end; except FtpClient1.Abort; ShowMessage('上传失败!'); frm_op_seae_edi_waiyun.Caption:='上传失败!'; i_soi:=1; end; finally FtpClient1.Abort; end; end; { if i_soi=0 then if bsSkinCheckRadioBox1.Checked then UpdateSOIStatus(1,frm_op_seae.t_op_seae.fieldbyname('编号').asstring) else UpdateSOIStatus(0,frm_op_seae.t_op_seae.fieldbyname('编号').asstring); } end; function Tfrm_op_seae_edi_WAIYUN.SCNVaild(cust: String): boolean; var i :integer; ls:TStringList; begin result:=false; try ls:=TStringList.Create; ls.Clear; ls.Text:=frm_op_seae.t_op_seae.fieldbyname(cust).asstring; for i:=0 to ls.Count-1 do begin if IsZhongwen(ls[i]) then begin MessageDlg('EDI信息中'+cust+'中有中文字符或TAB键!',mtWarning,[mbOk],0); end; if Length(ls[i])>35 then begin result:=true; MessageDlg('EDI信息中'+cust+'中每行字符不能超过35个字符!',mtWarning,[mbOk],0); end; end; if ls.Count>5 then begin result:=true; MessageDlg('EDI信息中'+cust+'不能超过5行,在货描中输入',mtWarning,[mbOk],0); end; finally ls.Free; end; end; end.