📄 mainfrm.cpp
字号:
}
SelectFTPFile(); //递归调用!
m_bSuc=FALSE;
while(!m_bSuc)
{
m_bSuc= m_pFtpConnection->SetCurrentDirectory(_T(".."));
}
}*/
}
void CMainFrame::OnExport()
{
// TODO: Add your command handler code here
CExportDlg dlg;
if(dlg.DoModal())
{
m_strBeginTime=dlg.m_strBeginTime;
m_strEndTime=dlg.m_strEndTime;
}
if(!ReadPoint())
{
strTemp.Format(_T("從數據庫中,取到%d條積分數據!"),m_nSize);
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
//AfxMessageBox(strTemp);
return;
}
else
{
strTemp.Format(_T("從數據庫中,取到%d條積分數據!"),m_nSize);
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
//AfxMessageBox(strTemp);
}
if(!UpLoadFile())
{
strTemp.Format(_T("積分數據,上偉到FTP失敗!"));
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
m_nSize=0;
AfxMessageBox(strTemp);
return;
}
else
{
strTemp =_T("");
strTemp.Format(_T("%d條積分數據,上偉到FTP成功!"),m_nSize);
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
m_nSize=0;
AfxMessageBox(strTemp);
}
}
BOOL CMainFrame::UpLoadFile()
{
CInternetSession * pInetSession; //会话对象
CFtpConnection * pFtpConnection; //连接对象
pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
try
{ int nPort=_wtoi(strFtpPort);
//新建连接对象
pFtpConnection=pInetSession->GetFtpConnection(strFtpServer,strFtpUser,strFtpPass,nPort);
}
catch(CInternetException *pEx)
{ CString errormessage;
//获取错误
TCHAR szError[1024];
if(pEx->GetErrorMessage(szError,1024))
{
errormessage.Format(_T("連接FTP服务器%s"),szError);
this->SendMessage( WM_STATUSMSG, (WPARAM)&errormessage );
SetDoc(errormessage);
}
else
{
errormessage.Format(_T("連接FTP服务器有一個未知錯誤!"));
this->SendMessage( WM_STATUSMSG, (WPARAM)&errormessage );
SetDoc(errormessage);
}
pEx->Delete();
pInetSession=NULL;
return FALSE;
}
int nNub;
BOOL bSircl=FALSE;
BOOL m_bSuc=FALSE;
m_strFtpPath=_T("");
CString strDir;
CStringArray m_strDirArray;
CString strFtpDir;
strFtpDir=m_strFTPDir;
if(strFtpDir.Right(1) != '/')
{
strFtpDir += '/';
}
if(strFtpDir.Left(1) == '/')
{
nNub=strFtpDir.GetLength();
strFtpDir=strFtpDir.Right(nNub-1);
}
int nPos=strFtpDir.Find('/');
if(nPos>0)
bSircl=TRUE;
while(bSircl)
{
strDir=strFtpDir.Left(nPos);
strFtpDir=strFtpDir.Mid(nPos+1);
nPos=strFtpDir.Find('/');
if(nPos>0)
{
bSircl=TRUE;
}
else
{
bSircl=FALSE;
}
m_bSuc=pFtpConnection->SetCurrentDirectory(strDir);
if(!m_bSuc) //进入目录里面
{
return FALSE;
}
m_bSuc=FALSE;
}
CString ABC;
pFtpConnection->GetCurrentDirectory(ABC);
CString strLocalFile,strRemoteFile;
CString strUpLoadFile;
//CTime tTime=CTime::GetCurrentTime();
//CString strTime;
//m_strBeginTime,m_strEndTime;
//strTime=tTime.Format(_T("%Y%m%d%H%M%S.CSV"));
//strUpLoadFile.Format(_T("TAIX_TO_CCH%s"),strTime);
pFtpConnection->Remove(m_strExportFile);
strLocalFile.Format(_T("%s\\%s"),strLocalDir,m_strExportFile);
if(!pFtpConnection->PutFile(strLocalFile,m_strExportFile))
{
return FALSE;
}
int n=GetLastError();
if(pFtpConnection!=NULL)
{
pFtpConnection->Close();
delete pFtpConnection;
}
delete pInetSession;
return TRUE;
}
BOOL CMainFrame::ReadPoint()
{
// TODO: Add your control notification handler code here
_variant_t _RcvDat;
CString strRcvDat;
CString strSQLText;
int RecordCount=0;
if(m_pConnection==NULL)
{
CString strConnect= _T("m_pConnection 對象為空");
this->SendMessage( WM_STATUSMSG, (WPARAM)&strConnect );
SetDoc(strConnect);
return FALSE ;
}
m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
try
{
CString strSQL;
strSQL.Format(_T("SELECT * FROM AutotollBonusPoint WHERE DispTime >=convert(datetime,'%s',21) AND DispTime <=convert(datetime,'%s',21) "),m_strBeginTime,m_strEndTime);
_variant_t varSQL(strSQL);
m_pRecordset->Open(varSQL,_variant_t((IDispatch *)m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
}
catch(_com_error *e)
{
CString errormessage;
errormessage.Format(_T("數據庫操作失敗,原因%s"),e->ErrorMessage());
this->SendMessage( WM_STATUSMSG, (WPARAM)&errormessage );
SetDoc(errormessage);
return FALSE;
}
CString strExpathName;
strExpathName.Format(_T("%s\\%s"),strLocalDir,m_strExportFile);
CStdioFile fData;
char cTemp[MAX_CHARSET];
if( !fData.Open(strExpathName, CFile::modeWrite | CFile::modeCreate))
{
CString strConnect= _T("文件創建失敗");
this->SendMessage( WM_STATUSMSG, (WPARAM)&strConnect );
SetDoc(strConnect);
return FALSE;
}
strRcvDat=_T("AccountNo/CardNo,RegTel,RegName,Contact,DispatchTime,PickupArea,PickupAreaNo,DestArea,DestAreaNo,JobNo,JobStatus,CarType,License,Fare,");
strRcvDat+=_T("\n");
fData.Write(Unicode2Char(strRcvDat, cTemp,CP_ACP), strlen(Unicode2Char( strRcvDat, cTemp, CP_ACP )) );
strRcvDat=_T("");
while(!m_pRecordset->adoEOF)
{
m_pRecordset->MoveNext();///移到下一条记录
RecordCount++;
}
if(RecordCount==0)
{
//CString strConnect= _T("从數據庫中,取到的數據為0!");
//this->SendMessage( WM_STATUSMSG, (WPARAM)&strConnect );
// SetDoc(strConnect);
return FALSE;
}
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
_RcvDat=m_pRecordset->GetFields()->GetItem("CardNo")->Value;
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+=_T(",");
}
_RcvDat=m_pRecordset->GetFields()->GetItem("RegPhone")->Value;
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+=_T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("PassName")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+= _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("Phone")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+= _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("DispTime")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+= strSQLText+ _T(",");
}
else
{
strRcvDat+= _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("OnDistName")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+= _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("OnDistCode")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat += _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("OffDistName")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+= _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("OffDistCode")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+ _T(",");
}
else
{
strRcvDat+= _T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("DispatcherID")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+_T(",");
}
else
{
strRcvDat+=_T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("DispStatus")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+_T(",");
}
else
{
strRcvDat+=_T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("CarType")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+_T(",");
}
else
{
strRcvDat+=_T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("BidTaxiNo")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText+_T(",");
}
else
{
strRcvDat+=_T(",");
}
_RcvDat=(m_pRecordset->GetFields()->GetItem("Fare")->Value);
if(_RcvDat.vt!=VT_NULL)
{
strSQLText=(TCHAR *)_bstr_t(_RcvDat);
strSQLText.TrimRight(_T(" "));
strRcvDat+=strSQLText;
}
strRcvDat+=_T("\n");
m_nSize++;
fData.Write(Unicode2Char(strRcvDat, cTemp,CP_ACP), strlen(Unicode2Char( strRcvDat, cTemp, CP_ACP )) );
strRcvDat=_T("");
m_pRecordset->MoveNext();
}
fData.Close( );
return TRUE;
}
/* CStdioFile file;
if( file.Open( _T("test.txt"), CFile::modeCreate|CFile::modeWrite) )
{
CString strTest(_T("中文,测试,代码\n"));
file.Write(Unicode2Char(strTest, cTemp,CP_ACP), strlen(Unicode2Char( strTest, cTemp, CP_ACP )) );
file.Close();
}*/
void CMainFrame::AutoExport()
{
// TODO: Add your command handler code here
CTime tNowTime,tYesterDayTime;
tNowTime=CTime::GetCurrentTime();
CTimeSpan cSpan(1,0,0,0);
tYesterDayTime=tNowTime-cSpan;
CString strTime,strBegTime,strEndTime;
strTime=tYesterDayTime.Format(_T("%Y-%m-%d"));
strBegTime.Format(_T("%s 00:00:00"),strTime);
strEndTime.Format(_T("%s 23:59:59"),strTime);
if(!ReadPoint())
{
strTemp.Format(_T("從數據庫中,取到%d條積分數據!"),m_nSize);
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
return;
}
else
{
strTemp.Format(_T("從數據庫中,取到%d條積分數據!"),m_nSize);
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
}
if(!UpLoadFile())
{
strTemp.Format(_T("積分數據,上偉到FTP失敗!"));
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
m_nSize=0;
return;
}
else
{
strTemp =_T("");
strTemp.Format(_T("%d條積分數據,上偉到FTP成功!"),m_nSize);
this->SendMessage( WM_STATUSMSG, (WPARAM)&strTemp );
SetDoc(strTemp);
m_nSize=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -