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

📄 serverdlg.cpp

📁 类似于QQ的聊天工具,分为客户端和服务器端,有共享空间,能发布公告,可传输文件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	}
}

void CServerDlg::OnBtnCloseserver() 
{
	// TODO: Add your control notification handler code here
	if(MessageBox("确定要暂停服务器吗?", "暂停服务器",
					MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		return;
	}

	m_SvrSock.CloseServer();
	
	/*m_strSysMsg.Format("服务器已经暂停服务  %s", m_strTime);
	int Index = m_lstShow.GetItemCount();
	m_lstShow.InsertItem(Index, m_strSysMsg);*/

	(GetDlgItem(IDC_BTN_CLOSESERVER))->EnableWindow(false);
	(GetDlgItem(IDC_BTN_STARTSERVER))->EnableWindow(true);
	(GetDlgItem(IDC_EDIT_PORT))->EnableWindow(true);
	(GetDlgItem(IDC_STC_PORT))->EnableWindow(true);
}

void CServerDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CTime time = CTime::GetCurrentTime();
	m_strTime = time.Format("20%y-%m-%d %H:%M:%S");
	CDialog::OnTimer(nIDEvent);
}

BOOL CServerDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	KillTimer(TIMERID_TIME);
	return CDialog::DestroyWindow();
}

void CServerDlg::OnFileEvent(WPARAM wParam, LPARAM lParam)
{
	m_ftManage.OnAccept(&(m_SvrSock.GetCn()));
}

void CServerDlg::OnBtnStartfileserver() 
{
	// TODO: Add your control notification handler code here
	if(!m_bConnentDB)
	{
		if(MessageBox("数据库尚未连接,打开数据库连接?",
			"系统提示", MB_YESNO | MB_ICONQUESTION) == IDYES)
		{
			OnBtnConnectdb();
		}
		else
		{
			return;
		}
	}
	
	/////////////////////////////////////////////////////////////////////////
	//检查文件服务文件夹是否存在
	CConn& cn = m_SvrSock.GetCn();
	CRecs  rs;
	CString strSql = "select sharedirectory from sharefileid";
	if(!rs.Open(cn.GetActiveConn(), (_variant_t)strSql))
	{
		return;
	}
	if(!rs.GetRs()->adoEOF)
	{
		_variant_t DirPath = rs.GetRs()->GetCollect((_variant_t)0L);
		CString strDirPath = (char*)(_bstr_t)DirPath;
		CFileFind finder;
		///////////////////////////////
		//查找文件服务目录是否存在
		if(finder.FindFile(strDirPath))
		{
			finder.FindNextFile();
			///////////////////////////
			//判断是否是文件夹
			if(!finder.IsDirectory())
			{
				CString msg = "系统检查到上次创建的文件服务目录\n已经不存在,";
				msg += "是否新创建一个文件服务目录?";
				if(MessageBox(msg, "系统提示",	MB_YESNO | MB_ICONQUESTION) == IDNO)
				{
					return;
				}
				CreateDirectory(strDirPath, NULL);
			}
		}
	}
	else
	{
		if(MessageBox("系统检查到您还没有创建文件服务目录,是否现在创建?", 
			"系统提示",	MB_YESNO | MB_ICONQUESTION) == IDNO)
		{
			return;
		}

		CFileDialog fdlg(false, NULL, "文件服务", OFN_HIDEREADONLY |
						  OFN_OVERWRITEPROMPT, "所有文件(*.*)|*.*||");
		fdlg.m_ofn.lpstrTitle = "设置文件服务目录";
		if(fdlg.DoModal() == IDCANCEL)
		{
			return;
		}
		CString strDirPath = fdlg.GetPathName();
		CreateDirectory(strDirPath, NULL);

		strSql = "insert into sharefileid values(0, '" + strDirPath + "')";
		if(!cn.ExecuteSql((_bstr_t)strSql))
		{
			AfxMessageBox("文件服务目录设置失败,请重试!");
			return;
		}
	}

	(GetDlgItem(IDC_BTN_STARTFILESERVER))->EnableWindow(false);
	(GetDlgItem(IDC_BTN_CLOSEFILESERVER))->EnableWindow(true);
	m_ftManage.InitFlieListenSock();
	//注册文件网络事件
	int ret = WSAAsyncSelect(m_ftManage.GetFlieListenSock(), m_hWnd, 
                              WM_FILEEVENT, FD_ACCEPT); 

}

void CServerDlg::OnBtnClosefileserver() 
{
	// TODO: Add your control notification handler code here
	m_ftManage.CloseFileSock();
	(GetDlgItem(IDC_BTN_STARTFILESERVER))->EnableWindow(true);
	(GetDlgItem(IDC_BTN_CLOSEFILESERVER))->EnableWindow(false);
}

void CServerDlg::OnBtnConnectdb() 
{
	// TODO: Add your control notification handler code here
	if(m_SvrSock.ConnectDB())
	{
		(GetDlgItem(IDC_BTN_CONNECTDB))->EnableWindow(false);
		(GetDlgItem(IDC_BTN_UNCONNECTDB))->EnableWindow(true);
		m_bConnentDB = true;
	}
}

void CServerDlg::OnBtnUnconnectdb() 
{
	// TODO: Add your control notification handler code here
		m_SvrSock.UnConnectDB();
		(GetDlgItem(IDC_BTN_CONNECTDB))->EnableWindow(true);
		(GetDlgItem(IDC_BTN_UNCONNECTDB))->EnableWindow(false);
		m_bConnentDB = false;
}

void CServerDlg::OnDealSysMsg(WPARAM wParam, LPARAM lParam)
{
	/////////////////////////////////////////////////
	//接收用户公告  [Add] dong 12-17
	if(lParam == 1007)
	{
		CString strBuf = (char*)wParam;
		CMsgBag mbTool;
		CString strUserId = mbTool.GetDesUserId(strBuf);
		CString strCall[2];
		mbTool.SplitDate(strBuf, strCall);
		CString strTmp;
		strTmp.Format("%s [%s]  %s\r\n%s\r\n\r\n", strUserId, strCall[0],
						m_strTime, strCall[1]);
		m_strCallBuf += strTmp;
		if(m_CallBoardHwnd)
		{
			::SetWindowText(::GetDlgItem(m_CallBoardHwnd, IDC_EDIT_CALLLOG), m_strCallBuf);
		}
		else
		{
			m_nNewCallCount++;
			CString strNewCallCount;
			strNewCallCount.Format(" %d ", m_nNewCallCount);
			GetDlgItem(IDC_STC_CALLMSG)->SetWindowText("收到" + strNewCallCount + "条新的用户公告...");
		}
		return;
	}

	////////////////////////////////////////////////
	//系统保留信息
	tagServerSysMsg* msg = (tagServerSysMsg*)wParam;
	msg->strSydMsg[6]    = m_strTime;

	int nIndex = m_lstShow.GetItemCount();
	m_lstShow.InsertItem(nIndex, msg->strSydMsg[0]);
	for(int i = 1; i < 7; i++)
	{
		m_lstShow.SetItemText(nIndex, i, msg->strSydMsg[i]);
	}
	
	delete msg;
}

CSvrSock& CServerDlg::GetSvrSock()
{
	return m_SvrSock;
}
void CServerDlg::OnBtnCallboard() 
{
	// TODO: Add your control notification handler code here
	if(m_CallBoardHwnd)
	{
		::SetActiveWindow(m_CallBoardHwnd);
		return;
	}
	
	m_nNewCallCount = 0;
	GetDlgItem(IDC_STC_CALLMSG)->SetWindowText("");
	CCallBoard* m_CallBoardDlg = new CCallBoard(this);
	m_CallBoardDlg->Create(IDD_CALLBOARD);
	m_CallBoardDlg->GetDlgItem(IDC_EDIT_CALLLOG)->SetWindowText(m_strCallBuf);
	m_CallBoardDlg->ShowWindow(true);
	m_CallBoardHwnd = m_CallBoardDlg->m_hWnd;
}

void CServerDlg::OnBtnSharefilemng() 
{
	// TODO: Add your control notification handler code here
	if(!m_bConnentDB)
	{
		if(MessageBox("数据库尚未连接,打开数据库连接?",
			"系统提示", MB_YESNO | MB_ICONQUESTION) == IDYES)
		{
			OnBtnConnectdb();
		}
		else
		{
			return;
		}
	}
	if(m_FileManageHwnd)
	{
		::SetActiveWindow(m_FileManageHwnd);
		return;
	}
	
	CFileManage* m_CfileManageDlg = new CFileManage(this);
	m_CfileManageDlg->Create(IDD_FILEDLG);
	m_CfileManageDlg->ShowWindow(true);
	m_FileManageHwnd = m_CfileManageDlg->m_hWnd;
}


CString CServerDlg::GetCurTime()
{
	return m_strTime;
}

CString& CServerDlg::GetCallBuff()
{
	return m_strCallBuf;
}

void CServerDlg::OnBtnSetfiledir() 
{
	// TODO: Add your control notification handler code here
	if(!m_bConnentDB)
	{
		if(MessageBox("数据库尚未连接,打开数据库连接?",
			"系统提示", MB_YESNO | MB_ICONQUESTION) == IDYES)
		{
			OnBtnConnectdb();
		}
		else
		{
			return;
		}
	}

	CFileDialog fdlg(false, NULL, "文件服务", 
	OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "所有文件(*.*)|*.*||");
	fdlg.m_ofn.lpstrTitle = "设置文件服务目录";
	if(fdlg.DoModal() == IDCANCEL)
	{
		return;
	}
	CString strDirPath = fdlg.GetPathName();

	CConn& cn = m_SvrSock.GetCn();
	CString strSql = "select sharedirectory from sharefileid";
	int ret = cn.IsExistRs((_bstr_t)strSql);
	if(1 == ret)
	{
		strSql = "update sharefileid set sharedirectory = '" + strDirPath + "'";
	}
	else if(0 == ret)
	{
		strSql = "insert into sharefileid values(0, '" + strDirPath + "')";
	}
	else
	{
		AfxMessageBox("文件服务目录设置失败,请重试!");
		return;
	}
	
	if(!cn.ExecuteSql((_bstr_t)strSql))
	{
		AfxMessageBox("文件服务目录设置失败,请重试!");
		return;
	}
	CreateDirectory(strDirPath, NULL);
	strDirPath.Insert(0, "文件服务目录设置成功:");
	MessageBox(strDirPath, "系统消息", MB_OK | MB_ICONINFORMATION);
}

⌨️ 快捷键说明

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