PageYou.cpp
资源名称:Netmanag.zip [点击查看]
上传用户:geanq888
上传日期:2007-01-03
资源大小:316k
文件大小:10k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // PageYou.cpp : implementation file
- //
- #include "stdafx.h"
- #include "NetManager.h"
- #include "PageYou.h"
- #include "GlobalsExtern.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- UINT g_FileUpload(LPVOID);
- /////////////////////////////////////////////////////////////////////////////
- // CPageYou property page
- IMPLEMENT_DYNCREATE(CPageYou, CPropertyPage)
- CPageYou::CPageYou() : CPropertyPage(CPageYou::IDD)
- {
- //{{AFX_DATA_INIT(CPageYou)
- m_sServerName = _T("");
- m_sDestination = _T("");
- m_sDestinationDir = _T("");
- m_sPassword = _T("");
- m_sUserName = _T("");
- m_sSourceFile1 = _T("");
- m_sSourceFile2 = _T("");
- m_sIP = _T("");
- m_sIPName = _T("");
- m_sDate = _T("");
- m_sTagDate = _T("");
- m_sTagMachine = _T("");
- m_bWithAddress = FALSE;
- m_bWithDate = FALSE;
- m_bOfflineOnEnd = FALSE;
- m_bOnlineOnStart = FALSE;
- //}}AFX_DATA_INIT
- }
- CPageYou::~CPageYou()
- {
- }
- void CPageYou::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPageYou)
- DDX_Control(pDX, IDC_IPNAME, m_IPName);
- DDX_Control(pDX, IDC_IP, m_IP);
- DDX_Control(pDX, IDC_DATE, m_Date);
- DDX_Control(pDX, IDC_SOURCEFILE2, m_SourceFile2);
- DDX_Control(pDX, IDC_SOURCEFILE1, m_SourceFile1);
- DDX_Text(pDX, IDC_FTPSERVER, m_sServerName);
- DDX_Text(pDX, IDC_DESTINATION, m_sDestination);
- DDX_Text(pDX, IDC_DESTINATIONDIR, m_sDestinationDir);
- DDX_Text(pDX, IDC_FTPPASSWORD, m_sPassword);
- DDX_Text(pDX, IDC_FTPUSERNAME, m_sUserName);
- DDX_Text(pDX, IDC_SOURCEFILE1, m_sSourceFile1);
- DDX_Text(pDX, IDC_SOURCEFILE2, m_sSourceFile2);
- DDX_Text(pDX, IDC_IP, m_sIP);
- DDX_Text(pDX, IDC_IPNAME, m_sIPName);
- DDX_Text(pDX, IDC_DATE, m_sDate);
- DDX_Text(pDX, IDC_TAG_DATE, m_sTagDate);
- DDX_Text(pDX, IDC_TAG_MACHINE, m_sTagMachine);
- DDX_Check(pDX, IDC_WITH_ADDRESS, m_bWithAddress);
- DDX_Check(pDX, IDC_WITH_DATE, m_bWithDate);
- DDX_Check(pDX, IDC_OFFLINE_ONEND, m_bOfflineOnEnd);
- DDX_Check(pDX, IDC_ONLINE_ONSTART, m_bOnlineOnStart);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPageYou, CPropertyPage)
- //{{AFX_MSG_MAP(CPageYou)
- ON_BN_CLICKED(IDB_ONLINE, OnOnline)
- ON_BN_CLICKED(IDB_OFFLINE, OnOffline)
- ON_BN_CLICKED(IDB_BROWSE_OFF, OnBrowseOff)
- ON_BN_CLICKED(IDB_BROWSE_ON, OnBrowseOn)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPageYou message handlers
- BOOL CPageYou::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- m_ToolTip.Create(this);
- m_ToolTip.Activate(TRUE);
- CWnd* pWnd = GetWindow(GW_CHILD);
- while(pWnd)
- {
- int nID = pWnd->GetDlgCtrlID();
- if (nID != -1)
- m_ToolTip.AddTool(pWnd, pWnd->GetDlgCtrlID());
- pWnd = pWnd->GetWindow(GW_HWNDNEXT);
- }
- CTime LoginTime = CTime::GetCurrentTime();
- CString sLoginTime = LoginTime.Format("%A, %B %d, %Y, %H:%M:%S");
- m_Date.SetWindowText(sLoginTime);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageYou::OnBrowseOn()
- {
- UpdateData();
- CFileDialog BrowseDialog(TRUE);
- if(BrowseDialog.DoModal() == IDOK)
- {
- m_sSourceFile1 = BrowseDialog.GetPathName();
- m_SourceFile1.SetWindowText(m_sSourceFile1);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageYou::OnBrowseOff()
- {
- UpdateData();
- CFileDialog BrowseDialog(TRUE);
- if(BrowseDialog.DoModal() == IDOK)
- {
- m_sSourceFile2 = BrowseDialog.GetPathName();
- m_SourceFile2.SetWindowText(m_sSourceFile2);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageYou::OnOnline()
- {
- UpdateData();
- CStringArray* pasUpload = new CStringArray;
- CString sWithDate = "";
- CString sWithAddress = "";
- if(m_bWithDate)
- sWithDate = "YES";
- if(m_bWithAddress)
- sWithAddress = "YES";
- pasUpload->Add(m_sSourceFile1);
- pasUpload->Add("[You]: Now you are On-line");
- pasUpload->Add(m_sServerName);
- pasUpload->Add(m_sUserName);
- pasUpload->Add(m_sPassword);
- pasUpload->Add(m_sDestinationDir);
- pasUpload->Add(m_sDestination);
- pasUpload->Add(m_sIPName);
- pasUpload->Add(m_sIP);
- pasUpload->Add(m_sTagDate);
- pasUpload->Add(m_sTagMachine);
- pasUpload->Add(sWithDate);
- pasUpload->Add(sWithAddress);
- AfxBeginThread(g_FileUpload, pasUpload);
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageYou::OnOffline()
- {
- UpdateData();
- CStringArray* pasUpload = new CStringArray;
- CString sWithDate = "";
- CString sWithAddress = "";
- if(m_bWithDate)
- sWithDate = "YES";
- if(m_bWithAddress)
- sWithAddress = "YES";
- pasUpload->Add(m_sSourceFile2);
- pasUpload->Add("[You]: Now you are Off-line");
- pasUpload->Add(m_sServerName);
- pasUpload->Add(m_sUserName);
- pasUpload->Add(m_sPassword);
- pasUpload->Add(m_sDestinationDir);
- pasUpload->Add(m_sDestination);
- pasUpload->Add(m_sIPName);
- pasUpload->Add(m_sIP);
- pasUpload->Add(m_sTagDate);
- pasUpload->Add(m_sTagMachine);
- pasUpload->Add(sWithDate);
- pasUpload->Add(sWithAddress);
- AfxBeginThread(g_FileUpload, pasUpload);
- }
- /////////////////////////////////////////////////////////////////////////////
- UINT g_FileUpload(LPVOID pParam)
- {
- CStringArray* pasUpload = ((CStringArray*)pParam);
- CString sFilePath = pasUpload->GetAt(0);
- CString sOutputText = pasUpload->GetAt(1);
- CString sServerName = pasUpload->GetAt(2);
- CString sUserName = pasUpload->GetAt(3);
- CString sPassword = pasUpload->GetAt(4);
- CString sDestinationDir = pasUpload->GetAt(5);
- CString sDestination = pasUpload->GetAt(6);
- CString sIPName = pasUpload->GetAt(7);
- CString sIP = pasUpload->GetAt(8);
- CString sTagDate = pasUpload->GetAt(9);
- CString sTagMachine = pasUpload->GetAt(10);
- CString sWithDate = pasUpload->GetAt(11);
- CString sWithAddress = pasUpload->GetAt(12);
- pasUpload->RemoveAll();
- delete pasUpload;
- g_AnimateWait->Play(0, -1, -1);
- CInternetSession INetSect(AfxGetAppName(), 0, INTERNET_OPEN_TYPE_DIRECT);
- CFtpConnection* pFtpConn;
- TRY
- {
- if(pFtpConn = INetSect.GetFtpConnection(sServerName, sUserName, sPassword))
- {
- if(sDestinationDir != "")
- {
- if(!pFtpConn->SetCurrentDirectory(sDestinationDir))
- g_WriteToHistory(TRUE, "[You]: Error - Change FTP Directory");
- }
- CInternetFile* pFtpFile;
- pFtpFile = pFtpConn->OpenFile(sDestination, GENERIC_WRITE);
- if(pFtpFile)
- {
- CTime LoginTime = CTime::GetCurrentTime();
- CString sLoginTime = "";
- if(sWithDate == "YES")
- sLoginTime = LoginTime.Format("%A, %B %d, %Y, %H:%M:%S");
- CString sMachine = "";
- if(sWithAddress == "YES")
- sMachine = sIPName + " - " + sIP;
- CString sBuffer;
- CStdioFile CInputFile;
- CInputFile.Open(sFilePath, CFile::modeRead);
- int nTimePos;
- bool bTagDateFound = FALSE;
- bool bTagMachineFound = FALSE;
- while(CInputFile.ReadString(sBuffer))
- {
- if((nTimePos = sBuffer.Find(sTagDate)) != -1)
- {
- sBuffer = sBuffer.Left(nTimePos) + sLoginTime + sBuffer.Right(sBuffer.GetLength() - nTimePos - 6);
- bTagDateFound = TRUE;
- }
- if((nTimePos = sBuffer.Find(sTagMachine)) != -1)
- {
- sBuffer = sBuffer.Left(nTimePos) + sMachine + sBuffer.Right(sBuffer.GetLength() - nTimePos - 9);
- bTagMachineFound = TRUE;
- }
- sBuffer += (char)0xa;
- pFtpFile->WriteString(sBuffer);
- }
- pFtpFile->Close();
- if(!bTagDateFound)
- AfxMessageBox("[You]: The tag " + sTagDate + " not found in " + sFilePath);
- if(!bTagMachineFound)
- AfxMessageBox("[You]: The tag " + sTagMachine + " not found in " + sFilePath);
- g_WriteToHistory(TRUE, sOutputText);
- }
- else
- g_WriteToHistory(TRUE, "[You]: Error - Upload File");
- }
- else
- g_WriteToHistory(TRUE, "[You]: Error - Opening FTP");
- }
- CATCH(CInternetException, pe)
- {
- TCHAR szCause[255];
- pe->GetErrorMessage(szCause, 255);
- CString sError = "[You]: Error - ";
- sError += szCause;
- g_WriteToOutput(FALSE, sError);
- }
- CATCH(CFileException, pe)
- {
- TCHAR szCause[255];
- pe->GetErrorMessage(szCause, 255);
- CString sError = "[You]: Error - ";
- sError += szCause;
- g_WriteToOutput(FALSE, sError);
- }
- END_CATCH;
- INetSect.Close();
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- BOOL CPageYou::PreTranslateMessage(MSG* pMsg)
- {
- // transate the message based on TTM_WINDOWFROMPOINT
- MSG msg = *pMsg;
- msg.hwnd = (HWND)m_ToolTip.SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt);
- CPoint pt = pMsg->pt;
- if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST)
- ::ScreenToClient(msg.hwnd, &pt);
- msg.lParam = MAKELONG(pt.x, pt.y);
- // Let the ToolTip process this message.
- m_ToolTip.RelayEvent(&msg);
- if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
- NextDlgCtrl();
- return CPropertyPage::PreTranslateMessage(pMsg);
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageYou::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- { // storing code
- ar << m_sServerName;
- ar << m_sDestination;
- ar << m_sDestinationDir;
- ar << m_sPassword;
- ar << m_sUserName;
- ar << m_sSourceFile1;
- ar << m_sSourceFile2;
- ar << m_sTagDate;
- ar << m_sTagMachine;
- ar << m_bOnlineOnStart;
- ar << m_bOfflineOnEnd;
- ar << m_bWithAddress;
- ar << m_bWithDate;
- }
- else
- { // loading code
- ar >> m_sServerName;
- ar >> m_sDestination;
- ar >> m_sDestinationDir;
- ar >> m_sPassword;
- ar >> m_sUserName;
- ar >> m_sSourceFile1;
- ar >> m_sSourceFile2;
- ar >> m_sTagDate;
- ar >> m_sTagMachine;
- ar >> m_bOnlineOnStart;
- ar >> m_bOfflineOnEnd;
- ar >> m_bWithAddress;
- ar >> m_bWithDate;
- }
- }
- /////////////////////////////////////////////////////////////////////////////