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.

367 lines
12 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_cma;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BusinessSkinForm, bsSkinCtrls, StdCtrls,inifiles, DB, ADODB;
type
Tfrm_op_seae_edi_cma = class(TForm)
Label2: TLabel;
Label1: TLabel;
Edit2: TEdit;
Edit1: TEdit;
bsSkinButton1: TbsSkinButton;
bsSkinButton2: TbsSkinButton;
bsBusinessSkinForm1: TbsBusinessSkinForm;
SaveDialog1: TSaveDialog;
Label3: TLabel;
Label4: TLabel;
Edit3: TEdit;
Edit4: TEdit;
t_op_ctn: TADOQuery;
bsSkinCheckRadioBox1: TbsSkinCheckRadioBox;
bsSkinCheckRadioBox2: TbsSkinCheckRadioBox;
procedure bsSkinButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
function get_txt(str:Tstringlist):integer;
function get_goods(str:widestring):widestring;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_op_seae_edi_cma: Tfrm_op_seae_edi_cma;
implementation
uses u_op_seae, my_sys_function, u_main, u_data_share;
{$R *.dfm}
function Tfrm_op_seae_edi_cma.get_goods(str:widestring):widestring;
var
str_all:Tstringlist;
r_str:widestring;
i:integer;
begin
str:=Changestr(trim(str));
str_all:=Tstringlist.Create;
str_all.Text:=str;
for i:=0 to str_all.Count-1 do
begin
r_str:=r_str+' '+str_all[i];
end;
result:=trim(r_str);
end;
function Tfrm_op_seae_edi_cma.get_txt(str:Tstringlist):integer;
var
str_all:Tstringlist;
j,Count:integer;
str_guodu:widestring;
str_pay:string;
begin
str_all:=Tstringlist.Create;
count:=0;
str.Add('UNB+UNOC:2+'+Edit1.TEXT+':ZZZ+'+Edit3.TEXT
+':ZZZ+'+GetDatetime(datetimetostr(now),2)+'+'
+frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring+#39);
count:=count+1;
str.Add('UNH+'+frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring+'+IFTMBF:D:99B:UN'+#39);
count:=count+1;
str.Add('BGM+335+'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+'+9'+#39);
count:=count+1;
str.Add('CTA+IC+:'+employee+#39);
count:=count+1;
str.Add('COM+'+frm_data_share.t_load_employee.fieldbyname('固定电话').asstring+':TE'+#39);
count:=count+1;
str.Add('DTM+137:'+GetDatetime(datetimetostr(now),1)+':203'+#39);
count:=count+1;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='' then
begin
showmessage('业务编号为:'+frm_op_seae.t_op_seae.fieldbyname('业务编号').asstring
+'的业务运输方式没有输入!!');
result:=-1;
exit;
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='DOOR-DOOR' then
begin
str.Add('TSR+27+2'+#39);
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='DOOR-CY' then
begin
str.Add('TSR+28+2'+#39);
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='CY-DOOR' then
begin
str.Add('TSR+29+2'+#39);
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='CY-CY' then
begin
str.Add('TSR+30+2'+#39);
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='OTHER' then
begin
str.Add('TSR+30+2'+#39);
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring)<>'' then
str_pay:=trim(frm_op_seae.t_op_seae.fieldbyname('预付地点').asstring);
if trim(frm_op_seae.t_op_seae.fieldbyname('到付地点').asstring)<>'' then
str_pay:=trim(frm_op_seae.t_op_seae.fieldbyname('到付地点').asstring);
count:=count+1;
str.Add('FTX+AAI+++'+frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring
+' Payable at '+str_pay+' '+
frm_op_seae.t_op_seae.fieldbyname('运输条款').asstring+#39);
count:=count+1;
str.Add('RFF+BM:'+frm_op_seae.t_op_seae.fieldbyname('主提单号').asstring+#39);
count:=count+1;
str.Add('RFF+ON:###NAD-CZ-ZZZ-['+frm_op_seae.t_op_seae.fieldbyname('发货人编号').asstring+']'+#39);
count:=count+1;
str.Add('RFF+CT:'+frm_op_seae.t_op_seae.fieldbyname('运费协议号').asstring+#39); //
count:=count+1;
str.Add('TDT+20+'+frm_op_seae.t_op_seae.fieldbyname('航次').asstring
+'+1+++++:::'+frm_op_seae.t_op_seae.fieldbyname('船名').asstring+#39);
count:=count+1;
str.Add('LOC+88+'+trim(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+'+trim(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+'+trim(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+7+'+trim(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('NAD+CA+CMDU:160:86++CMA-CGM'+#39);
count:=count+1;
str.Add('NAD+ZZZ+'+Edit1.TEXT+':160:86++'+Edit2.TEXT+#39);
count:=count+1;
str.Add('CTA+NT+'+employee+#39);
count:=count+1;
str.Add('COM+'+frm_data_share.t_load_employee.fieldbyname('邮箱').asstring+':EM'+#39);
count:=count+1;
str_all.Clear;
str_all.Text:=Changestr(frm_op_seae.t_op_seae.fieldbyname('发货人代码').asstring);
str_guodu:='NAD+CZ+++'+str_all[0]+'+';
if str_all.Count>=2 then
str_guodu:=str_guodu+str_all[1];
if (str_all.Count>=3) and (str_all.Count<=5) then
begin
for j:=2 to str_all.Count-1 do
begin
str_guodu:=str_guodu+':'+str_all[j]
end;
end;
if str_all.Count>5 then
begin
for j:=2 to 4 do
begin
str_guodu:=str_guodu+':'+str_all[j]
end;
end;
str_guodu:=str_guodu+#39;
str.Add(str_guodu);
count:=count+1;
str_all.Clear;
str_all.Text:=Changestr(frm_op_seae.t_op_seae.fieldbyname('收货人代码').asstring);
str_guodu:='NAD+CN+++'+str_all[0]+'+';
if str_all.Count>=2 then
str_guodu:=str_guodu+str_all[1];
if (str_all.Count>=3) and (str_all.Count<=5) then
begin
for j:=2 to str_all.Count-1 do
begin
str_guodu:=str_guodu+':'+str_all[j]
end;
end;
if str_all.Count>5 then
begin
for j:=2 to 4 do
begin
str_guodu:=str_guodu+':'+str_all[j]
end;
end;
str_guodu:=str_guodu+#39;
str.Add(str_guodu);
count:=count+1;
str_all.Clear;
str_all.Text:=Changestr(frm_op_seae.t_op_seae.fieldbyname('通知人代码').asstring);
str_guodu:='NAD+NI+++'+str_all[0]+'+';
if str_all.Count>=2 then
str_guodu:=str_guodu+str_all[1];
if (str_all.Count>=3) and (str_all.Count<=5) then
begin
for j:=2 to str_all.Count-1 do
begin
str_guodu:=str_guodu+':'+str_all[j]
end;
end;
if str_all.Count>5 then
begin
for j:=2 to 4 do
begin
str_guodu:=str_guodu+':'+str_all[j]
end;
end;
str_guodu:=str_guodu+#39;
str.Add(str_guodu);
count:=count+1;
str.Add('GID+1+'+frm_op_seae.t_op_seae.fieldbyname('件数').asstring+':'+
frm_op_seae.t_op_seae.fieldbyname('包装代码').asstring+#39); //
count:=count+1;
if bsSkinCheckRadioBox1.checked then
str.Add('FTX+AAA+++'+
frm_op_seae_edi_cma.get_goods(frm_op_seae.t_op_seae.fieldbyname('货物描述').asstring)+#39);
count:=count+1;
str.Add('MEA+AAE+WT+KGM:'+frm_op_seae.t_op_seae.fieldbyname('重量').asstring+#39);
count:=count+1;
if frm_op_seae.t_op_seae.FieldByName('货物标识').asstring='D' then
begin
str.Add('DGS+IMD+'+frm_op_seae.t_op_seae.fieldbyname('危险品分类').asstring
+'+'+frm_op_seae.t_op_seae.fieldbyname('危险品编号').asstring+#39);
count:=count+1;
str.Add('CTA+HG+:'+frm_data_share.t_load_employee.fieldbyname('固定电话').asstring+#39);
count:=count+1;
end;
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 frm_op_seae.t_op_seae.fieldbyname('是否自有箱').asboolean then
str.Add('EQD+CN++'+t_op_ctn.fieldbyname('EDI代码').asstring+'+1'+#39)
else
str.Add('EQD+CN++'+t_op_ctn.fieldbyname('EDI代码').asstring+'+2'+#39); //箱型 多箱型
count:=count+1;
str.Add('EQN+'+t_op_ctn.fieldbyname('数量').asstring+#39); //数量
count:=count+1;
if frm_op_seae.t_op_seae.FieldByName('货物标识').asstring='R' then
begin
str.Add('TMP+2+'+frm_op_seae.t_op_seae.fieldbyname('设置温度').asstring+':CEL'+#39);
count:=count+1;
end;
t_op_ctn.next;
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='DOOR-DOOR' then
begin
str.Add('NAD+SF+++'+Edit2.text+'+.'+#39);
count:=count+1;
str.Add('CTA+IC+:'+employee+#39);
count:=count+1;
str.Add('COM+'+frm_data_share.t_load_employee.fieldbyname('固定电话').asstring+':TE'+#39);
count:=count+1;
str.Add('NAD+ST+++'+Edit2.text+'+.'+#39);
count:=count+1;
str.Add('CTA+IC+:'+employee+#39);
count:=count+1;
str.Add('COM+'+frm_data_share.t_load_employee.fieldbyname('固定电话').asstring+':TE'+#39);
count:=count+1;
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='DOOR-CY' then
begin
str.Add('NAD+SF+++'+Edit2.text+'+.'+#39);
count:=count+1;
str.Add('CTA+IC+:'+employee+#39);
count:=count+1;
str.Add('COM+'+frm_data_share.t_load_employee.fieldbyname('固定电话').asstring+':TE'+#39);
count:=count+1;
end;
if trim(frm_op_seae.t_op_seae.fieldbyname('运输方式').asstring)='CY-DOOR' then
begin
str.Add('NAD+ST+++'+Edit2.text+'+.'+#39);
count:=count+1;
str.Add('CTA+IC+:'+employee+#39);
count:=count+1;
str.Add('COM+'+frm_data_share.t_load_employee.fieldbyname('固定电话').asstring+':TE'+#39);
count:=count+1;
end;
result:=count;
end;
procedure Tfrm_op_seae_edi_cma.bsSkinButton1Click(Sender: TObject);
var
str:Tstringlist;
i,Count,get_Count,bill_count:integer;
inifile1:Tinifile;
begin
str:=Tstringlist.Create;
str.Clear;
count:=0;
bill_count:=0;
if frm_op_seae.dxdbgrid1.SelectedCount>1 then
begin
for i:=0 to frm_op_seae.dxdbgrid1.SelectedCount-1 do
begin
frm_op_seae.t_op_seae.GotoBookmark(pointer(frm_op_seae.dxdbgrid1.selectedrows[i]));
get_Count:=frm_op_seae_edi_cma.get_txt(str);
if get_Count=-1 then
exit
else
count:=count+get_Count;
bill_count:=bill_count+1;
end;
str.Add('UNT+'+INTTOSTR(count)+'+1'+#39);
str.Add('UNZ+'+inttostr(bill_count)+'+100'+#39);
end
else
begin
get_Count:=frm_op_seae_edi_cma.get_txt(str);
if get_Count=-1 then
exit
else
count:=count+get_Count;
str.Add('UNT+'+INTTOSTR(count)+'+1'+#39);
str.Add('UNZ+1+100'+#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('CMA','SEND_CODE',edit1.text);
inifile1.WriteString('CMA','SEND_NAME',edit2.text);
inifile1.WriteString('CMA','RECEIVE_CODE',edit3.text);
inifile1.WriteString('CMA','RECEIVE_NAME',edit4.text);
inifile1.free;
close;
end;
procedure Tfrm_op_seae_edi_cma.FormShow(Sender: TObject);
var
inifile1:Tinifile;
begin
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
edit1.text:=inifile1.ReadString('CMA','SEND_CODE','');
edit2.text:=inifile1.ReadString('CMA','SEND_NAME','');
edit3.text:=inifile1.ReadString('CMA','RECEIVE_CODE','');
edit4.text:=inifile1.ReadString('CMA','RECEIVE_NAME','');
inifile1.free;
end;
end.