unit u_op_seae_edi_bb; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB; type Tfrm_op_seae_edi_bb = class(TForm) bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; SaveDialog1: TSaveDialog; Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Label2: TLabel; bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; procedure FormShow(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); private { Private declarations } public { Public declarations } function FormatListString(Old:TStrings;mCount,Strlength:integer):String; function FormatEdiString(old:String;Strlength:integer):String; end; var frm_op_seae_edi_bb: Tfrm_op_seae_edi_bb; implementation uses u_op_seae, u_main, my_sys_function, u_data_share; {$R *.dfm} procedure Tfrm_op_seae_edi_bb.FormShow(Sender: TObject); var inifile1:Tinifile; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); edit1.text:=inifile1.ReadString('BBEDI','SENDCODE',''); edit2.text:=inifile1.ReadString('BBEDI','RECIEVECODE',''); inifile1.free; end; procedure Tfrm_op_seae_edi_bb.bsSkinButton2Click(Sender: TObject); begin close; end; function Tfrm_op_seae_edi_bb.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 iStrlength then Result:=Copy(Result,1,Strlength); end; procedure Tfrm_op_seae_edi_bb.bsSkinButton1Click(Sender: TObject); 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:string; function 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 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 GetPortStr(Port:String):String; begin if Pos(',',Port)>0 then Result:=Copy(Port,1,Pos(',',Port)-1) else Result:=Port; end; begin SenderCode:=trim(edit1.Text) ; ReciverCode:=trim(edit2.Text) ; strType:='9C'; if frm_op_seae.dxdbgrid1.SelectedCount<=1 then begin if bsSkinCheckRadioBox2.Checked then begin aQuery2:=CreateAdoQuery; with aQuery2 do begin Close; SQL.Clear; SQL.Add('select * from t_op_seae_assistant where 编号='''+frm_op_seae.t_op_seae.fieldbyname('编号').AsString+''''); open; end; end; str:=Tstringlist.Create; str.Clear; str.Add('00:IFCSUM:MANIFEST:'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+#39); Count:=0; str.Add ('10:'+ ':'//trim(frm_op_seae.t_op_seae.fieldbyname('船名代码').AsString)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('船名').AsString) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('舶国籍代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('航次').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('航线代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('航线').asstring) +':' + trim(GetDatetime(frm_op_seae.t_op_seae.fieldbyname('预抵日期').asstring,0)) +':' + trim(GetDatetime(frm_op_seae.t_op_seae.fieldbyname('开船日期').asstring,0)) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('离港地点代码').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('离港地点').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('下一挂港代码').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('下一挂港').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('箱TEU').asstring) +':' + #39); str.Add('11::' + trim(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString) + #39); if trim(frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring) = 'FREIGHT PREPAID' then xtype := 'P' else if trim(frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring) = 'FREIGHT COLLECT' then xtype := 'C' else xtype := 'F'; str.add('12:' + trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('交货代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('交货地点').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring) +':' + XType +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('装货日期').asstring) +':' + '::::' +#39); str.add('13:' + trim(frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('目的地代码').asstring)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('目的地').asstring)+':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('中转港代码').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('中转港').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('提单签发地代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring) +':' + ':' +#39); try Temprslt := ''; TempStr:=TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('发货人代码').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('发货人代码').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('16::' + Temprslt + ':' + #39); finally Tempstr.Free; end; try Temprslt := ''; Tempstr := TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('收货人代码').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('收货人代码').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('17::' + Temprslt + ':' + #39); finally Tempstr.Free; end; try Temprslt := ''; Tempstr := TStringList.Create; Tempstr.Clear; // Tempstr.Assign(TGuidField); // Tempstr.Add(frm_op_seae.t_op_seae.FieldByName('通知人').AsString); // Temprslt := Temprslt + FormatListString(Tempstr,5,35) + ':'; // Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('通知人代码').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('通知人代码').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('18::' + Temprslt + ':' + #39); finally Tempstr.Free; end; try Temprslt := ''; Tempstr := TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('代理内容').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('代理内容').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('19::' + Temprslt + ':' + #39); finally Tempstr.Free; end; str.Add ('41:1' +':0'//+trim(frm_op_seae.t_op_seae.fieldbyname('货物序号').asstring)+'::' +':' +trim(frm_op_seae.t_op_seae.fieldbyname('件数').asstring) + '::' +trim(frm_op_seae.t_op_seae.fieldbyname('包装').asstring) + ':' +trim(frm_op_seae.t_op_seae.fieldbyname('重量').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('净重').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('尺码').asstring) +#39); str.Add ('43:' +':' +trim(frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring) +':' +'none:'//trim(frm_op_seae.t_op_seae.fieldbyname('危险品页号').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring) +':' +'none:::::::::'//trim(frm_op_seae.t_op_seae.fieldbyname('危险品标签').asstring) +'::::::::' +#39); try Tempstr:=TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.fieldbyname('唛头').asstring else Tempstr.Text:=frm_op_seae.t_op_seae.fieldbyname('唛头').asstring; str.Add ('44:' //+ Changestr(frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring)+ ':' + FormatListString(Tempstr,5,300)+ ':' +'::::' + #39); finally Tempstr.Free; end; // str.Add ('44:' // + Changestr(frm_op_seae.t_op_seae.fieldbyname('唛头').asstring)+ ':' // +':::::::::' + #39); try Tempstr:=TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.fieldbyname('货物描述').asstring else Tempstr.Text:=frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring; str.Add ('47:' //+ Changestr(frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring)+ ':' + FormatListString(Tempstr,5,300)+ ':' + #39); finally Tempstr.Free; end; Count:=Count+10; if trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then XType := 'F' else begin if trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='拼箱' then XType := 'L' else XType := 'E'; end; strsql:='select t_op_ctn.编号,t_op_ctn.代码,t_op_ctn.数量,t_op_ctn.箱号,t_op_ctn.封号,t_op_ctn.尺寸,t_op_ctn.箱型,t_op_ctn.件数,t_op_ctn.重量,t_op_ctn.尺码,t_code_ctn.EDI代码 from t_op_ctn ' +'left join t_code_ctn on t_code_ctn.代码=t_op_ctn.代码 WHERE t_op_ctn.编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; try rs:=Tadoquery.Create(application); rs.Connection := frm_main.db; rs.sql.clear; rs.sql.add(strsql); rs.Open; rs.First; while not rs.Eof do begin if XType = 'F' then begin str.Add ('51:' +'1:' +trim(rs.fieldbyname('箱号').asstring) +':' +trim(rs.fieldbyname('封号').asstring) +':' +trim(rs.fieldbyname('代码').asstring)+':' + XType +':' +trim(rs.fieldbyname('件数').asstring) +':' +trim(rs.fieldbyname('重量').asstring) +':' +trim(rs.fieldbyname('尺码').asstring) +':' +trim(rs.fieldbyname('数量').asstring) +':' +#39); end else begin str.Add ('51:' +'1:' +trim(rs.fieldbyname('箱号').asstring) +':' +trim(rs.fieldbyname('封号').asstring) +':' +trim(rs.fieldbyname('代码').asstring)+':' + XType +':' +trim(rs.fieldbyname('件数').asstring) +':' +trim(rs.fieldbyname('重量').asstring) +':' +trim(rs.fieldbyname('尺码').asstring) +':' +trim(rs.fieldbyname('数量').asstring) +':' +#39); end; Count:=Count+1; rs.Next; end; rs.Close; rs.Destroy; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; 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),1)+#39); Count:=0; 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])); if bsSkinCheckRadioBox2.Checked then begin aQuery2:=CreateAdoQuery; with aQuery2 do begin Close; SQL.Clear; SQL.Add('select * from t_op_seae_assistant where 编号='''+frm_op_seae.t_op_seae.fieldbyname('编号').AsString+''''); open; end; end; str.Add ('10:' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('船名代码').AsString)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('船名').AsString) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('舶国籍代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('航次').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('航线代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('航线').asstring) +':' + trim(GetDatetime(frm_op_seae.t_op_seae.fieldbyname('预抵日期').asstring,0)) +':' + trim(GetDatetime(frm_op_seae.t_op_seae.fieldbyname('开船日期').asstring,0)) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('离港地点代码').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('离港地点').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('下一挂港代码').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('下一挂港').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('箱TEU').asstring) +':' + #39); str.Add('11::' + trim(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString) + #39); if trim(frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring) = 'FREIGHT PREPAID' then xtype := 'P' else if trim(frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring) = 'FREIGHT COLLECT' then xtype := 'C' else xtype := 'F'; str.add('12:' + trim(frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('交货代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('交货地点').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring) +':' + xtype +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('装货日期').asstring) +':' + '::::' +#39); str.add('13:' + trim(frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('目的地代码').asstring)+':' + trim(frm_op_seae.t_op_seae.fieldbyname('目的地').asstring)+':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('中转港代码').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('中转港').asstring) +':' + ':'//trim(frm_op_seae.t_op_seae.fieldbyname('提单签发地代码').asstring) +':' + trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring) +':' + ':' +#39); try Temprslt := ''; TempStr:=TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('发货人代码').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('发货人代码').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('16::' + Temprslt + ':' + #39); finally Tempstr.Free; end; try Temprslt := ''; Tempstr := TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('收货人代码').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('收货人代码').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('17::' + Temprslt + ':' + #39); finally Tempstr.Free; end; try Temprslt := ''; Tempstr := TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('通知人代码').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('通知人代码').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('18::' + Temprslt + ':' + #39); finally Tempstr.Free; end; try Temprslt := ''; Tempstr := TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.FieldByName('代理内容').AsString else Tempstr.Text:=frm_op_seae.t_op_seae.FieldByName('代理内容').AsString; Temprslt := Temprslt + FormatListString(Tempstr,5,35); str.Add('19::' + Temprslt + ':' + #39); finally Tempstr.Free; end; str.Add ('41:1' +':0'//+trim(frm_op_seae.t_op_seae.fieldbyname('货物序号').asstring)+'::' +':' +trim(frm_op_seae.t_op_seae.fieldbyname('件数').asstring) +'::' +trim(frm_op_seae.t_op_seae.fieldbyname('包装').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('重量').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('净重').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('尺码').asstring) +#39); str.Add ('43:' +':' +trim(frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring) +':' +'none:'//trim(frm_op_seae.t_op_seae.fieldbyname('危险品页号').asstring) +':' +trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring) +':' +'none:::::::::'//trim(frm_op_seae.t_op_seae.fieldbyname('危险品标签').asstring) +'::::::::' +#39); try Tempstr:=TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.fieldbyname('唛头').asstring else Tempstr.Text:=frm_op_seae.t_op_seae.fieldbyname('唛头').asstring; str.Add ('44:' //+ Changestr(frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring)+ ':' + FormatListString(Tempstr,5,300)+ ':' + #39); finally Tempstr.Free; end; try Tempstr:=TStringList.Create; Tempstr.Clear; if bsSkinCheckRadioBox2.Checked then Tempstr.Text:=aQuery2.fieldbyname('货物描述').asstring else Tempstr.Text:=frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring; str.Add ('47:' //+ Changestr(frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring)+ ':' + FormatListString(Tempstr,5,300)+ ':' + #39); finally Tempstr.Free; end; Count:=Count+10; if trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then XType := 'F' else begin if trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='拼箱' then XType := 'L' else XType := 'E'; end; strsql:='select t_op_ctn.编号,t_op_ctn.代码,t_op_ctn.箱号,t_op_ctn.数量,t_op_ctn.封号,t_op_ctn.尺寸 ' +',t_op_ctn.箱型,t_op_ctn.件数,t_op_ctn.重量,t_op_ctn.尺码,t_code_ctn.EDI代码 from t_op_ctn ' +'left join t_code_ctn on t_code_ctn.代码=t_op_ctn.代码 WHERE t_op_ctn.编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; { strsql:='select 编号,代码,箱号,封号,尺寸,箱型,件数, 重量,尺码 from t_op_ctn' +' group by 编号,代码,箱号,封号,尺寸,箱型,件数,重量,尺码 having 编号=' +#39+frm_op_seae.t_op_seae.fieldbyname('编号').asstring+#39; } try rs:=Tadoquery.Create(application); rs.Connection := frm_main.db; rs.sql.clear; rs.sql.add(strsql); rs.Open; rs.First; while not rs.Eof do begin if XType = 'F' then begin str.Add ('51:' +'1:' +trim(rs.fieldbyname('箱号').asstring) +':' +trim(rs.fieldbyname('封号').asstring) +':' +trim(rs.fieldbyname('代码').asstring)+':' + XType +':' +trim(rs.fieldbyname('件数').asstring) +':' +trim(rs.fieldbyname('重量').asstring) +':' +trim(rs.fieldbyname('尺码').asstring) +':' +trim(rs.fieldbyname('数量').asstring) +':' +#39); end else begin str.Add ('51:' +'1:' +trim(rs.fieldbyname('箱号').asstring) +':' +trim(rs.fieldbyname('封号').asstring) +':' +trim(rs.fieldbyname('代码').asstring)+':' + XType +':' +trim(rs.fieldbyname('件数').asstring) +':' +trim(rs.fieldbyname('重量').asstring) +':' +trim(rs.fieldbyname('尺码').asstring) +':' +trim(rs.fieldbyname('数量').asstring) +':' +#39); end; Count:=Count+1; rs.Next; end; rs.Close; rs.Destroy; except on e:exception do begin rs.Close; rs.Destroy; exit; end; end; if k<>frm_op_seae.dxdbgrid1.SelectedCount-1 then begin str.Add ('52:'+#39); Count:=Count+1; end; end; str.Add ('99:'+ inttostr(Count+3)+#39); end; SaveDialog1.FileName:=frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring; if SaveDialog1.Execute then begin str.SaveToFile(SaveDialog1.FileName+'.txt'); showmessage('文件生成成功!'); end else begin showmessage('文件生成失败!'); exit; end; inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.WriteString('BBEDI','SENDCODE',edit1.text); inifile1.WriteString('BBEDI','RECIEVECODE',edit2.text); inifile1.free; close; end; end.