📄 task.cpp
字号:
// Task.cpp: implementation of the CTask class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Aotu.h"
#include "Task.h"
#include "Global.h"
#include "AdoManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTask::CTask()
{
TaskId = 0;
taskName = "";
selectStr = "";
insertStr = "";
sourceTable = "";
objectTable = "";
memset(&excuteTime,0,sizeof(excuteTime));
freday = 0;
frehour = 0;
freminute = 0;
memset(&startTime,0,sizeof(startTime));
memset(&endTime,0,sizeof(endTime));
memset(&preEXTime,0,sizeof(preEXTime));
memset(&nextEXTime,0,sizeof(nextEXTime));
countTime = 0;
successSum = 0;
failedSum = 0;
starthour = 0;
endhour = 0;
overflag = FALSE;
selectcount = 0;
}
CTask::~CTask()
{
}
BOOL CTask::Excute()
{
//执行导入操作
DATE szEndRecordTime; //记录最后一条插入记录的时间
memset(&szEndRecordTime,0,sizeof(szEndRecordTime));
char szPrinfo[1024]={0};//日志
int count=0; //成功记录条数
int errorcount=0; //错误记录条数
CoInitialize(NULL);
char szSel[2048]={0};
sprintf(szSel,selectStr,sourceTable,TimeToCStr(excuteTime));
CRecordSet *pSet=global.m_adoOR.CreateRecordSet(szSel);
if(!pSet)
{
m_log.PrintMsg("读取oracle数据集失败!",ERRORMSG);
m_log.PrintMsg(szSel,ERRORMSG);
m_log.PrintMsg(global.error.GetBuffer(0),ERRORMSG);
return FALSE;
}
try
{
if (pSet->IsEOF())
{
sprintf(szPrinfo,"%s 暂无更新数据!",taskName);
m_log.PrintMsg(szPrinfo,WARNMSG);
}else
{
while (!pSet->IsEOF())
{
CString strTemp="";
int itemp=selectcount;
for (int i=0;i<selectcount;i++)
{
//取字符,数字
//NWJ改成CString类型为好
CString Temp;
int iType;
char szInfo[2048]={0};
try
{
pSet->GetColVar(&Temp,i);
}
catch(...)
{
pSet->GetColVarSQL(iType,i);
sprintf(szInfo,"%d",iType);
Temp=szInfo;
}
strTemp=strTemp+"'"+Temp+"',";
}
if (strTemp.Right(1).Compare(",")==0)
strTemp=strTemp.Left(strTemp.GetLength()-1);
//取时间
//pSet->GetColVar(szEndRecordTime,selectcount);
pSet->GetColVar(szEndRecordTime,selectcount);
//组成插入字符串
CString insertTmp;
insertTmp.Format(insertStr,objectTable,strTemp);
int iError=global.m_adoDM.Execute(insertTmp.GetBuffer(0));
if (iError == -1)
{
sprintf(szPrinfo,"%s 插入记录错误!",taskName);
m_log.PrintMsg(szPrinfo,ERRORMSG);
m_log.PrintMsg(global.error.GetBuffer(0),ERRORMSG);
errorcount++;
}
else
{
count++;
}
pSet->MoveNext();
Sleep(0);
}
excuteTime = szEndRecordTime;
sprintf(szPrinfo,"%s 更新完成。成功插入%d条记录,出现错误%d条记录!",taskName,count,errorcount);
m_log.PrintMsg(szPrinfo);
}
}
catch(...)
{
global.m_adoOR.DestroyRecordSet(pSet);
m_log.PrintMsg("读取ORACLE数据失败!",ERRORMSG);
m_log.PrintMsg(global.error.GetBuffer(0),ERRORMSG);
return FALSE;
}
global.m_adoOR.DestroyRecordSet(pSet);
CoUninitialize();
return TRUE;
}
//DATE转换为字符串
CString CTask::TimeToCStr(DATE &date)
{
COleDateTime datetmp=date;
CString restr;
restr=datetmp.Format("%Y-%m-%d %H:%M:%S");
return restr;
}
//保存执行间隔
void CTask::OnSave()
{
CAdoManager m_ado;
HRESULT hr=m_ado.OpenDb(global.szConfigDB);
if(!SUCCEEDED(hr))
{
//AfxMessageBox("打开配置数据库ACCESS失败!");
m_log.PrintMsg("打开配置数据库ACCESS失败!",ERRORMSG);
}
char upsql[1024]={0};
CTime t1,t2;
t1=endTime;
t2=startTime;
CString strStartTemp,strEndTemp;
strStartTemp.Format("%04d-%02d-%02d %02d:%02d:%02d ",t2.GetYear(),t2.GetMonth(),t2.GetDay(),starthour,0,0); //精确到小时
strEndTemp.Format("%04d-%02d-%02d %02d:%02d:%02d ",t1.GetYear(),t1.GetMonth(),t1.GetDay(),endhour,0,0); //精确到小时
sprintf(upsql,"update t_task set freday=%d,frehour=%d,freminute=%d,starttime='%s',endtime='%s',overflag=%d where id=%d",freday,frehour,freminute,strStartTemp,strEndTemp,overflag,TaskId);
m_ado.Execute(upsql);
if (m_ado.IsOpen())
m_ado.CloseDb();
}
//保存执行时间
void CTask::SaveEX()
{
CAdoManager m_ado;
HRESULT hr=m_ado.OpenDb(global.szConfigDB);
if(!SUCCEEDED(hr))
{
//AfxMessageBox("打开配置数据库ACCESS失败!");
m_log.PrintMsg("打开配置数据库ACCESS失败!",ERRORMSG);
}
char upsql[1024]={0};
/*COleDateTime t1;
CTime t2;
t1=preEXTime;
t2=nextEXTime; */
COleDateTime t1,t2;
t1=preEXTime;
t2=nextEXTime;
CString strpreTemp,strnextTemp; //精确到秒
strpreTemp.Format("%04d-%02d-%02d %02d:%02d:%02d ",t1.GetYear(),t1.GetMonth(),t1.GetDay(),t1.GetHour(),t1.GetMinute(),t1.GetSecond());
strnextTemp.Format("%04d-%02d-%02d %02d:%02d:%02d ",t2.GetYear(),t2.GetMonth(),t2.GetDay(),t2.GetHour(),t2.GetMinute(),t2.GetSecond());
sprintf(upsql,"update t_task set preEXTime='%s',nextEXTime='%s' where id=%d",strpreTemp,strnextTemp,TaskId);
m_ado.Execute(upsql);
if (m_ado.IsOpen())
m_ado.CloseDb();
}
//保存执行一次完成后的信息
void CTask::SaveAfterEX()
{//更新四项 countTime successSum failedSum excuteTime
CAdoManager m_ado;
HRESULT hr=m_ado.OpenDb(global.szConfigDB);
if(!SUCCEEDED(hr))
{
// AfxMessageBox("打开配置数据库ACCESS失败!");
m_log.PrintMsg("打开配置数据库ACCESS失败!",ERRORMSG);
}
char upsql[1024]={0};
COleDateTime tmpDate=excuteTime;
CString strTemp; //精确到秒
strTemp.Format("%04d-%02d-%02d %02d:%02d:%02d ",tmpDate.GetYear(),tmpDate.GetMonth(),tmpDate.GetDay(),tmpDate.GetHour(),tmpDate.GetMinute(),tmpDate.GetSecond());
sprintf(upsql,"update t_task set excuteTime='%s',countTime=%d,successSum=%d,failedSum=%d where id=%d",strTemp,countTime,successSum,failedSum,TaskId);
m_ado.Execute(upsql);
if (m_ado.IsOpen())
m_ado.CloseDb();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -