📄 searchroom.cpp
字号:
// SearchRoom.cpp : implementation file
//
#include "stdafx.h"
#include "Dormitory.h"
#include "SearchRoom.h"
#include "student.h"
#include "StuRoom.h"
#include "search.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SearchRoom dialog
extern CDormitoryApp theApp;
SearchRoom::SearchRoom(CWnd* pParent /*=NULL*/)
: CDialog(SearchRoom::IDD, pParent)
{
//{{AFX_DATA_INIT(SearchRoom)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void SearchRoom::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SearchRoom)
DDX_Control(pDX, IDC_LISTstu, m_student);
DDX_Control(pDX, IDC_LISTroom, m_room);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SearchRoom, CDialog)
//{{AFX_MSG_MAP(SearchRoom)
ON_NOTIFY(NM_CLICK, IDC_LISTstu, OnClickLISTstu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SearchRoom message handlers
BOOL SearchRoom::OnInitDialog()
{
CDialog::OnInitDialog();
m_student.SetRedraw(FALSE);
m_room.SetRedraw(FALSE);
// TODO: Add extra initialization here
m_student.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
m_student.SetBkColor(RGB(0, 128, 128));
m_student.SetTextColor(RGB(0,0,0));
m_student.SetTextBkColor(RGB(0,128, 128));
m_student.InsertColumn(1,"学号");
m_student.InsertColumn(2,"姓名");
m_student.InsertColumn(3,"班级");
m_student.InsertColumn(4,"学院");
m_student.InsertColumn(5,"性别");
int wid = 25;
m_student.SetColumnWidth(0,wid*6);
m_student.SetColumnWidth(1,wid*6);
m_student.SetColumnWidth(2,wid*6);
m_student.SetColumnWidth(3,wid*6);
m_student.SetColumnWidth(4,wid*6);
m_room.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
m_room.SetBkColor(RGB(0, 128, 128));
m_room.SetTextColor(RGB(0,0,0));
m_room.SetTextBkColor(RGB(0,128, 128));
m_room.InsertColumn(1,"房间号");
m_room.InsertColumn(2,"楼层");
m_room.InsertColumn(3,"楼号");
m_room.InsertColumn(4,"学院");
m_room.InsertColumn(5,"面积");
m_room.InsertColumn(6,"阳台");
m_room.InsertColumn(7,"厕所");
m_room.InsertColumn(8,"床");
m_room.InsertColumn(9,"桌子");
m_room.InsertColumn(10,"椅子");
m_room.InsertColumn(11,"还可住几人");
m_room.SetColumnWidth(0,wid*6);
m_room.SetColumnWidth(1,wid*6);
m_room.SetColumnWidth(2,wid*6);
m_room.SetColumnWidth(3,wid*6);
m_room.SetColumnWidth(4,wid*6);
m_room.SetColumnWidth(5,wid*6);
m_room.SetColumnWidth(6,wid*6);
m_room.SetColumnWidth(7,wid*6);
m_room.SetColumnWidth(8,wid*6);
m_room.SetColumnWidth(9,wid*6);
m_room.SetColumnWidth(10,wid*6);
Cstudent *p;
int i=0;
if(!theApp.vec2)
return false;
else{
p=(Cstudent*)theApp.vec2->getFirstRecord();
while(p)
{
CString strTemp;
strTemp = p->getField("no");
strTemp.TrimRight();
m_student.InsertItem(i, strTemp);
strTemp = p->getField("name");
strTemp.TrimRight();
m_student.SetItemText(i,1, strTemp);
strTemp = p->getField("grade");
strTemp.TrimRight();
m_student.SetItemText(i, 2,strTemp);
strTemp = p->getField("dept");
strTemp.TrimRight();
m_student.SetItemText(i,3, strTemp);
strTemp = p->getField("sex");
strTemp.TrimRight();
m_student.SetItemText(i, 4,strTemp);
p=(Cstudent*)theApp.vec2->getNext();
}
}
m_student.SetRedraw(TRUE);
m_room.SetRedraw(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void SearchRoom::OnClickLISTstu(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int i = m_student.GetSelectionMark();
CString sno;
sno=m_student.GetItemText(i,0);
m_room.DeleteAllItems();
Csearch*sh;//引入查询类
sh=new Csearch();//创建查询对象
Croom* rm;
rm=(Croom*)sh->searchroom(sno);//查询宿舍对象,返回值赋给rm
if(rm)//如果找到相应宿舍,将其信息插入到列表框中
{
i=0;
CString strTemp;
strTemp = rm->getField("no");
strTemp.TrimRight();
m_room.InsertItem(i, strTemp);
strTemp = rm->getField("floor");
strTemp.TrimRight();
m_room.SetItemText(i,1, strTemp);
strTemp = rm->getField("building");
strTemp.TrimRight();
m_room.SetItemText(i,2, strTemp);
strTemp = rm->getField("dept");
strTemp.TrimRight();
m_room.SetItemText(i,3, strTemp);
strTemp = rm->getField("size");
strTemp.TrimRight();
m_room.SetItemText(i,4, strTemp);
strTemp = rm->getField("balcony");
strTemp.TrimRight();
m_room.SetItemText(i,5, strTemp);
strTemp = rm->getField("toilet");
strTemp.TrimRight();
m_room.SetItemText(i,6, strTemp);
strTemp = rm->getField("bed");
strTemp.TrimRight();
m_room.SetItemText(i,7, strTemp);
strTemp = rm->getField("desk");
strTemp.TrimRight();
m_room.SetItemText(i,8, strTemp);
strTemp = rm->getField("chair");
strTemp.TrimRight();
m_room.SetItemText(i,9, strTemp);
strTemp = rm->getField("remain");
strTemp.TrimRight();
m_room.SetItemText(i,10, strTemp);
}
else
MessageBox("该生没有分配宿舍");
UpdateData(FALSE);
m_room.SetRedraw(TRUE);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -