// ServerView.cpp : implementation of the CServerView class
//
#include "stdafx.h"
#include "Server.h"
#include "ServerDoc.h"
#include "ServerView.h"
#include "ServerAddrDlg.h"
#include "ClientContext.h"
#include "ClientManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CServerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CServerView
IMPLEMENT_DYNCREATE(CServerView, CListView)
BEGIN_MESSAGE_MAP(CServerView, CListView)
//{{AFX_MSG_MAP(CServerView)
ON_COMMAND(ID_SERVER_START, OnServerStart)
ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
// ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
// ON_UPDATE_COMMAND_UI(ID_SERVER_EXIT, OnUpdateServerExit)
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
// Standard printing commands
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServerView construction/destruction
CServerView::CServerView():
m_sListen(INVALID_SOCKET), //监听套接字
m_hCompPort(NULL), //完成端口
m_bRunning(FALSE), //服务器运行状态
m_nThreadNum(0), //子线程数量
m_usPaperLen(0) //试卷长度
{
m_pRecordSet.CreateInstance(__uuidof(Recordset)); //创建记录集指针
ZeroMemory(m_cPaper, PAPER_BUFFER_SIZE); //试题缓冲区
ZeroMemory(m_cAnswer, ANSWER_BUFFER_SIZE); //答案缓冲区
ZeroMemory(m_hThread, MAX_SUBTHREAD_SIZE); //子线程句柄
}
CServerView::~CServerView()
{
}
BOOL CServerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx = 50;
cs.cy = 600;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CServerView drawing
void CServerView::OnDraw(CDC* pDC)
{
CServerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/*
* 初始化
*/
void CServerView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
InitListCtrlSetting(); //初始化列表视图控件
InitListCtl(); //更新列表视图控件
ReadPaper(m_cPaper, m_cAnswer); //读取试卷
m_usPaperLen = strlen(m_cPaper); //试卷长度
}
/////////////////////////////////////////////////////////////////////////////
// CServerView printing
/////////////////////////////////////////////////////////////////////////////
// CServerView diagnostics
#ifdef _DEBUG
void CServerView::AssertValid() const
{
CListView::AssertValid();
}
void CServerView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CServerDoc* CServerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CServerDoc)));
return (CServerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CServerView message handlers
/*
* 初始化列表视图控件
*/
void CServerView::InitListCtrlSetting( void )
{
CListCtrl &listCtl = GetListCtrl(); //得到控件
LONG lStyle = GetWindowLong(listCtl.m_hWnd, GWL_STYLE); //获取风格
lStyle |= LVS_REPORT; //增加汇报风格
SetWindowLong(listCtl.m_hWnd, GWL_STYLE, lStyle); //设置style
DWORD dwStyle = ListView_GetExtendedListViewStyle(listCtl); //得到扩展风格
dwStyle|= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES; //增加选择整行网格线风格
ListView_SetExtendedListViewStyle (listCtl, dwStyle);
CRect clientRect;
listCtl.GetClientRect(&clientRect);//获取客户区域
int nCol; //列
LV_COLUMN lvCol; //结构
lvCol.mask = LVCF_FMT |LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
//第一列
nCol = 0;
lvCol.iSubItem = nCol;
lvCol.pszText = "学号";
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = (float)clientRect.Width()/100 * 25;
listCtl.InsertColumn(nCol, &lvCol);
//第二列
nCol = 1;
lvCol.iSubItem = nCol;
lvCol.pszText = "姓名";
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = (float)clientRect.Width()/100 * 25;
listCtl.InsertColumn(nCol, &lvCol);
//第三列
nCol = 2;
lvCol.iSubItem = nCol;
lvCol.pszText = "状态";
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = (float)clientRect.Width()/100 * 25;
listCtl.InsertColumn(nCol, &lvCol);
//第四列
nCol = 3;
lvCol.iSubItem = nCol;
lvCol.pszText = "成绩";
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = (float)clientRect.Width()/100 * 25;
listCtl.InsertColumn(nCol, &lvCol);
}
/*
* 更新列表视图控件
*/
void CServerView::InitListCtl( void )
{
CListCtrl &listCtl = GetListCtrl(); //得到列表视图控件
try
{
int nIndex=0; //记录序号
CString strSQL = "select * from Student"; //读取所有记录
m_pRecordSet->Open(_variant_t(strSQL),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
while (!m_pRecordSet->adoEOF)//记录尾
{
_variant_t var; //临时变量
CString strSN; //学号
CString strName; //姓名
CString strState; //状态
CString strGrade; //成绩
//读取“学号”字段
var = m_pRecordSet->GetCollect("STD_SN");
if (var.vt != VT_NULL)
{
strSN = (LPCSTR)_bstr_t(var);
}
//读取“姓名”字段
var = m_pRecordSet->GetCollect("STD_NAME");
if (var.vt != VT_NULL)
{
strName = (LPCSTR)_bstr_t(var);
}
//读取“状态”字段
var = m_pRecordSet->GetCollect("STD_STATE");
if (var.vt != VT_NULL)
{
strState = (LPCSTR)_bstr_t(var);
}
//读取“成绩”字段
var = m_pRecordSet->GetCollect("STD_GRADE");
if (var.vt != VT_NULL)
{
strGrade = (LPCSTR)_bstr_t(var);
}
//插入数据项
listCtl.InsertItem(nIndex, strSN); //学号
listCtl.SetItemText(nIndex, 1, strName); //姓名
listCtl.SetItemText(nIndex, 2, strState); //状态
listCtl.SetItemText(nIndex, 3, strGrade); //成绩
//定义考生信息
PSTUDENTINFO pStdIn = new STUDENTINFO;
pStdIn->strSN = strSN; //学号
pStdIn->strName = strName; //姓名
pStdIn->strState = strState; //状态
pStdIn->usGrade = atoi(strGrade); //成绩
m_vectStudent.push_back(pStdIn); //加入vector中
m_pRecordSet->MoveNext(); //移动记录
nIndex++; //记录序号加1
}
m_pRecordSet->Close();//关闭
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
catch(...)
{
AfxMessageBox("访问数据库服务器时发生异常。");
return;
}
}
/*
* 读取试卷
*/
BOOL CServerView::ReadPaper( char *pPaper , char *pAnswer)
{
ASSERT(pAnswer && pAnswer);
char *pPaperItem = pPaper; //试题缓冲区指针
char *pAnswerItem = pAnswer; //答案缓冲区指针
try
{
int nIndex=0; //记录序号
CString strSQL = "select * from Paper"; //读取所有记录
m_pRecordSet->Open(_variant_t(strSQL),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
while (!m_pRecordSet->adoEOF) //记录尾
{
_variant_t var; //临时变量
char *pTemp = NULL;
int len = 0; ;
strcpy(pPaperItem, "<"); //试题开始分隔符
pPaperItem++;
//读取“题号”字段
var = m_pRecordSet->GetCollect("PAP_ID");
if (var.vt != VT_NULL)
{
pTemp = _com_util::ConvertBSTRToString(_bstr_t(var));
len = strlen(pTemp); //字符串长度
strcpy(pPaperItem, pTemp); //复制字符串
strcpy(pPaperItem + len, "|"); //复制分隔符
pPaperItem += len + 1; //移动指针
len = 0;
delete pTemp;
pTemp = NULL;
}
pTemp = NULL;
//读取“问题”字段
var = m_pRecordSet->GetCollect("PAP_ITEM");
if (var.vt != VT_NULL)
{
pTemp = _com_util::ConvertBSTRToString(_bstr_t(var));
len = strlen(pTemp); //字符串长度
strcpy(pPaperItem, pTemp); //复制字符串
strcpy(pPaperItem + len, "|"); //复制分隔符
pPaperItem += len + 1; //移动指针
len = 0;
delete pTemp;
pTemp = NULL;
}
//读取�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
IOCP完全端口考试系统_完全代码.rar (68个子文件)
IOCP完全端口考试系统_完全代码
Client
Client.dsp 4KB
LoginDlg.cpp 2KB
StdAfx.cpp 208B
resource.h 2KB
ClientSocket.cpp 4KB
ClientDlg.h 2KB
ClientSocket.h 1KB
StdAfx.h 2KB
ClientDlg.cpp 10KB
Client.dsw 537B
Client.cpp 2KB
Item.h 1KB
Item.cpp 5KB
res
Client.rc2 398B
Client.ico 1KB
LoginDlg.h 1KB
Client.clw 2KB
Client.rc 7KB
Client.h 1KB
Server
ServerAddrDlg.h 1KB
StdAfx.cpp 208B
Server.aps 28KB
ServerDoc.h 1KB
Server.rc 12KB
ServerDoc.cpp 2KB
ClientContext.cpp 7KB
ClientManager.cpp 3KB
Server.h 1KB
MainFrm.h 2KB
ClientManager.h 1KB
msado15.tlh 88KB
Debug
Server.pdb 577KB
vc60.pdb 604KB
vc60.idb 305KB
ClientContext.obj 17KB
msado15.tlh 89KB
Server.pch 9MB
msado15.tli 75KB
MainFrm.obj 23KB
ServerDoc.obj 16KB
StdAfx.obj 139KB
ClientManager.obj 15KB
ServerView.obj 135KB
Server.obj 49KB
Server.exe 160KB
ServerAddrDlg.obj 17KB
Server.res 6KB
Server.ilk 487KB
msado15.tli 75KB
Server.clw 2KB
StdAfx.h 3KB
Server.dsp 5KB
MainFrm.cpp 3KB
Server.opt 48KB
Resource.h 824B
ServerView.cpp 22KB
ClientContext.h 2KB
Server.plg 2KB
ServerView.h 3KB
res
ServerDoc.ico 1KB
Server.ico 1KB
Server.rc2 398B
Toolbar.bmp 478B
Exam.mdb 452KB
Server.ncb 121KB
Server.cpp 5KB
ServerAddrDlg.cpp 2KB
Server.dsw 537B
共 68 条
- 1
资源评论
- qingkongwuyun2014-08-28可以运行,,
- blacker2011-10-20说是考试系统,其实没出题功能。不过好在代码都能运行
- bestbestboy2012-10-22运行可以通过
ahniyilin
- 粉丝: 34
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功