unit u_op_seae_feerp; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, dxDBTLCl, dxGrClms, ComCtrls, bsSkinTabs, bsSkinCtrls, Menus, kbmMemTable, kbmMemBinaryStreamFormat, Grids, DBGrids, ExtCtrls,ShellAPI, Excels, StdCtrls, Mask, wwdbedit, Wwdotdot, Wwdbcomb, RxLookup, wwdbdatetimepicker, wwdblook; type Tfrm_op_seae_feerp = class(TForm) bsSkinPanel1: TbsSkinPanel; PopupMenu2: TPopupMenu; N10: TMenuItem; N11: TMenuItem; N14: TMenuItem; N15: TMenuItem; N16: TMenuItem; bsSkinButton9: TbsSkinButton; t_op_seae: TADOQuery; memtblnostart: TkbmMemTable; memtblnostart1: TDataSource; kbmThreadDataSet1: TkbmThreadDataSet; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; bsSkinButton8: TbsSkinButton; PopupMenu1: TPopupMenu; EXCEL1: TMenuItem; N1: TMenuItem; EMAIL: TMenuItem; N3: TMenuItem; N4: TMenuItem; SaveDialog: TSaveDialog; Excel2: TExcel; t_excel_bill: TADOQuery; t_excel_billEX_ID: TAutoIncField; t_excel_billDSDesigner: TStringField; t_excel_billDSDesigner2: TStringField; t_excel_billDSDesigner3: TBlobField; t_excel_bill_bill: TADOQuery; t_excel_bill1: TDataSource; dxDBGrid1: TdxDBGrid; dxDBGridMaskColumn4: TdxDBGridMaskColumn; dxDBGrid1Column20: TdxDBGridColumn; dxDBGrid1Column22: TdxDBGridColumn; memtblnostartField: TIntegerField; memtblnostartField20GP: TIntegerField; memtblnostartField40HC: TIntegerField; dxDBGrid1Column23: TdxDBGridColumn; bsSkinPanel3: TbsSkinPanel; bsSkinPanel2: TbsSkinPanel; bsSkinButton10: TbsSkinButton; bsSkinButton5: TbsSkinButton; Label125: TLabel; wwDBLookupCombo49: TwwDBLookupCombo; Label30: TLabel; Edit7: TEdit; Label16: TLabel; wwDBDateTimePicker11: TwwDBDateTimePicker; Label17: TLabel; wwDBDateTimePicker12: TwwDBDateTimePicker; Label20: TLabel; RxDBLookupCombo22: TRxDBLookupCombo; Label124: TLabel; RxDBLookupCombo8: TRxDBLookupCombo; Label8: TLabel; RxDBLookupCombo6: TRxDBLookupCombo; memtblnostartField40GP: TIntegerField; memtblnostartField2: TStringField; memtblnostartField3: TStringField; memtblnostartField4: TFloatField; memtblnostartField5: TFloatField; memtblnostartTHC: TFloatField; memtblnostartField6: TFloatField; memtblnostartField7: TFloatField; memtblnostartField8: TFloatField; memtblnostartField9: TFloatField; memtblnostartCOD: TFloatField; memtblnostartField10: TFloatField; memtblnostartField11: TFloatField; memtblnostartField12: TFloatField; memtblnostartFloatField: TFloatField; memtblnostartField13: TFloatField; dxDBGrid1Column17: TdxDBGridColumn; dxDBGrid1Column18: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; dxDBGrid1Column8: TdxDBGridColumn; dxDBGrid1Column9: TdxDBGridColumn; dxDBGrid1Column10: TdxDBGridColumn; dxDBGrid1Column11: TdxDBGridColumn; dxDBGrid1Column12: TdxDBGridColumn; dxDBGrid1Column13: TdxDBGridColumn; dxDBGrid1Column14: TdxDBGridColumn; dxDBGrid1Column15: TdxDBGridColumn; dxDBGrid1Column16: TdxDBGridColumn; dxDBGrid1Column19: TdxDBGridColumn; dxDBGrid1Column21: TdxDBGridColumn; dxDBGrid1Column24: TdxDBGridColumn; memtblnostartField14: TStringField; memtblnostartField15: TStringField; dxDBGrid1Column25: TdxDBGridColumn; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure RadioGroup1Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton8Click(Sender: TObject); procedure N4Click(Sender: TObject); procedure EXCELClick(Sender: TObject); procedure EMAILClick(Sender: TObject); private procedure Creatememtbl; function getportcname(ename:string):string; // function SendEMail(Handle : THandle; Mail : TStrings):Cardinal; { Private declarations } public { Public declarations } end; var frm_op_seae_feerp: Tfrm_op_seae_feerp; implementation uses u_main, my_sys_function, u_op_seae_excel, u_data_share; {$R *.dfm} procedure Tfrm_op_seae_feerp.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_op_seae_feerp.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid1,caption); // savereggrid(dxdbgrid6,caption); // savereggrid(dxdbgrid9,caption); frm_op_seae_feerp.Hide; frm_op_seae_feerp.ManualFloat(frm_op_seae_feerp.BoundsRect ); frm_main.freeTabs('frm_op_seae_feerp'); action:=cafree; frm_op_seae_feerp:=nil; end; procedure Tfrm_op_seae_feerp.FormShow(Sender: TObject); var NewMenuItem:TMenuItem; begin loadreggrid(dxdbgrid1,false,caption); t_excel_bill.Close; t_excel_bill.SQL.Text:='select * from t_sys_excel where 属性=''客户收费清单'''; t_excel_bill.Open; with t_excel_bill do begin disablecontrols ; first ; while not eof do begin NewMenuItem:=TMenuItem.Create(Self); NewMenuItem.Name:='A'+fieldbyname('EX_ID').asString ; NewMenuItem.Caption:=fieldbyname('名称').asstring ; NewMenuItem.Tag:=fieldbyname('EX_ID').asinteger ; NewMenuItem.OnClick:=EXCELClick; EXCEL1.add(NewMenuItem); NewMenuItem:=TMenuItem.Create(Self); NewMenuItem.Name:='B'+fieldbyname('EX_ID').asString ; NewMenuItem.Caption:=fieldbyname('名称').asstring ; NewMenuItem.Tag:=fieldbyname('EX_ID').asinteger ; NewMenuItem.OnClick:=EMAILClick; EMAIL.add(NewMenuItem); Next ; end ; enablecontrols ; end ; end; procedure Tfrm_op_seae_feerp.RadioGroup1Click(Sender: TObject); var str:widestring; begin end; procedure Tfrm_op_seae_feerp.bsSkinButton9Click(Sender: TObject); begin sys_print('订舱信息统计',2,nil,nil,nil,nil,nil,memtblnostart1,nil,nil,nil,nil,nil); end; procedure Tfrm_op_seae_feerp.bsSkinButton10Click(Sender: TObject); var str:string; i:Integer; aQuery:TADOQuery; begin if RxDBLookupCombo6.DisplayValue='' then begin ShowMessage('客户名称不能为空!'); Exit; end; t_op_seae.Close; str:='where t_ch_fee.客户名称='+''''+RxDBLookupCombo6.DisplayValues[1]+''''; if edit7.text<>'' then str:=str+' and t_op_seae.航次 like '+''''+'%'+Edit7.text+'%'+''''; if wwDBLookupCombo49.text<>''then str:=str+' and t_op_seae.船名 like '+''''+'%'+wwDBLookupCombo49.text+'%'+''''; if wwDBDateTimePicker11.text<>''then str:=str+' and t_op_seae.开船日期>='+''''+wwDBDateTimePicker11.text+''''; if wwDBDateTimePicker12.text<>''then str:=str+' and t_op_seae.开船日期<='+''''+wwDBDateTimePicker12.text+''''; if RxDBLookupCombo22.DisplayValue<>''then str:=str+' and t_op_seae.装港代码='+''''+RxDBLookupCombo22.DisplayValues[2]+''''; if RxDBLookupCombo8.DisplayValue<>''then str:=str+' and t_op_seae.卸货代码='+''''+RxDBLookupCombo8.DisplayValues[2]+''''; t_op_seae.sql.text:='SELECT t_ch_fee.编号, t_ch_fee.客户名称, t_ch_fee.费用名称,t_ch_fee.币别,t_ch_fee.付费方式,t_ch_fee.金额,' +'t_ch_fee.结算金额 as 已收金额,(t_ch_fee.金额-t_ch_fee.结算金额) as 未收金额,' +'t_ch_fee.标准 as 标准,t_ch_fee.单价 as 单价,t_ch_fee.数量 as 数量,t_ch_fee.备注 as 费用备注,' +'t_op_seae.主提单号,t_op_seae.航次, t_op_seae.船名, t_op_seae.开船日期,t_op_seae.委托单位,' +'t_op_seae.装货港, t_op_seae.卸货港, ' +'t_op_seae.箱型1, t_op_seae.箱型2, t_op_seae.箱型3' +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 ' +str+' and t_ch_fee.类型='+''''+'收'+''''; t_op_seae.open; memtblnostart.Close; memtblnostart.Open; t_op_seae.First; i:=1; aQuery:=CreateAdoQuery; try while not t_op_seae.Eof do begin if not memtblnostart.Locate('编号',t_op_seae.fieldbyname('编号').AsString,[]) then begin memtblnostart.Insert; memtblnostart.FieldByName('序号').AsInteger:=i; memtblnostart['编号']:=t_op_seae['编号']; memtblnostart['主提单号']:=t_op_seae['主提单号']; memtblnostart['卸货港']:=t_op_seae['卸货港']; memtblnostart['委托单位']:=t_op_seae['委托单位']; memtblnostart['20GP']:=t_op_seae['箱型1']; memtblnostart['40GP']:=t_op_seae['箱型2']; memtblnostart['40HC']:=t_op_seae['箱型3']; memtblnostart.FieldByName('到付海运费').AsFloat:=0; memtblnostart.FieldByName('预付海运费').AsFloat:=0; memtblnostart.FieldByName('THC').AsFloat:=0; memtblnostart.FieldByName('电放费').AsFloat:=0; memtblnostart.FieldByName('安检费').AsFloat:=0; memtblnostart.FieldByName('并票费').AsFloat:=0; memtblnostart.FieldByName('分票费').AsFloat:=0; memtblnostart.FieldByName('COD改港费').AsFloat:=0; memtblnostart.FieldByName('更改费').AsFloat:=0; memtblnostart.FieldByName('换单费').AsFloat:=0; memtblnostart.FieldByName('铅封费').AsFloat:=0; memtblnostart.FieldByName('文件费').AsFloat:=0; memtblnostart.FieldByName('其他费用').AsFloat:=0; memtblnostart.Post; Inc(i); end; memtblnostart.Edit; if t_op_seae.FieldByName('费用名称').AsString='海运费' then begin if t_op_seae.FieldByName('付费方式').AsString='CC' then memtblnostart.FieldByName('到付海运费').AsFloat:=memtblnostart.FieldByName('到付海运费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat else memtblnostart.FieldByName('预付海运费').AsFloat:=memtblnostart.FieldByName('预付海运费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='THC' then begin memtblnostart.FieldByName('THC').AsFloat:=memtblnostart.FieldByName('THC').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='电放费' then begin memtblnostart.FieldByName('电放费').AsFloat:=memtblnostart.FieldByName('电放费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='安检费' then begin memtblnostart.FieldByName('安检费').AsFloat:=memtblnostart.FieldByName('安检费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='并票费' then begin memtblnostart.FieldByName('并票费').AsFloat:=memtblnostart.FieldByName('并票费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='分票费' then begin memtblnostart.FieldByName('分票费').AsFloat:=memtblnostart.FieldByName('分票费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='COD改港费' then begin memtblnostart.FieldByName('COD改港费').AsFloat:=memtblnostart.FieldByName('COD改港费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='更改费' then begin memtblnostart.FieldByName('更改费').AsFloat:=memtblnostart.FieldByName('更改费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='换单费' then begin memtblnostart.FieldByName('换单费').AsFloat:=memtblnostart.FieldByName('换单费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='铅封费' then begin memtblnostart.FieldByName('铅封费').AsFloat:=memtblnostart.FieldByName('铅封费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='文件费' then begin memtblnostart.FieldByName('文件费').AsFloat:=memtblnostart.FieldByName('文件费').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; if t_op_seae.FieldByName('费用名称').AsString='其他费用' then begin memtblnostart.FieldByName('其他费用').AsFloat:=memtblnostart.FieldByName('其他费用').AsFloat+t_op_seae.fieldbyname('金额').AsFloat; end; memtblnostart.Post; t_op_seae.Next; end; finally FreeAndNil(aQuery); end; memtblnostart.SortOn('序号',[]); end; procedure Tfrm_op_seae_feerp.Creatememtbl; begin end; procedure Tfrm_op_seae_feerp.bsSkinButton8Click(Sender: TObject); var Pnt:Tpoint; begin Pnt:=bsSkinButton8.ClientToScreen(Point(0,bsSkinButton8.Height)); PopupMenu1.Popup(Pnt.x,Pnt.y); end; procedure Tfrm_op_seae_feerp.N4Click(Sender: TObject); begin if t_op_SEAE.IsEmpty then exit; try frm_op_seae_excel:=tfrm_op_seae_excel.Create (self); frm_op_seae_excel.tradetype:='客户收费清单'; frm_op_seae_excel.data1.dataset:=memtblnostart; frm_op_seae_excel.ShowModal; finally frm_op_seae_excel.Free; end; end; procedure Tfrm_op_seae_feerp.EXCELClick(Sender: TObject); var str:Tstringlist; wide_str:widestring; i:integer; Y,j,GP20,GP40,HC40:INTEGER; YFHYF,DFHYF,DFF,THC,AJF,BPF,FPF,COD,GGF,HDF,QFF,WJF,QTF:Double; begin if t_excel_bill.IsEmpty then exit; t_excel_bill.Locate('EX_ID',TMenuItem(Sender).tag,[]); t_excel_billDSDesigner3.SaveToFile(ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.xls'); str:=Tstringlist.Create; str.Clear; excel2.Connect; Excel2.Exec('[open('+'"'+ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.xls'+'"'+')]'); memtblnostart.First; t_excel_bill_bill.Open; i:=0; J:=0; GP20:=0; GP40:=0; while not memtblnostart.Eof do begin Y:=memtblnostart.fieldbyname('序号').AsInteger; t_excel_bill_bill.First; while not t_excel_bill_bill.eof do begin if trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)<>'固定值'then begin if (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='序号') or (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='主提单号') or (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='委托单位') or (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='卸货港') or (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='20GP') or (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='40GP') or (trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)='40HC') then begin excel2.putstr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i, t_excel_bill_bill.fieldbyname('坐标X').asinteger, memtblnostart.fieldbyname(t_excel_bill_bill.fieldbyname('字段名称').asstring).asstring); end else begin excel2.PutExt(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i, t_excel_bill_bill.fieldbyname('坐标X').asinteger, memtblnostart.fieldbyname(t_excel_bill_bill.fieldbyname('字段名称').asstring).AsFloat); end; end else begin excel2.putstr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i, t_excel_bill_bill.fieldbyname('坐标X').asinteger, trim(t_excel_bill_bill.fieldbyname('固定值').asstring)); end; t_excel_bill_bill.next; end; i:=i+1; J:=memtblnostart.fieldbyname('序号').AsInteger; GP20:=GP20+memtblnostart.FieldByName('20GP').AsInteger; GP40:=GP40+memtblnostart.FieldByName('40GP').AsInteger; HC40:=HC40+memtblnostart.FieldByName('40HC').AsInteger; DFHYF:=DFHYF+memtblnostart.FieldByName('到付海运费').AsFloat; YFHYF:=YFHYF+memtblnostart.FieldByName('预付海运费').AsFloat; THC:=THC+memtblnostart.FieldByName('THC').AsFloat; DFF:=DFF+memtblnostart.FieldByName('电放费').AsFloat; AJF:=AJF+memtblnostart.FieldByName('安检费').AsFloat; BPF:=BPF+memtblnostart.FieldByName('并票费').AsFloat; FPF:=FPF+memtblnostart.FieldByName('分票费').AsFloat; COD:=COD+memtblnostart.FieldByName('COD改港费').AsFloat; GGF:=GGF+memtblnostart.FieldByName('更改费').AsFloat; HDF:=HDF+memtblnostart.FieldByName('换单费').AsFloat; QFF:=QFF+memtblnostart.FieldByName('铅封费').AsFloat; WJF:=WJF+memtblnostart.FieldByName('文件费').AsFloat; QTF:=QTF+memtblnostart.FieldByName('其他费用').AsFloat; memtblnostart.Next; end; excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,3,'合计'); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,5,IntToStr(GP20)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,6,IntToStr(GP40)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,7,IntToStr(HC40)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,8,'$'+floattostr(YFHYF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,9,'$'+floattostr(DFHYF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,10,'¥'+floattostr(THC)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,11,'¥'+floattostr(DFF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,12,'¥'+floattostr(AJF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,13,'¥'+floattostr(BPF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,14,'¥'+floattostr(FPF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,15,'¥'+floattostr(COD)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,16,'¥'+floattostr(GGF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,17,'¥'+floattostr(HDF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,18,'¥'+floattostr(QFF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,19,'¥'+floattostr(WJF)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,20,'¥'+floattostr(QTF)); excel2.PutStr(2,1,'MV.'+t_op_seae.fieldbyname('船名').asstring+' '+t_op_seae.fieldbyname('航次').asstring); excel2.PutStr(3,1,'ETD SHA:'+formatdatetime('YYYY-MM-DD',t_op_seae.fieldbyname('开船日期').asdatetime)); SaveDialog.Filter := '(*.xls)|*.xls'; SaveDialog.FileName := t_excel_bill.fieldbyname('名称').asstring+'.xls'; if SaveDialog.Execute then begin excel2.Exec('[SAVE.AS("'+SaveDialog.FileName+'";1;"";false;"";false)]'); excel2.Exec('[CLOSE(false)]'); excel2.Exec('[open("'+SaveDialog.FileName+'")]'); excel2.Exec('[APP.maxIMIZE()]'); //最大化excel end; deletefile(ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.xls'); end; { function Tfrm_op_railway_daterp.SendEMail(Handle : THandle; Mail : TStrings):Cardinal; TYPE TAttachAccessArray = ARRAY [0..0] OF TMapiFileDesc; PAttachAccessArray = ^TAttachAccessArray; VAR MapiMessage : TMapiMessage; Receip : TMapiRecipDesc; Attachments : PAttachAccessArray; AttachCount : INTEGER; iCount : INTEGER; FileName : STRING; BEGIN fillChar(MapiMessage, SizeOf(MapiMessage), #0); Attachments := NIL; fillChar(Receip,SizeOf(Receip), #0); IF Mail.Values['to'] <> '' THEN BEGIN Receip.ulReserved := 0; Receip.ulRecipClass := MAPI_TO; Receip.lpszName := StrNew(PChar(Mail.Values['to'])); Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to'])); Receip.ulEIDSize := 0; MapiMessage.nRecipCount := 1; MapiMessage.lpRecips := @Receip; END; AttachCount := 0; FOR iCount := 0 TO MaxInt DO BEGIN IF Mail.Values['attachment' + IntToStr(iCount)] = '' THEN BREAK; AttachCount := AttachCount + 1; END; IF AttachCount > 0 THEN BEGIN GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount); FOR iCount := 0 TO (AttachCount - 1) DO BEGIN FileName := Mail.Values['attachment' + IntToStr(iCount)]; Attachments[iCount].ulReserved := 0; Attachments[iCount].flFlags := 0; Attachments[iCount].nPosition := ULONG($FFFFFFFF); Attachments[iCount].lpszPathName := StrNew(PChar(FileName)); Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName))); Attachments[iCount].lpFileType := NIL; END; MapiMessage.nFileCount := AttachCount; MapiMessage.lpFiles := @Attachments^; END; IF Mail.Values['subject'] <> '' THEN MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject'])); IF Mail.Values['body'] <> '' THEN MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body'])); Result := MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0); FOR iCount := 0 TO (AttachCount - 1) DO BEGIN strDispose(Attachments[iCount].lpszPathName); strDispose(Attachments[iCount].lpszFileName); END; IF assigned(MapiMessage.lpszSubject) THEN strDispose(MapiMessage.lpszSubject); IF assigned(MapiMessage.lpszNoteText) THEN strDispose(MapiMessage.lpszNoteText); IF assigned(Receip.lpszAddress) THEN strDispose(Receip.lpszAddress); IF assigned(Receip.lpszName) THEN strDispose(Receip.lpszName); END; } procedure Tfrm_op_seae_feerp.EMAILClick(Sender: TObject); var str:Tstringlist; wide_str,filename:widestring; i:integer; Y,j,GP20,GP40:INTEGER; begin if t_excel_bill.IsEmpty then exit; t_excel_bill.Locate('EX_ID',TMenuItem(Sender).tag,[]); t_excel_billDSDesigner3.SaveToFile(ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.xls'); str:=Tstringlist.Create; str.Clear; excel2.Connect; Excel2.Exec('[open('+'"'+ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.xls'+'"'+')]'); memtblnostart.First; t_excel_bill_bill.Open; i:=0; J:=0; GP20:=0; GP40:=0; while not memtblnostart.Eof do begin Y:=memtblnostart.fieldbyname('序号').AsInteger; t_excel_bill_bill.First; while not t_excel_bill_bill.eof do begin if trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)<>'固定值'then begin if trim(t_excel_bill_bill.fieldbyname('字段名称').asstring)<>'序号'then begin excel2.putstr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i, t_excel_bill_bill.fieldbyname('坐标X').asinteger, memtblnostart.fieldbyname(t_excel_bill_bill.fieldbyname('字段名称').asstring).asstring); end else begin if J<>Y then begin excel2.putstr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i, t_excel_bill_bill.fieldbyname('坐标X').asinteger, memtblnostart.fieldbyname(t_excel_bill_bill.fieldbyname('字段名称').asstring).asstring); end; end; end else begin excel2.putstr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i, t_excel_bill_bill.fieldbyname('坐标X').asinteger, trim(t_excel_bill_bill.fieldbyname('固定值').asstring)); end; t_excel_bill_bill.next; end; i:=i+1; J:=memtblnostart.fieldbyname('序号').AsInteger; if memtblnostart.FieldByName('20GP').AsInteger=1 then begin GP20:=GP20+1; end else begin GP40:=GP40+1; end; memtblnostart.Next; end; excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,2,'合计'); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,4,IntToStr(GP20)); excel2.PutStr(t_excel_bill_bill.fieldbyname('坐标Y').asinteger+i+2,5,IntToStr(GP40)); excel2.PutStr(1,1,'订舱信息('+memtblnostart.fieldbyname('发列站点').AsString+'口岸)'); filename:=ExtractFilePath(application.ExeName)+'订舱信息'+formatdatetime('YYYYMMDDSS',Now)+'.XLS'; excel2.Exec('[SAVE.AS("'+filename+'";0;"";false;"";false)]'); excel2.Exec('[CLOSE(false)]'); // shellexecute(handle,'open',pchar(''+Logininfo.foxmail+''),pchar(''+ExtractFilePath(application.ExeName)+'订舱信息'+formatdatetime('YYYYMMDDSS',Now)+'.XLS'+''),nil,sw_shownormal); { frmsendmail:=Tfrmsendmail.Create(Self); try frmsendmail.Edit4.Text:=filename; frmsendmail.ShowModal; finally FreeAndNil(frmsendmail); end; } deletefile(filename); deletefile(ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.xls'); // filename:='"'+filename+'"'; // ShellExecute(1,pchar('Open'),PChar('D:\Program Files\Foxmail 7.0\Foxmail.exe'),pchar(filename),'',SW_SHOW); { mail := TStringList.Create; try mail.values['attachment0'] :=filename; sendEMail(Application.Handle, mail); finally mail.Free; end; } // filename:='"'+filename+'"'; // excel2.Exec('[open("'+SaveDialog.FileName+'")]'); // excel2.Exec('[APP.maxIMIZE()]'); //最大化excel // ShellExecute(1,pchar('Open'),PChar('mailto:xxx@xx?subject'),pchar(filename),'',SW_SHOW); // ShellExecute(Self.Handle, nil,PChar('mailto:xxx@xx?&Attach='+filename+''),nil,nil,1); end; function Tfrm_op_seae_feerp.getportcname(ename: string): string; var aQuery:TADOQuery; begin result:=ename; aQuery:=CreateAdoQuery; try with aQuery do begin sql.Add('select 中文名 from t_code_loaport where 英文名='''+ename+''''); Open; if not IsEmpty then result:=fieldbyname('中文名').AsString; end; finally FreeAndNil(aQuery); end; end; end.