connectserver.cpp

来自「本系统实现了简单的点歌功能」· C++ 代码 · 共 124 行

CPP
124
字号
// ConnectServer.cpp : implementation file
//

#include "stdafx.h"
#include "songclient.h"
#include "ConnectServer.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConnectServer dialog
BOOL CConnectServer::m_bShowDlg = true;
CString	CConnectServer::m_strserverip = "";
CString	CConnectServer::m_strdbname = "";
CString	CConnectServer::m_strusername = "";
CString	CConnectServer::m_strpassword = "";


CConnectServer::CConnectServer(CWnd* pParent /*=NULL*/)
	: CDialog(CConnectServer::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConnectServer)
	m_dbname = _T("song");
	m_password = _T("sa");
	m_serverip = _T("127.0.0.1");
	m_username = _T("");
	//}}AFX_DATA_INIT
}


void CConnectServer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConnectServer)
	DDX_Text(pDX, IDC_DatabaseName, m_dbname);
	DDX_Text(pDX, IDC_Password, m_password);
	DDX_Text(pDX, IDC_ServerIP, m_serverip);
	DDX_Text(pDX, IDC_Username, m_username);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConnectServer, CDialog)
	//{{AFX_MSG_MAP(CConnectServer)
	ON_BN_CLICKED(IDC_SaveLoginMsg, OnSaveLoginMsg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConnectServer message handlers

void CConnectServer::OnOK() 
{
	// TODO: Add extra validation here
	 UpdateData();	

    m_strserverip = m_serverip;
	m_strdbname = m_dbname;
	m_strusername = m_username;
	m_strpassword = m_password;
	
	CDialog::OnOK();
}

CString CConnectServer::GetServerIp()
{
	return m_strserverip;
}
 
CString CConnectServer::GetDatabaseName()
{
	return m_strdbname;
}

CString CConnectServer::GetUsername()
{
	return m_strusername;
}

CString CConnectServer::GetPassword()
{
	return m_strpassword;
}

CString CConnectServer::GetAppPath(void)
{
	char chPath[MAX_PATH];
	CString strPath;
	int strCount;

	GetModuleFileName(NULL,chPath,MAX_PATH);//得到执行文件名的全路径
	strPath = chPath;
	strCount = strPath.ReverseFind('\\');
	strPath = strPath.Mid(0,strCount)+"\\";
	return strPath;
}

void CConnectServer::OnSaveLoginMsg() 
{
	UpdateData();

   	FILE *fp = NULL;
	fp = fopen(GetAppPath() + "loginmsg.msg", "w");
	if(fp == NULL)
	{
		AfxMessageBox("创建文件失败.");
		return;
	}
	fprintf(fp, "%s\n", m_serverip);
	fprintf(fp, "%s\n", m_dbname);
	fprintf(fp, "%s\n", m_username);
	fprintf(fp, "%s\n", m_password);
	fclose(fp);
}

BOOL CConnectServer::IsShowDlg()
{
	return m_bShowDlg;
}

⌨️ 快捷键说明

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