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.

1084 lines
29 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_msc;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IdFTP,IdFTPCommon,
Dialogs, BusinessSkinForm, StdCtrls, bsSkinCtrls,inifiles, DB, ADODB;
type
Tfrm_op_seae_edi_msc = 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;
bsSkinRadioGroup2: TbsSkinRadioGroup;
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;
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): boolean; //判断必填项
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;//是否包含中文或双字节字符
{ Private declarations }
public
{ Public declarations }
function GetCorpsString(recordno,recordno1,fldName:string;aDataset:TDataset):String;
function GetvesselEdi(avessel: String): String;
function Gett_code_trade(atrade: String): String;
function GetPkgCode(Pkg:String):String;
function GetMlbCount(aDataset:TDataset;fldName:string): String;
function Record00(strType,SenderCode,ReciverCode:string):String;
function Record10(aDataset:TDataset):String;
function Record12(aDataset:TDataset):String;
function RecordBO(aDataset:TDataset):String;
function Record13(aDataset:TDataset):String;
function Record16_17_18(recordno,recordno1,fldName:string;aDataset:TDataset):String;
function RecordRB(strLen:integer;RecordNo,FldName:string;aDataset:TDataset):TStringlist;
function Record21(aDataset:TDataset):String;
function Record41(aDataset:TDataset):String;
function Record43(aDataset:TDataset):String;
function Record44_47(strLen,LoopCount:integer;RecordNo,FldName:string;aDataset:TDataset):TStringlist;
function Record51(aDataset:TDataset):TStringlist;
end;
var
frm_op_seae_edi_msc: Tfrm_op_seae_edi_msc;
implementation
uses u_op_seae, u_main, my_sys_function, u_data_share;
{$R *.dfm}
function Tfrm_op_seae_edi_msc.GetMlbCount(aDataset:TDataset;fldName:string): String;
begin
Result:='3';
if aDataset.fieldbyname(fldName).asstring='ONE' then
Result:='1'
else if aDataset.fieldbyname(fldName).asstring='TWO' then
Result:='2'
else if aDataset.fieldbyname(fldName).asstring='THREE' then
Result:='3'
else if aDataset.fieldbyname(fldName).asstring='FOUR' then
Result:='4'
else Result:='3';
end;
function Tfrm_op_seae_edi_msc.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_msc.Gett_code_trade(atrade: 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 航线='''+atrade+'''');
Open;
if IsEmpty then
Result:=''
else
Result:=FieldByName('EDI代码').AsString;
end;
finally
FreeAndNil(aQuery);
end;
end;
function Tfrm_op_seae_edi_msc.GetPkgCode(Pkg: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 代码='''+pkg+'''');
Open;
if not IsEmpty then
Result:=Trim(FieldByName('EDI代码').asstring)
else
Result:='';
end;
finally
FreeAndNil(aQuery);
end;
end;
function Tfrm_op_seae_edi_msc.GetCorpsString(recordno,recordno1,fldName:string;aDataset:TDataset):String;
var
TempStr:TStringList;
begin
TempStr:=TStringList.Create;
try
TempStr.Text:=FormatEdiString(aDataset.fieldbyname(fldName).AsString);
GetLengthTString(TempStr,100);
Result:=recordno+':';
Result:=Result+':';
if TempStr.Count-1>=0 then
Result:=Result+':'+TempStr[0]
else Result:=Result+':';
if TempStr.Count-1>=2 then
Result:=Result+':'+TempStr[2]
else Result:=Result+':';
if TempStr.Count-1>=3 then
Result:=Result+':'+TempStr[3]
else Result:=Result+':';
Result:=Result+'::::::::::::';
if TempStr.Count-1>=0 then
Result:=Result+':'+TempStr[0]
else Result:=Result+':';
if TempStr.Count-1>=2 then
Result:=Result+':'+TempStr[2]
else Result:=Result+':';
if TempStr.Count-1>=3 then
Result:=Result+' '+TempStr[3];
Result:=Result+#13#10;
if TempStr.Count-1>=1 then
Result:=Result+recordno1+':'+TempStr[1]+'/AD'
else Result:=Result+':'+'/AD';
if TempStr.Count-1>=1 then
Result:=Result+':'+TempStr[1]
else Result:=Result+':';
// Result:=Result+FormatListString(TempStr,6,35)+'''';
finally
FreeAndNil(TempStr);
end;
end;
function Tfrm_op_seae_edi_msc.Record00(strType,SenderCode,ReciverCode:string):String;
var SOI:string;
begin
case bsSkinRadioGroup2.ItemIndex of
0:SOI:='BKGAGTMSC';
1:SOI:='BOLAGTMSC';
end;
result:='00:MHEDI6'+':'+SOI+':20'+':'+ SenderCode+':'+GetDatetime(datetimetostr(now),3)+':::';
end;
function Tfrm_op_seae_edi_msc.Record10(aDataset:TDataset):String;
begin
result:='10:'+':'+GetvesselEdi(trim(aDataset.fieldbyname('船名').asstring)) //
+'::'
+':'+ trim(aDataset.fieldbyname('航次').asstring)
+':'+ GetvesselEdi(trim(aDataset.fieldbyname('航线').asstring))
+':::::::';
end;
function Tfrm_op_seae_edi_msc.Record12(aDataset:TDataset):String;
var strPAY:string;
begin
if frm_data_share.t_code_free.locate('付费方式',frm_op_seae.t_op_seae.fieldbyname('付费方式').asstring,[]) then
begin
strPAY:=frm_data_share.t_code_free.fieldbyname('代码').asstring;
end;
result:='12'+':'+trim(aDataset.fieldbyname('主提单号').asstring) //
+':N'
+':'
+':'+trim(aDataset.fieldbyname('目的地').asstring)
+':'+trim(aDataset.fieldbyname('目的地代码').asstring)
+':'+trim(aDataset.fieldbyname('目的地').asstring)
+':'+ trim(aDataset.fieldbyname('装港代码').asstring)
+':'+ trim(aDataset.fieldbyname('装货港').asstring)
+':'+ trim(aDataset.fieldbyname('运输条款').asstring)
+':'+ strPAY
+':'
+':N'
+':'+GetMlbCount(aDataset,'提单份数')
+':'+GetMlbCount(aDataset,'副本提单份数')
+':'
+':'
+':'
+':'+trim(aDataset.fieldbyname('船名').asstring)
+':'+trim(aDataset.fieldbyname('航次').asstring);
end;
function Tfrm_op_seae_edi_msc.RecordBO(aDataset:TDataset):String;
begin
result:='BO'+':' //
+':C'
+':'
+':'
+':'
+':'+trim(aDataset.fieldbyname('运费协议号').asstring)
+':'
+':'
+':'
+':'
+':'
+':'
+':'
+':S'
+':'
+':';
end;
function Tfrm_op_seae_edi_msc.Record13(aDataset:TDataset):String;
begin
result:='13'+':'+trim(aDataset.fieldbyname('卸货代码').asstring)
+':'+ trim(aDataset.fieldbyname('卸货港').asstring)
+':::::'
+':::::';
end;
function Tfrm_op_seae_edi_msc.Record16_17_18(recordno,recordno1,fldName:string;aDataset:TDataset):String;
begin
result:=GetCorpsString(recordno,recordno1,fldName,aDataset);
end;
function Tfrm_op_seae_edi_msc.Record21(aDataset:TDataset):String;
begin
result:='21:::COC:::::::'
+#39;
end;
function Tfrm_op_seae_edi_msc.Record41(aDataset:TDataset):String;
begin
result:='41::'
+':'+ trim(aDataset.fieldbyname('件数').asstring)
+':'+ GetPkgCode(trim(aDataset.fieldbyname('包装').asstring))
+':'
+':'
+':'+ trim(aDataset.fieldbyname('重量').asstring)
+':'+ trim(aDataset.fieldbyname('尺码').asstring)
+':'
+':'+ trim(aDataset.fieldbyname('运输方式').asstring);
end;
function Tfrm_op_seae_edi_msc.Record43(aDataset:TDataset):String;
begin
result:='43:';
if trim(aDataset.fieldbyname('货物标识').asstring)='D' THEN
begin
result:=result
+':'+trim(aDataset.fieldbyname('危险品分类').asstring)
+':'
+':'+trim(aDataset.fieldbyname('危险品编号').asstring)
+'::::::'
end
else
begin
result:=result+':::::::::'
end;
if trim(aDataset.fieldbyname('货物标识').asstring)='R' then
begin
result:=result+':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_msc.RecordRB(strLen: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
result.Add(sl1.Strings[L]);
end;
finally
sl.Free;
sl1.Free;
end;
end;
function Tfrm_op_seae_edi_msc.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_msc.Record51(aDataset:TDataset):TStringlist;
var strsql:string;
rs:TADOQuery;
begin
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;
with rs do
begin
Close;sql.clear;
SQL.Add('SELECT t_op_ctn.编号,t_op_ctn.数量, t_code_ctn.EDI代码,t_op_ctn.包装');
SQL.Add(',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.品名');
SQL.Add('FROM t_op_ctn');
SQL.Add('Left JOIN t_code_ctn ON t_op_ctn.代码 = t_code_ctn.代码');
SQL.Add('WHERE t_op_ctn.编号=:编号');
t_op_ctn.Parameters.ParamByName('编号').Value:=frm_op_seae.t_op_seae.fieldbyname('编号').asstring;
Open;First;
end;
while not rs.Eof do
begin
result.Add ('51:'
+':'+trim(rs.fieldbyname('箱号').asstring)
+':'
+':'+Trim(rs.fieldbyname('尺寸').asstring)+trim(rs.fieldbyname('箱型').asstring)
+':F'
+'::'
+':N'
+':N'
+':N'
+':'
+':N'
+':N'
+':N'
+':'+trim(rs.fieldbyname('EDI代码').asstring)
+':N'
+':'+trim(rs.fieldbyname('封号').asstring)
+':N');
rs.Next;
end;
finally
rs.Close;
rs.Destroy;
end;
end;
function Tfrm_op_seae_edi_msc.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_msc.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_msc.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_msc.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 then
begin
strC:=strC+'CHR(3900)';
end
else
if (str[i]=':') then
begin
strC:=strC+'CHR(5800)';
end
else
begin
strC:=strC+str[i];
end;
end;
result:=strC;
end;
function Tfrm_op_seae_edi_msc.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_msc.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_msc.bsSkinButton2Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_op_seae_edi_msc.FormShow(Sender: TObject);
var
inifile1:Tinifile;
begin
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
edit1.text:=inifile1.ReadString('EDI','MSCSEND','015');
edit2.text:=inifile1.ReadString('EDI','MSCRECIEVE','123456');
edit3.text:=inifile1.ReadString('EDI','MSCSENDNAME','');
edit4.text:=inifile1.ReadString('EDI','MSCFTPSERVER',get_parameters_value(77,''));
edit5.text:=inifile1.ReadString('EDI','MSCFTPPATH',get_parameters_value(78,'/'));
edit6.text:=inifile1.ReadString('EDI','MSCFTPNAME',get_parameters_value(79,''));
edit7.text:=inifile1.ReadString('EDI','MSCFTPPASS',get_parameters_value(80,''));
inifile1.free;
end;
procedure Tfrm_op_seae_edi_msc.bsSkinButton1Click(Sender: TObject);
var
Str:TStrings;
inifile1:Tinifile;
i:integer;
begin
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('此票业务可能含有中文字符或其他不规范字符,确实要继续上传吗!',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','MSCSEND',edit1.text);
inifile1.WriteString('EDI','MSCRECIEVE',edit2.text);
inifile1.WriteString('EDI','MSCSENDNAME',edit3.text);
inifile1.WriteString('EDI','MSCFTPSERVER',edit4.text);
inifile1.WriteString('EDI','MSCFTPPATH',edit5.text);
inifile1.WriteString('EDI','MSCFTPNAME',edit6.text);
inifile1.WriteString('EDI','MSCFTPPASS',edit7.text);
inifile1.free;
close;
end;
function Tfrm_op_seae_edi_msc.isEditrue(DataSet:TDataSet): boolean;
var
cntrs:String;
begin
result:=true;
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 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 Trim(frm_op_seae.t_op_seae.fieldbyname('最高温度').asstring)='' then begin
result:=false;
MessageDlg('最高温度不能为空',mtWarning,[mbOk],0);
exit;
end;
end;
if bsSkinRadioGroup2.ItemIndex=1 then begin
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(t_op_ctn.fieldbyname('箱号').asstring)='' then begin
result:=false;
MessageDlg('箱号不能为空!',mtWarning,[mbOk],0);
exit;
end;
if Trim(t_op_ctn.fieldbyname('封号').asstring)='' then begin
result:=false;
MessageDlg('封号不能为空!',mtWarning,[mbOk],0);
exit;
end;
t_op_ctn.Next;
end;
end;
end;
function Tfrm_op_seae_edi_msc.CreateEdiFile:TStrings;
var str,aTempList:TStringlist;
strType,SenderCode,ReciverCode:string;
i,k,LineNo:integer;
begin
try
aTempList:=TStringlist.create;
str:=TStringlist.create;
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
if not isEditrue(frm_op_seae.t_op_seae) then abort;
I:=0;
str.add(Record00(strType,SenderCode,ReciverCode));
str.add(Record10(frm_op_seae.t_op_seae));
str.add(Record12(frm_op_seae.t_op_seae));
str.add(Record13(frm_op_seae.t_op_seae));
str.add(Record16_17_18('16','SH','发货人代码',frm_op_seae.t_op_seae));
str.add(Record16_17_18('17','CO','收货人代码',frm_op_seae.t_op_seae));
str.add(Record16_17_18('18','C1','通知人代码',frm_op_seae.t_op_seae));
aTempList:=RecordRB(85,'RB','EDI备注',frm_op_seae.t_op_seae);
str.addstrings(aTempList);
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));
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);
aTempList:=Record51(frm_op_seae.t_op_seae);
str.addstrings(aTempList);
I:=str.Count;
end
else
begin
I:=0;
str.add(Record00(strType,SenderCode,ReciverCode));
str.add(Record10(frm_op_seae.t_op_seae));
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','SH','发货人代码',frm_op_seae.t_op_seae));
str.add(Record16_17_18('17','CO','收货人代码',frm_op_seae.t_op_seae));
str.add(Record16_17_18('18','N1','通知人代码',frm_op_seae.t_op_seae));
aTempList:=RecordRB(85,'RB','EDI备注',frm_op_seae.t_op_seae);
str.addstrings(aTempList);
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:=Record51(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_msc.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','MSCSEND',edit1.text);
inifile1.WriteString('EDI','MSCRECIEVE',edit2.text);
inifile1.WriteString('EDI','MSCSENDNAME',edit3.text);
inifile1.WriteString('EDI','MSCFTPSERVER',edit4.text);
inifile1.WriteString('EDI','MSCFTPPATH',edit5.text);
inifile1.WriteString('EDI','MSCFTPNAME',edit6.text);
inifile1.WriteString('EDI','MSCFTPPASS',edit7.text);
inifile1.free;
showmessage('文件上传成功!');
except
deletefile(str);
showmessage('文件上传错误!');
end;
idftp1.Free;
end;
procedure Tfrm_op_seae_edi_msc.bsSkinButton4Click(Sender: TObject);
begin
if frm_op_seae_edi_MSC.Height=349 then
frm_op_seae_edi_MSC.Height:=200
else
frm_op_seae_edi_MSC.Height:=349;
end;
end.