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.

480 lines
14 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_JTB;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB;
type
Tfrm_op_seae_edi_jtb = class(TForm)
bsBusinessSkinForm1: TbsBusinessSkinForm;
Label2: TLabel;
Edit2: TEdit;
Edit1: TEdit;
Label1: TLabel;
SaveDialog1: TSaveDialog;
bsSkinButton1: TbsSkinButton;
bsSkinButton2: TbsSkinButton;
procedure bsSkinButton2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure bsSkinButton1Click(Sender: TObject);
private
function FormatEdiString(str:String;Strlength:integer=0):String;
function FormatListString(Old:TStrings;mCount,Strlength:integer):String;
function GetLengthword(var s: String; l: Integer;str:String): String;
procedure GetLengthTString(var sl: TStringList; l: integer);
function GetCntrEdi(cntrsize: String):String;
function GetpkgsEdi(pkgs:String):String;
{ Private declarations }
public
{ Public declarations }
end;
var
frm_op_seae_edi_jtb: Tfrm_op_seae_edi_jtb;
implementation
uses u_op_seae, u_main, my_sys_function, u_data_share;
{$R *.dfm}
procedure Tfrm_op_seae_edi_jtb.bsSkinButton2Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_op_seae_edi_jtb.FormShow(Sender: TObject);
var
inifile1:Tinifile;
begin
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
edit1.text:=inifile1.ReadString('EDI','HCSEND','');
edit2.text:=inifile1.ReadString('EDI','HCRECIEVE','');
inifile1.free;
end;
procedure Tfrm_op_seae_edi_jtb.bsSkinButton1Click(Sender: TObject);
var
Str,sl1,sl:TStringList;
i,l,M:integer;
SenderCode,ReciverCode,strtemp:String;
aQuery:TADOQuery;
function GetShipperString:String;
var
TempStr:TStringList;
begin
TempStr:=TStringList.Create;
try
TempStr.Text:=FormatEdiString(frm_op_seae.t_op_seae.fieldbyname('·¢»õÈË´úÂë').AsString);
GetLengthTString(TempStr,35);
Result:='20:';
Result:=Result+':';
Result:=Result+FormatListString(TempStr,6,35)+'''';
finally
FreeAndNil(TempStr);
end;
end;
function GetConsigneString:String;
var
TempStr:TStringList;
begin
TempStr:=TStringList.Create;
try
TempStr.Text:=FormatEdiString(frm_op_seae.t_op_seae.fieldbyname('ÊÕ»õÈË´úÂë').AsString);
GetLengthTString(TempStr,35);
Result:='21:';
Result:=Result+':';
Result:=Result+FormatListString(TempStr,6,35)+'''';
finally
FreeAndNil(TempStr);
end;
end;
function GetNOTIFYString:String;
var
TempStr:TStringList;
begin
TempStr:=TStringList.Create;
try
TempStr.Text:=FormatEdiString(frm_op_seae.t_op_seae.fieldbyname('֪ͨÈË´úÂë').AsString);
GetLengthTString(TempStr,35);
Result:='22:';
Result:=Result+':';
Result:=Result+FormatListString(TempStr,6,35)+'''';
finally
FreeAndNil(TempStr);
end;
end;
function GetMARKSString:String;
var
TempStr:TStringList;
begin
TempStr:=TStringList.Create;
try
TempStr.Text:=FormatEdiString(frm_op_seae.t_op_seae.fieldbyname('ßéÍ·').AsString);
GetLengthTString(TempStr,35);
Result:='44:';
Result:=Result+FormatListString(TempStr,10,35)+'''';
finally
FreeAndNil(TempStr);
end;
end;
begin
str:=Tstringlist.Create;
sl1:=Tstringlist.Create;
sl:=Tstringlist.Create;
aQuery:=CreateAdoQuery;
try
SenderCode:=trim(Edit1.Text) ;
ReciverCode:=trim(Edit2.Text) ;
str.Add('00:IFTMBF:BOOKING:9:'+ SenderCode+':'+ReciverCode+':'+GetDatetime(datetimetostr(now),1)+':::'+'2.0'+#39);
str.Add('10:'+''+':'+ trim(frm_op_seae.t_op_seae.fieldbyname('´¬Ãû').asstring) +':'
+ trim(frm_op_seae.t_op_seae.fieldbyname('º½´Î').asstring)+'::::'+GetDatetime(trim(frm_op_seae.t_op_seae.fieldbyname('¿ª´¬ÈÕÆÚ').asstring),0)+#39);
strtemp:='';
if frm_data_share.t_code_free.locate('¸¶·Ñ·½Ê½',frm_op_seae.t_op_seae.fieldbyname('¸¶·Ñ·½Ê½').asstring,[]) then
begin
strtemp:=copy(frm_data_share.t_code_free.fieldbyname('´úÂë').asstring,1,1);
end
else
begin
strtemp:='P';
end;
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) +':'
+trim(frm_op_seae.t_op_seae.fieldbyname('Ä¿µÄµØ´úÂë').asstring) +':'
+trim(frm_op_seae.t_op_seae.fieldbyname('Ä¿µÄµØ').asstring)+#39); //´¬²°¾­ÓªÈË
str.Add('14:::'+'B:'+trim(frm_op_seae.t_op_seae.fieldbyname('Ö÷Ìáµ¥ºÅ').asstring)+'::::'
+trim(frm_op_seae.t_op_seae.fieldbyname('ÔËÊäÌõ¿î').asstring)+':'
+strtemp+'::::::::'
+trim(frm_op_seae.t_op_seae.fieldbyname('Ö÷Ìáµ¥ºÅ').asstring)+#39); //´¬²°¾­ÓªÈË
Str.Add(GetShipperString);
Str.Add(GetConsigneString);
Str.Add(GetNOTIFYString);
{
aQuery.Close;
aQuery.SQL.Text:='select * from t_op_ctn where 񅧏='''+frm_op_seae.t_op_seae.fieldbyname('񅧏').asstring+'''';
aQuery.Open;
i:=1;
strtemp:='';
if not aQuery.IsEmpty then begin
while not aQuery.Eof do begin
if aQuery.FieldByName('SOC').AsBoolean then
strtemp:='Y'
else
strtemp:='N';
str.Add ('40:'+inttostr(i)+':'+Trim(aQuery.fieldbyname('±íÏÖÐÎʽ').asstring)+':'+trim(aQuery.fieldbyname('ÊýÁ¿').asstring)+':'
+trim(aQuery.fieldbyname('Ïä״̬').asstring)+':'+trim(frm_op_seae.t_op_seae.fieldbyname('Ö÷Ìáµ¥ºÅ').asstring)
+'::'+strtemp+''''
);
inc(i);
aQuery.Next;
end;
end;
}
str.Add ('41:1::'+trim(frm_op_seae.t_op_seae.fieldbyname('»õÎï±êʶ').asstring)+':' // »õÎï±êʶ S/R/D/O
+trim(frm_op_seae.t_op_seae.fieldbyname('¼þÊý').asstring) +':'
+trim(GetpkgsEdi(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);
IF trim(frm_op_seae.t_op_seae.fieldbyname('»õÎï±êʶ').asstring)='R' THEN
BEGIN
str.Add ('43:' // ΣÏÕÆ·¡¢À䶳
+':'
+':'
+':'
+':'
+':'
+':'
+':'
+':::'
+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);
END;
IF trim(frm_op_seae.t_op_seae.fieldbyname('»õÎï±êʶ').asstring)='D'THEN
BEGIN
str.Add ('43:' // ΣÏÕÆ·¡¢À䶳
+trim(frm_op_seae.t_op_seae.fieldbyname('ΣÏÕÆ··ÖÀà').asstring) +':'
+''+':'
+trim(frm_op_seae.t_op_seae.fieldbyname('ΣÏÕÆ·±àºÅ').asstring) +':'
+''+':'
+':'
+':'
+':'
+'::'
+':'
+':::::::::'
+''+#39);
END;
Str.Add(GetMARKSString);
sl1.Text:=FormatEdiString(frm_op_seae.t_op_seae.fieldbyname('»õÎïÃèÊö').AsString);
GetLengthTString(sl1,35);
sl.text:='';
for L:=0 to sl1.Count-1 do begin
if Trim(sl1.Strings[L])<>'' then
sl.Add(sl1.Strings[L]);
end;
strtemp:='';
M:=1;
for L:=0 to sl.Count-1 do begin
if M<=5 then begin
if M=1 then begin
strtemp:='47:'+sl.Strings[L]+':';
end else begin
if M=5 then
strtemp:=strtemp+sl.Strings[L]
else
strtemp:=strtemp+sl.Strings[L]+':';
end;
end else begin
strtemp:=strtemp+'''';
Str.Add(strtemp);
M:=1;
strtemp:='47:'+sl.Strings[L]+':';
end;
M:=M+1;
end;
strtemp:=strtemp+'''';
Str.Add(strtemp);
aQuery.Close;
aQuery.SQL.Text:='select * from t_op_ctn where 񅧏='''+frm_op_seae.t_op_seae.fieldbyname('񅧏').asstring+'''';
aQuery.Open;
if not aQuery.IsEmpty then begin
while not aQuery.Eof do begin
// if aQuery.FieldByName('SOC').AsBoolean then
// strtemp:='1'
// else
strtemp:='2';
str.Add ('48:'+trim(aQuery.fieldbyname('ÏäºÅ').asstring)+':'+trim(aQuery.fieldbyname('·âºÅ').asstring)+':'
+GetCntrEdi(aQuery.fieldbyname('´úÂë').asstring)+':1:'+''
+':'+trim(IntToStr(aQuery.fieldbyname('¼þÊý').AsInteger))+':'+trim(GetpkgsEdi(aQuery.fieldbyname('°ü×°').asstring))+':'
+trim(FloatToStr(aQuery.fieldbyname('ÖØÁ¿').AsFloat))+':'
+''+':'+trim(FloatToStr(aQuery.fieldbyname('³ßÂë').AsFloat))+':'+strtemp+''''
);
aQuery.Next;
end;
end;
if frm_data_share.t_code_free.locate('¸¶·Ñ·½Ê½',frm_op_seae.t_op_seae.fieldbyname('¸¶·Ñ·½Ê½').asstring,[]) then
begin
strtemp:=copy(frm_data_share.t_code_free.fieldbyname('´úÂë').asstring,1,1);
end
else
begin
strtemp:='P';
end;
str.Add('60:'+strtemp+':'+trim(frm_op_seae.t_op_seae.fieldbyname('¸¶·Ñ·½Ê½').asstring)+#39); //´¬²°¾­ÓªÈË
strtemp:='';
if frm_data_share.t_code_loaport.Locate('Ó¢ÎÄÃû',frm_op_seae.t_op_seae.fieldbyname('Ç©µ¥µØµã').asstring,[])then
strtemp:=frm_data_share.t_code_loaport.fieldbyname('¸Û¿Ú´úÂë').AsString;
str.Add('71:'+':'+strtemp+':'+formatdatetime('YYYYMMDD',frm_op_seae.t_op_seae.fieldbyname('Ç©µ¥ÈÕÆÚ').AsDateTime)+':'+get_fenshu(trim(frm_op_seae.t_op_seae.fieldbyname('Ìáµ¥·ÝÊý').asstring))+#39); //´¬²°¾­ÓªÈË
I:=str.Count;
str.Add('99:'+intToStr(i+1)+'''');
{
for i:=0 to Str.Count-1 do begin
if IsZhongwen(Str[i]) then begin
MessageDlg('´ËƱҵÎñÓÐÖÐÎÄ×Ö·û»òTABµÈ²»¹æ·¶×Ö·û,ÇëÈ¥³ý×Ö·ûºóÖØÊÔ£¡',mtWarning,[mbYes],0);
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;
end;
function Tfrm_op_seae_edi_jtb.FormatEdiString(str: String;
Strlength: integer): 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;
end;
function Tfrm_op_seae_edi_jtb.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_jtb.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;
procedure Tfrm_op_seae_edi_jtb.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_jtb.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;
function Tfrm_op_seae_edi_jtb.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;
end.