unit u_op_seae_edi_PIL; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB,IdFTP,IdFTPCommon; type Tfrm_op_seae_edi_PIL = class(TForm) bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; SaveDialog1: TSaveDialog; Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Label2: TLabel; bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; bskngrpbx1: TbsSkinGroupBox; lbl1: TLabel; lbl2: TLabel; lbl3: TLabel; lbl4: TLabel; lbl5: TLabel; lbl6: TLabel; edt1: TEdit; edt2: TEdit; edt3: TEdit; edt4: TEdit; edt5: TEdit; edt6: TEdit; bsknrdgrp1: TbsSkinRadioGroup; btn1: TbsSkinButton; btn2: TbsSkinButton; Label3: TLabel; Edit3: TEdit; t_op_ctn: TADOQuery; t_op_ctn1: TDataSource; Edit4: TEdit; Label4: TLabel; Label5: TLabel; Edit5: TEdit; procedure FormShow(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); private { Private declarations } public { Public declarations } function GetStrNum(str:String):integer; function GetCntrEdi(cntrsize:String):String; function GetpkgsEdi(pkgs:String):String; function GetcustEdi(cust:String):String; function GetlineEdi(aline:String):String; function isEditrue(DataSet:TDataSet): boolean; function SPACES(len:integer):String; function Zeros(len:integer):String; function EditFieldVlaue(FieldVlaue:string;len:integer):String; function EditFieldVlaueZeros(FieldVlaue:string;len:integer):String; function _EditFieldVlaueZeros(FieldVlaue:string;len:integer):String; function GetvesselEdi(avessel:String):String; function GetLengthword(var s: String; l: Integer;str:String): String; procedure GetLengthTString(var sl: TStringList; l: integer); function GetBookDetail(CorpSName:string):string; function GetCntSum(BsNo:string):String; function FreightTerms(FT:string):String; function FormatFloatPIL(FT:string;i,d:integer):String; function TemperatureFormat(T:string):String; function FreferFormat(T:string):String; function Record00_HEADER:String; function Record11_VESSELVOYAGE(DataSet:TDataSet):String; function Record12_BL(DataSet:TDataSet):String; function Record13_BL(DataSet:TDataSet):String; function Record16_SHIPPER(DataSet:TDataSet):String; function Record17_BOOKINGPARTY(DataSet:TDataSet):String; function Record18_DECIDING(DataSet:TDataSet):String; function Record21_CONSIGNEE(DataSet:TDataSet):String; function Record26_Notify(DataSet:TDataSet):String; function Record41_DETAILS(DataSet:TDataSet;LineNo:string):String; function Record44_MARKS(DataSet:TDataSet;LineNo:string):Tstringlist; function Record47_DESCRIPTION(DataSet:TDataSet;LineNo:string):Tstringlist; function Record47_DESCRIPTION_Line(DataSet:TDataSet;LineNo:string):Tstringlist; function Record47_QTY(BsNo:string):String; function Record54_SPECIAL(DataSet:TDataSet;LineNo,Qty:string):String; function Record99(LineNo:string):String; function Record44_47(LineNo:string):Tstringlist; function CreateSIEdiFile:TStrings; end; var frm_op_seae_edi_PIL: Tfrm_op_seae_edi_PIL; implementation uses u_op_seae, u_main, my_sys_function, u_data_share; {$R *.dfm} function Tfrm_op_seae_edi_PIL.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_PIL.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_PIL.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_PIL.GetStrNum(str:String):integer; var i:integer; begin result:=0; if str='' then exit; for i:=1 to length(Str) do begin if str[i] in ['0','1','2','3','4','5','6','7','8','9'] then result:=result+1; end; end; function Tfrm_op_seae_edi_PIL.GetcustEdi(cust: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.CLEAR; SQL.Add('Select EDI代码 from t_crm_client where 客户简称='''+Cust+''''); Open; if not IsEmpty then result:=fieldbyname('EDI代码').AsString; end; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_PIL.isEditrue(DataSet:TDataSet): boolean; var cntrs:String; begin result:=true; if bsknrdgrp1.ItemIndex=1 then begin if trim(DataSet.fieldbyname('订舱单号').asstring)='' then begin result:=false; MessageDlg('PIL订舱单号不能为空',mtWarning,[mbOk],0); exit; end; if trim(Edit5.text)='' then begin result:=false; MessageDlg('订舱代理名称不能为空',mtWarning,[mbOk],0); exit; end; if Length(Edit5.text)>35 then begin result:=false; MessageDlg('订舱代理名称不能超过35字符',mtWarning,[mbOk],0); exit; end; end; if trim(EDIT1.TEXT)='' then begin result:=false; MessageDlg('发送方代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(EDIT2.TEXT)='' then begin result:=false; MessageDlg('接收方代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(EDIT3.TEXT)='' then begin result:=false; MessageDlg('预付订舱代理不能为空',mtWarning,[mbOk],0); exit; end; if trim(EDIT4.TEXT)='' then begin result:=false; MessageDlg('到付代理不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('主提单号').asstring)='' then begin result:=false; MessageDlg('提单号不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('付费方式').asstring)='' then begin result:=false; MessageDlg('付费方式不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('装港代码').asstring)='' then begin result:=false; MessageDlg('装港代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('装货港').asstring)='' then begin result:=false; MessageDlg('装货港不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('开船日期').asstring)='' then begin result:=false; MessageDlg('开船日期不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('预抵日期').asstring)='' then begin result:=false; MessageDlg('预抵日期不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('交货代码').asstring)='' then begin result:=false; MessageDlg('交货代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('卸货代码').asstring)='' then begin result:=false; MessageDlg('卸货代码不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('交货地点').asstring)='' then begin result:=false; MessageDlg('交货地点不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('目的地').asstring)='' then begin result:=false; MessageDlg('目的地不能为空',mtWarning,[mbOk],0); exit; end; if trim(DataSet.fieldbyname('签单地点').asstring)='' then begin result:=false; MessageDlg('签单地点不能为空',mtWarning,[mbOk],0); exit; end; if DataSet.fieldbyname('件数').asinteger=0 then begin result:=false; MessageDlg('件数不能为空',mtWarning,[mbOk],0); exit; end; if DataSet.fieldbyname('重量').asFloat=0 then begin result:=false; MessageDlg('总重量不能为空',mtWarning,[mbOk],0); exit; end; if DataSet.fieldbyname('尺码').asFloat=0 then begin result:=false; MessageDlg('总尺码不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='' then begin result:=false; MessageDlg('货物标识不能为空',mtWarning,[mbOk],0); exit; end; if trim(frm_op_seae.t_op_seae.FieldByName('货物标识').asstring)='D' then begin if Trim(frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring)='' then begin result:=false; MessageDlg('危险品等级不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring)='' then begin result:=false; MessageDlg('危险品编号不能为空',mtWarning,[mbOk],0); exit; end; if GetStrNum(Trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring))<>4 then begin result:=false; MessageDlg('危险品编号必须是4位数字',mtWarning,[mbOk],0); exit; end; end; if trim(frm_op_seae.t_op_seae.FieldByName('货物标识').asstring)='R' then begin if (Trim(frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring)='') then begin result:=false; MessageDlg('设置温度不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('最低温度').asstring)='' then begin result:=false; MessageDlg('最低温度不能为空',mtWarning,[mbOk],0); exit; end; if Trim(frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring)='' then begin result:=false; MessageDlg('最高温度不能为空',mtWarning,[mbOk],0); exit; end; if (Pos('.' ,frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring)<=0) or (Pos('.' ,frm_op_seae.t_op_seae.fieldbyname('最低温度').asstring)<=0) or (Pos('.' ,frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring)<=0) then begin result:=false; MessageDlg('温度格式输入不正确,请输入如此格式: -0.10 或 +0.10',mtWarning,[mbOk],0); exit; end; if (Pos('+' ,frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring)<=0) and (Pos('-' ,frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring)<=0) then begin result:=false; MessageDlg('设置温度格式输入不正确,请输入如此格式: -0.10 或 +0.10',mtWarning,[mbOk],0); exit; end; if (Pos('+' ,frm_op_seae.t_op_seae.fieldbyname('最低温度').asstring)<=0) and (Pos('-' ,frm_op_seae.t_op_seae.fieldbyname('最低温度').asstring)<=0) then begin result:=false; MessageDlg('最低温度格式输入不正确,请输入如此格式: -0.10 或 +0.10',mtWarning,[mbOk],0); exit; end; if (Pos('+' ,frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring)<=0) and (Pos('-' ,frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring)<=0) then begin result:=false; MessageDlg('最高温度格式输入不正确,请输入如此格式: -0.10 或 +0.10',mtWarning,[mbOk],0); exit; end; end; t_op_ctn.close; t_op_ctn.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring; t_op_ctn.open; if t_op_ctn.IsEmpty then begin result:=false; MessageDlg('集装箱不能为空',mtWarning,[mbOk],0); exit; end; t_op_ctn.First; while not t_op_ctn.Eof do begin if Trim(GetCntrEdi(t_op_ctn.fieldbyname('代码').asstring))='' then begin result:=false; MessageDlg('集装箱EDI代码不存在!',mtWarning,[mbOk],0); exit; end; t_op_ctn.Next; end; end; function Tfrm_op_seae_edi_PIL.GetBookDetail(CorpSName:string):string; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; SQL.Add('Select 快捷代码 from t_crm_client where 客户简称='''+CorpSName+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('快捷代码').AsString; finally FreeAndNil(aQuery); end; end; function Tfrm_op_seae_edi_PIL.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; function Tfrm_op_seae_edi_PIL.SPACES(len:integer):String; var i : integer; begin result:=''; for i :=0 to len-1 do begin if result='' then result:=' ' else result:=result+' '; end; end; function Tfrm_op_seae_edi_PIL.Zeros(len:integer):String; var i : integer; begin result:=''; for i :=0 to len-1 do begin if result='' then result:='0' else result:='0'+result; end; end; function Tfrm_op_seae_edi_PIL.EditFieldVlaue(FieldVlaue:string;len:integer):String; begin Result:=''; if Length(FieldVlaue)>=Len then Result:=Copy(FieldVlaue,1,Len) else Result:=FieldVlaue+SPACES(len-Length(FieldVlaue)); end; function Tfrm_op_seae_edi_PIL.EditFieldVlaueZeros(FieldVlaue:string;len:integer):String; begin Result:=''; if Length(FieldVlaue)>=Len then Result:=Copy(FieldVlaue,1,Len) else Result:=Zeros(len-Length(FieldVlaue))+FieldVlaue; end; function Tfrm_op_seae_edi_PIL._EditFieldVlaueZeros(FieldVlaue:string;len:integer):String; begin Result:=''; if Length(FieldVlaue)>=Len then Result:=Copy(FieldVlaue,1,Len) else Result:=FieldVlaue+Zeros(len-Length(FieldVlaue)); end; function Tfrm_op_seae_edi_PIL.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_PIL.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_PIL.GetCntSum(BsNo:string):String; var aAdoQuery:TAdoQuery; begin aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;Sql.Clear; Sql.Add('select sum(数量) as 数量 from t_op_ctn where 编号=:BsNo'); Parameters.ParamByName('BSNO').Value:=BSNO; Open;First; if not IsEmpty then result:=fieldbyname('数量').asstring else result:='0'; finally free; end; end; function Tfrm_op_seae_edi_PIL.FreightTerms(FT:string):String; var s,split :string; begin //Y:CY, F:CFS, I:FI, O:FO, D:Door, K:Hook, L:Tackle eg. YY=CY/CY Result:='YY'; if pos('-',FT)>0 then split:='-' else split:='/'; s:=Copy(FT,1,Pos(split,FT)-1); if s='CY' then Result:='Y' else if UpperCase(s)='CFS' then Result:='F' else if UpperCase(s)='FO' then Result:='O' else if UpperCase(s)='DOOR' then Result:='D' else if UpperCase(s)='HOOK' then Result:='K' else if UpperCase(s)='TACKLE' then Result:='L' else Result:='Y'; s:=Copy(FT,Pos(split,FT)+1,Length(ft)); if s='CY' then Result:=Result+'Y' else if UpperCase(s)='CFS' then Result:=Result+'F' else if UpperCase(s)='FO' then Result:=Result+'O' else if UpperCase(s)='DOOR' then Result:=Result+'D' else if UpperCase(s)='HOOK' then Result:=Result+'K' else if UpperCase(s)='TACKLE' then Result:=Result+'L' else Result:=Result+'Y'; end; function Tfrm_op_seae_edi_PIL.FreferFormat(T:string):String; var s1,s2 : string; begin result:=''; if pos('.',T)>0 then begin s1:=Copy(T,1,pos('.',T)-1); while Length(s1)<3 do s1:='0'+s1; s2:=Copy(T,pos('.',T)+1,Length(T)); while Length(s2)<2 do s2:=s2+'0'; end else begin s1:=T; while Length(s1)<3 do s1:='0'+s1; s2:='00'; end; result:=s1+s2; end; function Tfrm_op_seae_edi_PIL.TemperatureFormat(T:string):String; var s1,s2 : string; begin T:=StringReplace(T,'+','0',[rfReplaceAll]); result:=''; if pos('.',T)>0 then begin s1:=Copy(T,2,pos('.',T)-2); while Length(s1)<2 do s1:='0'+s1; s2:=Copy(T,pos('.',T)+1,Length(T)); while Length(s2)<2 do s2:=s2+'0'; end else begin s1:=Copy(T,2,Length(T)-1); while Length(s1)<2 do s1:='0'+s1; s2:='00'; end; result:=Copy(T,1,1)+s1+s2; end; function Tfrm_op_seae_edi_PIL.FormatFloatPIL(FT:string;i,d:integer):String; var s1,s2 : string; begin result:=''; if pos('.',FT)>0 then begin s1:=Copy(FT,1,pos('.',FT)-1); s1:=EditFieldVlaueZeros(s1,i); s2:=Copy(FT,pos('.',FT)+1,Length(FT)); s2:=_EditFieldVlaueZeros(s2,d); end else begin s1:=EditFieldVlaueZeros(FT,i); s2:='000'; end; result:=s1+s2; end; function Tfrm_op_seae_edi_PIL.Record00_HEADER:String; var SendCode,ReceiverCode :string; begin //9(2)X(3)X(20)X(2)X(8)X(6)9(12)X(1)X(5)X(5)X(4)X(15)X(167) Result:='00'; Result:=Result+'DOC'; { case bsknrdgrp1.ItemIndex of 0:Result:=Result+'DOC'; 1:Result:=Result+'BKG'; end; } Result:=Result+SPACES(20)+SPACES(2); // 123 4 SendCode:=EditFieldVlaue(Edit1.Text,8); //4 Result:=Result+SendCode; //5 Result:=Result+SPACES(6); //6 Result:=Result+GetDatetime(datetimetostr(now),1);//7 Result:=Result+SPACES(1); //8 Result:=Result+'CNTAO'; //9 Result:=Result+'CNTAO'; //10 case bsknrdgrp1.ItemIndex of 0:Result:=Result+'PBK'; 1:Result:=Result+'4.01'; end; Result:=EditFieldVlaue(Result,250); end; function Tfrm_op_seae_edi_PIL.Record11_VESSELVOYAGE(DataSet:TDataSet):String; begin // 9(2)X(1)X(10)X(20)X(8)9(8)9(8)X(12)9(8) Result:='11'; //1 Result:=Result+SPACES(1); //2 // Result:=Result+EditFieldVlaue(GetvesselEdi(trim(DataSet.fieldbyname('船名').asstring)),10); Result:=Result+EditFieldVlaue(Copy(trim(DataSet.fieldbyname('航次').asstring),1,3),10); //3 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('船名').asstring),20); //4 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('航次').asstring),8); //5 if DataSet.fieldbyname('预抵日期').IsNull then Result:=Result+FormatDateTime('YYYYMMDD',Now) else Result:=Result+FormatDateTime('YYYYMMDD',DataSet.fieldbyname('预抵日期').AsDateTime); //6 if DataSet.fieldbyname('开船日期').IsNull then Result:=Result+SPACES(8) else Result:=Result+FormatDateTime('YYYYMMDD',DataSet.fieldbyname('开船日期').AsDateTime); //7 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('航次').asstring),12); //8 if DataSet.fieldbyname('预抵日期').IsNull then Result:=Result+FormatDateTime('YYYYMMDD',Now) else Result:=Result+FormatDateTime('YYYYMMDD',DataSet.fieldbyname('预抵日期').AsDateTime); //9 Result:=EditFieldVlaue(Result,250); end; function Tfrm_op_seae_edi_PIL.Record12_BL(DataSet:TDataSet):String; var pc:string; begin // 9(2)X(20)X(20)X(20)X(5)X(5)X(5)X(2)X(2)X(2)X(3) // X(1)X(1)X(1)X(8)X(20)X(20)X(1)X(20)X(20)X(12)X(8)X(3)X(3)X(46) Result:='12'; case bsknrdgrp1.ItemIndex of 0:Result:=Result+EditFieldVlaue('+',20); //2 1:Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('订舱单号').asstring),20); //1 end; Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('主提单号').asstring),20); //3 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('主提单号').asstring),20); //4 Result:=Result+SPACES(5); //5 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('卸货代码').asstring),5); //6 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('装港代码').asstring),5); //7 Result:=Result+'FF'; //8 Result:=Result+'PP'; //9 Result:=Result+EditFieldVlaue(FreightTerms(DataSet.fieldbyname('运输条款').asstring),2); //10 Result:=Result+SPACES(3); //11 if DataSet.fieldbyname('付费方式').asstring='FREIGHT PREPAID' then PC:='P' else PC:='C'; Result:=Result+PC; //12 Result:=Result+'N'; //13 Result:=Result+'N'; //14 if DataSet.fieldbyname('截港日期').IsNull then Result:=Result+SPACES(8) else Result:=Result+FormatDateTime('YYYYMMDD',DataSet.fieldbyname('截港日期').AsDateTime); //15 Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('主提单号').asstring),20); //16 Result:=Result+SPACES(20); //17 Result:=Result+'F'; //18 Result:=Result+SPACES(20); //19 Result:=Result+SPACES(20); //20 Result:=Result+SPACES(12); //21 if DataSet.fieldbyname('开船日期').IsNull then Result:=Result+SPACES(8) //19 else Result:=Result+FormatDateTime('YYYYMMDD',DataSet.fieldbyname('开船日期').AsDateTime); //22 Result:=Result+EditFieldVlaue('PI',3); //23 Result:=Result+EditFieldVlaue('PI',3); //24 Result:=EditFieldVlaue(Result,250); end; function Tfrm_op_seae_edi_PIL.Record13_BL(DataSet:TDataSet):String; var s:string; begin Result:='13'; Result:=Result+SPACES(3); Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('装港代码').asstring),5); Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('卸货代码').asstring),5); Result:=Result+SPACES(5); Result:=Result+EditFieldVlaue(trim(DataSet.fieldbyname('卸货代码').asstring),5); Result:=Result+SPACES(20); Result:=Result+SPACES(10); Result:=Result+SPACES(45); Result:=Result+SPACES(5); Result:=Result+SPACES(5); Result:=Result+SPACES(5); s:=Copy(DataSet.fieldbyname('卸货代码').asstring,3,3); if (s='SSZ') or (s='BUE') or (s='MVD') or (s='PNG') or (s='NVT') or (s='RIO') then Result:=Result+'U' else Result:=Result+'N'; Result:=EditFieldVlaue(Result,250); end; function Tfrm_op_seae_edi_PIL.Record16_SHIPPER(DataSet:TDataSet):String; var l,m:integer; s:string; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; Result:='16'; Result:=Result+SPACES(3); Result:=Result+SPACES(10); Result:=Result+SPACES(3); Result:=Result+SPACES(4); sl1.Text:=DataSet.fieldbyname('发货人代码').AsString; GetLengthTString(sl1,35); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then begin sl.Add(EditFieldVlaue(sl1.Strings[L],35)); end; end; for L:=0 to sl.Count-1 do begin if L<=5 then begin s:=s+sl.Strings[L]; end end; Result:=Result+s; Result:=EditFieldVlaue(Result,250); sl.Free; sl1.Free; end; function Tfrm_op_seae_edi_PIL.Record17_BOOKINGPARTY(DataSet:TDataSet):String; var l,m:integer; s:string; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; Result:='17'; Result:=Result+SPACES(3); if DataSet.fieldbyname('付费方式').asstring='FREIGHT PREPAID' then Result:=Result+EditFieldVlaue(Edit3.Text,10) else Result:=Result+EditFieldVlaue(Edit4.Text,10); case bsknrdgrp1.ItemIndex of 0:Result:=Result+SPACES(3); else Result:=Result+'001'; end; Result:=Result+SPACES(4); case bsknrdgrp1.ItemIndex of 0:Result:=Result+SPACES(35); else Result:=Result+EditFieldVlaue(Edit5.Text,35); end; { sl1.Text:=Edit3.Text; // GetBookDetail(DataSet.fieldbyname('货代公司').AsString); GetLengthTString(sl1,35); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then begin sl.Add(EditFieldVlaue(sl1.Strings[L],35)); end; end; for L:=0 to sl.Count-1 do begin if L<=5 then begin s:=s+sl.Strings[L]; end end; Result:=Result+s; } Result:=EditFieldVlaue(Result,250); sl.Free; sl1.Free; end; function Tfrm_op_seae_edi_PIL.Record18_DECIDING(DataSet:TDataSet):String; var l,m:integer; s:string; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; Result:='18'; Result:=Result+SPACES(3); if DataSet.fieldbyname('付费方式').asstring='FREIGHT PREPAID' then Result:=Result+EditFieldVlaue(Edit3.Text,10) else Result:=Result+EditFieldVlaue(Edit4.Text,10); case bsknrdgrp1.ItemIndex of 0:Result:=Result+SPACES(3); else Result:=Result+'001'; end; Result:=Result+SPACES(1); sl1.Text:=DataSet.fieldbyname('发货人代码').AsString; GetLengthTString(sl1,35); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then begin sl.Add(EditFieldVlaue(sl1.Strings[L],35)); end; end; for L:=0 to sl.Count-1 do begin if L<=5 then begin s:=s+sl.Strings[L]; end end; Result:=Result+s; Result:=EditFieldVlaue(Result,250); sl.Free; sl1.Free; end; function Tfrm_op_seae_edi_PIL.Record21_CONSIGNEE(DataSet:TDataSet):String; var l,m:integer; s:string; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; Result:='21'; Result:=Result+SPACES(3); Result:=Result+SPACES(10); Result:=Result+SPACES(3); Result:=Result+SPACES(4); sl1.Text:=DataSet.fieldbyname('收货人代码').AsString; GetLengthTString(sl1,35); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then begin sl.Add(EditFieldVlaue(sl1.Strings[L],35)); end; end; for L:=0 to sl.Count-1 do begin if L<=5 then begin s:=s+sl.Strings[L]; end end; Result:=Result+s; Result:=EditFieldVlaue(Result,250); sl.Free; sl1.Free; end; function Tfrm_op_seae_edi_PIL.Record26_Notify(DataSet:TDataSet):String; var l,m:integer; s:string; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(2)9(1)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; Result:='26'; Result:=Result+SPACES(2); Result:=Result+'1'; Result:=Result+SPACES(10); Result:=Result+SPACES(3); Result:=Result+SPACES(4); sl1.Text:=DataSet.fieldbyname('通知人代码').AsString; GetLengthTString(sl1,35); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then begin sl.Add(EditFieldVlaue(sl1.Strings[L],35)); end; end; for L:=0 to sl.Count-1 do begin if L<=5 then begin s:=s+sl.Strings[L]; end end; Result:=Result+s; Result:=EditFieldVlaue(Result,250); sl.Free; sl1.Free; end; function Tfrm_op_seae_edi_PIL.Record44_47(Lineno:string):Tstringlist; var LineHeads:string; begin if result=nil then result:=Tstringlist.Create else result.Clear; try LineHeads:='44'; LineHeads:=LineHeads+SPACES(3); LineHeads:=LineHeads+EditFieldVlaueZeros(LineNo,3); result.Add(EditFieldVlaue(LineHeads,250)); LineHeads:='47'; LineHeads:=LineHeads+SPACES(3); LineHeads:=LineHeads+EditFieldVlaueZeros(LineNo,3); result.Add(EditFieldVlaue(LineHeads,250)); finally end; end; function Tfrm_op_seae_edi_PIL.Record41_DETAILS(DataSet:TDataSet;LineNo:string):String; var l,m:integer; GoodsNo:string; aAdoQuery:TAdoQuery; begin //9(2)X(3)9(3)X(9)X(1)9(6)9(4)9(8)v9999(8)v9999(7)v9999(7)v999X(48)X(4)X(4)X(3)X(3)X(1)X(117) aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;Sql.Clear; Sql.Add('select 代码 from t_Code_Goods where 货物名称=:货物名称'); Parameters.ParamByName('货物名称').Value:=frm_op_seae.t_op_seae.fieldbyname('货物名称').AsString; Open; if not IsEmpty then GoodsNo:=Fieldbyname('代码').asstring; finally free; end; Result:='41'; Result:=Result+SPACES(3); Result:=Result+EditFieldVlaueZeros(LineNo,3); Result:=Result+EditFieldVlaue(GoodsNo,9); Result:=Result+'Y'; Result:=Result+EditFieldVlaueZeros(DataSet.fieldbyname('数量').AsString,6); Result:=Result+EditFieldVlaueZeros(DataSet.fieldbyname('TEU').AsString,4); Result:=Result+FormatFloatPIL(DataSet.fieldbyname('重量').AsString,8,3); Result:=Result+FormatFloatPIL(DataSet.fieldbyname('重量').AsString,8,3); Result:=Result+FormatFloatPIL(DataSet.fieldbyname('尺码').AsString,7,3); Result:=Result+FormatFloatPIL(DataSet.fieldbyname('尺码').AsString,7,3); Result:=Result+SPACES(48); Result:=Result+EditFieldVlaue(GoodsNo,4); Result:=Result+EditFieldVlaue(DataSet.fieldbyname('尺寸').AsString+DataSet.fieldbyname('箱型').AsString,4); //箱型 Result:=Result+'KGM'; Result:=Result+'MTQ'; if frm_op_seae.t_op_seae.fieldbyname('是否自有箱').IsNull then Result:=Result+'N' else if strtobool(frm_op_seae.t_op_seae.fieldbyname('是否自有箱').value) then Result:=Result+'Y' else Result:=Result+'N'; Result:=EditFieldVlaue(Result,250); end; function Tfrm_op_seae_edi_PIL.Record44_MARKS(DataSet:TDataSet;LineNo:string):Tstringlist; var l,m:integer; s,LineHeads:string; str:Tstringlist; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; if result=nil then result:=Tstringlist.Create else result.Clear; str:=Tstringlist.Create; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; try LineHeads:='44'; LineHeads:=LineHeads+SPACES(3); LineHeads:=LineHeads+EditFieldVlaueZeros(LineNo,3); sl1.Text:=DataSet.fieldbyname('唛头').AsString; GetLengthTString(sl1,20); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then sl.Add(EditFieldVlaue(sl1.Strings[L],20)); end; M:=1; for L:=0 to sl.Count-1 do begin if M<=12 then begin if M=1 then begin s:=sl.Strings[L]; end else begin if M=12 then begin s:=s+sl.Strings[L]; end else s:=s+sl.Strings[L]; end; end else begin // Str.Add(LineHeads+S); Str.Add(EditFieldVlaue(LineHeads+S,250)); M:=1; s:=sl.Strings[L]; end; M:=M+1; end; // Str.Add(LineHeads+S); Str.Add(EditFieldVlaue(LineHeads+S,250)); result.AddStrings(str); finally str.Free; sl.Free; sl1.Free; end; end; function Tfrm_op_seae_edi_PIL.Record47_QTY(BSNO:string):String; begin Result:=frm_op_seae.t_op_seae.fieldbyname('件数').asstring+frm_op_seae.t_op_seae.fieldbyname('包装').asstring; Result:='47'+SPACES(3)+'001'+Result; Result:=EditFieldVlaue(Result,250); end; { function Tfrm_op_seae_edi_PIL.Record47_QTY(BSNO:string):String; var aAdoQuery:TAdoQuery; begin aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;Sql.Clear; Sql.Add('select 包装,sum(件数) as 件数 from t_op_ctn where 编号=:BsNo'); Sql.Add('Group by 包装'); Parameters.ParamByName('BSNO').Value:=BSNO; Open;First; while not Eof do begin if Result='' then Result:=fieldbyname('件数').asstring+fieldbyname('包装').asstring else Result:=Result+fieldbyname('件数').asstring+fieldbyname('包装').asstring; Next; end; finally free; end; Result:='47'+SPACES(3)+'001'+Result; Result:=EditFieldVlaue(Result,250); end; } function Tfrm_op_seae_edi_PIL.Record47_DESCRIPTION(DataSet:TDataSet;LineNo:string):Tstringlist; var i,j,l,m,c:integer; s,LineHeads:string; str:Tstringlist; sl:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; if result=nil then result:=Tstringlist.Create else result.Clear; str:=Tstringlist.Create; sl:=Tstringlist.Create; sl.Text:=DataSet.fieldbyname('货物描述').AsString; GetLengthTString(sl,30); c:=Trunc(sl.Count/8)+1; try for i:=1 to c do begin s:=''; LineHeads:='47'; LineHeads:=LineHeads+SPACES(3); LineHeads:=LineHeads+EditFieldVlaueZeros(LineNo,3); for j:=1 to 8 do begin if (i-1)*8+j<=sl.Count then s:=s+EditFieldVlaue(sl.Strings[(i-1)*8+j-1],30); end; if Trim(s)<>'' then result.Add(EditFieldVlaue(LineHeads+s,250)); end; finally str.Free; sl.Free; end; end; function Tfrm_op_seae_edi_PIL.Record47_DESCRIPTION_Line(DataSet:TDataSet;LineNo:string):Tstringlist; var l,m:integer; s,LineHeads:string; str:Tstringlist; sl:Tstringlist; sl1:Tstringlist; begin //9(2)X(3)X(10)X(3)X(4)X(35)X(35)X(35)X(35)X(35)X(17)X(18)X(4)X(5)X(9) s:=''; if result=nil then result:=Tstringlist.Create else result.Clear; str:=Tstringlist.Create; sl:=Tstringlist.Create; sl1:=Tstringlist.Create; try LineHeads:='47'; LineHeads:=LineHeads+SPACES(3); LineHeads:=LineHeads+EditFieldVlaueZeros(LineNo,3); sl1.Text:=DataSet.fieldbyname('货物描述').AsString; GetLengthTString(sl1,30); sl.text:=''; for L:=0 to sl1.Count-1 do begin if Trim(sl1.Strings[L])<>'' then sl.Add(EditFieldVlaue(sl1.Strings[L],30)); end; M:=1; for L:=0 to sl.Count-1 do begin if M<=12 then begin if M=1 then begin s:=sl.Strings[L]; end else begin if M=12 then begin s:=s+sl.Strings[L]; end else s:=s+sl.Strings[L]; end; end else begin M:=1; Str.Add(EditFieldVlaue(LineHeads+S,250)); s:=sl.Strings[L]; end; M:=M+1; end; // Str.Add(LineHeads+S); Str.Add(EditFieldVlaue(LineHeads+S,250)); result.AddStrings(str); finally str.Free; sl.Free; sl1.Free; end; end; function Tfrm_op_seae_edi_PIL.Record54_SPECIAL(DataSet:TDataSet;LineNo,Qty:string):String; begin //9(2) X(3) 9(3) 9(3) X(1) 9(3) v999(3) v999(3) v99X(1)9(3)v99X(1)9(3)v99X(1)X(210) result:='54'; //12 result:=result+SPACES(3); //345 result:=result+EditFieldVlaueZeros(LineNo,3); //678 result:=result+EditFieldVlaueZeros(Qty,3); //9 10 11 result:=result+'C'; //12 result:=result+SPACES(5); //最低温度 //13 14 15 16 1 7 result:=result+SPACES(5); // 最高温度 // 18 19 20 21 22 { result:=result+TemperatureFormat(DataSet.fieldbyname('最低温度').AsString); result:=result+TemperatureFormat(DataSet.fieldbyname('最高温度').AsString); } result:=result+TemperatureFormat(DataSet.fieldbyname('设置温度').AsString); // 23 24 25 26 27 result:=result+'N'; //28 if Trim(DataSet.fieldbyname('冷藏通风量').AsString)<>'' then result:=result+FreferFormat(DataSet.fieldbyname('冷藏通风量').AsString) else result:=result+EditFieldVlaue(DataSet.fieldbyname('冷藏通风量').AsString,5); //29 30 31 32 33 result:=result+'Y'; //34 result:=result+TemperatureFormat(DataSet.fieldbyname('设置温度').AsString); // 35 36 37 38 39 If Trim(DataSet.fieldbyname('冷藏通风量').AsString)<>'' then result:=result+'H' else result:=result+'C'; //40 Result:=EditFieldVlaue(Result,250); end; function Tfrm_op_seae_edi_PIL.Record99(LineNo:string):String; begin //9(2)X(3)9(6)X(239) result:='99'; result:=result+SPACES(3); result:=result+EditFieldVlaueZeros(LineNo,6); Result:=EditFieldVlaue(Result,250); end; procedure Tfrm_op_seae_edi_PIL.FormShow(Sender: TObject); var inifile1:Tinifile; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); edit1.text:=inifile1.ReadString('PILEDI','SENDCODE',''); edit2.text:=inifile1.ReadString('PILEDI','RECIEVECODE',''); edit3.text:=inifile1.ReadString('PILEDI','BOOKAGENT',''); edit4.text:=inifile1.ReadString('PILEDI','BOOKAGENTCC',''); edit5.text:=inifile1.ReadString('PILEDI','BOOKAGENTNAME',''); edt1.text:=inifile1.ReadString('PILEDI','FTPSERVER',''); edt2.text:=inifile1.ReadString('PILEDI','FTPPATH','/'); edt3.text:=inifile1.ReadString('PILEDI','FTPNAME',''); edt4.text:=inifile1.ReadString('PILEDI','FTPPASS',''); edt5.text:=inifile1.ReadString('PILEDI','ESINAME',''); edt6.text:=inifile1.ReadString('PILEDI','ESIPASS',''); inifile1.free; end; procedure Tfrm_op_seae_edi_PIL.bsSkinButton2Click(Sender: TObject); begin close; end; function Tfrm_op_seae_edi_PIL.CreateSIEdiFile:TStrings; var k,LineNo,qty,i:integer; str:Tstringlist; inifile1:Tinifile; aAdoQuery:TAdoQuery; begin str:=Tstringlist.Create; if frm_op_seae.dxdbgrid1.SelectedCount<=1 then begin str.Add(Record00_HEADER); str.Add(Record11_VESSELVOYAGE(frm_op_seae.t_op_seae)); str.Add(Record12_BL(frm_op_seae.t_op_seae)); str.Add(Record13_BL(frm_op_seae.t_op_seae)); str.Add(Record16_SHIPPER(frm_op_seae.t_op_seae)); str.Add(Record17_BOOKINGPARTY(frm_op_seae.t_op_seae)); str.Add(Record18_DECIDING(frm_op_seae.t_op_seae)); str.Add(Record21_CONSIGNEE(frm_op_seae.t_op_seae)); str.Add(Record26_Notify(frm_op_seae.t_op_seae)); LineNo:=1; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;Sql.Clear; Sql.Add('select 编号,尺寸,箱型,Sum(数量) 数量,Sum(重量) 重量,Sum(尺码) 尺码,Sum(TEU) TEU from t_op_ctn where 编号=:BsNo'); Sql.Add('Group by 编号,尺寸,箱型'); Parameters.ParamByName('BSNO').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring; Open;First; while not Eof do begin qty:=fieldbyname('数量').AsInteger; str.Add(Record41_DETAILS(TDataSet(aAdoQuery),IntToStr(LineNo))); str.AddStrings(Record44_MARKS(frm_op_seae.t_op_seae,IntToStr(LineNo))); if LineNo =1 then str.Add(Record47_QTY(frm_op_seae.t_op_seae.fieldbyname('编号').asstring)); str.AddStrings(Record47_DESCRIPTION(frm_op_seae.t_op_seae,IntToStr(LineNo))); if frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring='R' then for i:=1 to qty do str.Add(Record54_SPECIAL(frm_op_seae.t_op_seae,IntToStr(LineNo),IntToStr(i))); Next; LineNo:=LineNo+1; end; finally free; end; end else begin str.Add(Record00_HEADER); str.Add(Record11_VESSELVOYAGE(frm_op_seae.t_op_seae)); for k:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do begin frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[k])); str.Add(Record12_BL(frm_op_seae.t_op_seae)); str.Add(Record13_BL(frm_op_seae.t_op_seae)); str.Add(Record16_SHIPPER(frm_op_seae.t_op_seae)); str.Add(Record17_BOOKINGPARTY(frm_op_seae.t_op_seae)); str.Add(Record18_DECIDING(frm_op_seae.t_op_seae)); str.Add(Record21_CONSIGNEE(frm_op_seae.t_op_seae)); str.Add(Record26_Notify(frm_op_seae.t_op_seae)); LineNo:=1; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;Sql.Clear; Sql.Add('select 编号,尺寸,箱型,Sum(重量) 重量,Sum(尺码) 尺码,Sum(TEU) TEU from t_op_ctn where 编号=:BsNo'); Sql.Add('Group by 编号,尺寸,箱型'); Parameters.ParamByName('BSNO').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring; Open;First; while not Eof do begin qty:=fieldbyname('数量').AsInteger; if LineNo =1 then str.Add(Record47_QTY(frm_op_seae.t_op_seae.fieldbyname('编号').asstring)); str.AddStrings(Record47_DESCRIPTION(frm_op_seae.t_op_seae,IntToStr(LineNo))); if frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring='R' then for i:=1 to qty do str.Add(Record54_SPECIAL(frm_op_seae.t_op_seae,IntToStr(LineNo),IntToStr(i))); Next; LineNo:=LineNo+1; end; finally free; end; str.AddStrings(Record44_MARKS(frm_op_seae.t_op_seae,'1')); str.Add(Record47_QTY(frm_op_seae.t_op_seae.fieldbyname('编号').asstring)); str.AddStrings(Record47_DESCRIPTION(frm_op_seae.t_op_seae,'1')); if frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring='R' then // str.Add(Record54_SPECIAL(frm_op_seae.t_op_seae,'001')); end; end; str.Add(Record99(IntToStr(frm_op_seae.dxdbgrid1.SelectedCount))); result:=str; end; procedure Tfrm_op_seae_edi_PIL.btn1Click(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('PILEDI','SENDCODE',edit1.text); inifile1.WriteString('PILEDI','RECIEVECODE',edit2.text); inifile1.WriteString('PILEDI','BOOKAGENT',edit3.text); inifile1.WriteString('PILEDI','BOOKAGENTCC',edit4.text); inifile1.WriteString('PILEDI','BOOKAGENTNAME',edit5.text); inifile1.WriteString('PILEDI','FTPSERVER',edt1.text); inifile1.WriteString('PILEDI','FTPPATH',edt2.text); inifile1.WriteString('PILEDI','FTPNAME',edt3.text); inifile1.WriteString('PILEDI','FTPPASS',edt4.text); inifile1.WriteString('PILEDI','ESINAME',edt5.text); inifile1.WriteString('PILEDI','ESIPASS',edt6.text); inifile1.free; ScriptPath:=ExtractFilePath(ParamStr(0))+'EDIFILE\'; if not DirectoryExists(ScriptPath) then CreateDir(ScriptPath); ftpar:=Trim(edt1.Text); if ftpar='' then begin MessageDlg('请设置FTP地址!',mtWarning,[mbOk],0); exit; end; if bsknrdgrp1.ItemIndex=1 then begin ftpname:=Trim(edt3.Text); if ftpar='' then begin MessageDlg('请设置FTP用户名!',mtWarning,[mbOk],0); exit; end; ftppass:=Trim(edt4.Text); if ftpar='' then begin MessageDlg('请设置FTP密码!',mtWarning,[mbOk],0); exit; end; end else begin ftpname:=Trim(edt5.Text); if ftpar='' then begin MessageDlg('请设置FTP用户名!',mtWarning,[mbOk],0); exit; end; ftppass:=Trim(edt6.Text); if ftpar='' then begin MessageDlg('请设置FTP密码!',mtWarning,[mbOk],0); exit; end; if Trim(edit3.text)='' then begin MessageDlg('订舱代理不能为空',mtWarning,[mbOk],0); exit; end; if Trim(edit4.text)='' then begin MessageDlg('到付订舱代理不能为空',mtWarning,[mbOk],0); exit; end; end; ftppath:=Trim(edt2.Text); str:=ScriptPath +frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.txt'; str_file:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.txt'; strL:=Tstringlist.Create; try StrL:=CreateSIEdiFile; 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_PIL.btn2Click(Sender: TObject); begin if frm_op_seae_edi_PIL.Height=293 then frm_op_seae_edi_PIL.Height:=158 else frm_op_seae_edi_PIL.Height:=293; end; procedure Tfrm_op_seae_edi_PIL.bsSkinButton1Click(Sender: TObject); var Str:TStrings; inifile1:Tinifile; i:integer; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.WriteString('PILEDI','SENDCODE',edit1.text); inifile1.WriteString('PILEDI','RECIEVECODE',edit2.text); inifile1.WriteString('PILEDI','BOOKAGENT',edit3.text); inifile1.WriteString('PILEDI','BOOKAGENTCC',edit4.text); inifile1.WriteString('PILEDI','FTPSERVER',edt1.text); inifile1.WriteString('PILEDI','FTPPATH',edt2.text); inifile1.WriteString('PILEDI','FTPNAME',edt3.text); inifile1.WriteString('PILEDI','FTPPASS',edt4.text); inifile1.WriteString('PILEDI','ESINAME',edt5.text); inifile1.WriteString('PILEDI','ESIPASS',edt6.text); inifile1.free; if not isEditrue(frm_op_seae.t_op_seae) then exit; str:=Tstringlist.Create; Str:=CreateSIEdiFile; try for i:=0 to Str.Count-1 do begin if IsZhongwen(Str[i])<>'' then begin ShowMessage('此票业务含有中文字符或其他不规范字符,不能继续上传!'+#13#10+Str[i]); exit; end; end; SaveDialog1.FileName:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring; if SaveDialog1.Execute then begin str.SaveToFile(SaveDialog1.FileName+'.pms'); showmessage('文件生成成功!'); end else begin showmessage('文件生成失败!'); exit; end; finally FreeAndNil(Str); end; close; end; end.