unit u_op_seae_edi_NB; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, StdCtrls, ExtCtrls, DB, ADODB,XMLDoc, XMLIntf, xmldom, msxmldom, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdCoder, IdCoder3to4, IdCoderMIME,DateUtils,EncdDecd,Httpapp, IdHashMessageDigest,IdGlobal, IdHash,U_md5, IdMessage, IdURI, IniFiles, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP,IdAttachmentFile; type // head NBEDIhead = record sndcom:string; // 是 发送方公司 sender:string; // 否 发送方部门 fromop:string; // 是 发送方操作员简称 fromtele:string; // 是 操作员联系电话 fromfax:string; // 否 操作员联系传真 frommail:string; // 是 操作员联系邮件地址 fromopc:string; // 否 操作员联系手机 fromope:string; // 否 操作员全称 accom:string; // 是 接收方公司 accepter:string; // 否 接收方部门 toop:string; // 否 接收方 操作员 sendtime:TDateTime; // 是 报文发送时间 editype:string; // 是 报文类型(VGM:VERMAS ; 船司订舱:IFTMBF ; 货代间订舱:SHPORD ; 船司提单:SHPMIN) EdiID:string; // 是 报文参考号 EdiName:string; // 否 报文文件名 EdiMode:string; // 是 报文格式 := 'HYXML'; EdiReceiver:string; // 是 接收方EDI代码 EdiSender:string; // 是 接收方EDI代码 end; //Forward NBEDIForward = record EdiForwardFMT:string; // 否 EDI加工参数 显式要求的转换格式 EdiForwardType:string; // 否 EDI加工参数 转发方式 EdiForwardURL:string; // 否 EDI加工参数 转发地址 EdiForwardId:string; // 否 EDI加工参数 转发账号 EdiForwardPass:string; // 否 EDI加工参数 转发密码 EdiForwardREFE1:string; // 否 EDI加工参数 通用参数1 EdiForwardREFE2:string; // 否 EDI加工参数 通用参数2 EdiForwardREFE3:string; // 否 EDI加工参数 通用参数3 船代名称 EdiForwardREFE4:string; // 否 EDI加工参数 通用参数4 船代代码 EdiForwardREFE5:string; // 否 EDI加工参数 通用参数5 报文功能(9:新增 5:修改 1:取消) end; //reference NBEDIreference = record blfreight:string; // 是 报文功能(9:新增 5:修改 1:取消) refid:string; // 否 客户端系统托单ID freid:string; // 否 操作系统托单ID referenceno:string; // 否 托运编号 bookingno:string; // 是 订舱编号 workno:string; // 是 工作编号 sale:string; // 否 销售业务员 billofladingno:string; // 是 提单号 end; //baseinfo NBEDIbaseinfo = record orderman:string; // 是 订舱单位 source:string; // 否 货物来源 usdaccountshipper:string; // 否 结算货主(美圆) customshipper:string; // 否 报关货主 rmbaccountshipper:string; // 否 结算货主(人民币) paymenttermcode:string; // 是 付款方式代码(P/C/E) 预付到付其他? paymentterm:string; // 是 付款方式 payableat:string; // 否 第三地付款地点 shippingitem:string; // 是 运费条款 billofladingtype:string; // 是 提单类型 shipper:string; // 是 提单货主 可99次循环 若有超过35个字符的行:注意:收发通每行限数35个字符,超过部分请另起一行 consignee:string; // 是 收货人 可99次循环 若有超过35个字符的行:注意:收发通每行限数35个字符,超过部分请另起一行 notifyparty:string; // 是 通知人 可99次循环 若有超过35个字符的行:注意:收发通每行限数35个字符,超过部分请另起一行 notifyparty2:string; // 否 第二通知人 可99次循环 若有超过35个字符的行:注意:收发通每行限数35个字符,超过部分请另起一行 ordermemo:string; // 否 订舱说明 numberoforiginals:string; // 是 提单正本数 numberofcopys:string; // 否 提单副本数 placeofissuecode:string; // 是 签单地代码 placeofissue:string; // 是 签单地 timeofissue:string; // 是 签单时间 end; //cargo NBEDIcargo = record APPLICANT:string; // 否 询价单位 BOKKINGPARTY:string; // 否 签协议的单位代码 FOBPARTY:string; // 否 国外订舱单位 SCNO:string; // 否 美线服务合同号 QUARANTINECODING:string; // 否 检疫代码 SCACCODE:string; // 否 美线服务合同号 QUOTATIONNO:string; // 否 运费协议号 CHARGETYPE:string; // 否 费率本代码 NVOCCHBLNO:string; // 否 NVOCC号 realshipper:string; // 否 真实提单货主 可99次循环 realconsignee:string; // 否 真实收货人 可99次循环 realnotifyparty:string; // 否 真实通知人 可99次循环 realnotifyparty2:string; // 否 真实第二通知人 可99次循环 end; //booking NBEDIbooking = record shipmentdate:string; // 否 装期 expirydate:string; // 否 效期 tranship:string; // 否 转船标识 batch:string; // 否 分批标识 quotationno:string; // 否 服务合同号 end; //freight NBEDIfreight = record fl:string; // 否 整箱拼箱标准(F/L) masterlclno:string; // 否 主票提单号 requestdate:string; // 否 要求配舱日期 lastdate:string; // 否 最晚配舱日期 arrivedate:string; // 否 要求到达日期 end; //port ediport = record placeofreceipt:string; // 否 收货地点 portofloading:string; // 是 装货港 portoftranship:string; // 否 中转港 portofdischarge:string; // 是 卸货港 placeofdelivery:string; // 是 目的港 finaldestination:string; // 否 最终目的地 co_placeofreceipt:string; // 否 收货地点代码 co_portofloading:string; // 是 装货港代码 co_portoftranship:string; // 否 中转港代码 co_portofdischarge:string; // 是 卸货港代码 co_placeofdelivery:string; // 是 目的港代码 co_finaldestination:string; // 否 最终目的地代码 end; //vessel edivessel = record carrier:string; // 是 船公司 oceanvessel:string; // 是 船名 voyno:string; // 是 航次 etd:TDateTime; // 是 开航日期 deliverymode:string; // 否 运输方式 end; //info2nd ediinfo2nd = record carrier:string; // 否 二程船公司 oceanvessel:string; // 否 二程船名 voyno:string; // 否 二程航次 etd:string; // 否 二程开航日期 deliverymode:string; // 否 二程运输方式 remarks:string; // 否 二程备注 可99次循环 end; //containers edicontainers = record containertype:string; // 是 箱型 containerno:string; // 是 箱号 sealno:string; // 是 封号 containernoofpkgs:string; // 是 件数 containergrossweight:string; // 是 毛重 containercbm:string; // 是 体积 containerpackagingcode:string; // 是 箱货物包装类型代码 containerpackaging:string; // 是 箱货物包装类型 containerdescription:string; // 否 箱货物描述 containermarksandnumbers:string; // 否 箱麦头 vgmgrossmassweight:string; // 是 VGM总重量 vgmweighingmethod:string; // 是 VGM称重方式 vgmweighingtime:string; // 是 VGM称重时间 vgmresponsibleparty:string; // 是 VGM联系单位 vgmauthorizedperson:string; // 是 VGM授权联系人 vgmauthorizedpersontele:string; // 是 VGM授权联系人电话 vgmauthorizedpersonmail:string; // 否 VGM授权联系人邮件 vgmremark:string; // 否 VGM其他备注内容 end; //goods NBEDIgoods = record marksandnumbers:string; // 是 麦头 可99次循环 noofpkgs:string; // 是 包装件数 packagingcode:string; // 是 包装类型代码 packaging:string; // 是 包装类型 cargoid:string; // 是 货物类型(GC/RF/DR) hscode:string; // 否 海关编码 description:string; // 是 货物描述(英文货名) 可99次循环 cdescription:string; // 否 货物描述(中文货名) 可99次循环 grossweight:string; // 是 毛重 cbm:string; // 是 体积 specialgoods:string; // 否 特殊货物说明 可99次循环 end; //dr NBEDIdr = record ediCLASS:string; // 否 CLASS 危险品分类 PAGE:string; // 否 危险品页号 UNDGNO:string; // 否 联合国危险品编号 TECNAME:string; // 否 技术名称 PACKGROUP:string; // 否 包装组别 ediLABEL:string; // 否 LABEL 危险品标签 可99次循环 FLASHPOINT:string; // 否 危险货物闪点 FLASHUNIT:string; // 否 闪点温度计量单位 C=摄氏 F=华氏 EMSNO:string; // 否 应急措施号 MFAGNO:string; // 否 医疗急救措施指南号 MPT:string; // 否 海运污染 Y/N Elinkman:string; // 否 紧急联系人 EMS CONTACT应急联系 DANGEROUS:string; // 否 危险品信息 TEMPERATURE:string; // 否 冷藏品温度要求 TEMPERATUREUNIT:string; // 否 冷藏温度计量单位 C=摄氏 F=华氏 MINTEMPERATURE:string; // 否 冷藏最低温度 MAXTEMPERATURE:string; // 否 冷藏最高温度 ALLCOLDTORAGE:string; // 否 全程冷藏 Y/N VENTI:string; // 否 通风量 REEFER:string; // 否 冷藏信息 可99次循环 end; //loadplan NBEDIloadplan = record entryno:string; // 否 进仓编号 warehouse:string; // 否 仓库 landcarrier:string; // 否 车队 stuffdate:TDateTime; // 否 装箱时间 stuffmode:string; // 否 装箱方式 stuffaddress:string; // 否 装箱地点 stuffmemo:string; // 否 装箱备注 end; //announce NBEDIannounce = record announce:string; //否 订舱说明 end; //goodsdetail VGM没有 船司订舱、货代间订舱、船司提单有 NBEDIgoodsdetail = record cargosequenceno:string; // 是 分货物序号 marksandnumbers:string; // 是 麦头 可99次循环 noofpkgs:string; // 是 包装件数 packagingcode:string; // 是 包装类型代码 packaging:string; // 是 包装类型 cargoid:string; // 是 货物类型(GC/RF/DR) hscode:string; // 否 海关编码 description:string; // 是 货物描述(英文货名) 可99次循环 cdescription:string; // 否 货物描述(中文货名) 可99次循环 grossweight:string; // 是 毛重 cbm:string; // 是 体积 specialgoods:string; // 否 特殊货物说明 可99次循环 end; //goodsdetail_dr VGM没有 船司订舱、货代间订舱、船司提单有 NBEDIgoodsdetail_dr = record ediCLASS:string; // 否 CLASS 危险品分类 PAGE:string; // 否 危险品页号 UNDGNO:string; // 否 联合国危险品编号 TECNAME:string; // 否 技术名称 PACKGROU:string; // 否 包装组别 ediLABEL:string; // 否 LABEL 危险品标签 可99次循环 FLASHPOINT:string; // 否 危险货物闪点 FLASHUNIT:string; // 否 闪点温度计量单位 C=摄氏 F=华氏 EMSNO:string; // 否 应急措施号 MFAGNO:string; // 否 医疗急救措施指南号 MPT:string; // 否 海运污染 Y/N Elinkman:string; // 否 紧急联系人 EMS CONTACT应急联系 DANGEROUS:string; // 否 危险品信息 TEMPERATURE:string; // 否 冷藏品温度要求 TEMPERATUREUNIT:string; // 否 冷藏温度计量单位 C=摄氏 F=华氏 MINTEMPERATURE:string; // 否 冷藏最低温度 MAXTEMPERATURE:string; // 否 冷藏最高温度 ALLCOLDTORAGE:string; // 否 全程冷藏 Y/N VENTI:string; // 否 通风量 REEFER:string; // 否 冷藏信息 可99次循环 end; //goodsdetail_containers 只有船司提单有 NBEDIgoodsdetail_containers = record containertype:string; // 是 箱型 containerno:string; // 是 sealno:string; // 是 containernoofpkgs:string; // 是 containergrossweight:string; // 是 containercbm:string; // 是 end; var MyContainers : array [0..99] of edicontainers; MyNBEDIgoodsdetail : array [0..99] of NBEDIgoodsdetail; MyNBEDIgoodsdetail_containers : array [0..99] of array [0..99] of NBEDIgoodsdetail_containers; goods_ctn_count: array [0..99] of integer; type TFrm_op_seae_edi_NB = class(TForm) bsSkinPanel1: TbsSkinPanel; bsSkinPanel2: TbsSkinPanel; WJGN: TbsSkinRadioGroup; HDTD: TbsSkinCheckGroup; BWTYPE: TbsSkinRadioGroup; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton3: TbsSkinButton; t_sys_company: TADOQuery; XMLDocument1: TXMLDocument; SaveDialog1: TSaveDialog; IdSMTP1: TIdSMTP; IdMessage1: TIdMessage; CheckBox1: TCheckBox; Label1: TLabel; Label2: TLabel; Edit1: TEdit; procedure bsSkinButton3Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } function GetNBEDIhead(var MyNBEDIhead : NBEDIhead):Boolean; function GetNBEDIForward(var MyNBEDIForward : NBEDIForward):Boolean; function GetNBEDIreference(var MyNBEDIreference : NBEDIreference):Boolean; function GetNBEDIbaseinfo(var MyNBEDIbaseinfo : NBEDIbaseinfo):Boolean; function GetNBEDIcargo(var MyNBEDIcargo : NBEDIcargo):Boolean; function GetNBEDIbooking(var MyNBEDIbooking : NBEDIbooking):Boolean; function GetNBEDIfreight(var MyNBEDIfreight : NBEDIfreight):Boolean; function Getediport(var MyPort : ediport):Boolean; function Getedivessel(var MyVessel : edivessel):Boolean; function Getediinfo2nd(var Myinfo2nd : ediinfo2nd):Boolean; function Getedicontainers(var ContainerCount:Integer):Boolean; function GetNBEDIgoods(var MyNBEDIgoods : NBEDIgoods):Boolean; function GetNBEDIdr(var MyNBEDIdr : NBEDIdr):Boolean; function GetNBEDIloadplan(var MyNBEDIloadplan : NBEDIloadplan):Boolean; function GetNBEDIgoodsdetail(var goodscount : Integer):Boolean; function GetNBEDIannounce(var myNBEDIannounce :NBEDIannounce):Boolean; public { Public declarations } function GetCompany:String; function CheckParaExist(para:string):Boolean; function GetCntrVGM(cntrsize: String):String; function GetPackVGM(cntrsize: String):String; function GetECodeVGM(cntrsize: String):String; function GetTelVGM(cntrsize: String):String; function GetDepartmentVGM(cntrsize: String):String; function CheckSendorCode:Boolean; function IsZhongwen(Str: String): Boolean; function SeparateEC(Str: String): string; function GetEmailVGM(cntrsize: String):String; function GetShipVGM(Ship:String): String; function GetShipFTP(Ship:String): String; function Changestr(str:widestring):string; function GetClient(str:string):TStringList; procedure MakeVGM(xmltype:Integer); procedure sendmail; procedure SendFile; function GetCustCode(CorpID:string):string; end; var Frm_op_seae_edi_NB: TFrm_op_seae_edi_NB; HasM:Boolean; //是否有错 RequestFile:string; filerole,filetype,filename,goodstype:string; //文件功能 报文类型 文件名称 货物类型 MyNBEDIgoodsdetail_dr : array of NBEDIgoodsdetail_dr; const PackageName:array[0..50] of string= ( 'Bag','Bale, compressed','Barrel','Basket','Bin','Bobbin','Box', 'Bucket','Bundle','Cage','Can, cylindrical','Carboy, non-protected','Carton','Case', 'Cask','Chest','Coil','Cone','Container','Crate','Cylinder', 'Drum','Flask','Frame','Hamper','Hogshead','Intermediate bulk container','Jar', 'Jug','Keg','Liftvan','Package','Pail','Pallet','Pieces', 'Rack','Reel','Roll','Sack','Set','Sheet','Skid', 'Spool','Tank, rectangular','Tray','Trunk','Tub','Tube','Unit', 'Unpacked or unpackaged','Van Pack' ); PackageCode:array[0..50] of string= ( 'BG','BL','BA','BK','BI','BB','BX', 'BJ','BE','CG','CX','CO','CT','CS', 'CK','CH','CL','AJ','CN','CR','CY', 'DR','FL','FR','HR','HG','WA','JR', 'JG','KG','LV','PK','PL','PX','PP', 'RK','RL','RO','SA','SX','ST','SI', 'SO','TK','PU','TR','TP','TU','UN', 'NE','VK' ); implementation uses u_op_seae, my_sys_function, u_main, u_data_share, u_op_seae_assistant; {$R *.dfm} function TFrm_op_seae_edi_NB.GetNBEDIhead(var MyNBEDIhead : NBEDIhead):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; if BWTYPE.ItemIndex=0 then filetype:='SHPMBF'; // IFTMBF ? if BWTYPE.ItemIndex=1 then filetype:='SHPORD'; if BWTYPE.ItemIndex=2 then filetype:='VERMAS'; if BWTYPE.ItemIndex=3 then filetype:='SHPMIN'; if hdtd.Checked[0] then filename:=frm_op_seae.t_op_seae.fieldbyname('委托编号').AsString+':'+FormatDateTime('yyyymmddhhmmss',Now) else filename:='TD:'+frm_op_seae.t_op_seae.fieldbyname('委托编号').AsString+':'+FormatDateTime('yyyymmddhhmmss',Now) ; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; if not t_sys_company.Active then t_sys_company.Open; if (IsZhongwen(t_sys_company.fieldbyname('VGM发送代码').AsString)) or (not CheckParaExist(t_sys_company.fieldbyname('VGM发送代码').AsString)) then begin HasM:=True; ShowMessage('发送方代码未配置或不能包含中文!请检查!'); Exit; end; MyNBEDIhead.sndcom := t_sys_company.fieldbyname('VGM发送代码').AsString; if (IsZhongwen(GetECodeVGM(employee))) or (not CheckParaExist(GetECodeVGM(employee))) then begin HasM:=True; ShowMessage('发送方操作员不能为空或包含中文!请检查!'); Exit; end; MyNBEDIhead.fromop:=GetECodeVGM(employee); if not CheckParaExist(GetTelVGM(employee)) then begin HasM:=True; ShowMessage('操作员联系电话未配置!请检查!'); Exit; end; MyNBEDIhead.fromtele:=GetTelVGM(employee); if bwtype.ItemIndex=2 then MyNBEDIhead.frommail:= 'dongshengsoft@dongshengsoft.com' else MyNBEDIhead.frommail:= GetEmailVGM(employee) ; if Trim(MyNBEDIhead.frommail)='' then begin HasM:=True; ShowMessage('操作员联系邮箱未配置!请检查!'); Exit; end; MyNBEDIhead.fromopc := empmobil; MyNBEDIhead.fromope := employeecode; if Trim(aQuery.fieldbyname('船公司').AsString)='' then begin HasM:=True; ShowMessage('接收方公司为空!船公司不能为空!'); Exit; end; MyNBEDIhead.accom := aQuery.fieldbyname('船公司').AsString; MyNBEDIhead.sendtime := Now; MyNBEDIhead.editype := filetype; MyNBEDIhead.EdiID :=filename; MyNBEDIhead.EdiName:= filename; MyNBEDIhead.EdiMode :='HYXML'; if Trim(GetShipVGM(aQuery.fieldbyname('船公司').AsString))='' then begin HasM:=True; ShowMessage('船公司的'+BWTYPE.Items[BWTYPE.ItemIndex]+'代码未配置'); Exit; end; MyNBEDIhead.EdiReceiver:=GetShipVGM(aQuery.fieldbyname('船公司').AsString); MyNBEDIhead.EdiSender:=t_sys_company.fieldbyname('VGM发送代码').AsString; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIForward(var MyNBEDIForward : NBEDIForward):Boolean; begin Result:=False; if WJGN.ItemIndex=0 then filerole:='9'; if WJGN.ItemIndex=1 then filerole:='5'; if WJGN.ItemIndex=2 then filerole:='1'; MyNBEDIForward.EdiForwardREFE5:= filerole; Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIreference(var MyNBEDIreference : NBEDIreference):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; if WJGN.ItemIndex=0 then filerole:='9'; if WJGN.ItemIndex=1 then filerole:='5'; if WJGN.ItemIndex=2 then filerole:='1'; MyNBEDIreference.blfreight:= filerole; MyNBEDIreference.bookingno:= frm_op_seae.t_op_seae.fieldbyname('主提单号').AsString; MyNBEDIreference.referenceno:= aQuery.fieldbyname('业务编号').AsString; MyNBEDIreference.workno:=aQuery.fieldbyname('主提单号').AsString; if CheckBox1.Checked then MyNBEDIreference.sale:=Edit1.Text else MyNBEDIreference.sale:='gu'; if CheckBox1.Checked then begin if not CheckParaExist(MyNBEDIreference.sale) then begin HasM:=True; ShowMessage('COSCO公司必须录入销售业务员编号!'); Exit; end; end; MyNBEDIreference.billofladingno := aQuery.fieldbyname('主提单号').AsString; if not CheckParaExist(MyNBEDIreference.billofladingno) then begin HasM:=True; ShowMessage('主提单号不存在!不能生成XML!请检查!'); Exit; end; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIbaseinfo(var MyNBEDIbaseinfo : NBEDIbaseinfo):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; MyNBEDIbaseinfo.orderman:=aQuery.fieldbyname('船公司').AsString; MyNBEDIbaseinfo.paymentterm:=aQuery.fieldbyname('付费方式').AsString; { if not CheckParaExist(MyNBEDIbaseinfo.paymentterm) then begin HasM:=True; ShowMessage('付费方式不存在!不能生成XML!请检查!'); Exit; end; } if Pos('PREPAID',MyNBEDIbaseinfo.paymentterm)>0 then MyNBEDIbaseinfo.paymenttermcode:='P' else if Pos('COLLECT',MyNBEDIbaseinfo.paymentterm)>0 then MyNBEDIbaseinfo.paymenttermcode:='C' else MyNBEDIbaseinfo.paymenttermcode:='E'; MyNBEDIbaseinfo.shippingitem:=aQuery.fieldbyname('运输条款').AsString; // 收发通必须填写 MyNBEDIbaseinfo.shipper := aQuery.fieldbyname('发货人代码').AsString; { if not CheckParaExist(MyNBEDIbaseinfo.shipper) then begin HasM:=True; ShowMessage('发货人必须填写!'); Exit; end; } MyNBEDIbaseinfo.consignee:=aQuery.fieldbyname('收货人代码').AsString; { if not CheckParaExist(MyNBEDIbaseinfo.consignee) then begin HasM:=True; ShowMessage('收货人必须填写!'); Exit; end; } MyNBEDIbaseinfo.notifyparty:=aQuery.fieldbyname('通知人代码').AsString; { if not CheckParaExist(MyNBEDIbaseinfo.notifyparty) then begin HasM:=True; ShowMessage('通知人必须填写!'); Exit; end; } if not HDTD.Checked[0] then MyNBEDIbaseinfo.notifyparty2:=aQuery.fieldbyname('第二通知人').AsString; if aQuery.fieldbyname('提单份数').AsString='ONE' then MyNBEDIbaseinfo.numberoforiginals:='1'; if aQuery.fieldbyname('提单份数').AsString='TWO' then MyNBEDIbaseinfo.numberoforiginals:='2'; if aQuery.fieldbyname('提单份数').AsString='THREE' then MyNBEDIbaseinfo.numberoforiginals:='3'; if aQuery.fieldbyname('提单份数').AsString='FOUR' then MyNBEDIbaseinfo.numberoforiginals:='4'; if aQuery.fieldbyname('提单份数').AsString='FIVE' then MyNBEDIbaseinfo.numberoforiginals:='5'; if aQuery.fieldbyname('提单份数').AsString='SIX' then MyNBEDIbaseinfo.numberoforiginals:='6'; if aQuery.fieldbyname('提单份数').AsString='SEVEN' then MyNBEDIbaseinfo.numberoforiginals:='7'; if aQuery.fieldbyname('提单份数').AsString='EIGHT' then MyNBEDIbaseinfo.numberoforiginals:='8'; if aQuery.fieldbyname('提单份数').AsString='NINE' then MyNBEDIbaseinfo.numberoforiginals:='9'; if aQuery.fieldbyname('提单份数').AsString='THEN' then MyNBEDIbaseinfo.numberoforiginals:='10'; if aQuery.fieldbyname('提单份数').AsString='NONE' then MyNBEDIbaseinfo.numberoforiginals:='0'; if Trim(aQuery.fieldbyname('提单份数').AsString)='' then MyNBEDIbaseinfo.numberoforiginals:='0'; // MyNBEDIbaseinfo.numberoforiginals:=aQuery.fieldbyname('提单份数').AsString; MyNBEDIbaseinfo.placeofissuecode:='NBPORTEDI'; MyNBEDIbaseinfo.placeofissue:=aQuery.fieldbyname('签单地点').AsString; MyNBEDIbaseinfo.timeofissue:=aQuery.fieldbyname('签单日期').AsString; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIcargo(var MyNBEDIcargo : NBEDIcargo):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; MyNBEDIcargo.QUOTATIONNO := aQuery.fieldbyname('运费协议号').AsString; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIbooking(var MyNBEDIbooking : NBEDIbooking):Boolean; begin Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIfreight(var MyNBEDIfreight : NBEDIfreight):Boolean; begin Result:=True; end; function TFrm_op_seae_edi_NB.Getediport(var MyPort : ediport):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; MyPort.portofloading:=aQuery.fieldbyname('装货港').AsString; {if not CheckParaExist(MyPort.portofloading) then begin HasM:=True; ShowMessage('装货港不能为空!'); Exit; end; } MyPort.portofdischarge:=aQuery.fieldbyname('卸货港').AsString; MyPort.placeofdelivery:=aQuery.fieldbyname('目的地').AsString; MyPort.co_portofloading:=aQuery.fieldbyname('装港代码').AsString; { if not CheckParaExist(MyPort.co_portofloading) then begin HasM:=True; ShowMessage('装港代码不能为空!'); Exit; end; } MyPort.co_portofdischarge:=aQuery.fieldbyname('卸货代码').AsString; MyPort.co_placeofdelivery:=aQuery.fieldbyname('目的地代码').AsString; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.Getedivessel(var MyVessel : edivessel):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; MyVessel.carrier:=aQuery.fieldbyname('船公司').AsString; MyVessel.oceanvessel:=aQuery.fieldbyname('船名').AsString; { if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyVessel.oceanvessel) then begin HasM:=True; ShowMessage('船名不能为空!'); Exit; end; end; } MyVessel.voyno:=aQuery.fieldbyname('航次').AsString; MyVessel.etd:= aQuery.fieldbyname('开船日期').AsDateTime; { if not CheckParaExist(aQuery.fieldbyname('开船日期').AsString) then begin HasM:=True; ShowMessage('开船日期不能为空!'); Exit; end; } FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.Getediinfo2nd(var Myinfo2nd : ediinfo2nd):Boolean; begin Result:=True; end; function TFrm_op_seae_edi_NB.Getedicontainers(var ContainerCount:Integer):Boolean; var aQuery,bQuery:TADOQuery; SQLStr:string; i:Integer; begin Result:=False; aQuery:=CreateAdoQuery; bQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with bQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; if HDTD.Checked[0] then begin SQLStr:='SELECT t_op_ctn_fendan.*,t_code_ctn.EDI代码 FROM t_op_ctn_fendan INNER JOIN t_code_ctn ON t_op_ctn_fendan.代码=t_code_ctn.代码' +' where as_id='+QuotedStr(bQuery.fieldbyname('as_id').AsString); end else begin SQLStr:='SELECT t_op_ctn.*, t_code_ctn.EDI代码 FROM t_op_ctn INNER JOIN t_code_ctn ON t_op_ctn.代码 = t_code_ctn.代码' +' WHERE t_op_ctn.编号='+QuotedStr(bQuery.fieldbyname('编号').AsString); end; with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; ContainerCount:=aQuery.RecordCount; if ContainerCount=0 then begin HasM:=True; ShowMessage('集装箱信息不能为空!'); Exit; end; aQuery.First; for i:=0 to ContainerCount-1 do begin MyContainers[i].containertype:=GetCntrVGM(aQuery.fieldbyname('代码').AsString); if not CheckParaExist(MyContainers[i].containertype) then begin HasM:=True; ShowMessage('箱型'+BWTYPE.Items[BWTYPE.ItemIndex]+'代码未设置!'); Exit; end; MyContainers[i].containerno:=aQuery.fieldbyname('箱号').AsString; if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyContainers[i].containerno) then begin HasM:=True; ShowMessage('箱号不能为空!'); Exit; end; end; MyContainers[i].sealno:=aQuery.fieldbyname('封号').AsString; { if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyContainers[i].sealno) then begin HasM:=True; ShowMessage('封号不能为空!'); Exit; end; end; } MyContainers[i].containernoofpkgs:=aQuery.fieldbyname('数量').AsString; {if not CheckParaExist(MyContainers[i].containernoofpkgs) then begin HasM:=True; ShowMessage('件数不能为空!'); Exit; end; } MyContainers[i].containergrossweight:=aQuery.fieldbyname('重量').AsString; {if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyContainers[i].containergrossweight) then begin HasM:=True; ShowMessage('毛重不能为空!'); Exit; end; end; } MyContainers[i].containercbm:=aQuery.fieldbyname('尺码').AsString; { if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyContainers[i].containercbm) then begin HasM:=True; ShowMessage('体积不能为空!'); Exit; end; end; } MyContainers[i].containerpackagingcode:=aQuery.fieldbyname('包装').AsString; { MyContainers[i].containerpackagingcode:=GetPackVGM(aQuery.fieldbyname('包装').AsString); if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyContainers[i].containerpackagingcode) then begin HasM:=True; ShowMessage('包装'+BWTYPE.Items[BWTYPE.ItemIndex]+'代码未设置!'); //包装EDI代码未设置(VGM) Exit; end; end; } MyContainers[i].containerpackaging:=aQuery.fieldbyname('包装').AsString; { if BWTYPE.ItemIndex<>0 then begin if not CheckParaExist(MyContainers[i].containerpackaging) then begin HasM:=True; ShowMessage('包装不能为空!'); Exit; end; end; } //t_op_ctn_fendan 没有称重重量字段,用重量来代替 if HDTD.Checked[0] then begin if BWTYPE.ItemIndex<>2 then MyContainers[i].vgmgrossmassweight:='' else MyContainers[i].vgmgrossmassweight:=aQuery.fieldbyname('重量').AsString; end else begin if BWTYPE.ItemIndex<>2 then MyContainers[i].vgmgrossmassweight:='' else MyContainers[i].vgmgrossmassweight:=aQuery.fieldbyname('称重重量').AsString; end; if BWTYPE.ItemIndex=2 then begin if not CheckParaExist(MyContainers[i].vgmgrossmassweight) then begin HasM:=True; ShowMessage('重量不能为空!'); Exit; end; end; //t_op_ctn_fendan 没有称重方式,用SM1来代替 if not HDTD.Checked[0] then begin if BWTYPE.ItemIndex<>2 then MyContainers[i].vgmweighingmethod:='' else begin if (Trim(aQuery.fieldbyname('称重方式').AsString)='') or (Trim(aQuery.fieldbyname('称重方式').AsString)='累加') then MyContainers[i].vgmweighingmethod:='SM2'else MyContainers[i].vgmweighingmethod:= 'SM1'; end; end; if HDTD.Checked[0] then begin if BWTYPE.ItemIndex=2 then MyContainers[i].vgmweighingmethod:= 'SM1'; end; //t_op_ctn_fendan 没有VGM称重日期,用开船日期前三天来代替 if HDTD.Checked[0] then begin if BWTYPE.ItemIndex=2 then MyContainers[i].vgmweighingtime:=FormatDateTime('yyyy-mm-dd',bQuery.fieldbyname('开船日期').AsDateTime-3); end else begin if BWTYPE.ItemIndex=2 then begin if Trim(aQuery.fieldbyname('VGM称重日期').AsString)='' then MyContainers[i].vgmweighingtime:=FormatDateTime('yyyy-mm-dd',bQuery.fieldbyname('开船日期').AsDateTime-3) else MyContainers[i].vgmweighingtime:=aQuery.fieldbyname('VGM称重日期').AsString; end; end; if BWTYPE.ItemIndex=2 then begin MyContainers[i].vgmresponsibleparty :=GetDepartmentVGM(employee); if not CheckParaExist(MyContainers[i].vgmresponsibleparty) then begin HasM:=True; ShowMessage(BWTYPE.Items[BWTYPE.ItemIndex]+'联系单位不能为空!'); Exit; end; end; MyContainers[i].vgmauthorizedperson:=employeecode; MyContainers[i].vgmauthorizedpersontele:=emptel; aQuery.Next; end; FreeAndNil(aQuery); FreeAndNil(bQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIgoods(var MyNBEDIgoods : NBEDIgoods):Boolean; var aQuery:TADOQuery; SQLStr:string; s:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; MyNBEDIgoods.marksandnumbers:=aQuery.fieldbyname('唛头').AsString; //是否必填待定 {if not CheckParaExist(MyNBEDIgoods.marksandnumbers) then begin HasM:=True; ShowMessage('唛头不能为空!'); Exit; end; } MyNBEDIgoods.noofpkgs:=aQuery.fieldbyname('件数').AsString; MyNBEDIgoods.packagingcode:=trim(GetPackVGM(aQuery.fieldbyname('包装').AsString)); //MyNBEDIgoods.packagingcode:=aQuery.fieldbyname('包装').AsString; MyNBEDIgoods.packaging:=aQuery.fieldbyname('包装').AsString; //* 货物类型(GC/RF/DR) s:= aQuery.fieldbyname('货物标识').AsString; if s='D' then goodstype:='DR' else if s='R' then goodstype:='RF' else goodstype:='GC'; MyNBEDIgoods.cargoid:=goodstype; MyNBEDIgoods.description:=aQuery.fieldbyname('货物描述').AsString; MyNBEDIgoods.cdescription:=aQuery.fieldbyname('货物描述').AsString; MyNBEDIgoods.grossweight:=aQuery.fieldbyname('重量').AsString; MyNBEDIgoods.cbm:=aQuery.fieldbyname('尺码').AsString; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIdr(var MyNBEDIdr : NBEDIdr):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; if aQuery.fieldbyname('货物标识').AsString ='D' then begin MyNBEDIdr.ediclass:=aQuery.fieldbyname('危险品分类').AsString; MyNBEDIdr.UNDGNO:= aQuery.fieldbyname('危险品编号').AsString; end; if aQuery.fieldbyname('货物标识').AsString ='R' then begin MyNBEDIdr.TEMPERATURE:=aQuery.fieldbyname('设置温度').AsString; MyNBEDIdr.TEMPERATUREUNIT:=aQuery.fieldbyname('温度单位').AsString; MyNBEDIdr.MINTEMPERATURE:=aQuery.fieldbyname('最低温度').AsString; MyNBEDIdr.MAXTEMPERATURE:=aQuery.fieldbyname('最高温度').AsString; end; FreeAndNil(aQuery); Result:=True; end; procedure TFrm_op_seae_edi_NB.MakeVGM(xmltype:Integer); var fNode,pNode,mNode,cNode,dNode,eNode,gNode: IXMLNode; {定义7层节点} sl:TStringList; i,k,Elength,Wlength,Clength:Integer; myhead:NBEDIhead; myForward:NBEDIForward; myreference:NBEDIreference; mybaseinfo:NBEDIbaseinfo; mycargo:NBEDIcargo; mybooking:NBEDIbooking; myfreight:NBEDIfreight; myport:ediport; myvessel:edivessel; myinfo:ediinfo2nd; ContainerCount,goodscount:Integer; mygoods:NBEDIgoods; mydr:NBEDIdr; myloadolan:NBEDIloadplan; myNBEDIannounce :NBEDIannounce; begin XMLDocument1.XML.Clear; XMLDocument1.Active := True; XMLDocument1.Version := '1.0'; XMLDocument1.Encoding := 'GB2312'; //添加根节点 edi fNode := XMLDocument1.AddChild('edi'); // 为根节点添加子节点:HEAD pNode := fNode.AddChild('head'); GetNBEDIhead(myhead); cNode := pNode.AddChild('sndcom'); //* cNode.Text := myhead.sndcom; cNode := pNode.AddChild('sender'); cNode.Text :=myhead.sender; cNode := pNode.AddChild('fromop'); //* cNode.Text := myhead.fromop; cNode := pNode.AddChild('fromtele'); //* cNode.Text := myhead.fromtele; cNode := pNode.AddChild('fromfax'); cNode.Text := myhead.fromfax; cNode := pNode.AddChild('frommail'); //* cNode.Text := myhead.frommail; cNode := pNode.AddChild('fromopc'); cNode.Text := myhead.fromopc; cNode := pNode.AddChild('fromope'); cNode.Text := myhead.fromope; cNode := pNode.AddChild('accom'); //* cNode.Text :=myhead.accom; cNode := pNode.AddChild('accepter'); cNode.Text :=myhead.accepter; cNode := pNode.AddChild('toop'); cNode.Text :=myhead.toop; cNode := pNode.AddChild('sendtime'); //* cNode.Text:=FormatDateTime('yyyy-mm-dd hh:mm:ss',myhead.sendtime); cNode := pNode.AddChild('editype'); //* cNode.Text:=myhead.editype; cNode := pNode.AddChild('EdiID'); //* cNode.Text:=myhead.EdiID; cNode := pNode.AddChild('EdiName'); cNode.Text:=myhead.EdiName; cNode := pNode.AddChild('EdiMode'); //* cNode.Text:=myhead.EdiMode; cNode := pNode.AddChild('EdiReceiver'); //* cNode.Text := myhead.EdiReceiver; cNode := pNode.AddChild('EdiSender'); //* cNode.Text := myhead.EdiSender; // 为根节点添加子节点:Forward pNode := fNode.AddChild('Forward'); GetNBEDIForward(myForward); cNode := pNode.AddChild('EdiForwardFMT'); cNode.Text := myForward.EdiForwardFMT; cNode := pNode.AddChild('EdiForwardType'); cNode.Text := myForward.EdiForwardType; cNode := pNode.AddChild('EdiForwardURL'); cNode.Text := myForward.EdiForwardURL; cNode := pNode.AddChild('EdiForwardId'); cNode.Text := myForward.EdiForwardId; cNode := pNode.AddChild('EdiForwardPass'); cNode.Text := myForward.EdiForwardPass; cNode := pNode.AddChild('EdiForwardREFE1'); cNode.Text := myForward.EdiForwardREFE1; cNode := pNode.AddChild('EdiForwardREFE2'); cNode.Text := myForward.EdiForwardREFE2; cNode := pNode.AddChild('EdiForwardREFE3'); cNode.Text := myForward.EdiForwardREFE3; cNode := pNode.AddChild('EdiForwardREFE4'); cNode.Text := myForward.EdiForwardREFE4; cNode := pNode.AddChild('EdiForwardREFE5'); cNode.Text := myForward.EdiForwardREFE5; // 为根节点添加子节点:reference pNode := fNode.AddChild('reference'); GetNBEDIreference(myreference); cNode := pNode.AddChild('blfreight'); //* cNode.Text := myreference.blfreight; cNode := pNode.AddChild('refid'); cNode.Text := myreference.refid; cNode := pNode.AddChild('freid'); cNode.Text := myreference.freid; cNode := pNode.AddChild('referenceno'); cNode.Text := myreference.referenceno; cNode := pNode.AddChild('bookingno'); //* cNode.Text := myreference.bookingno; cNode := pNode.AddChild('workno'); //* cNode.Text := myreference.workno; cNode := pNode.AddChild('sale'); cNode.Text := myreference.sale; cNode := pNode.AddChild('billofladingno'); //* cNode.Text := myreference.billofladingno; // 为根节点添加子节点:detail pNode := fNode.AddChild('detail'); //增加二级子节点 baseinfo mNode:= pNode.AddChild('baseinfo'); GetNBEDIbaseinfo(mybaseinfo); cNode := mNode.AddChild('orderman'); //* 订舱单位 如果录了,就取订舱代理,如果没录就取company里的shortname cNode.Text := mybaseinfo.orderman; cNode := mNode.AddChild('source'); cNode := mNode.AddChild('usdaccountshipper'); cNode.Text := mybaseinfo.usdaccountshipper; cNode := mNode.AddChild('customshipper'); cNode.Text := mybaseinfo.customshipper; cNode := mNode.AddChild('rmbaccountshipper'); cNode.Text := mybaseinfo.rmbaccountshipper; cNode := mNode.AddChild('paymenttermcode'); //* 付款方式代码(P/C/E) cNode.Text := mybaseinfo.paymenttermcode; cNode := mNode.AddChild('paymentterm'); //* cNode.Text := mybaseinfo.paymentterm; cNode := mNode.AddChild('payableat'); cNode.Text := mybaseinfo.payableat; cNode := mNode.AddChild('shippingitem'); //* cNode.Text := mybaseinfo.shippingitem; cNode := mNode.AddChild('billofladingtype'); //* cNode.Text := mybaseinfo.billofladingtype; cNode := mNode.AddChild('shipper'); //* sl:=TStringList.Create; sl.Text:=mybaseinfo.shipper; for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; cNode := mNode.AddChild('consignee'); //* sl:=TStringList.Create; sl.Text:=mybaseinfo.consignee; for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; cNode := mNode.AddChild('notifyparty'); //* sl:=TStringList.Create; sl.Text:=mybaseinfo.notifyparty; for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; cNode := mNode.AddChild('notifyparty2'); if Trim(mybaseinfo.notifyparty2)<>'' then begin sl:=TStringList.Create; sl.Text:=mybaseinfo.notifyparty2; for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; end else begin dNode := cNode.AddChild('text'); end; cNode := mNode.AddChild('ordermemo'); cNode.Text := mybaseinfo.ordermemo; cNode := mNode.AddChild('numberoforiginals'); //* cNode.Text := mybaseinfo.numberoforiginals; cNode := mNode.AddChild('numberofcopys'); cNode.Text := mybaseinfo.numberofcopys; cNode := mNode.AddChild('placeofissuecode'); //* cNode.Text := mybaseinfo.placeofissuecode; cNode := mNode.AddChild('placeofissue'); //* cNode.Text := mybaseinfo.placeofissue; cNode := mNode.AddChild('timeofissue'); //* cNode.Text := mybaseinfo.timeofissue; //增加二级子节点 cargo mNode:= pNode.AddChild('cargo'); GetNBEDIcargo(mycargo); cNode := mNode.AddChild('APPLICANT'); cNode.Text := mycargo.APPLICANT; cNode := mNode.AddChild('BOKKINGPARTY'); cNode.Text := mycargo.BOKKINGPARTY; cNode := mNode.AddChild('FOBPARTY'); cNode.Text := mycargo.FOBPARTY; cNode := mNode.AddChild('SCNO'); cNode.Text := mycargo.SCNO; cNode := mNode.AddChild('QUARANTINECODING'); cNode.Text := mycargo.QUARANTINECODING; cNode := mNode.AddChild('SCACCODE'); cNode.Text := mycargo.SCACCODE; cNode := mNode.AddChild('QUOTATIONNO'); cNode.Text := mycargo.QUOTATIONNO; cNode := mNode.AddChild('CHARGETYPE'); cNode.Text := mycargo.CHARGETYPE; cNode := mNode.AddChild('NVOCCHBLNO'); cNode.Text := mycargo.NVOCCHBLNO; cNode := mNode.AddChild('realshipper'); dNode := cNode.AddChild('text'); dNode.Text := mycargo.realshipper; cNode := mNode.AddChild('realconsignee'); dNode := cNode.AddChild('text'); dNode.Text := mycargo.realconsignee; cNode := mNode.AddChild('realnotifyparty'); dNode := cNode.AddChild('text'); dNode.Text := mycargo.realnotifyparty; cNode := mNode.AddChild('realnotifyparty2'); dNode := cNode.AddChild('text'); dNode.Text := mycargo.realnotifyparty2; //增加二级子节点 booking mNode:= pNode.AddChild('booking'); GetNBEDIbooking(mybooking); cNode := mNode.AddChild('shipmentdate'); cNode.Text := mybooking.shipmentdate; cNode := mNode.AddChild('expirydate'); cNode.Text := mybooking.expirydate; cNode := mNode.AddChild('tranship'); cNode.Text := mybooking.tranship; cNode := mNode.AddChild('batch'); cNode.Text := mybooking.batch; cNode := mNode.AddChild('quotationno'); cNode.Text := mybooking.quotationno; //增加二级子节点 freight mNode:= pNode.AddChild('freight'); GetNBEDIfreight(myfreight); cNode := mNode.AddChild('fl'); cNode.Text := myfreight.fl; cNode := mNode.AddChild('masterlclno'); cNode.Text := myfreight.masterlclno; cNode := mNode.AddChild('requestdate'); cNode.Text := myfreight.requestdate; cNode := mNode.AddChild('lastdate'); cNode.Text := myfreight.lastdate; cNode := mNode.AddChild('arrivedate'); cNode.Text := myfreight.arrivedate; //增加三级子节点 port cNode := mNode.AddChild('port'); Getediport(myport); dNode := cNode.AddChild('placeofreceipt'); dNode.Text := myport.placeofreceipt; dNode := cNode.AddChild('portofloading'); //* 装货港 dNode.Text := myport.portofloading; dNode := cNode.AddChild('portoftranship'); dNode.Text := myport.portoftranship; dNode := cNode.AddChild('portofdischarge'); //* 卸货港 dNode.Text := myport.portofdischarge; dNode := cNode.AddChild('placeofdelivery'); //* 目的港 dNode.Text:=myport.placeofdelivery; dNode := cNode.AddChild('finaldestination'); dNode.Text:=myport.finaldestination; dNode := cNode.AddChild('co_placeofreceipt'); dNode.Text:=myport.co_placeofreceipt; dNode := cNode.AddChild('co_portofloading'); //* 装货港代码 dNode.Text:=myport.co_portofloading; dNode := cNode.AddChild('co_portoftranship'); dNode.Text:=myport.co_portoftranship; dNode := cNode.AddChild('co_portofdischarge'); //* 卸货港代码 dNode.Text:=myport.co_portofdischarge; dNode := cNode.AddChild('co_placeofdelivery'); //* 目的港代码 dNode.Text:=myport.co_placeofdelivery; dNode := cNode.AddChild('co_finaldestination'); dNode.Text:=myport.co_finaldestination; //增加三级子节点vessel cNode := mNode.AddChild('vessel'); Getedivessel(myvessel); dNode := cNode.AddChild('carrier'); //* 船公司 dNode.Text:=myvessel.carrier; dNode := cNode.AddChild('oceanvessel'); //* 船名 dNode.Text:=myvessel.oceanvessel; dNode := cNode.AddChild('voyno'); //* 航次 dNode.Text:=myvessel.voyno; dNode := cNode.AddChild('etd'); //* 开航日期 dNode.Text:= FormatDateTime('yyyy-mm-dd',myvessel.etd); dNode := cNode.AddChild('deliverymode'); dNode.Text := myvessel.deliverymode; //增加三级子节点info2nd cNode := mNode.AddChild('info2nd'); Getediinfo2nd(myinfo); dNode := cNode.AddChild('carrier'); dNode.Text := myinfo.carrier; dNode := cNode.AddChild('oceanvessel'); dNode.Text := myinfo.oceanvessel; dNode := cNode.AddChild('voyno'); dNode.Text := myinfo.voyno; dNode := cNode.AddChild('etd'); dNode.Text := myinfo.etd; dNode := cNode.AddChild('deliverymode'); dNode.Text := myinfo.deliverymode; dNode := cNode.AddChild('remarks'); eNode := dNode.AddChild('text'); eNode.Text := myinfo.remarks; //增加三级子节点container cNode := mNode.AddChild('container'); //若集装箱没录,提示:集装箱信息不能为空 Getedicontainers(ContainerCount); if ContainerCount =0 then begin HasM:=True; ShowMessage('集装箱信息不存在!不能生成EDI文件!请检查!'); Exit; end; for i:=0 to ContainerCount-1 do begin dNode := cNode.AddChild('containers'); //可无限循环 eNode := dNode.AddChild('containertype'); //* 箱型 箱型不能为空 eNode.Text:=mycontainers[i].containertype; eNode := dNode.AddChild('containerno'); //* 箱号 箱型不能为空 eNode.Text:=mycontainers[i].containerno; eNode := dNode.AddChild('sealno'); //* 封号 不能为空 eNode.Text:=mycontainers[i].sealno; eNode := dNode.AddChild('containernoofpkgs'); //* 件数 不能为空 eNode.Text:=mycontainers[i].containernoofpkgs; eNode := dNode.AddChild('containergrossweight'); //* 毛重 不能为空 eNode.Text:=mycontainers[i].containergrossweight; eNode := dNode.AddChild('containercbm'); //* 体积 不能为空 eNode.Text:=mycontainers[i].containercbm; eNode := dNode.AddChild('containerpackagingcode'); //* 箱货物包装类型代码 包装类型代码未配置 eNode.Text:=mycontainers[i].containerpackagingcode; eNode := dNode.AddChild('containerpackaging'); //* 箱货物包装类型 包装不能为空 eNode.Text:=mycontainers[i].containerpackaging; eNode := dNode.AddChild('containerdescription'); gNode := eNode.AddChild('text'); gNode.Text := mycontainers[i].containerdescription; eNode := dNode.AddChild('containermarksandnumbers'); eNode.Text := mycontainers[i].containermarksandnumbers; eNode := dNode.AddChild('vgmgrossmassweight'); //VGM总重量 不能为空 eNode.Text:=mycontainers[i].vgmgrossmassweight; eNode := dNode.AddChild('vgmweighingmethod'); //VGM称重方式 不能为空 eNode.Text:=mycontainers[i].vgmweighingmethod; eNode := dNode.AddChild('vgmweighingtime'); //VGM称重时间 不能为空 空则取开船前三天 eNode.Text:=mycontainers[i].vgmweighingtime; eNode := dNode.AddChild('vgmresponsibleparty'); //VGM联系单位 eNode.Text:=mycontainers[i].vgmresponsibleparty; eNode := dNode.AddChild('vgmauthorizedperson'); //VGM授权联系人 eNode.Text:=mycontainers[i].vgmauthorizedperson; eNode := dNode.AddChild('vgmauthorizedpersontele'); //VGM授权联系人电话 eNode.Text:=mycontainers[i].vgmauthorizedpersontele; eNode := dNode.AddChild('vgmauthorizedpersonmail'); //VGM授权联系人邮件 eNode.Text := mycontainers[i].vgmauthorizedpersonmail; eNode := dNode.AddChild('vgmremark'); //VGM其他备注内容 eNode.Text := mycontainers[i].vgmremark; end; //增加二级子节点 goods mNode:= pNode.AddChild('goods'); GetNBEDIgoods(mygoods); cNode := mNode.AddChild('marksandnumbers'); //* 唛头 if Trim(mygoods.marksandnumbers)='' then begin dNode := cNode.AddChild('text'); end else begin sl:=TStringList.Create; sl.Text:=mygoods.marksandnumbers; for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; end; cNode := mNode.AddChild('noofpkgs'); //* 包装件数 cNode.Text:=mygoods.noofpkgs; cNode := mNode.AddChild('packagingcode'); //* 包装类型代码 cNode.Text:=mygoods.packagingcode; cNode := mNode.AddChild('packaging'); //* 包装类型 cNode.Text:=mygoods.packaging; cNode := mNode.AddChild('cargoid'); //* 货物类型(GC/RF/DR) cNode.Text:=mygoods.cargoid; cNode := mNode.AddChild('hscode'); //海关编码 cNode.Text:=mygoods.hscode; cNode := mNode.AddChild('description'); //货物描述(英文货名) if Trim(mygoods.description)='' then begin dNode := cNode.AddChild('text'); end else begin sl:=TStringList.Create; sl.Text:=SeparateEC(mygoods.description); for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; end; cNode := mNode.AddChild('cdescription'); //货物描述(中文货名) Wlength:= Length(mygoods.description); Elength:= Length(SeparateEC(mygoods.description)); if Trim(Copy(mygoods.description,Elength,WLength-Elength-1) )='' then begin dNode := cNode.AddChild('text'); end else begin sl:=TStringList.Create; sl.Text:=Copy(mygoods.description,Elength,WLength-Elength-1); for i:=0 to sl.Count-1 do begin dNode := cNode.AddChild('text'); dNode.Text:=sl[i]; end; sl.Free; end; cNode := mNode.AddChild('grossweight'); //* 毛重 cNode.Text:= mygoods.grossweight; cNode := mNode.AddChild('cbm'); //* 体积 cNode.Text:= mygoods.cbm; cNode := mNode.AddChild('specialgoods'); //特殊货物说明 dNode := cNode.AddChild('text'); dNode.Text := mygoods.specialgoods; //增加二级子节点 dr mNode := pNode.AddChild('dr'); GetNBEDIdr(mydr); cNode := mNode.AddChild('CLASS'); cNode.Text := mydr.ediCLASS; cNode := mNode.AddChild('PAGE'); cNode.Text := mydr.PAGE; cNode := mNode.AddChild('UNDGNO'); cNode.Text := mydr.UNDGNO; cNode := mNode.AddChild('TECNAME'); cNode.Text := mydr.TECNAME; cNode := mNode.AddChild('PACKGROUP'); cNode.Text := mydr.PACKGROUP ; cNode := mNode.AddChild('LABEL'); dNode := cNode.AddChild('text'); dNode.Text := mydr.ediLABEL; cNode := mNode.AddChild('FLASHPOINT'); cNode.Text := mydr.FLASHPOINT; cNode := mNode.AddChild('FLASHUNIT'); cNode.Text := mydr.FLASHUNIT; cNode := mNode.AddChild('EMSNO'); cNode.Text := mydr.EMSNO; cNode := mNode.AddChild('MFAGNO'); cNode.Text := mydr.MFAGNO; cNode := mNode.AddChild('MPT'); cNode.Text := mydr.MPT; cNode := mNode.AddChild('Elinkman'); cNode.Text := mydr.Elinkman; cNode := mNode.AddChild('DANGEROUS'); dNode := cNode.AddChild('text'); dNode.Text := mydr.DANGEROUS; cNode := mNode.AddChild('TEMPERATURE'); cNode.Text := mydr.TEMPERATURE; cNode := mNode.AddChild('TEMPERATUREUNIT'); cNode.Text := mydr.TEMPERATUREUNIT; cNode := mNode.AddChild('MINTEMPERATURE'); cNode.Text := mydr.MINTEMPERATURE; cNode := mNode.AddChild('MAXTEMPERATURE'); cNode.Text := mydr.MAXTEMPERATURE; cNode := mNode.AddChild('ALLCOLDTORAGE'); cNode.Text := mydr.ALLCOLDTORAGE; cNode := mNode.AddChild('VENTI'); cNode.Text := mydr.VENTI; cNode := mNode.AddChild('REEFER'); dNode := cNode.AddChild('text'); dNode.Text := mydr.REEFER; //增加二级子节点 loadplan mNode := pNode.AddChild('loadplan'); GetNBEDIloadplan(myloadolan); cNode := mNode.AddChild('entryno'); cNode.Text := myloadolan.entryno; cNode := mNode.AddChild('warehouse'); cNode.Text := myloadolan.warehouse; cNode := mNode.AddChild('landcarrier'); cNode.Text := myloadolan.landcarrier; cNode := mNode.AddChild('stuffdate'); // cNode.Text := myloadolan.stf cNode := mNode.AddChild('stuffmode'); cNode.Text := myloadolan.stuffmode; cNode := mNode.AddChild('stuffaddress'); cNode.Text := myloadolan.stuffaddress; cNode := mNode.AddChild('stuffmemo'); cNode.Text := myloadolan.stuffmemo; //增加二级子节点 announce mNode := pNode.AddChild('announce'); GetNBEDIannounce(myNBEDIannounce); sl:=TStringList.Create; sl.Text:=myNBEDIannounce.announce; for i:=0 to sl.Count-1 do begin cNode := mNode.AddChild('text'); cNode.Text:=sl[i]; end; sl.Free; //增加二级子节点 remarks mNode := pNode.AddChild('remarks'); //分品名 只要不是VGM都有 可无限循环 if xmltype <>2 then begin GetNBEDIgoodsdetail(goodscount); for i:=0 to goodscount-1 do begin mNode := pNode.AddChild('goodsdetail'); cNode := mNode.AddChild('cargosequenceno'); cNode.Text:=MyNBEDIgoodsdetail[i].cargosequenceno; cNode := mNode.AddChild('marksandnumbers'); dNode := cNode.AddChild('text'); dNode.Text:=MyNBEDIgoodsdetail[i].marksandnumbers; cNode := mNode.AddChild('noofpkgs'); cNode.Text:=MyNBEDIgoodsdetail[i].noofpkgs; cNode := mNode.AddChild('packagingcode'); cNode.Text:=MyNBEDIgoodsdetail[i].packagingcode; cNode := mNode.AddChild('packaging'); cNode.Text:=MyNBEDIgoodsdetail[i].packaging; cNode := mNode.AddChild('cargoid'); cNode.Text:=MyNBEDIgoodsdetail[i].cargoid; cNode := mNode.AddChild('hscode'); cNode.Text:=MyNBEDIgoodsdetail[i].hscode; cNode := mNode.AddChild('description'); dNode := cNode.AddChild('text'); dNode.Text:=MyNBEDIgoodsdetail[i].description; cNode := mNode.AddChild('cdescription'); dNode := cNode.AddChild('text'); dNode.Text:=MyNBEDIgoodsdetail[i].cdescription; cNode := mNode.AddChild('grossweight'); cNode.Text:=MyNBEDIgoodsdetail[i].grossweight; cNode := mNode.AddChild('cbm'); cNode.Text:=MyNBEDIgoodsdetail[i].cbm; cNode := mNode.AddChild('specialgoods'); dNode := cNode.AddChild('text'); dNode.Text:=MyNBEDIgoodsdetail[i].specialgoods; // 东胜七没有加dr。这里也不加了 //dNode := cNode.AddChild('dr'); //eNode := dNode.AddChild('CLASS') ; //只有船司提单有 if xmltype=3 then begin cNode := mNode.AddChild('container'); for k:=0 to goods_ctn_count[i]-1 do begin dNode := cNode.AddChild('containers') ; eNode := dNode.AddChild('containertype'); eNode.Text := MyNBEDIgoodsdetail_containers[i,k].containertype; eNode := dNode.AddChild('containerno'); eNode.Text := MyNBEDIgoodsdetail_containers[i,k].containerno; eNode := dNode.AddChild('sealno'); eNode.Text := MyNBEDIgoodsdetail_containers[i,k].sealno; eNode := dNode.AddChild('containernoofpkgs'); eNode.Text := MyNBEDIgoodsdetail_containers[i,k].containernoofpkgs; eNode := dNode.AddChild('containergrossweight'); eNode.Text := MyNBEDIgoodsdetail_containers[i,k].containergrossweight; eNode := dNode.AddChild('containercbm'); eNode.Text := MyNBEDIgoodsdetail_containers[i,k].containercbm; end; end; end; end; end; function TFrm_op_seae_edi_NB.GetNBEDIloadplan(var MyNBEDIloadplan : NBEDIloadplan):Boolean; begin Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIgoodsdetail(var goodscount :Integer):Boolean; var aQuery,bQuery,cQuery:TADOQuery; SQLStr:string; i,k:Integer; begin Result:=False; aQuery:=CreateAdoQuery; bQuery:=CreateAdoQuery; cQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with bQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; if HDTD.Checked[0] then begin SQLStr:='select sum(重量) 重量 ,SUM(件数) 件数,SUM(尺码) 尺码,AS_ID,唛头,封号,包装,箱号 from t_op_ctn_fendan ' +' where AS_ID='+QuotedStr(bQuery.fieldbyname('AS_ID').AsString)+' group by AS_ID,唛头,封号,包装,箱号 ' ; end else begin SQLStr:='select sum(重量) 重量 ,SUM(件数) 件数,SUM(尺码) 尺码,编号,唛头,封号,包装,箱号 from t_op_ctn ' +' WHERE 编号='+QuotedStr(bQuery.fieldbyname('编号').AsString) +' group by 编号,唛头,封号,包装,箱号' ; end; with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; goodscount:=aQuery.recordcount; if goodscount=0 then begin // HasM:=True; // ShowMessage('没有货物信息!'); Exit; end; aQuery.First; for i:=0 to goodscount-1 do begin MyNBEDIgoodsdetail[i].cargosequenceno:=IntToStr(i+1); MyNBEDIgoodsdetail[i].marksandnumbers:=aQuery.fieldbyname('唛头').AsString; MyNBEDIgoodsdetail[i].noofpkgs:=aQuery.fieldbyname('件数').AsString; MyNBEDIgoodsdetail[i].packagingcode:=Trim(GetPackVGM(aQuery.fieldbyname('包装').AsString)); MyNBEDIgoodsdetail[i].packaging:=aQuery.fieldbyname('包装').AsString; MyNBEDIgoodsdetail[i].cargoid:=goodstype; MyNBEDIgoodsdetail[i].grossweight:=aQuery.fieldbyname('重量').AsString; MyNBEDIgoodsdetail[i].cbm:= aQuery.fieldbyname('尺码').AsString; if HDTD.Checked[0] then begin SQLStr:='select a.*,b.EDI代码 from t_op_ctn_fendan a INNER JOIN t_code_ctn b ON a.代码 = b.代码 where a.AS_ID=' +QuotedStr(aQuery.fieldbyname('AS_ID').AsString)+' and a.箱号='+QuotedStr(aQuery.fieldbyname('箱号').AsString); end else begin SQLStr:='select a.*,b.EDI代码 from t_op_ctn a INNER JOIN t_code_ctn b ON a.代码 = b.代码 where a.编号=' +QuotedStr(aQuery.fieldbyname('编号').AsString)+' and a.箱号='+QuotedStr(aQuery.fieldbyname('箱号').AsString); end; with cQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; goods_ctn_count[i]:=cQuery.RecordCount; cQuery.First; for k:=0 to cQuery.RecordCount-1 do begin MyNBEDIgoodsdetail_containers[i,k].containertype:=GetCntrVGM(cQuery.fieldbyname('代码').AsString); MyNBEDIgoodsdetail_containers[i,k].containerno:=cQuery.fieldbyname('箱号').AsString; MyNBEDIgoodsdetail_containers[i,k].sealno:=cQuery.fieldbyname('封号').AsString; MyNBEDIgoodsdetail_containers[i,k].containernoofpkgs:=cQuery.fieldbyname('件数').AsString; MyNBEDIgoodsdetail_containers[i,k].containergrossweight:=cQuery.fieldbyname('重量').AsString; MyNBEDIgoodsdetail_containers[i,k].containercbm:=cQuery.fieldbyname('尺码').AsString; cQuery.Next; end; aQuery.Next; end; FreeAndNil(aQuery); FreeAndNil(bQuery); FreeAndNil(cQuery); Result:=True; end; function TFrm_op_seae_edi_NB.GetNBEDIannounce(var myNBEDIannounce :NBEDIannounce):Boolean; var aQuery:TADOQuery; SQLStr:string; begin Result:=False; aQuery:=CreateAdoQuery; if HDTD.Checked[0] then SQLStr:='select * from t_op_seae_assistant where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString) else SQLStr:='select * from t_op_seae where 编号='+QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString); with aQuery do begin Close; SQL.Clear; SQL.Add(SQLStr); Open; end; if HDTD.Checked[0] then myNBEDIannounce.announce:='' else myNBEDIannounce.announce:=aQuery.fieldbyname('销售订舱说明').AsString; FreeAndNil(aQuery); Result:=True; end; function TFrm_op_seae_edi_NB.CheckParaExist(para:string):Boolean; begin Result:=False; if Trim(para)<>'' then Result:=True; end; function TFrm_op_seae_edi_NB.GetEmailVGM(cntrsize: String):String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 邮箱 from t_sys_employee where 姓名='''+cntrsize+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('邮箱').AsString; end; finally FreeAndNil(aQuery); end; end; //获取时间戳 java里的时间是从1970年1月1日0点到当前的间隔 function GetJavaTime( d: TDateTime ): Int64; var dJavaStart: TDateTime; begin dJavaStart := EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 ); Result := MilliSecondsBetween( d, dJavaStart ); end; //读取XML文件节点信息 不加任何回车换行 function ReadXml(node: IXMLNode): string; var nodeList,attrList: IXMLNodeList; str,strName,strValue: string; i: Integer; begin Result := ''; if not node.HasChildNodes then Exit; attrList := node.AttributeNodes; {根节点的属性清单} nodeList := node.ChildNodes; {根节点下的子节点列表} str := '<' + node.NodeName; //先读取属性 for i := 0 to attrList.Count - 1 do begin strName := attrList[i].NodeName; strValue := attrList[i].NodeValue; str := str + ' ' + strName + '=' + AnsiQuotedStr(strValue, '"'); end; str := str + '>';// + sLineBreak; {sLineBreak 是常量, 相当于 #13#10 此处不加,网站自动解析} //读取子节点 for i := 0 to nodeList.Count - 1 do begin strName := nodeList[i].NodeName; if nodeList[i].IsTextElement then begin strValue := nodeList[i].NodeValue; str := str + '<' + strName + '>' + strValue + '' ;//+ sLineBreak; //此处不加,网站自动解析 end else if nodeList[i].HasChildNodes then begin str := str + ReadXml(nodeList[i]); {递归} str := str + '' ;//+ sLineBreak; {封口} //此处不加,网站自动解析 end; end; str := str + ''; {封口} Result := str; end; function TFrm_op_seae_edi_NB.CheckSendorCode:Boolean; begin { Result:=False; with t_sys_company do begin Close; SQL.Clear; SQL.Add('select top 1 * from t_sys_company '); Open; end; if Trim(Edit1.Text)=Trim(t_sys_company.fieldbyname('VGM发送代码').AsString) then Result:=True; } end; function TFrm_op_seae_edi_NB.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)) or (Str[i]=Chr(9)) then begin Result:=True; Exit; end; end; end; function TFrm_op_seae_edi_NB.SeparateEC(Str: String): string; var i:Integer; begin if Str='' then Exit; for i:=1 to Length(Str) do begin if (Str[i]<=Chr(127)) then Result:=Result+Str[i] else Break; end; end; function TFrm_op_seae_edi_NB.GetShipVGM(Ship:String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add(' Select 代码,VGM代码,FTP接收代码,客户简称,客户全称,揽货人,录入人,录入日期 from t_crm_client '); SQL.Add(' where 客户性质<>''目标'' and 船公司=1 and 客户简称='''+Ship+''''); SQL.Add(' order by 代码 '); Open; if not IsEmpty then Result:=Trim(FieldByName('VGM代码').asstring) else Result:=''; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetShipFTP(Ship:String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 代码,VGM代码,FTP接收代码,客户简称,客户全称,揽货人,录入人,录入日期 from t_crm_client'); SQL.Add('where 客户性质<>''目标'' and 船公司=1 and 客户简称='''+Ship+''''); SQL.Add('order by 代码'); Open; if not IsEmpty then Result:=Trim(FieldByName('FTP接收代码').asstring) else Result:=''; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.Changestr(str:widestring):string; var i:integer; strC:widestring; begin strC:=str; strC:=StringReplace(strC,'''''','"',[rfReplaceAll]); strC:=StringReplace(strC,'''',''',[rfReplaceAll]); strC:=StringReplace(strC,'&','&',[rfReplaceAll]); strC:=StringReplace(strC,'>','>',[rfReplaceAll]); strC:=StringReplace(strC,'<','<',[rfReplaceAll]); result:=strC; end; function TFrm_op_seae_edi_NB.GetCntrVGM(cntrsize: String):String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select VGM代码 from t_code_ctn where 代码='''+cntrsize+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('VGM代码').AsString; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetPackVGM(cntrsize: 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 代码='''+cntrsize+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('EDI代码').AsString; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetDepartmentVGM(cntrsize: String):String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select VGM代码 from t_code_subcomp where 分部名称=(select 分部名称 from t_sys_employee where 姓名='''+cntrsize+''')'); Open; if IsEmpty then Result:='' else Result:=FieldByName('VGM代码').AsString; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetECodeVGM(cntrsize: String):String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 代码 from t_sys_employee where 姓名='''+cntrsize+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('代码').AsString; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetTelVGM(cntrsize: String):String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 固定电话 from t_sys_employee where 姓名='''+cntrsize+''''); Open; if IsEmpty then Result:='' else Result:=FieldByName('固定电话').AsString; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetCompany:String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select top 1 简称 from t_sys_company '); Open; if IsEmpty then Result:='' else Result:=FieldByName('简称').AsString; end; finally FreeAndNil(aQuery); end; end; function TFrm_op_seae_edi_NB.GetClient(str:string):TStringList; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try Result:=TStringList.Create; with aQuery do begin Close;SQL.Clear; SQL.Add('Select top 1 客户简称,客户全称,VGM代码 from t_crm_client where 客户简称='+QuotedStr(str)); Open; Result.Add(FieldByName('客户简称').AsString); Result.Add(FieldByName('客户全称').AsString); Result.Add(FieldByName('VGM代码').AsString); end; finally FreeAndNil(aQuery); end; end; procedure TFrm_op_seae_edi_NB.bsSkinButton3Click(Sender: TObject); begin close; end; procedure TFrm_op_seae_edi_NB.FormShow(Sender: TObject); var ini:TIniFile; begin if frm_op_seae.t_op_seae.IsEmpty then begin ShowMessage('没有数据!不能生成EDI,请返回检查!'); Exit; end; ini:= Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); CheckBox1.checked:=False; label2.visible:=False; edit1.visible:=false; Edit1.Text:=ini.ReadString('COSCO','Sale',''); ini.Free; idsmtp1.Username:='admin@dongshengsoft.com'; //设置登陆帐号 idsmtp1.Password:='ds!@#)(*';// 设置登陆密码 idsmtp1.Host:='smtpcom.263xmail.com';// 设置SMTP地址 idsmtp1.Port :=25; if idsmtp1.Connected = False then begin try idsmtp1.Connect; except Exit; // 连接失败 的话 退出该执行过程 end; end; end; procedure TFrm_op_seae_edi_NB.bsSkinButton1Click(Sender: TObject); begin SendFile; end; procedure TFrm_op_seae_edi_NB.bsSkinButton2Click(Sender: TObject); begin HasM:=False; MakeVGM(BWTYPE.ItemIndex); if HasM then Exit; if SaveDialog1.Execute then begin XMLDocument1.SaveToFile(SaveDialog1.FileName+'.XML'); XMLDocument1.Active:=False; showmessage('文件生成成功!'); end else begin showmessage('文件生成失败!'); exit; end; end; procedure TFrm_op_seae_edi_NB.sendmail; begin with IdMessage1 do begin Body.Clear; // 先清空上次发送的内容 CharSet :='GB2312'; // 不设置这个中文会乱码 Subject :='申请发送VGM-主提单号: '+frm_op_seae.t_op_seae.fieldbyname('主提单号').AsString+' '+GetCustCode(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString); // 设置邮件发送的标题 Body.Text := '公司名称:'+GetCompany+#13#10+'申请人:'+employee+#13#10+'邮箱:'+#13#10 +'电话:'+GetTelVGM(employee)+#13#10+'主提单号:'+frm_op_seae.t_op_seae.fieldbyname('主提单号').AsString; //设置邮件发送的内容 From.Address := 'admin@dongshengsoft.com'; //设置发件人 Recipients.EMailAddresses :='dongshengsoft@dongshengsoft.com'; //设置收件人 TIdAttachmentFile.Create(MessageParts,RequestFile); end; try idsmtp1.Send(IdMessage1); except end; end; function FormatEncodeDate(s:string):string; begin Result:=StringReplace(s,' ','+',[rfreplaceall]); Result:=StringReplace(Result,':','%3a',[rfreplaceall]); end; function URLEncode(const S: string; const InQueryString: Boolean): string; var Idx: Integer; begin Result := ''; for Idx := 1 to Length(S) do begin case S[Idx] of 'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.': Result := Result + S[Idx]; ' ': if InQueryString then Result := Result + '+' else Result := Result + '%20'; else Result := Result + '%' + SysUtils.IntToHex(Ord(S[Idx]), 2); end; end; end; procedure TFrm_op_seae_edi_NB.SendFile; var s1,s2,s: string; IdHttp : TIdHTTP; Url : string;//请求地址 //返回信息 ResponseStream : TStringStream; ResponseStr: string; //请求信息 RequestStr : string; RequestStream : TStringStream; //请求参数 Realdate:TDateTime; Requestdate,RequestOrg,RequestSign:string; RequestContent,RequestDateSTamp:string; aQuery:TADOQuery; begin HasM:=false; //先检查有无本编号的发送记录 aQuery:=TADOQuery.Create(nil); aQuery.Connection:=frm_main.db; with aQuery do begin Close; SQL.Clear; SQL.Add('select * from t_op_state where 业务状态='+QuotedStr(BWTYPE.Items[BWTYPE.ItemIndex]+'已发送')+' and 编号='+quotedstr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString)+' order by 顺序'); Open; end; //有则提示,是否继续 没有点NO则继续 在后面发送成功再加入数据库 t_op_state表内 if aQuery.RecordCount>0 then begin if application.MessageBox(pchar('已经有本业务的'+BWTYPE.Items[BWTYPE.ItemIndex]+'发送记录,是否继续?'),'提示',mb_yesno)=idno then begin FreeAndNil(aQuery); Exit; end; end; MakeVGM(BWTYPE.ItemIndex); //有错误,退出 if HasM then Exit; //开始发送 IdHttp := TIdHTTP.Create(nil); idhttp.Request.ContentType:='application/x-www-form-urlencoded'; //TStringStream对象用于保存响应信息 ResponseStream := TStringStream.Create(''); RequestStream := TStringStream.Create(''); Realdate:=Now; //初始化各参数 Requestdate:=FormatDateTime('yyyy-mm-dd hh:mm:ss',Realdate); RequestDateSTamp:=FormatEncodeDate(Requestdate); RequestOrg:='dssoft' + 'ced93003-1577-4ff4-9fcf-73a52408eb36' + Requestdate; RequestSign:=UpperCase(MD5Print(MD5String(RequestOrg))); RequestContent:=URLEncode(EncodeString(XMLDocument1.XML.GetText),False); RequestFile:=IntToStr(GetJavaTime(Realdate))+'.XML'; XMLDocument1.SaveToFile(RequestFile); try Url := 'http://api.nbeport.com/router/rest' ; try //以流的方式提交参数 RequestStr:='user_id=dssoft&format=json×tamp='+RequestDateSTamp+'&sign='+RequestSign +'&method=cargoedi.demessage.msgrec.post&deaId='+t_sys_company.fieldbyname('VGM发送代码').AsString +'&userId=dssoft&docName='+RequestFile+'&docType='+filetype+'&docLength='+IntToStr(Length(RequestContent)) +'&docContent='+RequestContent+'&channel=WSTOM&destDeaId='+ GetShipVGM(frm_op_seae.t_op_seae.fieldbyname('船公司').AsString) +'&port=CNTAO'; RequestStream.WriteString(RequestStr); IdHttp.Post(Url,RequestStream,ResponseStream); except on e : Exception do begin ShowMessage(e.Message); end; end; //获取网页返回的信息 ResponseStr := ResponseStream.DataString; //网页中的存在中文时,需要进行UTF8解码 ResponseStr := UTF8Decode(ResponseStr); //发送成功,t_op_state表添加记录 if (Pos('T',ResponseStr)>0) then begin if WJGN.ItemIndex=0 then s:='新增'; if WJGN.ItemIndex=1 then s:='修改'; if WJGN.ItemIndex=2 then s:='取消'; with aQuery do begin Close; SQL.Clear; SQL.Add('insert into t_op_state (编号,业务状态,是否完成,完成时间,录入日期,完成人,录入人,备注,系统加入) values (' +QuotedStr(frm_op_seae.t_op_seae.fieldbyname('编号').AsString)+','+QuotedStr(BWTYPE.Items[BWTYPE.ItemIndex]+'已发送')+',1,' +QuotedStr(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now))+','+QuotedStr(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now))+',' +QuotedStr(employee)+','+QuotedStr(employee)+','+QuotedStr(s)+',1)'); ExecSQL; end; FreeAndNil(aQuery); //发送一封邮件 if BWTYPE.ItemIndex=2 then sendmail; //ShowMessage(ResponseStr); ShowMessage('提交成功!') ; end else ShowMessage('提交失败!'); //ShowMessage(ResponseStr);// DeleteFile(RequestFile); finally IdHttp.Free; RequestStream.Free; ResponseStream.Free; end; end; procedure TFrm_op_seae_edi_NB.CheckBox1Click(Sender: TObject); var ini:TIniFile; begin ini:= Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); if CheckBox1.Checked then begin Label2.Visible:=True; Edit1.Visible:=True; Edit1.Text:=ini.ReadString('COSCO','Sale',''); end else begin Label2.Visible:=False; Edit1.Visible:=False; ini.WriteString('COSCO','Sale',Edit1.Text); end; ini.Free; end; procedure TFrm_op_seae_edi_NB.FormClose(Sender: TObject; var Action: TCloseAction); var ini:TIniFile; begin if Trim(Edit1.Text)<>'' then begin ini:= Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); ini.WriteString('COSCO','Sale',Edit1.Text); ini.Free; end; end; function TFrm_op_seae_edi_NB.GetCustCode(CorpID: string): string; var i:integer; aQuery:TADOQuery; begin Result:=CorpID; aQuery:=createADOQuery; with aQuery do try Close;SQL.Clear; SQL.Add('select 代码 from t_crm_client where 客户简称='''+CorpID+''''); Open; Result:=fieldByName('代码').AsString finally FreeAndNil(aQuery); end; end; end.