⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgconfigserver.cpp

📁 基于domino系统邮件数据库编写的邮件助手程序
💻 CPP
字号:
// DlgConfigServer.cpp : implementation file
//

#include "stdafx.h"
#include "DominoMinder.h"
#include "DlgConfigServer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgConfigServer dialog


CDlgConfigServer::CDlgConfigServer(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgConfigServer::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgConfigServer)
	//}}AFX_DATA_INIT
}


void CDlgConfigServer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgConfigServer)
	DDX_Control(pDX, IDC_COMBO_SERVER_LIST, m_oComboBoxServerList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgConfigServer, CDialog)
	//{{AFX_MSG_MAP(CDlgConfigServer)
	ON_BN_CLICKED(IDC_BUTTON_ADDSERVER, OnButtonAddServer)
	ON_BN_CLICKED(IDC_BUTTON_DELSERVER, OnButtonDelServer)
	ON_EN_CHANGE(IDC_EDIT_ADDSERVER, OnChangeEditAddServer)
	ON_BN_CLICKED(IDC_BUTTON_SERVICE_DISABLE, OnButtonServiceDisable)
	ON_BN_CLICKED(IDC_BUTTON_SERVICE_ENABLE, OnButtonServiceEnable)
	ON_BN_CLICKED(IDC_BUTTON_SERVICE_SAVE, OnButtonServiceSave)
	ON_CBN_SELCHANGE(IDC_COMBO_SERVER_LIST, OnSelchangeComboServerList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgConfigServer message handlers

void CDlgConfigServer::OnOK(){}
void CDlgConfigServer::OnCancel(){}


//将IDC_EDIT_ADDSERVER中的服务器名添加到IDC_COMBO_SERVER_LIST中
void CDlgConfigServer::OnButtonAddServer()
{
	/*
	//test
	m_oComboBoxServerList.AddString( "wrewwer" );
	CListBox* pListServiceEnabled = (CListBox*) GetDlgItem( IDC_LIST_SERVICE_ENABLED );
	pListServiceEnabled->AddString( "344" );
	pListServiceEnabled->AddString( "343424" );
	pListServiceEnabled->AddString( "法" );
	pListServiceEnabled->AddString( "方法" );
	pListServiceEnabled->AddString( "对法" );
	pListServiceEnabled->AddString( "对adsf方法" );
	return;
	*/
	
	//计算服务器名
	CString strServer;
	this->GetDlgItemText( IDC_EDIT_ADDSERVER, strServer );
	if ( strServer.GetLength() == 0 ) return;
	//加上默认端口
	if ( strServer.Find(":",0) == -1 ) {
		CString sPort;
		sPort.Format( ":%d", INTERNET_DEFAULT_HTTP_PORT );
		strServer += sPort;
	}
	//查重
	for ( int i=0; i<m_oComboBoxServerList.GetCount(); i++ ) {
		CString strText;
		m_oComboBoxServerList.GetLBText(i, strText);
		if ( strServer == strText ) return;
	}

	//登录到服务器,并获取服务信息
	CString rgServiceName[100];
	int nServiceCnt = 0;

	CDominoMessage *pDominoMsg = CDominoMessage::GetInstance();
	if ( pDominoMsg->AddServer(strServer) ) {
		CString sRes = pDominoMsg->Login(strServer);
		if ( sRes == "" ) {
			//获取服务信息
			pDominoMsg->GetServiceCfg(strServer);
			nServiceCnt = pDominoMsg->GetServiceCnt(strServer);
			if ( nServiceCnt <= 0 ) {
				//没有可用服务
				char sz[51]; memset(sz,0,sizeof(sz));
				LoadString( NULL, IDS_NO_VALID_SERVICE, sz, 50 );
				MessageBox( sz );
				return;
			}
		} else {
			//登录错误
			pDominoMsg->DelServer(strServer);
			MessageBox( sRes );
			return;
		}
	} else {
		//增加服务器失败
		char sz[51]; memset(sz,0,sizeof(sz));
		LoadString( NULL, IDS_ADDSERVER_FAIL, sz, 50 );
		MessageBox( sz );
		return;
	}

	//添加服务器到列表
	m_oComboBoxServerList.AddString( strServer );
	m_oComboBoxServerList.SetCurSel( m_oComboBoxServerList.FindStringExact(0,strServer) );

	//添加服务到列表
	pDominoMsg->LoadConfigServer( this, strServer );
	/*
	CListBox* pListServiceEnabled  = (CListBox*) GetDlgItem( IDC_LIST_SERVICE_ENABLED );
	CListBox* pListServiceDisabled = (CListBox*) GetDlgItem( IDC_LIST_SERVICE_DISABLED );
	for ( i=0; i<nServiceCnt; i++ ) {
		pListServiceEnabled->AddString( rgServiceName[i] );
	}
	*/
}

//删除IDC_COMBO_SERVER_LIST中当前选择的
void CDlgConfigServer::OnButtonDelServer() 
{
	CListBox* pListServiceEnabled  = (CListBox*) GetDlgItem( IDC_LIST_SERVICE_ENABLED );
	CListBox* pListServiceDisabled = (CListBox*) GetDlgItem( IDC_LIST_SERVICE_DISABLED );
	pListServiceEnabled->ResetContent();
	pListServiceDisabled->ResetContent();

	if ( (m_oComboBoxServerList.GetCount() == 1) && (m_oComboBoxServerList.GetCurSel()==0) ) {
		m_oComboBoxServerList.ResetContent();
	} else {
		m_oComboBoxServerList.DeleteString( m_oComboBoxServerList.GetCurSel() );
	}
}

//防止服务器名过长
void CDlgConfigServer::OnChangeEditAddServer() 
{
	CString strText;
	GetDlgItemText( IDC_EDIT_ADDSERVER, strText );
	if ( strText.GetLength() > 40 ) {
		SetDlgItemText( IDC_EDIT_ADDSERVER, strText.GetBufferSetLength(40) );
	}

}

void CDlgConfigServer::transListBoxSels( CListBox* pLBS, CListBox* pLBT )
{
	int rgIndex[100]; //最大肯定不会超过100吧:)
	CString rgText[100];

	int nCount = pLBS->GetSelCount();
	pLBS->GetSelItems(nCount, rgIndex);

	for ( int i=0; i<nCount; i++ ) {
		pLBS->GetText(rgIndex[i], rgText[i]);
	}

	for ( i=nCount-1; i>=0; i-- ) {
		if ( pLBT->FindStringExact(0, rgText[i]) == -1 ) {
			pLBT->AddString( rgText[i] );
		}
		pLBS->DeleteString( rgIndex[i] );
	}
}

//禁用服务
void CDlgConfigServer::OnButtonServiceDisable() 
{
	transListBoxSels(
		(CListBox*) GetDlgItem( IDC_LIST_SERVICE_ENABLED ),
		(CListBox*) GetDlgItem( IDC_LIST_SERVICE_DISABLED )
	);
}

//启用服务
void CDlgConfigServer::OnButtonServiceEnable() 
{
	transListBoxSels(
		(CListBox*) GetDlgItem( IDC_LIST_SERVICE_DISABLED ),
		(CListBox*) GetDlgItem( IDC_LIST_SERVICE_ENABLED )
	);	
}

//保存当前服务器的服务配置
void CDlgConfigServer::OnButtonServiceSave() 
{
	CConfig* pCfg = CConfig::GetInstance();
	pCfg->SaveConfigServer( this );
}

//切换服务器列表-切换服务配置显示
// 若已装载到DominoMessage队列,则从队列中装载配置;否则从配置文档中装载(同时装载到DominoMsg队列)
void CDlgConfigServer::OnSelchangeComboServerList() 
{
	CString strSvrName;
	m_oComboBoxServerList.GetLBText( m_oComboBoxServerList.GetCurSel(), strSvrName );

	CConfig* pCfg = CConfig::GetInstance();
	pCfg->LoadConfigServer( this, strSvrName );
	
	/*
	CDominoMessage* pDominoMsg = CDominoMessage::GetInstance();
	if ( pDominoMsg->GetCount() > 0 ) {
		pDominoMsg->LoadConfigServer( this, strSvrName );
	} else {
		CConfig* pCfg = CConfig::GetInstance();
		pCfg->LoadConfigServer( this, strSvrName );
	}
	*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -