unit crm_OnLineShippingOrder; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, BusinessSkinForm, bsSkinCtrls, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, dxDBTLCl, dxGrClms, Grids, DBGridEh, StdCtrls, Mask, bsSkinBoxCtrls,u_op_seae_DsWebService,SoapHTTPClient,InvokeRegistry, Menus, kbmMemTable,my_sys_function; type Tfrm_crm_OnLineShippingOrder = class(TForm) bsSkinPanel2: TbsSkinPanel; bsSkinPanel3: TbsSkinPanel; bsSkinButton1: TbsSkinButton; dxdbgrd1: TdxDBGrid; bsBusinessSkinForm1: TbsBusinessSkinForm; ds1: TDataSource; qryInsert: TADOQuery; dxdbgrd1Column2: TdxDBGridColumn; dxdbgrd1Column3: TdxDBGridColumn; dxdbgrd1Column5: TdxDBGridColumn; dxdbgrd1Column6: TdxDBGridColumn; qrysearch: TADOQuery; MT2: TkbmMemTable; StringField1: TStringField; StringField2: TStringField; StringField3: TStringField; StringField4: TStringField; StringField5: TStringField; StringField6: TStringField; StringField7: TStringField; StringField8: TStringField; StringField9: TStringField; StringField10: TStringField; StringField11: TStringField; StringField12: TStringField; StringField13: TStringField; StringField14: TStringField; StringField15: TStringField; dxdbgrd1Column7: TdxDBGridColumn; dxdbgrd1Column8: TdxDBGridColumn; dxdbgrd1Column9: TdxDBGridColumn; dxdbgrd1Column11: TdxDBGridColumn; bsSkinButton3: TbsSkinButton; t_ch_fee: TADOQuery; bsSkinButton10: TbsSkinButton; qryGetOpseae: TADOQuery; qryGetOpseae2: TADOQuery; qryGetCompany: TADOQuery; MT1: TkbmMemTable; MT1BSNO: TStringField; MT1BSSTATUS: TStringField; MT1BSDATE: TStringField; MT1MBLNO: TStringField; MT1CUSTNO: TStringField; MT1SHIPPER: TStringField; MT1SHIPPERID: TStringField; MT1ETD: TStringField; MT1ETA: TStringField; MT1PORTLOADID: TStringField; MT1PORTDISCHARGEID: TStringField; MT1DESTINATIONID: TStringField; MT1INPUTBY: TStringField; MT1AUDITOR: TStringField; MT1FORWARDER: TStringField; MT1CARRIER: TStringField; MT1CtnInfo: TStringField; MT1CNTR: TStringField; MT1TimeMark: TStringField; MT1VESSEL: TStringField; MT1VOYNO: TStringField; MT1ISSUEPLACE: TStringField; MT1BOOKINGTYPE: TStringField; MT1OLDBSNO: TStringField; MT1CONSIGNEE: TStringField; MT1NOTIFYPARTY: TStringField; MT1DESCRIPTION: TStringField; MT1NOPKGS: TStringField; MT1PKGS: TStringField; MT1GROSSWEIGHT: TStringField; MT1KGS: TStringField; MT1MEASUREMENT: TStringField; MT1CBM: TStringField; MT1BOOKINGDESCRIPTION: TStringField; MT1PLACEDELIVERY: TStringField; MT1PLACEDELIVERYID: TStringField; MT1SERVICE: TStringField; MT1BLFRT: TStringField; MT1PORTLOAD: TStringField; MT1PORTDISCHARGE: TStringField; MT1DESTINATION: TStringField; MT1MARKS: TStringField; MT1TOTALNO: TStringField; MT1SENDERCOMPANY: TStringField; MT1SENDERCOMPANYID: TStringField; MT1SENDERNAME: TStringField; MT1CARGOID: TStringField; MT1COMPANYID: TStringField; MT1KINDPKGS: TStringField; MT1CLOSEDOCDATE: TStringField; procedure bsSkinButton1Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure dxdbgrd1DblClick(Sender: TObject); function UnformatAfrstr(str:string):string; procedure bsSkinButton3Click(Sender: TObject); procedure SaveBooking; procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); private XML,OPTYPE:String; OpSeaeCount:Integer; function REHH(str:string):string; public function GetXML(_OPTYPE:string):integer; overload; function GetXML:integer; overload; end; var frm_crm_OnLineShippingOrder: Tfrm_crm_OnLineShippingOrder; implementation uses u_op_seae, u_data_share, U_SelectLinkMan, u_sys_progress, u_main; //using {$R *.dfm} procedure Tfrm_crm_OnLineShippingOrder.bsSkinButton1Click(Sender: TObject); var _s,url:string; aa:DsWebServiceSoap; begin url:= get_WebseviceURL; aa:=GetDsWebServiceSoap(false,get_WebseviceURL);//'http://192.168.1.105:5427/webservice/DsWebService.asmx'); //首先获取订舱信息 _s:=''; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+frm_data_share.t_load_employee.fieldbyname('订舱系统序列号').asstring+' '; _s:=_s+' 1 '; _s:=_s+' '; _s:=_s+' 1.0 '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+MT1.fieldbyname('BSNO').asstring+' '; _s:=_s+' '; _s:=_s+' '; XML:=aa.SetBookingCargoSpaceAudit(_s); //XML:=aa.ReceiveBookingCargoSpace(_s); //Opseaecount:= frm_data_share.countString('Opseae',xml); //result:= Opseaecount; if (pos('成功',XML)>0) then begin ShowMessage('驳回成功'); MT1.Delete; MT1.Post; end else begin ShowMessage('驳回失败'); end; end; function Tfrm_crm_OnLineShippingOrder.GetXML(_OPTYPE:string): integer; var _s,url,block,CompanySPXNO:string; aa:DsWebServiceSoap; p1,p2:integer; begin OPTYPE:= _OPTYPE; if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.bsSkinGauge1.ProgressText:='正在获取数据请等候。。。'; frm_sys_progress.bsSkinGauge1.MaxValue:=100; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.Value:=0; qrysearch.Close; qrysearch.SQL.text:='select * from t_code_subcomp where 分部名称=(select 分部名称 from t_sys_employee where 姓名='''+employee+''')'; qrysearch.Open; CompanySPXNO:=qrysearch.fieldbyname('订舱系统序列号').asstring; try frm_data_share.t_load_employee.open; //qryGetCompany.close; //qryGetCompany.Parameters.ParamByName('分部名称').Value:= frm_data_share.t_load_employee.fieldbyname('分部名称').AsString; //qryGetCompany.open; url:= get_WebseviceURL; aa:=GetDsWebServiceSoap(false,get_WebseviceURL);//'http://192.168.1.105:5427/webservice/DsWebService.asmx'); //首先获取订舱信息 _s:=''; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+frm_data_share.t_load_employee.fieldbyname('订舱系统序列号').asstring+' '; _s:=_s+' '+CompanySPXNO+' '; _s:=_s+' '+OPTYPE+' '; _s:=_s+' '; _s:=_s+' 1.0 '; _s:=_s+' '; _s:=_s+' '; //ShowMessage(_s); XML:=aa.BusinessAction('ShippingOrder','Receive',_s); XML:=StringReplace(XML,'#$A','',[rfReplaceAll]); p1:=frm_data_share.GettimePotion(1,'',XML); p2:=frm_data_share.GettimePotion(1,'',xml); XML:=copy(XML,p1,p2-p1); //ShowMessage(XML); Opseaecount:= frm_data_share.countString('Opseae',xml); result:= Opseaecount; finally frm_sys_progress.Close; frm_sys_progress.Free; frm_sys_progress:=nil; if (XML='') then begin result:=0; //showmessage('没有连接到服务器'); end; end; end; function Tfrm_crm_OnLineShippingOrder.GetXML: integer; begin result:=GetXML(OPTYPE); end; procedure Tfrm_crm_OnLineShippingOrder.FormShow(Sender: TObject); var _ts:widestring; _s,Opseae,ctn,block,ctnblock,mes:string; ctncount,p1,p2,p3,p4,_i:integer; begin //1.计算有多少个opseae单元,并据此分块 MT1.close; if (OpSeaeCount=0) then begin ShowMessage('没有待接收的订舱信息。您可能需要<同步shippingbox信息>'); close; end else begin for _i:=1 to OpSeaeCount do begin p1:=frm_data_share.GettimePotion(_i,'',xml); p2:=frm_data_share.GettimePotion(_i,'',xml); block:=Copy(xml,p1,p2-p1); ctncount:=frm_data_share.countString('CTNINFO',block); if (ctncount>0) then begin p3:=frm_data_share.GettimePotion(1,'',block); //第一条 p4:=frm_data_share.GettimePotion(ctncount,'',block)+10; //最后一条 ctnblock:= Copy(block,p3,p4-p3); //把集装箱信息去掉 p2:=frm_data_share.GettimePotion(_i,'',xml); block:=Copy(xml,p1,p2-p1); end; MT1.Open; MT1.Edit; MT1.Insert; MT1['BSNO']:=frm_data_share.GetXMLValue('BSNO',block); MT1['MBLNO']:=frm_data_share.GetXMLValue('MBLNO',block); MT1['ETD']:=frm_data_share.GetXMLValue('ETD',block); MT1['CLOSINGDATE']:=frm_data_share.GetXMLValue('CLOSINGDATE',block); MT1['PORTDISCHARGEID']:=frm_data_share.GetXMLValue('PORTDISCHARGEID',block); MT1['PORTDISCHARGE']:=frm_data_share.GetXMLValue('PORTDISCHARGE',block); MT1['VESSEL']:=frm_data_share.GetXMLValue('VESSEL',block); MT1['VOYNO']:=frm_data_share.GetXMLValue('VOYNO',block); MT1['ReceiverCOMPANY']:=frm_data_share.GetXMLValue('ReceiverCOMPANY',block); MT1['ReceiverNAME']:=frm_data_share.GetXMLValue('ReceiverNAME',block); MT1['CNTR']:=frm_data_share.GetXMLValue('CNTR',block); MT1['TimeMark']:=frm_data_share.GetXMLValue('TIMEMARK',block); MT1['CLOSEDOCDATE']:=frm_data_share.GetXMLValue('CLOSEDOCDATE',block); MT1.Post; end; end; end; procedure Tfrm_crm_OnLineShippingOrder.SaveBooking; var _s,_t,_id,_no,block,xml,onlinetimemark,onlinePosted,mttimemark,url,kjqj,wtdw,ETD,CLOSINGDATE,CLOSEDOCDATE,BSNO:string; //保存 aa:DsWebServiceSoap; p1,p2,_c,_i,_r,_L:Integer; username,marks:string; UPDField,MTField:TStringList; begin username:=frm_data_share.t_load_employee.fieldbyname('姓名').asstring; UPDField:=TStringList.Create; MTField:=TStringList.Create; UPDField.Add('主提单号'); MTField.Add('MBLNO'); UPDField.Add('船名'); MTField.Add('VESSEL'); UPDField.Add('航次'); MTField.Add('VOYNO'); UPDField.Add('卸货港'); MTField.Add('PORTDISCHARGE'); UPDField.Add('截港日期'); MTField.Add('CLOSINGDATE'); UPDField.Add('截单日期'); MTField.Add('CLOSEDOCDATE'); UPDField.Add('开船日期'); MTField.Add('ETD'); if (MT1.fieldbyname('CLOSINGDATE').asstring='') then begin CLOSINGDATE:='null'; end else begin CLOSINGDATE:=StringReplace(''''+MT1.fieldbyname('CLOSINGDATE').asstring+'''','/','-',[rfReplaceAll]); end; if (MT1.fieldbyname('ETD').asstring='') then begin ETD:='null'; end else begin ETD:=StringReplace(''''+MT1.fieldbyname('ETD').asstring+'''','/','-',[rfReplaceAll]); end; if (MT1.fieldbyname('CLOSEDOCDATE').asstring='') then begin CLOSEDOCDATE:='null'; end else begin CLOSEDOCDATE:=StringReplace(''''+MT1.fieldbyname('CLOSEDOCDATE').asstring+'''','/','-',[rfReplaceAll]); end; BSNO:= MT1.fieldbyname('BSNO').AsString; _r:= MessageDlg('接受此票入货通知吗? '+#13#10+'选择“Yes”:提单号、船名/航次、卸货港、截港日期和开船日期 将会更新到本票业务当中'+#13#10+'选择“NO”:将不会覆盖您的现有内容,只更新目前未填的内容',mtWarning,[mbyes,mbno],0) ; case _r of mrYes:begin //2 查询该bsno的时间标签是否 url:= get_WebseviceURL; aa:=GetDsWebServiceSoap(false,url); _s:=' '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+BSNO+' '; _s:=_s+' '; _s:=_s+' '; xml:=aa.GetBsnoInfo(_s); p1:=frm_data_share.GettimePotion(1,'',xml); p2:=frm_data_share.GettimePotion(1,'',xml); block:=Copy(xml,p1,p2-p1); onlinetimemark:=frm_data_share.GetXMLValue('TimeMark',block); onlinePosted:=frm_data_share.GetXMLValue('ISPOSTED',block); mttimemark:=MT1.fieldbyname('TimeMark').AsString; if (onlinetimemark<>mttimemark) then begin ShowMessage('此条业务内容发生变化,请点击“重新查询”'); end else begin //if optype='1' Qrysearch.Close; Qrysearch.SQL.Text:='select * from t_op_seae where 订舱序列号='''+BSNO+''''; Qrysearch.Open; if (Qrysearch.RecordCount=0) then //0 新增 begin //判断该订舱序列号是否于系统内存在,如不存在则报警并退出。 showmessage('本业务于本系统中不存在,可能是该业务已被删除或发生变更,请联系相关业务人员。'); end else if (Qrysearch.RecordCount>0) then //1更新 begin qryGetOpseae2.Close; qryGetOpseae2.Parameters.ParamByName('订舱序列号').Value:=BSNO; qryGetOpseae2.Open; with Qryinsert do begin Close; //function WeekofYear(Date: TDate): integer; //取得当前日期的周次 _id:=qryGetOpseae2.fieldbyname('编号').asstring; _no:=get_no(Date,'SE'); kjqj:=inttostr(WeekofYear(Date)); sql.clear; //SQL.Add(' delete from t_op_ctn where 编号 in (select 编号 from t_op_seae where 订舱序列号='''+MT1.fieldbyname('OLDBSNO').asstring+''') '); SQL.Add(' update t_op_seae set '); SQL.Add(' 主提单号=:MBLNO, 开船日期='+ETD+', 截港日期='+CLOSINGDATE+', 卸货港=:PORTDISCHARGE'); SQL.Add(' ,卸货代码=:PORTDISCHARGEID '); SQL.Add(' ,船名=:VESSEL,航次=:VOYNO,截单日期='+CLOSEDOCDATE); SQL.Add(' where 订舱序列号=:BSNO'); Parameters.ParamByName('BSNO').Value:=BSNO; Parameters.ParamByName('MBLNO').Value:=MT1.fieldbyname('MBLNO').asstring; // Parameters.ParamByName('CUSTNO').Value:=_no;// //Parameters.ParamByName('ETD').Value:=MT1.fieldbyname('ETD').asstring; //Parameters.ParamByName('ETA').Value:=MT1.fieldbyname('ETA').asstring; Parameters.ParamByName('PORTDISCHARGE').Value:=MT1.fieldbyname('PORTDISCHARGE').asstring; Parameters.ParamByName('PORTDISCHARGEID').Value:=MT1.fieldbyname('PORTDISCHARGEID').asstring; Parameters.ParamByName('VESSEL').Value:=MT1.fieldbyname('VESSEL').asstring; Parameters.ParamByName('VOYNO').Value:=MT1.fieldbyname('VOYNO').asstring; // Parameters.ParamByName('CLOSEDOCDATE').Value:=MT1.fieldbyname('CLOSEDOCDATE').asstring; ExecSQL; end; //发送接收信息 _s:=''; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+frm_data_share.t_crm_client_weituo.fieldbyname('订舱系统序列号').asstring+' '; _s:=_s+' 3 ';//3 入货通知 _s:=_s+' '+datetimetostr(Date)+' '; _s:=_s+' 1.0 '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+BSNO+' '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '; XML:=aa.SetBookingCargoSpaceAudit(_s); MT1.Delete ; //记录日志 qryGetOpseae.Close; qryGetOpseae.Parameters.ParamByName('编号').Value:=_id; qryGetOpseae.Open; Booking_add(qryGetOpseae,_id,MT1.fieldbyname('ReceiverNAME').asstring,MT1.fieldbyname('ReceiverCOMPANY').asstring,BSNO,'接受入货通知'); showmessage('接收成功'); end end; end; mrNo:begin url:= get_WebseviceURL; aa:=GetDsWebServiceSoap(false,url); _s:=' '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+BSNO+' '; _s:=_s+' '; _s:=_s+' '; xml:=aa.GetBsnoInfo(_s); p1:=frm_data_share.GettimePotion(1,'',xml); p2:=frm_data_share.GettimePotion(1,'',xml); block:=Copy(xml,p1,p2-p1); onlinetimemark:=frm_data_share.GetXMLValue('TimeMark',block); onlinePosted:=frm_data_share.GetXMLValue('ISPOSTED',block); mttimemark:=MT1.fieldbyname('TimeMark').AsString; if (onlinetimemark<>mttimemark) then begin ShowMessage('此条业务内容发生变化,请点击“重新查询”'); end else begin //if optype='1' Qrysearch.Close; Qrysearch.SQL.Text:='select * from t_op_seae where 订舱序列号='''+BSNO+''''; Qrysearch.Open; if (Qrysearch.RecordCount=0) then //0 新增 begin //判断该订舱序列号是否于系统内存在,如不存在则报警并退出。 showmessage('本业务于本系统中不存在,可能是该业务已被删除或发生变更,请联系相关业务人员。'); end else if (Qrysearch.RecordCount>0) then //1更新 begin qryGetOpseae2.Close; qryGetOpseae2.Parameters.ParamByName('订舱序列号').Value:=BSNO; qryGetOpseae2.Open; _L:=UPDField.Count; for _i:=0 to _L-1 do begin with Qryinsert do begin Close; //function WeekofYear(Date: TDate): integer; //取得当前日期的周次 if qryGetOpseae2.FieldByName(UPDField[_i]).AsString<>'' then Continue; sql.clear; //SQL.Add(' delete from t_op_ctn where 编号 in (select 编号 from t_op_seae where 订舱序列号='''+MT1.fieldbyname('OLDBSNO').asstring+''') '); SQL.Add(' update t_op_seae set '); SQL.Add(UPDField[_i]+'=:'+MTField[_i]); //ShowMessage(UPDField[_i]+'=:'+MTField[_i]); SQL.Add(' where 订舱序列号=:BSNO'); Parameters.ParamByName('BSNO').Value:=BSNO; Parameters.ParamByName(MTField[_i]).Value:=MT1.fieldbyname(MTField[_i]).asstring; ExecSQL; end; end; //发送接收信息 _s:=''; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+frm_data_share.t_crm_client_weituo.fieldbyname('订舱系统序列号').asstring+' '; _s:=_s+' 3 ';//3 入货通知 _s:=_s+' '+datetimetostr(Date)+' '; _s:=_s+' 1.0 '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '+BSNO+' '; _s:=_s+' '; _s:=_s+' '; _s:=_s+' '; XML:=aa.SetBookingCargoSpaceAudit(_s); MT1.Delete ; //记录日志 qryGetOpseae.Close; qryGetOpseae.Parameters.ParamByName('编号').Value:=_id; qryGetOpseae.Open; Booking_add(qryGetOpseae,_id,MT1.fieldbyname('ReceiverNAME').asstring,MT1.fieldbyname('ReceiverCOMPANY').asstring,BSNO,'接受入货通知'); showmessage('接收成功'); end end; end; end; if frm_op_seae.t_op_seae2.DataSet<>nil then begin TADOQUERY(frm_op_seae.t_op_seae2.DataSet).Requery; frm_op_seae.t_op_seae.Locate('订舱序列号',BSNO,[]); end; end; function Tfrm_crm_OnLineShippingOrder.UnformatAfrstr(str: string): string; begin Result:=Trim(str); Result:=StringReplace(Result,'&','&',[rfReplaceAll]); Result:=StringReplace(Result,'<','<',[rfReplaceAll]); Result:=StringReplace(Result,'"','"',[rfReplaceAll]); Result:=StringReplace(Result,'>','>',[rfReplaceAll]); Result:=StringReplace(Result,''','''',[rfReplaceAll]); //Result:=StringReplace(Result,'\n;','#13#10',[rfReplaceAll]); end; function Tfrm_crm_OnLineShippingOrder.REHH(str: string): string; var _r:string; begin _r:=StringReplace (str, '\\\\', #13#10, [rfReplaceAll]); result:=_r; end; procedure Tfrm_crm_OnLineShippingOrder.bsSkinButton3Click(Sender: TObject); var _s,url:string; aa:DsWebServiceSoap; begin SaveBooking; end; procedure Tfrm_crm_OnLineShippingOrder.dxdbgrd1DblClick(Sender: TObject); begin SaveBooking; end; procedure Tfrm_crm_OnLineShippingOrder.bsSkinButton4Click(Sender: TObject); begin {try frm_SelectLinkMan:=Tfrm_SelectLinkMan.Create (self); frm_SelectLinkMan.ShowModal; finally frm_SelectLinkMan.Free; end;} end; procedure Tfrm_crm_OnLineShippingOrder.bsSkinButton10Click(Sender: TObject); begin GetXML(); FormShow(Sender); end; end.