SetDlgSelectSite.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:8k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // SetDlgSelectSite.cpp : implementation file
- //
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "QuickFTP.h"
- #include "SetDlgSelectSite.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSetDlgSelectSite dialog
- CSetDlgSelectSite::CSetDlgSelectSite(CWnd* pParent /*=NULL*/)
- : CDialog(CSetDlgSelectSite::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSetDlgSelectSite)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pSiteHead = NULL ;
- memset( &m_CurSelSite , 0 , sizeof( m_CurSelSite ) ) ;
- }
- void CSetDlgSelectSite::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSetDlgSelectSite)
- DDX_Control(pDX, IDC_LIST_SITE, m_SiteList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSetDlgSelectSite, CDialog)
- //{{AFX_MSG_MAP(CSetDlgSelectSite)
- ON_BN_CLICKED(IDC_BUTTON_ADD_SITE, OnButtonAddSite)
- ON_BN_CLICKED(IDC_BUTTON_EDIT_SITE, OnButtonEditSite)
- ON_BN_CLICKED(IDC_BUTTON_DEL_SITE, OnButtonDelSite)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST_SITE, OnDblclkListSite)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSetDlgSelectSite message handlers
- void CSetDlgSelectSite::OnOK()
- {
- // TODO: Add extra validation here
- SaveSiteInfoToFile( ) ;
- GetCurSelSite() ;
- DeleteAllSite() ;
- CDialog::OnOK();
- }
- void CSetDlgSelectSite::OnCancel()
- {
- // TODO: Add extra cleanup here
- SaveSiteInfoToFile( ) ;
- DeleteAllSite() ;
- CDialog::OnCancel();
- }
- void CSetDlgSelectSite::OnButtonAddSite()
- {
- // TODO: Add your control notification handler code here
- CSetDlgInputSite sitedlg ;
- if( sitedlg.DoModal() == IDOK )
- {
- if( !AddSite( &sitedlg.m_SiteInfo ) )
- MessageBox( "Can't add site!" ) ;
- InitSiteList( ) ;
- }
- }
- void CSetDlgSelectSite::OnButtonEditSite()
- {
- // TODO: Add your control notification handler code here
- int iCount = m_SiteList.GetSelectedCount();
- if( iCount > 1 || iCount <= 0)
- return ;
- int iCurSel = m_SiteList.GetNextItem( -1 , LVNI_SELECTED ) ;
- if( iCurSel == -1 )
- return ;
- CSetDlgInputSite sitedlg ;
- GetOneSite( iCurSel , &sitedlg.m_SiteInfo ) ;
- if( sitedlg.DoModal() == IDOK )
- {
- ReplaceOneSite( iCurSel , &sitedlg.m_SiteInfo ) ;
- InitSiteList( ) ;
- }
- }
- void CSetDlgSelectSite::OnButtonDelSite()
- {
- // TODO: Add your control notification handler code here
- int iCount = m_SiteList.GetSelectedCount();
- if( iCount > 1 || iCount <= 0)
- return ;
- int iCurSel = m_SiteList.GetNextItem( -1 , LVNI_SELECTED ) ;
- if( iCurSel == -1 )
- return ;
- DeleteOneSite( iCurSel ) ;
- InitSiteList( ) ;
- }
- BOOL CSetDlgSelectSite::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_ImageList.Create(16, 16, ILC_COLOR8, 0, 4);
- HICON hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME ) ;
- m_ImageList.Add( hIcon ) ;
- m_SiteList.SetImageList( &m_ImageList , LVSIL_SMALL ) ;
- if( m_pSiteHead == NULL )
- {
- m_pSiteHead = new SITEQUEUEITEM ;
- memset( m_pSiteHead , 0 , sizeof( SITEQUEUEITEM ) ) ;
- }
- if( ReadSiteFromFile( ) )
- {
- InitSiteList( ) ;
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BOOL CSetDlgSelectSite::ReadSiteFromFile()
- {
- CFile file ;
- SITEINFO site ;
- SITEQUEUEITEM* pSiteItem ;
- SITEQUEUEITEM* pCurItem ;
- pCurItem = m_pSiteHead ;
- int ItemSize = sizeof( SITEINFO ) ;
- int ReadSize = 1 ;
- if( file.Open( "SiteInfo.QFP" , CFile::modeRead ) )
- {
- while( ReadSize )
- {
- ReadSize = file.Read( &site , ItemSize ) ;
- if( ReadSize != ItemSize )
- break ;
- memcpy( &pCurItem->site , &site , ItemSize ) ;
- pSiteItem = new SITEQUEUEITEM ;
- memset( pSiteItem , 0 , sizeof( SITEQUEUEITEM ) ) ;
- pCurItem->pNext = pSiteItem ;
- pCurItem = pSiteItem ;
- }
- }
- else
- return false ;
- file.Close() ;
- return true ;
- }
- BOOL CSetDlgSelectSite::InitSiteList()
- {
- SITEQUEUEITEM* pCurItem ;
- m_SiteList.DeleteAllItems( ) ;
- pCurItem = m_pSiteHead ;
- int nItem = 0 ;
- while( pCurItem->pNext != NULL )
- {
- m_SiteList.InsertItem( nItem , pCurItem->site.sitename , 0 ) ;
- pCurItem->iNo = nItem ;
- pCurItem = pCurItem->pNext ;
- nItem ++ ;
- }
- return true ;
- }
- BOOL CSetDlgSelectSite::SaveSiteInfoToFile()
- {
- CFile file ;
- if( !file.Open( "SiteInfo.QFP" , CFile::modeCreate|CFile::modeWrite ) )
- {
- return false ;
- }
- SITEQUEUEITEM* pCurItem ;
- pCurItem = m_pSiteHead ;
- while( pCurItem->pNext != NULL )
- {
- try
- {
- file.Write( &pCurItem->site , sizeof( SITEINFO ) ) ;
- }
- catch( CFileException* e )
- {
- e->Delete( ) ;
- }
- pCurItem = pCurItem->pNext ;
- }
- file.Close() ;
- return true ;
- }
- BOOL CSetDlgSelectSite::AddSite(SITEINFO *pSite)
- {
- SITEQUEUEITEM* pSiteItem ;
- SITEQUEUEITEM* pCurItem ;
- pCurItem = m_pSiteHead ;
- while( pCurItem->pNext != NULL )
- pCurItem = pCurItem->pNext ;
- memcpy( &pCurItem->site , pSite , sizeof( SITEINFO ) ) ;
- pSiteItem = new SITEQUEUEITEM ;
- memset( pSiteItem , 0 , sizeof( SITEQUEUEITEM ) );
- pCurItem->pNext = pSiteItem ;
- return true ;
- }
- BOOL CSetDlgSelectSite::DeleteAllSite()
- {
- SITEQUEUEITEM* pCurItem ;
- pCurItem = m_pSiteHead ;
- while( m_pSiteHead != NULL )
- {
- pCurItem = m_pSiteHead ;
- m_pSiteHead = m_pSiteHead->pNext ;
- delete pCurItem ;
- }
- return true ;
- }
- BOOL CSetDlgSelectSite::DeleteOneSite(int iNo)
- {
- SITEQUEUEITEM* pCurItem = m_pSiteHead ;
- SITEQUEUEITEM* pPreItem = m_pSiteHead ;
- if( pCurItem->iNo == iNo )
- {
- m_pSiteHead = m_pSiteHead->pNext ;
- delete pCurItem ;
- pCurItem = NULL ;
- return true ;
- }
- else
- {
- pPreItem = pCurItem ;
- pCurItem = pCurItem->pNext ;
- }
- while( pCurItem->pNext != NULL )
- {
- if( pCurItem->iNo == iNo )
- break ;
- pPreItem = pCurItem ;
- pCurItem = pCurItem->pNext ;
- }
- if( pCurItem->pNext == NULL )
- {
- MessageBox( "Can't find this item ! Can't del !" ) ;
- return false ;
- }
- pPreItem->pNext = pCurItem->pNext ;
- delete pCurItem ;
- pCurItem = NULL ;
- return true ;
- }
- BOOL CSetDlgSelectSite::ReplaceOneSite(int iNo , SITEINFO* pSite )
- {
- SITEQUEUEITEM* pCurItem = m_pSiteHead ;
- while( pCurItem->pNext != NULL )
- {
- if( pCurItem->iNo == iNo )
- break ;
- pCurItem = pCurItem->pNext ;
- }
- if( pCurItem->pNext == NULL )
- {
- MessageBox( "Can't find this item !" ) ;
- return false ;
- }
- memcpy( &pCurItem->site , pSite , sizeof( SITEINFO ) ) ;
- return true ;
- }
- BOOL CSetDlgSelectSite::GetOneSite(int iNo, SITEINFO *pSite)
- {
- SITEQUEUEITEM* pCurItem = m_pSiteHead ;
- while( pCurItem->pNext != NULL )
- {
- if( pCurItem->iNo == iNo )
- break ;
- pCurItem = pCurItem->pNext ;
- }
- if( pCurItem->pNext == NULL )
- {
- MessageBox( "Can't find this item !" ) ;
- return false ;
- }
- memcpy( pSite , &pCurItem->site , sizeof( SITEINFO ) ) ;
- return true;
- }
- BOOL CSetDlgSelectSite::GetCurSelSite()
- {
- int iCount = m_SiteList.GetSelectedCount();
- if( iCount > 1 || iCount <= 0)
- return false ;
- int iCurSel = m_SiteList.GetNextItem( -1 , LVNI_SELECTED ) ;
- if( iCurSel == -1 )
- return false ;
- GetOneSite( iCurSel , &m_CurSelSite ) ;
- return true ;
- }
- void CSetDlgSelectSite::OnDblclkListSite(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- /*
- int iCount = m_SiteList.GetSelectedCount() ;
- if( iCount != 1 )
- return ;
- int iItem = -1 ;
- iItem = m_SiteList.GetNextItem( iItem , LVNI_SELECTED ) ;
- */
- OnOK( ) ;
- *pResult = 0;
- }