unit u_op_seae_TaskContrast;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, iWebPDFEditorLib_TLB, ExtCtrls,
Buttons, DB, ADODB, bsSkinCtrls, DBCtrls, bsdbctrls, StdCtrls, RxLookup,
wwdbedit, Wwdotdot, Wwdbcomb, wwdbdatetimepicker, Mask, wwdblook,
ComCtrls, bsSkinTabs, Wwdbigrd, Wwdbgrid, Grids, DBGridEh, cxControls,
cxSplitter, Menus, ToolWin, ImgList, kbmMemTable,
IdAttachmentFile,IdText, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
IdMessageClient, IdSMTPBase, IdSMTP,IdMessage,IdAttachment, RXSplit,
dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid;
type
TfrmOpSeae_TaskContrast = class(TForm)
pnl1: TPanel;
qry_op_seae: TADOQuery;
ds_op_seae2: TDataSource;
lbl38: TLabel;
lbl39: TLabel;
lbl40: TLabel;
lbl41: TLabel;
lbl42: TLabel;
lbl43: TLabel;
lbl44: TLabel;
lbl45: TLabel;
lbl46: TLabel;
lbl47: TLabel;
lbl48: TLabel;
dbtxt1: TDBText;
btn5: TbsSkinSpeedButton;
lbl50: TLabel;
bsknpnl1: TbsSkinPanel;
lbldc: TLabel;
dbedt3: TDBEdit;
dbedt4: TDBEdit;
dbedt5: TDBEdit;
dbedt6: TDBEdit;
dbedt7: TDBEdit;
dbedt8: TDBEdit;
RxDBLookupCombo1: TRxDBLookupCombo;
dbedt9: TDBEdit;
dbedt10: TDBEdit;
dbedt11: TDBEdit;
dbedt12: TDBEdit;
dbedt13: TDBEdit;
scrlbx2: TScrollBox;
bsknpnl4: TbsSkinPanel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
lbl9: TLabel;
lbl10: TLabel;
lbl11: TLabel;
lbl12: TLabel;
lbl13: TLabel;
lbl15: TLabel;
lbl16: TLabel;
lbl17: TLabel;
lbl18: TLabel;
lbl19: TLabel;
lbl20: TLabel;
lbl22: TLabel;
lbl24: TLabel;
lbl25: TLabel;
lbl30: TLabel;
lbl31: TLabel;
lbl14: TLabel;
lbl21: TLabel;
lbl23: TLabel;
lbl26: TLabel;
lbl27: TLabel;
lbl28: TLabel;
lbl29: TLabel;
lbl4: TLabel;
lbl32: TLabel;
lbl33: TLabel;
lbl34: TLabel;
lbl35: TLabel;
lbl36: TLabel;
lbl37: TLabel;
dbedt1: TDBEdit;
wdbdtmpckr1: TwwDBDateTimePicker;
wdbdtmpckr2: TwwDBDateTimePicker;
wdbdtmpckr3: TwwDBDateTimePicker;
wdbdtmpckr4: TwwDBDateTimePicker;
wdbdtmpckr5: TwwDBDateTimePicker;
bskndbchckrdbx1: TbsSkinDBCheckRadioBox;
dbmmo4: TDBMemo;
dbmmo5: TDBMemo;
dbmmo6: TDBMemo;
dbmmo7: TDBMemo;
dbmmo8: TDBMemo;
dbedt2: TDBEdit;
dbmmo9: TDBMemo;
cxspltr1: TcxSplitter;
pnl4_jjx: TPanel;
bsknpnl2: TbsSkinPanel;
wdblkpcmb1: TwwDBLookupCombo;
dbgrdh1: TDBGridEh;
bsknpnl3: TbsSkinPanel;
lbl52: TLabel;
dbtxtTEU: TDBText;
lbl53: TLabel;
dbtxt2: TDBText;
dbtxt3: TDBText;
lbl54: TLabel;
dbtxt4: TDBText;
lbl55: TLabel;
lbl56: TLabel;
dbtxt5: TDBText;
bsknpnl5: TbsSkinPanel;
lbl58: TLabel;
dbtxtTEU1: TDBText;
lbl59: TLabel;
dbtxt6: TDBText;
dbtxt7: TDBText;
lbl60: TLabel;
dbtxt8: TDBText;
lbl61: TLabel;
lbl62: TLabel;
dbtxt9: TDBText;
dbedt14: TDBEdit;
dbedt15: TDBEdit;
dbedt16: TDBEdit;
dbedt17: TDBEdit;
dbedt18: TDBEdit;
dbedt19: TDBEdit;
dbedt20: TDBEdit;
dbedt21: TDBEdit;
dbedt22: TDBEdit;
dbedt23: TDBEdit;
dbedt24: TDBEdit;
dbedt25: TDBEdit;
dbedt26: TDBEdit;
dbedt29: TDBEdit;
dbedt30: TDBEdit;
dbedt32: TDBEdit;
dbedt33: TDBEdit;
dbedt35: TDBEdit;
dbmmo3: TDBMemo;
lbl3: TLabel;
lbl2: TLabel;
dbmmo2: TDBMemo;
lbl1: TLabel;
dbmmo1: TDBMemo;
dbedt34: TDBEdit;
dbedt36: TDBEdit;
dbedt27: TDBEdit;
dbedt28: TDBEdit;
dbedt31: TDBEdit;
pm1_tsk_vcMenu: TPopupMenu;
mni_mniN1Confirm: TMenuItem;
mni_mniN2ConfirmAndFinish: TMenuItem;
il1: TImageList;
tlb1: TToolBar;
btn1Forword: TToolButton;
btn2Confirm: TToolButton;
btnCancelTask: TToolButton;
btn12: TToolButton;
spl1: TSplitter;
wwDBGrid1: TwwDBGrid;
lbl57: TLabel;
il2_taskmenu: TImageList;
wwDBGrid: TwwDBGrid;
ds_op_ctn1: TDataSource;
qry_op_ctn: TADOQuery;
qry_op_ctndetail: TADOQuery;
ds_op_ctndetail1: TDataSource;
mailSend: TkbmMemTable;
strngfldSendStringField: TStringField;
strngfldSendField: TStringField;
strngfldSendField2: TStringField;
strngfldSendField3: TStringField;
strngfldSendField4: TStringField;
strngfldSendField5: TStringField;
strngfldSendField6: TStringField;
strngfldSendField7: TStringField;
iwbpdfdtr1: TiWebPDFEditor;
bsknpnl2_right: TbsSkinPanel;
scrlbx1: TScrollBox;
bsknpnl6_left: TbsSkinPanel;
cxspltr2: TcxSplitter;
btn1_RefreshPDF: TButton;
btn1pdfDownload: TSpeedButton;
spl2: TSplitter;
pnl2_td: TPanel;
pnl2_ch_fee_edi: TPanel;
qry1_op_seae_edi_mail_bcinfo: TADOQuery;
qry2_op_seae_edi_rp_iftmbc: TADOQuery;
ds1_op_seae_edi_mail_bcinfo: TDataSource;
ds2_op_seae_edi_rp_iftmbc: TDataSource;
pnl2_rptBC: TPanel;
lbl66: TLabel;
dbedtF_TSR_TSR: TDBEdit;
lbl67: TLabel;
dbedtF_DC0_LOC_ZAddrCode: TDBEdit;
lbl68: TLabel;
dbedtA: TDBEdit;
lbl69: TLabel;
lbl70: TLabel;
dbedtF_JGSHJ1: TDBEdit;
dbedtF_JDSHJ1: TDBEdit;
dbedtF_JGSHJ2: TDBEdit;
dbedtF_JDSHJ2: TDBEdit;
lbl72: TLabel;
lbl71: TLabel;
dbmmoF_WP_EQN_Num: TDBMemo;
lbl73: TLabel;
lbl74: TLabel;
dbedtF_DC0_LOC_XAddrCode: TDBEdit;
lbl75: TLabel;
dbedtF_DC0_LOC_XAddrCode1: TDBEdit;
lbl76: TLabel;
dbedtF_DC0_LOC_XAddrCode2: TDBEdit;
pnl2_BC: TPanel;
lbl49: TLabel;
lbl51: TLabel;
lbl63: TLabel;
lbl64: TLabel;
lbl65: TLabel;
lbl77: TLabel;
lbl78: TLabel;
dbedtF_HX: TDBEdit;
dbedtF_JGSHJ: TDBEdit;
dbedtF_JDSHJ: TDBEdit;
dbedtF_YZH: TDBEdit;
dbmmoF_EXT_IsMatchBusiRemark: TDBMemo;
dbedtF_CM: TDBEdit;
dbedtF_HC: TDBEdit;
lbl79: TLabel;
dbmmo10: TDBMemo;
btn1_ImportAssistInfo: TButton;
lbl80: TLabel;
dbedtF_ETD: TDBEdit;
lbl81: TLabel;
dbedtF_HYH: TDBEdit;
lbl82: TLabel;
lbl83: TLabel;
dbedt37: TDBEdit;
mmo1_extMatch: TMemo;
Label1: TLabel;
DBEdit1: TDBEdit;
ToolButton1: TToolButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure btnCoseClick(Sender: TObject);
procedure btnCancelTaskClick(Sender: TObject);
procedure mniN1ConfirmClick(Sender: TObject);
procedure mni_mniN2ConfirmAndFinishClick(Sender: TObject);
procedure btn1ForwordClick(Sender: TObject);
procedure btn1_RefreshPDFClick(Sender: TObject);
procedure btn1pdfDownloadClick(Sender: TObject);
procedure cxspltr2Moved(Sender: TObject);
procedure cxspltr2BeforeClose(Sender: TObject;
var AllowClose: Boolean);
procedure cxspltr2BeforeOpen(Sender: TObject; var AllowOpen: Boolean);
procedure btn1_ImportAssistInfoClick(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
private
{ Private declarations }
m_pdfFileName:string;
m_bsno:string;
m_qryTask:TADOQuery;
procedure InitialBusiData();
procedure openpdfFile();
function sendmail( mailSendTbl: TkbmMemTable;mailtype,bsno:string;ishtml:Boolean):Boolean;
procedure InitialTDWindow();
procedure InitialCh_fee_edi_Window();
public
{ Public declarations }
public procedure InitialData( qryTask:TADOQuery; bsno1:string;pdfpath:string);
end;
var
frmOpSeae_TaskContrast: TfrmOpSeae_TaskContrast;
implementation
{$R *.dfm}
uses my_sys_function,u_main, u_tree_main, u_data_share, u_sys_progress,
u_op_seae_TaskContrast_TD, u_ch_fee_edi, u_op_letter;
///
/// 临时目录
///
function GetWinTempPath: string;
var
TempDir: array[0..255] of char;
begin
GetTempPath(255, @TempDir);
Result := strPas(TempDir);
end;
procedure TfrmOpSeae_TaskContrast.InitialData( qryTask:TADOQuery; bsno1:string ;pdfpath:string);
var
state,tasktype,strtmp:string;
strsql:string;
begin
m_qryTask:=qryTask;
m_bsno:=bsno1;
m_pdfFileName:=pdfpath;
tasktype:= m_qryTask.FieldByName('任务类型').AsString;
qry1_op_seae_edi_mail_bcinfo.Active:=False;
qry2_op_seae_edi_rp_iftmbc.Active:=false;
pnl2_BC.Visible:=false;
pnl2_rptBC.Visible:=False;
if(tasktype='HAHYedi') or ( tasktype='提单确认' ) then
begin
//iwbpdfdtr1.visible:=false;
cxspltr2.Visible:=False;
bsknpnl2_right.Visible:=False;
pnl2_td.Align:= alClient;
pnl2_td.Visible:=True;
pnl2_ch_fee_edi.Visible:=False;
btn1_RefreshPDF.Visible:=False;
InitialTDWindow();
end
else
begin
pnl2_td.Visible:=false;
//
if(tasktype='Invoice') or ( tasktype='INVOIC' ) then
begin
cxspltr2.Visible:=False;
bsknpnl2_right.Visible:=False;
pnl2_ch_fee_edi.Align:= alClient;
pnl2_ch_fee_edi.Visible:=True;
btn1_RefreshPDF.Visible:=False;
InitialCh_fee_edi_Window();
end
else
begin
btn1_RefreshPDF.Visible:=true;
pnl2_ch_fee_edi.Visible:=false;
//iwbpdfdtr1.visible:=true;
//bsknpnl2_right.Align:= alClient;
bsknpnl2_right.Visible:=true;
cxspltr2.visible:=true;
if(tasktype='BC') or (tasktype='BA') then
begin
pnl2_BC.Visible:=True;
dbedtF_HYH.Color:=dbedt37.Color;//默认
strsql:='SELECT TOP 1 F_CM ,F_HC,F_HX,F_YZH,F_JGSHJ,F_JDSHJ,F_SeaNo,F_ETD,F_HYH,F_Remark from t_op_seae_edi_mail_bcinfo where '
+' F_Base_MailID =''' + m_qryTask.fieldbyname('邮件编号').AsString +''';';
qry1_op_seae_edi_mail_bcinfo.SQL.Text:=strsql;
qry1_op_seae_edi_mail_bcinfo.Active:=True;
strtmp:= m_qryTask.fieldbyname('文件编号').AsString;
if(strtmp<>'') then
begin
strsql:= 'select * from t_op_seae_edi_rp_iftmbc where '
+' F_Base_ReportID =''' +strtmp +''';';
qry2_op_seae_edi_rp_iftmbc.sql.Text:=strsql;
qry2_op_seae_edi_rp_iftmbc.Active:=true;
end;
cxspltr1.Visible:= False;
pnl4_jjx.Visible:= False;
if(cxspltr2.State=ssClosed) then //ssOpened, ssClosed
pnl2_rptBC.Visible:=True;
end
else
begin
pnl2_BC.Visible:=False;
end;
end;
if(pnl2_BC.Visible=False) and (tasktype<>'BCL') then
begin
pnl4_jjx.Visible:= True;
cxspltr1.Visible:= True;
end;
//
end;
//
state:=m_qryTask.fieldbyname('任务状态').AsString;
//状态处理
btnCancelTask.Enabled:=False;
btn2Confirm.Enabled:=False;
btn1Forword.Enabled:=False;
mni_mniN1Confirm.Visible:=false;
mni_mniN2ConfirmAndFinish.Visible:=False;
if(m_qryTask.FieldByName('是否完成').AsInteger<1) then
begin
btnCancelTask.Enabled:=true;
mni_mniN2ConfirmAndFinish.Visible:=true;
if tasktype='VC' then
begin
btn2Confirm.Enabled:=True;
mni_mniN1Confirm.Visible:=false;
//btn1Forword.Enabled:=True;
end
else
begin
btn2Confirm.Enabled:=True;
if(state<>'PENDING') then
mni_mniN1Confirm.Visible:=True;
//btn1Forword.Enabled:=True;
end;
end ;
if (tasktype='VC') or (tasktype='SEAWAY') or (tasktype='BC') or (tasktype='BA') then
begin
btn1Forword.Enabled:=True;
end ;
end;
procedure TfrmOpSeae_TaskContrast.InitialBusiData();
var
strtmp,strtmp1:string;
begin
//通过编号获取数据信息
qry_op_seae.Close;
qry_op_seae.SQL.clear;
qry_op_seae.SQL.Add('select * from t_op_seae where 编号='''+ m_bsno + '''');
qry_op_seae.open;
qry_op_ctn.Active:=False;
qry_op_ctn.Active:=True;
qry_op_ctndetail.Active:=false;
qry_op_ctndetail.Active:=True;
if( pnl2_td.Visible) then
begin
frmOp_seae_Taskcontrast_TD.BindData(Self.m_qryTask,qry_op_seae,qry_op_ctn);
end
else if(pnl2_ch_fee_edi.Visible) then
begin
frmCh_fee_edi.BindData(Self.m_qryTask,True);
end;
if( pnl2_BC.Visible) then
begin
//合约号--运费协议号
//dbedtF_HYH
// dbedt37
mmo1_extMatch.text:='';
if Trim(qry1_op_seae_edi_mail_bcinfo.FieldByName('F_Remark').AsString )<>'' then
begin
strtmp1:=Trim(qry1_op_seae_edi_mail_bcinfo.FieldByName('F_Remark').AsString );
mmo1_extMatch.Text:=strtmp1;
end;
if(dbedtF_HYH.Text<>'') and (dbedt37.Text<>'') and (dbedtF_HYH.Text<>dbedt37.Text) then
begin
dbedtF_HYH.Color:=clRed;
strtmp:=Format('约号(合同号)与业务系统运费协议号不一致:%s~%s',[dbedtF_HYH.Text,dbedt37.Text]);
if(dbmmoF_EXT_IsMatchBusiRemark.Text<>'') then
begin
if( dbmmoF_EXT_IsMatchBusiRemark.Text ='匹配BC报文无异常') then
begin
if Trim(strtmp1)='' then mmo1_extMatch.Text:=strtmp else
mmo1_extMatch.Lines.Append(strtmp);
end
else
if Trim(strtmp1)='' then mmo1_extMatch.Text:=strtmp else
mmo1_extMatch.Lines.Append(strtmp);
mmo1_extMatch.Lines.Append(dbmmoF_EXT_IsMatchBusiRemark.Text);
end
else
begin
if Trim(strtmp1)='' then mmo1_extMatch.Text:=strtmp else
mmo1_extMatch.Lines.Append(strtmp);
mmo1_extMatch.Lines.Append('暂时没有BC报文对比结果!');
end;
end
else if (dbmmoF_EXT_IsMatchBusiRemark.Text='') then
mmo1_extMatch.Lines.Append('暂时没有BC报文对比结果!')
else
mmo1_extMatch.Lines.Append(dbmmoF_EXT_IsMatchBusiRemark.Text);
end;
end;
///
///
///
procedure TfrmOpSeae_TaskContrast.openpdfFile();
var
filename,naspath,info:string;
begin
if(LowerCase(ExtractFileExt(m_pdfFileName))<>'.pdf' ) then
Exit;
//本地路径直接拷贝
if(FileExists(m_pdfFileName) ) then
begin
btn1pdfDownload.Visible:=true;
filename:= GetWinTempPath()+ '_cp'+FormatDateTime('MMDDhhmmss',Now)+'.pdf'; //
if(FileExists(filename)) then
DeleteFile(filename);
CopyFile(pChar(m_pdfFileName),pChar(filename),false);
//等待1秒
Sleep(1000);
info:='加载到本地缓存失败文件,无法完成文件复制:请确认您有访问Nass服务器的权限和本地临时目录的写入权限\n或者确认文件是否损坏!'
+'\n或者pdf文件格式当前显示控件不支持,可以尝试通过"下载本地"按钮下载后使用本地应用程序打开!';
if(FileExists(filename)) then
begin
try
iwbpdfdtr1.LoadFromFile(filename);
except
on ex:Exception do
begin
ShowMessage('加载文件失败:'+ex.Message
+'\n可以尝试通过"下载本地"按钮下载后使用本地应用程序打开!');
end;
end;
end
else
begin
ShowMessage(info);
end;
//iwbpdfdtr1.LoadFromFile(m_pdfFileName)
end
else if(m_pdfFileName<>'')then
ShowMessage('要加载的文件不存在');
end;
procedure TfrmOpSeae_TaskContrast.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
try
if(iwbpdfdtr1.currentpage>0) then
iwbpdfdtr1.CloseRead;
except
;
end;
//延迟半秒
Sleep(500);
//iwbpdfdtr1.FreeInstance;
//iwbpdfdtr1:=nil;
end;
procedure TfrmOpSeae_TaskContrast.FormShow(Sender: TObject);
begin
InitialBusiData();
self.iwbpdfdtr1.TitleBarVisible:= False;
//self.iwbpdfdtr1.ToolbarVisible:=False;
iwbpdfdtr1.CloseButtonVisible:=False;
iwbpdfdtr1.SidebarVisible:=False;
iwbpdfdtr1.SignToolbarVisible:=False;
//
iwbpdfdtr1.CloseButtonVisible:=False;
iwbpdfdtr1.SidebarVisible:=False;
iwbpdfdtr1.SignToolbarVisible:=False;
iwbpdfdtr1.OpenButtonVisible:=False;
iwbpdfdtr1.SaveButtonVisible:=false;
iwbpdfdtr1.FullScreenButtonVisible:=false;
iwbpdfdtr1.PrintButtonVisible:=false;
iwbpdfdtr1.PrintSetButtonVisible:=False;
iwbpdfdtr1.SidebarVisible:=false;
btn1pdfDownload.Visible:=False;
// 调整加载文件的位置,初始化完成后再加载pdf文件
openpdfFile();
end;
procedure TfrmOpSeae_TaskContrast.btnCoseClick(Sender: TObject);
begin
close();
end;
procedure TfrmOpSeae_TaskContrast.btnCancelTaskClick(Sender: TObject);
var
sql:string;
begin
if( Application.MessageBox(PChar('您确实要直接结束该任务吗?'+#13#10+'结束任务将直接关闭任务!,是否结束任务?'),'信息提示',MB_YESNO+ MB_ICONQUESTION)<>IDYES) then
Exit;
//
try
//** m_qryTask.Connection.BeginTrans;
m_qryTask.Edit;
m_qryTask.FieldByName('完成时间').AsDateTime:=Now;
m_qryTask.FieldByName('是否完成').AsInteger:=1;
m_qryTask.FieldByName('任务状态').AsString:='结束';
m_qryTask.FieldByName('操作人').AsString:=employee;
m_qryTask.Post;
//
sql:='INSERT INTO t_op_task_state ( [任务编号],[任务状态],[操作人])VALUES (''%s'' ,''%s'' ,''%s'')';
sql:=Format(sql,[m_qryTask.fieldbyname('任务编号').asstring,'结束',employee] );
m_qryTask.Connection.Execute(sql);
//** m_qryTask.Connection.CommitTrans;
m_qryTask.Requery();
Application.MessageBox(PChar('操作完成'),'信息提示');
close();
except
on e:Exception do
begin
// on except
//* m_qryTask.Connection.RollbackTrans;
m_qryTask.Cancel();
Application.MessageBox(PChar('处理发生错误: '+E.Message),'信息提示');
end;
end;
end;
///
///
///
procedure TfrmOpSeae_TaskContrast.mniN1ConfirmClick(Sender: TObject);
var
sql:string;
optype:string;
begin
//确认 ORIGINAL FTP
//if(m_qryTask.FieldByName('任务类型').AsString='ORIGINAL') and (m_qryTask.FieldByName('任务来源').AsString='FTP' ) then
begin
//
optype:='PENDING';
try
//** m_qryTask.Connection.BeginTrans;
m_qryTask.Edit;
m_qryTask.FieldByName('完成时间').AsDateTime:=Now;
//m_qryTask.FieldByName('是否完成').AsInteger:=1;
m_qryTask.FieldByName('任务状态').AsString:=optype;
m_qryTask.FieldByName('操作人').AsString:=employee;
m_qryTask.Post;
//
sql:='INSERT INTO t_op_task_state ( [任务编号],[任务状态],[操作人])VALUES (''%s'' ,''%s'' ,''%s'')';
sql:=Format(sql,[m_qryTask.fieldbyname('任务编号').asstring,optype,employee] );
m_qryTask.Connection.Execute(sql);
//** m_qryTask.Connection.CommitTrans;
m_qryTask.Requery();
Application.MessageBox(PChar('操作完成'),'信息提示');
close();
except
on e:Exception do
begin
// on except
//** m_qryTask.Connection.RollbackTrans;
m_qryTask.Cancel();
Application.MessageBox(PChar('处理发生错误: '+E.Message),'信息提示');
end;
end;
end;
end;
///
/// 确认并完成任务
///
procedure TfrmOpSeae_TaskContrast.mni_mniN2ConfirmAndFinishClick(
Sender: TObject);
var
sql,strtmp:string;
mainno,bsno,filename,filetype:string;
optype:string;
isok:Boolean;
remark:string;
begin
//确认 ORIGINAL FTP
//if(m_qryTask.FieldByName('任务类型').AsString='ORIGINAL') and (m_qryTask.FieldByName('任务来源').AsString='FTP' ) then
//
mainno:=m_qryTask.fieldbyname('提单号').AsString;
bsno:=m_qryTask.fieldbyname('SEA编号').AsString;
strtmp:=m_qryTask.fieldbyname('任务类型').AsString;
filename:=m_qryTask.fieldbyname('电子档案路径').AsString;
remark:=m_qryTask.fieldbyname('备注').AsString;
//检查是否允许挂单
if strtmp ='ORIGINAL' then
begin
if( frm_tree_main.checkGuadanTimes(remark)=False) then
begin
if( Application.MessageBox(PChar('该票业务不是第一次挂单,您确信要挂单吗?'),'信息提示',MB_YESNO+ MB_ICONQUESTION)<>IDYES) then
Exit;
end;
end;
optype:='完成';
isok:=true;
try
if strtmp ='提单确认' then
begin
if(qry_op_seae.Recordset.RecordCount>0) then
if( Application.MessageBox(PChar('是否执行数据导入操作?'+#13#10+'选择[是]执行勾选项的导入,否则直接完成任务不执行导入.'),'信息提示',MB_YESNO+ MB_ICONQUESTION)=IDYES) then
begin
//处理中有自己的事务
isok:= frmOp_seae_Taskcontrast_TD.DoImportData();
close;
Exit;
end;
end;
if strtmp ='ORIGINAL' then
begin
filetype:='船公司挂单';
isok:= frm_tree_main.Guadan(mainNo,bsno, filetype,filename);
end
else if( strtmp='BC') OR (strtmp='BA') then
begin
filetype:='入货通知';
isok:= frm_tree_main.Guadan(mainNo,bsno, filetype,filename);
end
else if strtmp ='VC' then
begin
filetype:='VC挂单';
end
else if strtmp ='INVOIC' then
begin
//
if(frmCh_fee_edi.DoImportData()) then
begin
close();
Exit;
end;
end;
//挂单
if (isok=true) then
begin
m_qryTask.Edit;
m_qryTask.FieldByName('完成时间').AsDateTime:=Now;
m_qryTask.FieldByName('是否完成').AsInteger:=1;
m_qryTask.FieldByName('任务状态').AsString:=optype;
m_qryTask.FieldByName('操作人').AsString:=employee;
m_qryTask.Post;
//
sql:='INSERT INTO t_op_task_state ( [任务编号],[任务状态],[操作人])VALUES (''%s'' ,''%s'' ,''%s'')';
sql:=Format(sql,[m_qryTask.fieldbyname('任务编号').asstring,optype,employee] );
m_qryTask.Connection.Execute(sql);
m_qryTask.Requery();
Application.MessageBox(PChar('操作完成'),'信息提示');
close();
end ;
except
on e:Exception do
begin
Application.MessageBox(PChar('处理发生错误: '+E.Message),'信息提示');
end;
end;
//
end;
procedure TfrmOpSeae_TaskContrast.btn1ForwordClick(Sender: TObject);
var
strsql, str,wtdw,strsjr,tasktype,YJ_FILEID,FNType,strtmp:string;
mainno,bsno:string;//主提单号,编号
aQuery,qryMail:TADOQuery;
ishtml:Boolean;
errorinfo:string;
isok:Boolean;
filename:string;
wtbh:string;//委托编号/PO ,委托编号在BC/BA转发时如果非空并且不是TSE开头则转发标题加___委托编号
begin
//
isok:=True;
errorinfo:='';
tasktype:= m_qryTask.FieldByName('任务类型').AsString;
//单据类型
FNType:='VC_SEAWAY_提单留底';
if( (tasktype='BC') or (tasktype='BA') ) then
FNType:='入货通知';
ishtml:=False;
if(qry_op_seae.Recordset.RecordCount<1) then
begin
Application.MessageBox('没有业务数据,无法转发!','信息提示',MB_OK+MB_ICONINFORMATION) ;
Exit;
end;
wtdw:=qry_op_seae.FieldByName('委托单位').AsString;
if( (wtdw)='') then
begin
Application.MessageBox('委托单位为空,无法转发!','信息提示',MB_OK+MB_ICONINFORMATION) ;
Exit;
end;
mainno:=m_qryTask.fieldbyname('提单号').AsString;
bsno:= qry_op_seae.FieldByName('编号').AsString;
filename:=m_qryTask.fieldbyname('电子档案路径').AsString;
strtmp:= qry_op_seae.FieldByName('委托编号').AsString;
if((strtmp='') or (Pos('TSE',UpperCase(strtmp))=1)) then
wtbh:=''
else
wtbh:='___'+strtmp;
//单据类型--->BC/BA:入货通知
// VC/Seaway:VC_SEAWAY_提单留底
// d.收件人
str:=' select d.*,c.客户名称 from t_code_cust_mailproject_detail d left join t_code_cust_mailproject c '
+' on (c.方案代码=d.方案代码) where 单据类型=''' + FNType + ''' and c.客户名称='''+wtdw+''' and '
+' d.方案代码 in '
+'( SELECT distinct 客户邮件方案 from t_op_seae where 委托单位='''+wtdw+''' and isnull(客户邮件方案,'''')<>'''' '
+'and 编号='''+ bsno +''' )';
aQuery:=CreateAdoQuery();
with aQuery do
begin
close;sql.Clear;
SQL.Add(str);
Open;
strsjr:='';
if IsEmpty then
begin
Application.MessageBox(pchar('委托单位[' + FNType +']邮件方案为空或者该票票业务没有选择邮件方案,无法转发!'),'信息提示',MB_OK+MB_ICONINFORMATION) ;
Close;
exit;
end ;
//多条方案的邮件人
First;
while not eof do
begin
//
if strsjr='' then
strsjr := fieldbyname('收件人').AsString
else
strsjr := strsjr +',' +fieldbyname('收件人').AsString;
Next;
end;
if(pos('@',strsjr)<1) then
begin
Application.MessageBox('邮件方案的收件人地址不正确,请确认后再转发!','信息提示',MB_OK+MB_ICONINFORMATION) ;
Close;
Exit;
end;
First;
end ;
//
mailSend.EmptyTable;
mailSend.Open;
mailSend.Insert;
mailSend.FieldByName('收件人').AsString:= strsjr;//fieldbyname('收件人').AsString;
mailSend.FieldByName('邮件签名').AsString:=MailSignName;//frm_data_share.t_sys_employee.fieldbyname('邮件签名').AsString;
//默认主题
mailsend.fieldbyname('邮件主题').AsString:= tasktype+':'+ mainno;
if (tasktype='BC') or (tasktype='BA') or (tasktype='VC') OR ( (UpperCase(tasktype)='SEAWAY') and (m_qryTask.fieldbyname('任务来源').AsString='邮件') ) then
begin
YJ_FILEID:=m_qryTask.fieldbyname('邮件编号').AsString;
qryMail:=CreateAdoQuery();
ishtml:=True;
qryMail.Close;
qryMail.SQL.Clear;
qryMail.SQL.Add('SELECT [邮件主题],[邮件内容] FROM [t_op_seae_edi_mail] where [邮件ID]='''+YJ_FILEID+''';') ;
qryMail.Open;
if(not qryMail.Eof) then
begin
//
str:='转发:'+qryMail.fieldbyname('邮件主题').AsString;
if(FNType='入货通知') then //BC/BA类的委托编号不为空且不为[TSE]开头则邮件标题+[___委托编号]
str:= str +wtbh;
mailsend.fieldbyname('邮件主题').AsString :=str;
mailSend.FieldByName('附件名称').AsString:=filename ;
str:=qryMail.fieldbyname('邮件内容').AsString;
mailSend.FieldByName('邮件内容').AsString:=str;
//容错处理:发送记录里有空白邮件!!!!
if( qryMail.fieldbyname('邮件主题').AsString ='') and (filename='') then
begin
qryMail.Close();
ShowMessage('未能获得邮件主题和附件名称,不能发送:转发失败');
Exit;
end;
end;
end
else if(tasktype='SEAWAY') then
begin
//YJ_FILEID:=m_qryTask.fieldbyname('文件编号').AsString;
str:='SEAWAY BILL:'+mainno ;// fieldbyname('主题模板').AsString +FormatDateTime('YYYYMMDDHHMMSS',now) ;
//str:=StringReplace(str,'[客户名称]',qry1_qdtm.fieldbyname('客户名称').AsString ,[]);
mailsend.fieldbyname('邮件主题').AsString :=str;
mailSend.FieldByName('附件名称').AsString:=filename ;
if aQuery.fieldbyname('邮件内容').IsNull then
str:=' '
else
str:=aQuery.fieldbyname('邮件内容').AsString;
mailSend.FieldByName('邮件内容').AsString:=str;
mailSend.FieldByName('单据类型').AsString:=aQuery.fieldbyname('单据类型').AsString;
mailSend.FieldByName('编号').AsString:=bsno;//t_op_letter.DataSource.DataSet.fieldbyname('编号').AsString;
mailSend.FieldByName('主提单号').AsString:=mainno ;//t_op_letter.DataSource.DataSet.fieldbyname('主提单号').AsString;
end;
mailSend.Post;
try
//** m_qryTask.Connection.BeginTrans;
isok:= sendmail(mailSend,FNType,bsno,ishtml) ;
if(isok) then
begin
//如果是BC/BA则挂单
if(m_qryTask.FieldByName('是否完成').AsInteger=0) and ( (tasktype='BC') or (tasktype='BA') ) then
begin
//挂单 filetype:='入货通知';
isok:= frm_tree_main.Guadan(mainNo,bsno,'入货通知',filename);
if(isok) then
begin
strsql:='INSERT INTO t_op_task_state ( [任务编号],[任务状态],[操作人])VALUES (''%s'' ,''%s'' ,''%s'')';
strsql:=Format(strsql,[bsno, tasktype+ '挂单',employee] );
m_qryTask.Connection.Execute(strsql);
end
else
ShowMessage('邮件已转发;但是自动挂单失败!');
end;
//更新状态
m_qryTask.Edit;
m_qryTask.FieldByName('完成时间').AsDateTime:=Now;
m_qryTask.FieldByName('是否完成').AsInteger:=1;
m_qryTask.FieldByName('任务状态').AsString:='已转发';
m_qryTask.FieldByName('操作人').AsString:=employee;
m_qryTask.Post;
//
strsql:='INSERT INTO t_op_task_state ( [任务编号],[任务状态],[操作人])VALUES (''%s'' ,''%s'' ,''%s'')';
strsql:=Format(strsql,[m_qryTask.fieldbyname('任务编号').asstring,'已转发',employee] );
m_qryTask.Connection.Execute(strsql);
//** m_qryTask.Connection.CommitTrans;
m_qryTask.Requery();
Application.MessageBox(PChar('操作完成'),'信息提示');
aQuery.Close();
close();
end
else
Application.MessageBox(PChar('邮件转发失败!'),'信息提示');
except
on ex:exception do
begin
//** m_qryTask.Connection.RollbackTrans;
m_qryTask.Cancel();
Application.MessageBox(PChar('转发失败:'+ex.Message),'信息提示',MB_OK+MB_ICONINFORMATION);
exit;
end;
end;
Close();
// //读取邮件内容进行转发
//准备数据
//发送
end;
function TfrmOpSeae_TaskContrast.sendmail( mailSendTbl: TkbmMemTable;mailtype,bsno:string;ishtml:Boolean):Boolean;
var
i:integer;
str_memo:Tmemo;
SMTP1:TIdSMTP;
IdMsg:TIdMessage;
strfile,mailremarks,naspath,strnr,lognr:string;
//
emptybody, textbody, htmlbody : TIdText;
idAtta: TIdAttachmentFile;
filename:string;
begin
Result:= true;
try
naspath:=get_parameters_value(175,'\\223.223.95.160\data');
try
frm_tree_main.ConnectDownServer();
except on ex: Exception do
begin
;//s
end;
end;
if not ASSIGNED(frm_sys_progress) then
frm_sys_progress:=tfrm_sys_progress.Create(application);
frm_sys_progress.bsSkinGauge1.ProgressText:='正在发送邮件。。。';
frm_sys_progress.Show;
frm_sys_progress.bsSkinGauge1.MaxValue:=1;
frm_sys_progress.bsSkinGauge1.MinValue:=0;
frm_sys_progress.bsSkinGauge1.Value:=0;
begin
SMTP1:=TIdSMTP.Create(nil);
IdMsg:=TIdMessage.Create(nil);
str_memo:=Tmemo.create(nil);
SMTP1.AuthType := satDefault; //(satNone, satDefault, satSASL);
SMTP1.username:=MailAddress;
SMTP1.Password :=MailPw;
SMTP1.Host :='mail.sdsmartlogistics.com';
//----------------
{
SMTP1.username:='dev003@dongshengsoft.com';
SMTP1.Password :='carey2017';
SMTP1.Host :='smtpcom.263xmail.com';
}
//debug
SMTP1.Port :=25;
try
SMTP1.Connect;
except
on e : Exception do
begin
ShowMessage('连接邮箱出错:'+E.Message);
Result:=False;
Exit;
end;
end;
if not SMTP1.Connected then
begin
SMTP1.Connect;
end;
try
with IdMsg do
begin
body.Clear;
if(ishtml) then
begin
IdMsg:=TIDMessage.create();
emptybody := TIdText.Create(IdMsg.MessageParts, nil);
emptybody.ContentType := 'multipart/alternative';
emptybody.ParentPart := -1;
textbody := TIdText.Create(IdMsg.MessageParts, nil);
textbody.Body.Text := 'plain text part';
textbody.ContentType := 'text/plain';
textbody.ParentPart := 0;
htmlbody := TIdText.Create(IdMsg.MessageParts, nil);
htmlbody.body.text :=mailSendTbl.fieldbyname('邮件内容').AsString;// '
This is a email saying weeeeee
黑体字';
htmlbody.ContentType := 'text/html';
htmlbody.ParentPart := 0;
IdMsg.ContentType := 'multipart/related; type="multipart/alternative"';
//IdMsg.ContentType :='text/html';
IdMsg.CharSet:='iso-8859-1';
IdMsg.Encoding:=meMIME;
// IdMsg.body:=null;//mailSendTbl.fieldbyname('邮件内容').AsString;
lognr:=mailtype + '挂单,具体内容请查阅邮件 ';
end
else
begin
// textbody := TIdText.Create(IdMsg.MessageParts, nil);
// textbody.Body.Text := 'plain text part';
// textbody.ContentType := 'text/plain';
//textbody.ParentPart := 0;
//textbody.Body.Text:= mailSendTbl.fieldbyname('邮件内容').AsString;
Body.Text:=mailSendTbl.fieldbyname('邮件内容').AsString;
lognr :=Body.Text;
end;
From.address :=MailAddress;
Recipients.EMailAddresses :=mailSendTbl.FieldByName('收件人').AsString;
Subject:=mailSendTbl.FieldByName('邮件主题').AsString;
strfile:= mailSend.FieldByName('附件名称').AsString;
//-----------------
if(FileExists(strfile)) then
begin
//---------------------
{
filename:= GetWinTempPath()+ExtractFileName(strfile); //
if(FileExists(filename)) then
DeleteFile(filename);
//本地路径直接拷贝
if(FileExists(strfile) ) then
begin
CopyFile(pChar(strfile),pChar(filename),false);
end;
if(not FileExists(filename)) then
filename := strfile;
}
//--------------
idAtta:= TIdAttachmentFile.Create(MessageParts,strfile);
idAtta.ContentType:='application/octet-stream';
idAtta.ContentDisposition:='attachment';
idAtta.ContentTransfer:='base64';
idAtta.FileName:=ExtractFileName(strfile);
end;
end;
if not SMTP1.Connected then
begin
Sleep(1000);
SMTP1.Connect;
end;
SMTP1.Send(IdMsg);
// 长度判断
Insert_mail_Log(bsno,mailtype,mailSendTbl.FieldByName('收件人').AsString,mailSendTbl.FieldByName('邮件主题').AsString,lognr,mailSend.FieldByName('附件名称').AsString);
finally
SMTP1.Disconnect;
end;
try
finally
str_memo.Free;
SMTP1.Free;
IdMsg.Free;
end;
end;
finally
frm_sys_progress.close;
frm_sys_progress:=nil;
end;
end;
procedure TfrmOpSeae_TaskContrast.btn1_RefreshPDFClick(Sender: TObject);
var
filename,naspath,sfilename:string;
begin
sfilename :=ExtractFileExt(m_pdfFileName);
if(LowerCase(sfilename)<>'.pdf' ) then
begin
ShowMessage('文件格式错误: '+sfilename);
Exit;
end;
try
iwbpdfdtr1.CloseRead;
except
end;
//本地路径直接拷贝
frm_tree_main.ConnectDownServer();
if(FileExists(m_pdfFileName) ) then
begin
filename:= GetWinTempPath()+ '_cp'+FormatDateTime('MMDDhhmmss',Now)+'.pdf'; //
if(FileExists(filename)) then
DeleteFile(filename);
CopyFile(pChar(m_pdfFileName),pChar(filename),false);
//等待1秒
Sleep(2000);
iwbpdfdtr1.LoadFromFile(filename);
end;
end;
procedure TfrmOpSeae_TaskContrast.btn1pdfDownloadClick(Sender: TObject);
var
filename,naspath,sfilename:string;
dlg:TSaveDialog;
begin
sfilename :=ExtractFileExt(m_pdfFileName);
//本地路径直接拷贝
frm_tree_main.ConnectDownServer();
if(FileExists(m_pdfFileName) ) then
begin
dlg:=TSaveDialog.Create(self);
dlg.FileName:=ExtractFileName(m_pdfFileName);
dlg.Filter:=sfilename;
if(dlg.Execute()) then
begin
filename:=dlg.FileName;
if(FileExists(filename)) then
begin
if( Application.MessageBox('要保存的文件已经存在是否覆盖?','信息提醒',MB_YESNO+MB_ICONEXCLAMATION)<>ID_YES) then
Exit;
end;
CopyFile(pChar(m_pdfFileName),pChar(filename),false);
end;
end;
//
end;
procedure TfrmOpSeae_TaskContrast.InitialTDWindow();
begin
if not Assigned(frmOp_seae_Taskcontrast_TD) then
frmOp_seae_Taskcontrast_TD:=TfrmOp_seae_Taskcontrast_TD.create(nil);
frmOp_seae_Taskcontrast_TD.parent:=pnl2_td;
frmOp_seae_Taskcontrast_TD.Align:= alClient;
frmOp_seae_Taskcontrast_TD.Show();
end;
procedure TfrmOpSeae_TaskContrast.InitialCh_fee_edi_Window();
begin
if not Assigned(frmCh_fee_edi) then
frmCh_fee_edi:=TfrmCh_fee_edi.create(nil);
frmCh_fee_edi.parent:=pnl2_ch_fee_edi;
frmCh_fee_edi.Align:= alClient;
frmCh_fee_edi.Show();
end;
procedure TfrmOpSeae_TaskContrast.cxspltr2Moved(Sender: TObject);
begin
if cxspltr2.Left<200 then
begin
bsknpnl2_right.Left:=200+cxspltr2.Width;
cxspltr2.Left:=200;
end;
end;
procedure TfrmOpSeae_TaskContrast.cxspltr2BeforeClose(Sender: TObject;
var AllowClose: Boolean);
begin
if( m_qryTask<>nil) and ( (m_qryTask.FieldByName('任务类型').AsString='BC') or
(m_qryTask.FieldByName('任务类型').AsString='BA') ) then
pnl2_rptBC.Visible:=True;
end;
procedure TfrmOpSeae_TaskContrast.cxspltr2BeforeOpen(Sender: TObject;
var AllowOpen: Boolean);
begin
pnl2_rptBC.Visible:=false;
end;
procedure TfrmOpSeae_TaskContrast.btn1_ImportAssistInfoClick(
Sender: TObject);
begin
//
if(m_qryTask.FieldByName('是否公共').AsBoolean=True) then
Exit;
if ( (m_qryTask.FieldByName('任务类型').AsString<>'BC') and
(m_qryTask.FieldByName('任务类型').AsString<>'BA') ) then
Exit ;
//
if(qry_op_seae.Eof) then
Exit;
if(qry1_op_seae_edi_mail_bcinfo=nil) or (qry1_op_seae_edi_mail_bcinfo.Eof) then
Exit;
try
qry_op_seae.Edit;
qry_op_seae.FieldByName('船名').AsString:=qry1_op_seae_edi_mail_bcinfo.fieldbyname('F_CM').AsString;
qry_op_seae.FieldByName('航次').AsString:=qry1_op_seae_edi_mail_bcinfo.fieldbyname('F_HC').AsString;
qry_op_seae.FieldByName('截港日期').AsString:=qry1_op_seae_edi_mail_bcinfo.fieldbyname('F_JGSHJ').AsString;
qry_op_seae.FieldByName('截单日期').AsString:=qry1_op_seae_edi_mail_bcinfo.fieldbyname('F_JDSHJ').AsString;
if(qry1_op_seae_edi_mail_bcinfo.fieldbyname('F_ETD').AsString<>'') then
qry_op_seae.FieldByName('开船日期').AsString:=qry1_op_seae_edi_mail_bcinfo.fieldbyname('F_ETD').AsString;
qry_op_seae.Post;
ShowMessage('辅助信息导入成功!');
qry_op_seae.Requery();
except
on ex:Exception do
begin
ShowMessage('辅助信息导入失败:'+ex.Message);
end;
end;
end;
procedure TfrmOpSeae_TaskContrast.ToolButton1Click(Sender: TObject);
begin
try
frm_op_letter:=tfrm_op_letter.Create (self);
frm_op_letter.bsTypeid:=3;
frm_op_letter.t_op_letter.DataSource:=ds_op_seae2;
frm_op_letter_insert:=true;
frm_op_letter.t_op_letter.Open;
frm_op_letter.t_op_letter_rh.Open;
{
frm_op_letter.bsSkinNotebook1.PageIndex:=7;
frm_op_letter.DataSource1.DataSet:=frm_op_letter.t_op_letter_rh;
frm_op_letter.t_op_letter.Insert;
frm_op_letter.t_op_letter['函电名称']:='入货通知';
frm_op_letter.t_op_letter['HEAD_TO']:=frm_op_letter.GetCorpCName(frm_op_letter.t_op_letter.DataSource.DataSet.FieldByName('委托单位').asstring);
frm_op_letter.t_op_letter.Post;
frm_op_letter.t_op_letter_rh.insert;
}
frm_op_letter.ShowModal;
finally
frm_op_letter.Free;
frm_op_letter:=nil;
end;
end;
end.