You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DONGSHENG6/EDI/u_op_seae_edi_line.~pas

1663 lines
53 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

unit u_op_seae_edi_line;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IdFTP,IdFTPCommon,
Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB;
type
Tfrm_op_seae_edi_kline = 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;
bsSkinButton4: TbsSkinButton;
bsSkinGroupBox1: TbsSkinGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
t_op_ams: TADOQuery;
t_op_ams1: TDataSource;
t_op_seae_assistant: TADOQuery;
bsSkinRadioGroup2: TbsSkinRadioGroup;
Label8: TLabel;
Edit8: TEdit;
procedure bsSkinButton2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure bsSkinButton1Click(Sender: TObject);
procedure bsSkinButton3Click(Sender: TObject);
procedure bsSkinButton4Click(Sender: TObject);
private
function isEditrue(DataSet:TDataSet): string; //判断必填项
function GetStrNum(str:String):integer;//判断数字位数
function FormatListString(Old:TStrings;mCount,Strlength:integer):String;//根据长度要求格式化字符串
function FormatEdiString(str:String;Strlength:integer=0):String;//特殊字符加 :
function CreateEdiFile:TStrings;//订舱报文
function GetLengthword(var s: String; l: Integer;str:String): String;//根据长度要求截取字符串
procedure GetLengthTString(var sl:TStringList;l:integer);//根据长度格式化 tstringlist
function IsZhongwen(Str:String):Boolean;//是否包含中文或双字节字符
function CreateVgmFile:TStrings;//订舱报文
{ Private declarations }
public
{ Public declarations }
function GetShipEdiNO(Ship:String): String;
function GetPortEdiID(Port:String): String;
function GetCntrEdi(cntrsize: String):String;
function GetCorpsString(recordno,fldName:string;aDataset:TDataset):String;
function Record00(strType,SenderCode,ReciverCode:string):String;
function Record02(SenderCode,ReciverCode:string;aDataset:TDataset):String;
function Record03(SenderCode,ReciverCode:string;aDataset:TDataset):String;
function Record11(aDataset:TDataset):String;
function Record12(aDataset:TDataset):String;
function Record15(aDataset:TDataset):String;
function Record17(aDataset:TDataset):String;
function Record20_21_22_23(recordno,fldName:string;aDataset:TDataset):String;
function Record41(aLineno:string;aDataset:TDataset):String;
function Record41Ctn(aLineno:string;aDataset:TDataset):String;
function Record43(aDataset:TDataset):String;
function Record44_47(strLen,LoopCount:integer;RecordNo,FldName:string;aDataset:TDataset):TStringlist;
function Record48(aDataset:TDataset):TStringlist;
function Record49(aDataset,aDatasetItems:TDataset):String;
function Record51(aLineno:string;aDataset:TDataset):String;
function ControlLines(FieldMessage,FldName:string):String;
function get_txtvgm(str:Tstringlist):integer;
// function Record48(aDataset:TDataset):TStringlist;
end;
var
frm_op_seae_edi_kline: Tfrm_op_seae_edi_kline;
implementation
uses u_op_seae, u_main, my_sys_function, u_data_share;
{$R *.dfm}
function Tfrm_op_seae_edi_kline.ControlLines(FieldMessage,FldName:string):String;
var i:Integer;
sl : TStrings;
begin
Result:='';
sl:=TStringList.create;
try
sl.Clear;
sl.Text:=Changestr(frm_op_seae.t_op_seae.fieldbyname(FldName).asstring);
if sl.Count>7 then
begin
if Result='' then
Result:=FieldMessage+' 不能大于7行!'
else Result:=Result+#13#10+FieldMessage+' 不能大于7行!';
end;
for i:=0 to sl.Count-1 do
begin
if IsZhongwen(sl[i]) then
begin
if Result='' then
Result:=FieldMessage+' '+sl[i]+'中有中文字符或TAB键!'
else Result:=Result+#13#10+FieldMessage+' '+sl[i]+'中有中文字符或TAB键!';
end;
if i=0 then
begin
if Length(sl[i])>70 then
begin
if Result='' then
Result:=FieldMessage+' '+sl[i]+'第'+IntToStr(i+1)+'行字符不能超过70个字符!'
else Result:=Result+#13#10+FieldMessage+' '+sl[i]+'第'+IntToStr(i+1)+'行字符不能超过70个字符!';
end;
end
else
if Length(sl[i])>35 then
begin
if Result='' then
Result:=FieldMessage+' '+sl[i]+'第'+IntToStr(i+1)+'行字符不能超过35个字符!'
else Result:=Result+#13#10+' '+sl[i]+FieldMessage+'第'+IntToStr(i+1)+'行字符不能超过35个字符!';
end;
end;
finally
sl.Free;
end;
end;
function Tfrm_op_seae_edi_kline.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 客户性质<>''目标'' and 客户简称='''+Ship+'''');
SQL.Add('order by 代码');
Open;
if not IsEmpty then
Result:=Trim(FieldByName('EDI代码').asstring)
else
Result:='';
end;
finally
FreeAndNil(aQuery);
end;
end;
function Tfrm_op_seae_edi_kline.GetCntrEdi(cntrsize: String):String;
var
aQuery:TADOQuery;
begin
aQuery:=CreateAdoQuery;
try
with aQuery do begin
Close;SQL.Clear;
SQL.Add('Select MSC代码 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_kline.GetPortEdiID(Port:String): String;
var
aQuery:TADOQuery;
begin
aQuery:=CreateAdoQuery;
try
with aQuery do begin
Close;SQL.Clear;
SQL.Add('Select EDI代码 from t_code_disport where 英文名='''+Port+'''');
Open;
if not IsEmpty then
Result:=Trim(FieldByName('EDI代码').asstring)
else
Result:='';
end;
finally
FreeAndNil(aQuery);
end;
end;
function Tfrm_op_seae_edi_kline.GetCorpsString(recordno,fldName:string;aDataset:TDataset):String;
var
TempStr:TStringList;
begin
TempStr:=TStringList.Create;
try
TempStr.Text:=FormatEdiString(aDataset.fieldbyname(fldName).AsString);
GetLengthTString(TempStr,60);
Result:=recordno+':';
Result:=Result+':';
Result:=Result+FormatListString(TempStr,6,60)+'''';
finally
FreeAndNil(TempStr);
end;
end;
function Tfrm_op_seae_edi_kline.Record00(strType,SenderCode,ReciverCode:string):String;
begin
if bsSkinRadioGroup2.ItemIndex=0 then
begin
result:='00:IFTMIN:Shipping instruction'+':'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+#39;
end
else
begin
result:='00:IFTMIN:Shipping instruction'+':'+trim(strType)+':'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+#39;
end;
end;
function Tfrm_op_seae_edi_kline.Record02(SenderCode,ReciverCode:string;aDataset:TDataset):String;
begin
result:='02'+':'+trim(aDataset.fieldbyname('委托编号').asstring)+'-'+Copy(FormatDateTime('YYYYMMDD',Date),7,2) // 2
+':'+trim(aDataset.fieldbyname('主提单号').asstring) // 3
+':'+ trim(aDataset.fieldbyname('运输条款').asstring) //4
+':'+SenderCode //5
+':'+ReciverCode //6
+':' //7
+':' //8
+':' //9
+':' //10
+':' //11
+':' // 12
+':' //13
+':' //14
+':' //15
+':'+trim(aDataset.fieldbyname('运费协议号').asstring) //16
+':' //17
+':' //18
+#39;
end;
function Tfrm_op_seae_edi_kline.Record03(SenderCode,ReciverCode:string;aDataset:TDataset):String;
var mbltype,Str1,Str2,ISSUECODE,SignDate:string;
begin
if trim(frm_op_seae.t_op_seae.fieldbyname('签单方式').asstring)<>'正本' then
mbltype:='W'
else mbltype:='O';
if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='ONE' then
Str1:='1'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='TWO' then
Str1:='2'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='THREE' then
Str1:='3'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='FOUR' then
Str1:='4'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='FIVE' then
Str1:='5'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='SIX' then
Str1:='6'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='SERVEN' then
Str1:='7'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='EIGHT' then
Str1:='8'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='NIGHT' then
Str1:='9'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='TEN' then
Str1:='10'
else if frm_op_seae.t_op_seae.fieldbyname('提单份数').asstring='NONE' then
Str1:='0';
///
if frm_op_seae.t_op_seae.fieldbyname('副本提单份数').asstring='ONE' then
Str2:='1'
else if frm_op_seae.t_op_seae.fieldbyname('副本提单份数').asstring='TWO' then
Str2:='2'
else if frm_op_seae.t_op_seae.fieldbyname('副本提单份数').asstring='THREE' then
Str2:='3'
else if frm_op_seae.t_op_seae.fieldbyname('副本提单份数').asstring='NONE' then
Str2:='0';
if frm_op_seae.t_op_seae.fieldbyname('签单日期').asstring<>'' then
SignDate:=GetDatetime(datetimetostr(frm_op_seae.t_op_seae.fieldbyname('签单日期').asDatetime),0);
if GetPortEdiID(trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring))='' then
ISSUECODE:='CNTAO'
else ISSUECODE:=GetPortEdiID(trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring));
result:='03'+':'+mbltype // 2
+':'+ISSUECODE // 3
+':'+ trim(frm_op_seae.t_op_seae.fieldbyname('签单地点').asstring) //4
+':'+SignDate //5
+':'+Str1 //6
+':'+Str2 //7
+':'+'N' //8
+#39;
end;
function Tfrm_op_seae_edi_kline.Record11(aDataset:TDataset):String;
begin
result:='11:'
+':'+trim(aDataset.fieldbyname('船名').asstring) // 3
+':'+ trim(aDataset.fieldbyname('航次').asstring)//4
+':::' //5 6 7
+':' //8
+':' //9
+':' //10
+'::::' //11 12 13 14
+#39;
end;
function Tfrm_op_seae_edi_kline.Record12(aDataset:TDataset):String;
var czNo:string;
begin
if GetShipEdiNO(aDataset.fieldbyname('场站').asstring)='' then
czNo:=''
else czNo:=GetShipEdiNO(aDataset.fieldbyname('场站').asstring);
result:='12'+':'+ trim(aDataset.fieldbyname('装港代码').asstring) // 2
+':'+ trim(aDataset.fieldbyname('装货港').asstring) //3
+':' + trim(aDataset.fieldbyname('装港代码').asstring) //4
+':' + trim(aDataset.fieldbyname('装货港').asstring) //5
+':'+trim(aDataset.fieldbyname('卸货代码').asstring)//6
+':'+trim(aDataset.fieldbyname('卸货港').asstring) //7
+':' //8
+':' //9
+':'+trim(aDataset.fieldbyname('交货代码').asstring) //10
+':'+trim(aDataset.fieldbyname('交货地点').asstring) // 11
+':' //12
+':' //13
+':'+trim(aDataset.fieldbyname('装货港').asstring) //14
+#39;
end;
function Tfrm_op_seae_edi_kline.Record15(aDataset:TDataset):String;
var strtype,PayAtAddr:string;
begin
if frm_data_share.t_code_free.locate('付费方式',frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring,[]) then
begin
strtype:=frm_data_share.t_code_free.fieldbyname('代码').asstring;
end;
if strtype='P' then
PayAtAddr:=frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring+' AT '+ frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring
else
if strtype='C' then PayAtAddr:=frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring+' AT '+ frm_op_seae.t_op_seae.fieldbyname('到付地点').asstring;
result:='15:1:'+PayAtAddr //3
+':'+ strtype //4
+':'
+'::::::' //5-11
+#39;
end;
function Tfrm_op_seae_edi_kline.Record17(aDataset:TDataset):String;
var strtype:string;
begin
result:='17:'+Changestr(aDataset.fieldbyname('EDI备注').asString) //
+#39;
end;
function Tfrm_op_seae_edi_kline.Record20_21_22_23(recordno,fldName:string;aDataset:TDataset):String;
var i:Integer;
sl : TStringList;
aAdoQuery:TAdoQuery;
cityname, postalcode, countrycode:string;
begin
cityname:='';
postalcode:='';
countrycode:='';
sl:=TStringList.create;
aAdoQuery:=CreateAdoQuery;
with aAdoQuery do
begin
Close;Sql.Clear;
sql.Add('Select * from t_op_ams where 编号=:编号');
Parameters.ParamByName('编号').Value:=aDataset.fieldbyname('编号').asstring;
Open;First;
end;
try
sl.Clear;
sl.Text:=Changestr(frm_op_seae.t_op_seae.fieldbyname(FldName).asstring);
if sl.Count=7 then
for i:=0 to sl.Count-1 do
begin
Result:=Result+':'+sl[i];
end
else
begin
for i:=0 to sl.Count-1 do
begin
Result:=Result+':'+sl[i];
end;
i:=0;
for i:=0 to 7-sl.Count-1 do
begin
Result:=Result+':';
// if recordno='20' then
//showmessage(Result);
end;
end;
case StrToInt(recordno) of
20:
if Trim(Edit8.Text)='' then
Result:=recordno+':'+Result+':B::'
else Result:=recordno+':'+Result+':'+'N'+':'+Edit8.Text+':';
21: Result:=recordno+':'+Result+':';
22: Result:=recordno+':'+Result+':';
23: Result:=recordno+':'+Result+':';
end;
if aAdoQuery.FieldByName('所在国家').AsString='EUR' then
begin
if fldName='发货人代码' then
begin
sl.Clear;
sl.Text:=Changestr(aAdoQuery.fieldbyname('AMS发货人').asstring);
for i:=0 to sl.Count-1 do
begin
if i=0 then
cityname:=sl[i];
if i=1 then
postalcode:=sl[i];
if i=2 then
countrycode:=sl[i];
end
end;
if fldName='收货人代码' then
begin
sl.Clear;
sl.Text:=Changestr(aAdoQuery.fieldbyname('AMS收货人').asstring);
for i:=0 to sl.Count-1 do
begin
if i=0 then
cityname:=sl[i];
if i=1 then
postalcode:=sl[i];
if i=2 then
countrycode:=sl[i];
end
end;
if fldName='通知人代码' then
begin
sl.Clear;
sl.Text:=Changestr(aAdoQuery.fieldbyname('AMS通知人').asstring);
for i:=0 to sl.Count-1 do
begin
if i=0 then
cityname:=sl[i];
if i=1 then
postalcode:=sl[i];
if i=2 then
countrycode:=sl[i];
end
end;
if fldName='第二通知人' then
begin
sl.Clear;
sl.Text:=Changestr(aDataset.fieldbyname('DOOR地址').asstring);
for i:=0 to sl.Count-1 do
begin
if i=0 then
cityname:=sl[i];
if i=1 then
postalcode:=sl[i];
if i=2 then
countrycode:=sl[i];
end
end;
Result:=Result+':'+cityname+':'+':'+postalcode+':'+countrycode;
end;
Result:=Result+#39;
finally
sl.Free;
end;
end;
function Tfrm_op_seae_edi_kline.Record41(alineno:string;aDataset:TDataset):String;
begin
result:='41'
+':'+alineno
+':'+trim(aDataset.fieldbyname('hts').asstring) // 2 3
+':'+trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring) //4
+':'+trim(aDataset.fieldbyname('件数').asstring) //5
+':'+ trim(aDataset.fieldbyname('包装').asstring) //6
+':'+ trim(aDataset.fieldbyname('包装').asstring) //7
+':'+ trim(aDataset.fieldbyname('重量').asstring) //8
+':'+ trim(aDataset.fieldbyname('尺码').asstring) //9
+':' //10
+':' //11
+':' //12
+':' //13
+':' //14
+':'+trim(aDataset.fieldbyname('重量').asstring) //15
+':' //16
+':' //17
+':' //18
+#39;
end;
function Tfrm_op_seae_edi_kline.Record41ctn(alineno:string;aDataset:TDataset):String;
begin
result:='41'
+':'+alineno
+':'+trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring) // 2 3
+':'+trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring) //4
+':'+trim(aDataset.fieldbyname('件数').asstring) //5
+':'+ trim(aDataset.fieldbyname('包装').asstring) //6
+':'+ trim(aDataset.fieldbyname('包装').asstring) //7
+':'+ trim(aDataset.fieldbyname('重量').asstring) //8
+':'+ trim(aDataset.fieldbyname('尺码').asstring) //9
+':' //10
+':' //11
+':' //12
+':' //13
+':' //14
+':'+trim(aDataset.fieldbyname('重量').asstring) //15
+':' //16
+':' //17
+':' //18
+#39;
end;
function Tfrm_op_seae_edi_kline.Record43(aDataset:TDataset):String;
begin
result:='43:';
if trim(aDataset.fieldbyname('货物标识').asstring)='D' THEN
begin
result:=result
+':'+trim(aDataset.fieldbyname('危险品分类').asstring) //2
+':' //3
+':'+trim(aDataset.fieldbyname('危险品编号').asstring) //4
+':' //5
+':' //6
+':' //7
+':' //8
+':' //9
+':' //11
+':' //12
+':' //13
+':' //14
+':' //15
+':' //16
+':' //17
+':' //18
+':' //19
+':' //20
+':37' //21
end
else
begin
result:=result+':::::::::'
end;
if trim(aDataset.fieldbyname('货物标识').asstring)='R' then
begin
result:=result+':'+trim(frm_op_seae.t_op_seae.fieldbyname('冷藏通风量').asstring)
+':C'
+':'+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;
end
else
begin
result:=result+':::::'+#39;
end;
end;
function Tfrm_op_seae_edi_kline.Record44_47(strLen,LoopCount:integer;RecordNo,FldName:string;aDataset:TDataset):TStringlist;
var sl,sl1:Tstringlist;
m,l:integer;
s:string;
begin
result:=Tstringlist.Create;
sl:=Tstringlist.Create;
sl1:=Tstringlist.Create;
try
sl1.Text:=FormatEdiString(aDataset.fieldbyname(FldName).AsString);
GetLengthTString(sl1,strLen);
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<=LoopCount then begin
if M=1 then begin
s:=RecordNo+':'+sl.Strings[L]+':';
end else begin
if M=LoopCount then
s:=s+sl.Strings[L]
else
s:=s+sl.Strings[L]+':';
end;
end else begin
S:=S+'''';
result.Add(S);
M:=1;
s:=RecordNo+':'+sl.Strings[L]+':';
end;
M:=M+1;
end;
S:=S+'''';
result.Add(S);
finally
sl.Free;
sl1.Free;
end;
end;
function Tfrm_op_seae_edi_kline.Record48(aDataset:TDataset):TStringlist;
var strsql,strtype:string;
rs:TADOQuery;
begin
if frm_op_seae.t_op_seae.fieldbyname('是否自有箱').asboolean then
strtype:='Y'
ELSE strtype:='N';
result:=TStringlist.Create;
strsql:='select 代码,编号,尺寸,箱型,sum(数量) as 数量 from t_op_ctn group by 代码,编号,尺寸,箱型 having 编号='
+#39+aDataset.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
result.Add ('48:'+Trim(GetCntrEdi(rs.fieldbyname('代码').asstring)) //2
+':'+trim(rs.fieldbyname('数量').asstring) //3
+':'+'F' //4
+':' //5
+':' //6
+':' //7
+':' //8
+':'+strtype //9
+':' //10
+':' //11
+#39);
rs.Next;
end;
finally
rs.Close;
rs.Destroy;
end;
end;
function Tfrm_op_seae_edi_kline.Record49(aDataset,aDatasetItems:TDataset):String;
begin
result:='49'
+':'+trim(aDataset.fieldbyname('箱号').asstring) // 2
+':'+trim(aDatasetItems.fieldbyname('件数').asstring) //3
+':'+ trim(aDatasetItems.fieldbyname('重量').asstring) //4
+':'+ trim(aDatasetItems.fieldbyname('尺码').asstring) //5
+#39;
end;
function Tfrm_op_seae_edi_kline.Record51(alineno:string;aDataset:TDataset):String;
begin
result:='51'
+':'+alineno // 2
+':'+trim(aDataset.fieldbyname('箱号').asstring) //3
+':'+ trim(GetCntrEdi(aDataset.fieldbyname('代码').asstring)) //4
+':'+ trim(aDataset.fieldbyname('封号').asstring) //5
+':' //6
+':' //7
+':' //8
+':' //9
+':'+ trim(aDataset.fieldbyname('件数').asstring) //10
+':'+ trim(aDataset.fieldbyname('包装').asstring) //11
+':'+ trim(aDataset.fieldbyname('重量').asstring) //12
+':'+ trim(aDataset.fieldbyname('重量').asstring) //13
+':'+ trim(aDataset.fieldbyname('尺码').asstring) //14
+#39;
end;
function Tfrm_op_seae_edi_kline.IsZhongwen(Str: String): Boolean;
var
i:Integer;
begin
Result:=false;
if Str='' then Exit;
for i:=1 to Length(Str) do begin
if Str[i]>Chr(127) then begin
Result:=True;
Exit;
end;
end;
end;
function Tfrm_op_seae_edi_kline.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_kline.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_kline.FormatEdiString(str:String;Strlength:integer=0):String;
var
i:integer;
strC:widestring;
begin
strC:='';
for i:=1 to length(str) do
begin
if ((str[i]=#39) or (str[i]=':') or (str[i]='+') or (str[i]='?') or (str[i]=';')) then
begin
strC:=strC+'?'+str[i];
end
else
begin
strC:=strC+str[i];
end;
end;
result:=strC;
{
Result:=Trim(str);
Result:=StringReplace(Result,'?','??',[rfReplaceAll]);
Result:=StringReplace(Result,':','?:',[rfReplaceAll]);
Result:=StringReplace(Result,'''','?''',[rfReplaceAll]);
Result:=StringReplace(Result,'+','?+',[rfReplaceAll]);
}
end;
function Tfrm_op_seae_edi_kline.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 i<NewStrs.Count then begin
Result:=Result+NewStrs.Strings[i];
end;
if i<mCount-1 then
Result:=Result+':';
end;
finally
FreeAndNil(NewStrs);
end;
end;
function Tfrm_op_seae_edi_kline.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;
procedure Tfrm_op_seae_edi_kline.bsSkinButton2Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_op_seae_edi_kline.FormShow(Sender: TObject);
var
inifile1:Tinifile;
begin
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
edit1.text:=inifile1.ReadString('EDI','KLINESEND','');
edit2.text:=inifile1.ReadString('EDI','KLINERECIEVE','123456');
edit3.text:=inifile1.ReadString('EDI','KLINESENDNAME','');
edit4.text:=inifile1.ReadString('EDI','KLINEFTPSERVER',get_parameters_value(77,''));
edit5.text:=inifile1.ReadString('EDI','KLINEFTPPATH',get_parameters_value(78,'/'));
edit6.text:=inifile1.ReadString('EDI','KLINEFTPNAME',get_parameters_value(79,''));
edit7.text:=inifile1.ReadString('EDI','KLINEFTPPASS',get_parameters_value(80,''));
inifile1.free;
end;
procedure Tfrm_op_seae_edi_kline.bsSkinButton1Click(Sender: TObject);
var
Str:TStrings;
inifile1:Tinifile;
i:integer;
begin
if bsSkinRadioGroup2.ItemIndex=1 then
str:=Tstringlist.Create;
try
if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then
if bsSkinRadioGroup2.ItemIndex=1 then
Str:=CreateEdiFile
else
Str:=CreateEdiFile
else if Pos('主票',(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring))>0 then
else
begin
Exit;
end;
for i:=0 to Str.Count-1 do begin
if IsZhongwen(Str[i]) then begin
if MessageDlg('此票业务可能含有中文字符或其他不规范字符('+Str[i]+'),确实要继续上传吗!',mtWarning,[mbYes,mbNo],0)=mrNo then
exit;
end;
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;
finally
FreeAndNil(Str)
end;
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
inifile1.WriteString('EDI','KLINESEND',edit1.text);
inifile1.WriteString('EDI','KLINERECIEVE',edit2.text);
inifile1.WriteString('EDI','KLINESENDNAME',edit3.text);
inifile1.WriteString('EDI','KLINEFTPSERVER',edit4.text);
inifile1.WriteString('EDI','KLINEFTPPATH',edit5.text);
inifile1.WriteString('EDI','KLINEFTPNAME',edit6.text);
inifile1.WriteString('EDI','KLINEFTPPASS',edit7.text);
inifile1.free;
close;
end;
function Tfrm_op_seae_edi_kline.isEditrue(DataSet:TDataSet): string;
var
ErrorMessage:WideString;
aAdoQuery:TAdoQuery;
begin
result:='';
aAdoQuery:=CreateAdoQuery;
if ErrorMessage='' then ErrorMessage:=ControlLines('发货人','发货人代码')
else ErrorMessage:=ErrorMessage+#13#10+ControlLines('发货人','发货人代码');
if ErrorMessage='' then ErrorMessage:=ControlLines('收货人','收货人代码')
else ErrorMessage:=ErrorMessage+#13#10+ControlLines('收货人','收货人代码');
if ErrorMessage='' then ErrorMessage:=ControlLines('通知人','通知人代码')
else ErrorMessage:=ErrorMessage+#13#10+ControlLines('通知人','通知人代码');
if DataSet.fieldbyname('第二通知人').asstring<>'' then
if ErrorMessage='' then ErrorMessage:=ControlLines('第二通知人','第二通知人')
else ErrorMessage:=ErrorMessage+#13#10+ControlLines('第二通知人','第二通知人');
if trim(DataSet.fieldbyname('付费方式').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='付费方式不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'付费方式不能为空';
end;
if trim(DataSet.fieldbyname('船名').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='船名不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'船名不能为空';
end;
if trim(DataSet.fieldbyname('航次').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='航次不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'航次不能为空';
end;
if trim(DataSet.fieldbyname('装港代码').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='装港代码不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'装港代码不能为空';
end;
if trim(DataSet.fieldbyname('装货港').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='装货港不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'装货港不能为空';
end;
if trim(DataSet.fieldbyname('开船日期').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='开船日期不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'开船日期不能为空';
end;
if trim(DataSet.fieldbyname('交货地点').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='交货地点不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'交货地点不能为空';
end;
if trim(DataSet.fieldbyname('目的地').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='目的地不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'目的地不能为空';
end;
if trim(DataSet.fieldbyname('目的地代码').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='目的地代码不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'目的地代码不能为空';
end;
if trim(DataSet.fieldbyname('货物描述').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='货物描述不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'货物描述不能为空';
end;
if trim(DataSet.fieldbyname('唛头').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='唛头不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'唛头不能为空';
end;
if DataSet.fieldbyname('件数').asinteger=0 then begin
if ErrorMessage='' then ErrorMessage:='件数不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'件数不能为空';
end;
if DataSet.fieldbyname('重量').asFloat=0 then begin
if ErrorMessage='' then ErrorMessage:='重量不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'重量不能为空';
end;
if DataSet.fieldbyname('尺码').asFloat=0 then begin
if ErrorMessage='' then ErrorMessage:='尺码不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'尺码不能为空';
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='货物标识不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'货物标识不能为空';
end;
if trim(DataSet.fieldbyname('运费协议号').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='运费协议号不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'运费协议号不能为空';
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
if ErrorMessage='' then ErrorMessage:='危险品等级不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'危险品等级不能为空';
end;
if Trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring)='' then begin
if ErrorMessage='' then ErrorMessage:='危险品编号不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'危险品编号不能为空';
end;
if GetStrNum(Trim(frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring))<>4 then begin
if ErrorMessage='' then ErrorMessage:='危险品编号必须是4位数字'
else ErrorMessage:=ErrorMessage+#13#10+'危险品编号必须是4位数字';
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
if ErrorMessage='' then ErrorMessage:='设置温度不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'设置温度不能为空';
end;
if Trim(frm_op_seae.t_op_seae.fieldbyname('冷藏通风量').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='冷藏通风量不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'冷藏通风量不能为空';
end;
end;
if frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring<>'' then
if Length(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)<>6 then
begin
if ErrorMessage='' then ErrorMessage:='HS CODE 必须为6位'
else ErrorMessage:=ErrorMessage+#13#10+'HS CODE 必须为6位';
end;
if bsSkinRadioGroup2.ItemIndex=1 then
begin
t_op_ctn.close;
t_op_ctn.Parameters.ParamByName('编号').Value:=DataSet.fieldbyname('编号').asstring;
t_op_ctn.open;
if t_op_ctn.IsEmpty then
begin
if ErrorMessage='' then ErrorMessage:='集装箱不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'集装箱不能为空';
end;
t_op_ctn.First;
while not t_op_ctn.Eof do
begin
if Trim(t_op_ctn.fieldbyname('箱号').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='箱号不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'箱号不能为空';
end;
if Trim(t_op_ctn.fieldbyname('封号').asstring)='' then
begin
if ErrorMessage='' then ErrorMessage:='封号不能为空'
else ErrorMessage:=ErrorMessage+#13#10+'封号不能为空';
end;
t_op_ctn.Next;
end;
with aAdoQuery do
try
close;sql.Clear;
sql.add('select * from t_op_ctn_detail');
sql.add('where ctn_id in (select ctn_id from t_op_ctn where 编号='''+DataSet.fieldbyname('编号').asstring+''')');
open;First;
while not eof do
begin
if fieldbyname('hts').asstring<>'' then
if Length(fieldbyname('hts').asstring)<>6 then
begin
if ErrorMessage='' then ErrorMessage:='HS CODE:'+fieldbyname('hts').asstring+' 必须为6位'
else ErrorMessage:=ErrorMessage+#13#10+'HS CODE:'+fieldbyname('hts').asstring+' 必须为6位';
end;
Next;
end;
finally
Free;
end;
end;
Result:=ErrorMessage;
end;
function Tfrm_op_seae_edi_kline.CreateEdiFile:TStrings;
var str,aTempList:TStringlist;
strType,SenderCode,ReciverCode:string;
i,k,LineNo,FirstLineNo:integer;
at_op_ctn,at_op_ctnItmes,aAdoQuery:TAdoQuery;
ErrorMessage:string;
begin
try
aTempList:=TStringlist.create;
str:=TStringlist.create;
at_op_ctn:=CreateAdoQuery;
at_op_ctnItmes:=CreateAdoQuery;
aAdoQuery:=CreateAdoQuery;
with at_op_ctn,sql do
begin
close;Clear;
add('select * from t_op_ctn');
add('where 编号=:编号');
parameters.ParamByName('编号').Value:='';
end;
with at_op_ctnItmes,sql do
begin
close;Clear;
add('select * from t_op_ctn_detail');
add('where ctn_id=:ctn_id');
parameters.ParamByName('ctn_id').Value:=0;
end;
SenderCode:=trim(edit1.Text) ;
ReciverCode:=trim(edit2.Text) ;
if bsSkinRadioGroup1.ItemIndex=0 then
strType:='9'
else if bsSkinRadioGroup1.ItemIndex=1 then
strType:='2'
else if bsSkinRadioGroup1.ItemIndex=2 then
strType:='3'
else if bsSkinRadioGroup1.ItemIndex=3 then
strType:='4'
else strType:='9';
I:=0;
if frm_op_seae.dxdbgrid1.SelectedCount<=1 then
begin
ErrorMessage:=isEditrue(frm_op_seae.t_op_seae);
if ErrorMessage<>'' then
begin
showmessage(ErrorMessage);
Abort;
end;
I:=0;
str.add(Record00(strType,SenderCode,ReciverCode));
str.add(Record02(SenderCode,ReciverCode,frm_op_seae.t_op_seae));
str.add(Record03(SenderCode,ReciverCode,frm_op_seae.t_op_seae));
str.add(Record11(frm_op_seae.t_op_seae));
str.add(Record12(frm_op_seae.t_op_seae));
str.add(Record15(frm_op_seae.t_op_seae));
str.add(Record17(frm_op_seae.t_op_seae));
str.add(Record20_21_22_23('20','发货人代码',frm_op_seae.t_op_seae));
str.add(Record20_21_22_23('21','收货人代码',frm_op_seae.t_op_seae));
str.add(Record20_21_22_23('22','通知人代码',frm_op_seae.t_op_seae));
if frm_op_seae.t_op_seae.FieldByName('第二通知人').AsString<>'' then
begin
str.add(Record20_21_22_23('23','第二通知人',frm_op_seae.t_op_seae));
end;
LineNo:=1;
with aAdoQuery,sql do
begin
close;Clear;
add('select * from t_op_ctn_detail');
add('where ctn_id in (select ctn_id from t_op_ctn where 编号='''+frm_op_seae.t_op_seae.FieldByName('编号').AsString+''')');
Open;First;
end;
FirstLineNo:=0;
if not aAdoQuery.IsEmpty then
begin
with at_op_ctn do
begin
Close;
Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.FieldByName('编号').AsString;
Open;First;
while not eof do
begin
with at_op_ctnItmes,sql do
begin
Close;
Parameters.ParamByName('ctn_id').Value:=at_op_ctn.FieldByName('ctn_id').Asinteger;
Open;First;
if not at_op_ctnItmes.IsEmpty then
begin
while not eof do
begin
str.add(Record41(IntToStr(LineNo),at_op_ctnItmes));
if FirstLineNo=0 then
if trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)<>'S' then
str.add(Record43(frm_op_seae.t_op_seae));
FirstLineNo:=FirstLineNo+1;
aTempList:=Record44_47(35,10,'44','唛头',at_op_ctn);
str.addstrings(aTempList);
aTempList:=Record44_47(70,5,'47','货物描述',at_op_ctnItmes);
str.addstrings(aTempList);
str.add(Record49(at_op_ctn,at_op_ctnItmes));
LineNo:=LineNo+1;
Next;
end;
end
else
begin
str.add(Record41ctn(IntToStr(LineNo),at_op_ctn));
if trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)<>'S' then
str.add(Record43(frm_op_seae.t_op_seae));
aTempList:=Record44_47(35,10,'44','唛头',at_op_ctn);
str.addstrings(aTempList);
aTempList:=Record44_47(70,5,'47','货物描述',at_op_ctn);
str.addstrings(aTempList);
str.add(Record49(at_op_ctn,at_op_ctn));
LineNo:=LineNo+1;
end;
end;
Next;
end;
end;
end
else
begin
str.add(Record41ctn(IntToStr(LineNo),frm_op_seae.t_op_seae));
if trim(frm_op_seae.t_op_seae.fieldbyname('货物标识').asstring)<>'S' then
str.add(Record43(frm_op_seae.t_op_seae));
aTempList:=Record44_47(35,10,'44','唛头',frm_op_seae.t_op_seae);
str.addstrings(aTempList);
aTempList:=Record44_47(70,5,'47','货物描述',frm_op_seae.t_op_seae);
str.addstrings(aTempList);
LineNo:=LineNo+1;
end;
aTempList:=Record48(frm_op_seae.t_op_seae);
str.addstrings(aTempList);
LineNo:=1;
with at_op_ctn do
begin
Close;
Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.FieldByName('编号').AsString;
Open;First;
while not eof do
begin
// str.add(Record49(at_op_ctn));
str.add(Record51(IntToStr(LineNo),at_op_ctn));
LineNo:=LineNo+1;
Next;
end;
end;
I:=str.Count;
end
else
begin
{
I:=0;
str.add(Record00(strType,SenderCode,ReciverCode));
for k:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do
begin
lineno:=0;
frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[k]));
if not isEditrue(frm_op_seae.t_op_seae) then abort;
str.add(Record12(frm_op_seae.t_op_seae));
str.add(Record13(frm_op_seae.t_op_seae));
str.add(Record16_17_18('16','发货人代码',frm_op_seae.t_op_seae));
str.add(Record16_17_18('17','收货人代码',frm_op_seae.t_op_seae));
str.add(Record16_17_18('18','通知人代码',frm_op_seae.t_op_seae));
str.add(Record21(frm_op_seae.t_op_seae));
str.add(Record41(frm_op_seae.t_op_seae));
str.add(Record43(frm_op_seae.t_op_seae));
lineno:=8;
aTempList:=Record44_47(35,10,'44','唛头',frm_op_seae.t_op_seae);
str.addstrings(aTempList);
lineno:=lineno+aTempList.count;
aTempList:=Record44_47(70,5,'47','货物描述',frm_op_seae.t_op_seae);
str.addstrings(aTempList);
lineno:=lineno+aTempList.count;
aTempList:=Record52(frm_op_seae.t_op_seae);
str.addstrings(aTempList);
lineno:=lineno+aTempList.count;
I:=I+lineno;
end;
I:=I+3;
}
end;
finally
str.Add('99:'+intToStr(i+1)+'''');
Result:=str;
freeandnil(aTempList);
//freeandnil(str);
end;
end;
procedure Tfrm_op_seae_edi_kline.bsSkinButton3Click(Sender: TObject);
var
IdFTP1:TIdFTP;
str:widestring;
str_file:widestring;
ftpar,ftpname,ftppass,ftppath,ScriptPath:String;
StrL:TStrings;
inifile1:Tinifile;
i:integer;
begin
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);
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
if Trim(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring)='整箱' then
if bsSkinRadioGroup2.ItemIndex=1 then
StrL:=CreateEdiFile
else
StrL:=CreateEdiFile
else if Pos('主票',(frm_op_seae.t_op_seae.fieldbyname('装运方式').asstring))>0 then
else begin
Exit;
end;
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;
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
inifile1.WriteString('EDI','JCSEND',edit1.text);
inifile1.WriteString('EDI','JCRECIEVE',edit2.text);
inifile1.WriteString('EDI','JCSENDNAME',edit3.text);
inifile1.WriteString('EDI','JCFTPSERVER',edit4.text);
inifile1.WriteString('EDI','JCFTPPATH',edit5.text);
inifile1.WriteString('EDI','JCFTPNAME',edit6.text);
inifile1.WriteString('EDI','JCFTPPASS',edit7.text);
inifile1.free;
showmessage('文件上传成功!');
except
deletefile(str);
showmessage('文件上传错误!');
end;
idftp1.Free;
end;
procedure Tfrm_op_seae_edi_kline.bsSkinButton4Click(Sender: TObject);
begin
if frm_op_seae_edi_kline.Height=349 then
frm_op_seae_edi_kline.Height:=200
else
frm_op_seae_edi_kline.Height:=349;
end;
function Tfrm_op_seae_edi_kline.get_txtvgm(str:Tstringlist):integer;
var
str_all,sl:Tstringlist;
i,count:integer;
SM,Carrer:string;
begin
{
i:=0;
case RadioGroup2.ItemIndex of
0:Carrer:='MAEU';
1:Carrer:='SAFM';
2:Carrer:='MCPU';
end;
str_all:=Tstringlist.Create;
count:=0;
str.Add('UNB+UNOC:3+'+Edit1.TEXT+':ZZZ+'+'INTTRA'
+':ZZZ+'+GetDatetime(datetimetostr(now),2)+'+'
+frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring+#39);
str.Add('UNH+001+VERMAS:D:16A:UN:0.8'+#39);
count:=count+1;
if RadioGroup3.ItemIndex=0 then
str.Add('BGM+XXX+'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+'+9'+#39) //9原始 5 更新
else str.Add('BGM+XXX+'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+'+5'+#39); //9原始 5 更新
count:=count+1;
count:=count+1;
t_op_ctn.close;
t_op_ctn.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring;
t_op_ctn.open;
t_op_ctn.first;
while not t_op_ctn.eof do
begin
if (t_op_ctn.fieldbyname('称重方式').asstring<>'') or (t_op_ctn.fieldbyname('称重方式').asstring<>'无') then
begin
i:=i+1;
str.Add('DTM+137:'+GetDatetime(datetimetostr(now),1)+':203'+#39);
count:=count+1;
str.Add('EQD+CN+'+t_op_ctn.fieldbyname('箱号').asstring+':6346:5'+#39); //数量
count:=count+1;
str.Add('RFF+BN:'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+#39);
count:=count+1;
str.Add('RFF+AOW:'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+#39);
count:=count+1;
str.Add('MEA+AAE+VGM+KGM:'+t_op_ctn.fieldbyname('称重重量').asstring+#39); ////累加 无
count:=count+1;
if Trim(t_op_ctn.fieldbyname('称重方式').asstring)='累加' then
SM:='SM2'
else if Trim(t_op_ctn.fieldbyname('称重方式').asstring)='总重' then
SM:='SM1';
str.Add('DOC+'+SM+':VGM:306'+#39); ////累加 无
count:=count+1;
str.Add('NAD+SPC+++'+Changestr(Edit2.Text)+#39); ////累加 无
count:=count+1;
str.Add('NAD+CA+'+GetShipEdiNO(frm_op_seae.t_op_seae.fieldbyname('船公司').asstring)+'::86++'+frm_op_seae.t_op_seae.fieldbyname('船公司').asstring+#39);
count:=count+1;
str.Add('UNT+9+'+IntToStr(i)+#39);
count:=count+1;
end;
t_op_ctn.next;
end;
result:=count;
}
end;
function Tfrm_op_seae_edi_kline.CreateVgmFile:TStrings;
var
str:Tstringlist;
i,count:integer;
SM,Carrer:string;
begin
i:=0;
str:=Tstringlist.Create;
try
count:=0;
str.Add('UNB+UNOC:3+'+Edit1.TEXT+':ZZZ+'+'CMA-CGM'
+':ZZZ+'+GetDatetime(datetimetostr(now),2)+'+'
+frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring+#39);
str.Add('UNH+0001+VERMAS:D:16A:UN:0.4'+#39);
count:=count+1;
if bsSkinRadioGroup1.ItemIndex=0 then
str.Add('BGM+XXX+'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+'++9'+#39) //9原始 5 更新
else str.Add('BGM+XXX+'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+'++5'+#39); //9原始 5 更新
count:=count+1;
str.Add('DTM+137:'+GetDatetime(datetimetostr(now),1)+':203'+#39);
count:=count+1;
t_op_ctn.close;
t_op_ctn.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring;
t_op_ctn.open;
t_op_ctn.first;
while not t_op_ctn.eof do
begin
if (t_op_ctn.fieldbyname('称重方式').asstring<>'') or (t_op_ctn.fieldbyname('称重方式').asstring<>'无') then
begin
i:=i+1;
// str.Add('EQD+CN+'+t_op_ctn.fieldbyname('箱号').asstring+':6346:5'+GetCtnCode(t_op_ctn.fieldbyname('箱型').asstring,t_op_ctn.fieldbyname('尺寸').asstring)+':6346:5'+#39); //数量 //
count:=count+1;
str.Add('RFF+BN:'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+#39);
count:=count+1;
str.Add('LOC+88+'+frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring
+':139:6:'+trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring)+#39);
count:=count+1;
str.Add('LOC+65+'+frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring
+':139:6:'+trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring)+#39);
count:=count+1;
str.Add('LOC+11+'+frm_op_seae.t_op_seae.fieldbyname('卸货代码').asstring
+':139:6:'+trim(frm_op_seae.t_op_seae.fieldbyname('卸货港').asstring)+#39);
count:=count+1;
str.Add('LOC+9+'+frm_op_seae.t_op_seae.fieldbyname('装港代码').asstring
+':139:6:'+trim(frm_op_seae.t_op_seae.fieldbyname('装货港').asstring)+#39);
count:=count+1;
str.Add('DTM+WAT:'+GetDatetime(datetimetostr(now),1)+':203'+#39); ////累加 无
count:=count+1;
str.Add('MEA+AAE+VGM+KGM:'+t_op_ctn.fieldbyname('称重重量').asstring+#39); ////累加 无
count:=count+1;
if Trim(t_op_ctn.fieldbyname('称重方式').asstring)='累加' then
SM:='SM2'
else if Trim(t_op_ctn.fieldbyname('称重方式').asstring)='总重' then
SM:='SM1';
str.Add('DOC+'+SM+':VGM:306'+#39); ////累加 无
count:=count+1;
str.Add('NAD+SPC+++'+Changestr(Edit2.Text)+#39); ////累加 无
count:=count+1;
str.Add('NAD+CA+'+GetShipEdiNO(frm_op_seae.t_op_seae.fieldbyname('船公司').asstring)+'::86++'+frm_op_seae.t_op_seae.fieldbyname('船公司').asstring+#39);
count:=count+1;
str.Add('UNT+12+'+IntToStr(i)+#39);
count:=count+1;
end;
t_op_ctn.next;
end;
result:=count;
finally
result:=str;
str.free;
end;
end;
end.