www.gusucode.com > VC++毕业设计_高校宿舍管理系统附论文源码程序 > VC++毕业设计_高校宿舍管理系统附论文源码程序/code/源代码/InhabitantsDoc.cpp
//Download by http://www.NewXing.com // InhabitantsDoc.cpp : implementation of the CInhabitantsDoc class // #include "stdafx.h" #include "Inhabitants.h" #include "InhabitantsDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CInhabitantsDoc IMPLEMENT_DYNCREATE(CInhabitantsDoc, CDocument) BEGIN_MESSAGE_MAP(CInhabitantsDoc, CDocument) //{{AFX_MSG_MAP(CInhabitantsDoc) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CInhabitantsDoc construction/destruction CInhabitantsDoc::CInhabitantsDoc() { // TODO: add one-time construction code here } CInhabitantsDoc::~CInhabitantsDoc() { } BOOL CInhabitantsDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; //打开数据库 HRESULT result = m_dbHouse.Open(); if(FAILED(result)) AfxMessageBox("open database failed!"); //设置程序标题 SetTitle("中南民族大学学生宿舍管理系统 V1.0.0"); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CInhabitantsDoc serialization void CInhabitantsDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CInhabitantsDoc diagnostics #ifdef _DEBUG void CInhabitantsDoc::AssertValid() const { CDocument::AssertValid(); } void CInhabitantsDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CInhabitantsDoc commands int CInhabitantsDoc::AddUser(USER &user) { /*返回值: 0 已经存在 -1 添加失败 1 添加成功 */ //判断是否存在该学生了 CString strSql; strSql.Format("select * from house where roomtype = '%s' and buildingnum = %d and roomnum = %d and bednum = %d", user.strRoomtype,user.nBuildingnum,user.nRoomnum,user.nBednum); CCommand<CAccessor<CHouseAccessor> > dbHouse; long* pCount = new long; if(dbHouse.Open(m_dbHouse.m_session,strSql,NULL,pCount) != S_OK) { AfxMessageBox("error"); delete pCount; return -1; } if(dbHouse.MoveFirst() == S_OK) { delete pCount; dbHouse.Close(); return 0; } delete pCount; dbHouse.Close(); //增加学生到数据库中 m_dbHouse.MoveLast(); _tcscpy( m_dbHouse.m_roomtype,user.strRoomtype ); m_dbHouse.m_buildingnum = user.nBuildingnum; m_dbHouse.m_roomnum = user.nRoomnum; m_dbHouse.m_bednum = user.nBednum; _tcscpy(m_dbHouse.m_studentname,user.strName); _tcscpy(m_dbHouse.m_major,user.strMajor); _tcscpy(m_dbHouse.m_remarks,user.strRemarks); _tcscpy(m_dbHouse.m_housetel,user.strHouseTel); _tcscpy(m_dbHouse.m_id,user.strId); _tcscpy(m_dbHouse.m_sex,user.strSex); _tcscpy(m_dbHouse.m_national,user.strNationNal); HRESULT hResult = m_dbHouse.Insert(); if( FAILED( hResult ) ) { AfxMessageBox( _T( "Error inserting the current record" ) ); return -1; } return 1; } //删除符合条件的学生 BOOL CInhabitantsDoc::DeleteUser(CString strSql) { CCommand<CAccessor<CHouseAccessor> > dbHouse; long* pCount = new long; if(dbHouse.Open(m_dbHouse.m_session,strSql, NULL,pCount,DBGUID_DEFAULT,FALSE) != S_OK) { AfxMessageBox("error"); delete pCount; return FALSE; } delete pCount; dbHouse.Close(); return TRUE; } void CInhabitantsDoc::DeleteContents() { //关闭数据库 m_dbHouse.Close(); m_dbHouse.m_session.Close(); CDocument::DeleteContents(); }