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

📄 myworkview.cpp

📁 用visual c++实现的教室信息管理系统(基于DB2数据库)
💻 CPP
字号:
// myworkView.cpp : implementation of the CMyworkView class
//

#include "stdafx.h"
#include "mywork.h"

#include "myworkSet.h"
#include "myworkDoc.h"
#include "myworkView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyworkView

IMPLEMENT_DYNCREATE(CMyworkView, CRecordView)

BEGIN_MESSAGE_MAP(CMyworkView, CRecordView)
	//{{AFX_MSG_MAP(CMyworkView)
	ON_BN_CLICKED(IDC_BUILD, OnBuild)
	ON_BN_CLICKED(IDC_TIME, OnTime)
	ON_BN_CLICKED(IDC_ROOM, OnRoom)
	ON_BN_CLICKED(IDC_REG, OnReg)
	ON_BN_CLICKED(IDC_SHOW, OnShow)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyworkView construction/destruction

CMyworkView::CMyworkView()
	: CRecordView(CMyworkView::IDD)
{
	m_db.Open(_T("DB2"));
	m_db.ExecuteSQL("create table s061221129.occupy(cno char(3) not null,dno char(4) not null,otime char(3) not null,wno char(1) not null,primary key (cno,dno,otime,wno));alter table s061221129.occupy add constraint ref_key_c foreign key (cno) references s061221129.classroom(cno) on delete no action on update no action add constraint ref_key_d foreign key (dno) references s061221129.dept(dno) on delete no action on update no action;create table s061221129.dept(dno char(4) not null,dname char(20) not null,primary key (dno));create table s061221129.classroom(cno char(3) not null,primary key (cno))");
	//{{AFX_DATA_INIT(CMyworkView)
		// NOTE: the ClassWizard will add member initialization here
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CMyworkView::~CMyworkView()
{
//	m_db.ExecuteSQL("drop table s061221129.occupy;drop table s061221129.dept;drop table s061221129.classroom");
//	m_db.ExecuteSQL("drop table s061221129.dept");
//	m_db.ExecuteSQL("drop table s061221129.classroom");
}

void CMyworkView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyworkView)
	DDX_Control(pDX, IDC_TIME, m_time);
	DDX_Control(pDX, IDC_SHOW, m_show);
	DDX_Control(pDX, IDC_ROOM, m_room);
	DDX_Control(pDX, IDC_REG, m_reg);
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Control(pDX, IDC_DELETE, m_delete);
	DDX_Control(pDX, IDC_BUILD, m_build);
	//}}AFX_DATA_MAP
}

BOOL CMyworkView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRecordView::PreCreateWindow(cs);
}

void CMyworkView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_myworkSet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	////// 初始化表格外观
	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
    m_list.InsertColumn(0,_T("教室"),LVCFMT_IMAGE|LVCFMT_LEFT);
    m_list.InsertColumn(1,"占用时间");
	m_list.InsertColumn(2,"周次");
    for(int i=0;i<3;i++)
	m_list.SetColumnWidth(i,160);
	times=0;
	mdept.Open(AFX_DB_USE_DEFAULT_TYPE,"s061221129.DEPT");
	mroom.Open(AFX_DB_USE_DEFAULT_TYPE,"s061221129.CLASSROOM");
	moccu.Open(AFX_DB_USE_DEFAULT_TYPE,"s061221129.OCCUPY");


}

/////////////////////////////////////////////////////////////////////////////
// CMyworkView printing

BOOL CMyworkView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyworkView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyworkView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyworkView diagnostics

#ifdef _DEBUG
void CMyworkView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CMyworkView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

CMyworkDoc* CMyworkView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyworkDoc)));
	return (CMyworkDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyworkView database support
CRecordset* CMyworkView::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CMyworkView message handlers

void CMyworkView::OnBuild() 
{
	// TODO: Add your control notification handler code here
	if(times==0)
	{	
	m_list.DeleteAllItems();
	if(mdept.GetRecordCount()==0)
	{
		mdept.AddNew();
		mdept.m_DNO="1001";
		mdept.m_DNAME="中文系";
		mdept.Update();
		mdept.AddNew();
		mdept.m_DNO="1002";
		mdept.m_DNAME="物理系";
		mdept.Update();
		mdept.AddNew();
		mdept.m_DNO="1003";
		mdept.m_DNAME="数学系";
		mdept.Update();
		mdept.AddNew();
		mdept.m_DNO="1004";
		mdept.m_DNAME="计算机系";
		mdept.Update();
		mdept.AddNew();
		mdept.m_DNO="1005";
		mdept.m_DNAME="电子系";
		mdept.Update();
		mdept.AddNew();
		mdept.m_DNO="1006";
		mdept.m_DNAME="历史系";
		mdept.Update();
	}

	if(mroom.GetRecordCount()==0)
	{
	    mroom.AddNew();
        mroom.m_CNO="101";
	    mroom.Update();
	    mroom.AddNew();
	    mroom.m_CNO="102";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="103";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="104";
    	mroom.Update();
    	mroom.AddNew();
        mroom.m_CNO="105";
       	mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="106";
	    mroom.Update();
    	mroom.AddNew();
        mroom.m_CNO="107";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="108";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="109";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="110";
    	mroom.Update();
    	mroom.AddNew();
        mroom.m_CNO="201";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="202";
	    mroom.Update();
    	mroom.AddNew();
        mroom.m_CNO="203";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="204";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="205";
    	mroom.Update();
    	mroom.AddNew();
        mroom.m_CNO="206";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="207";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="208";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="209";
	    mroom.Update();
	    mroom.AddNew();
        mroom.m_CNO="210";
    	mroom.Update();
	}

    if(moccu.GetRecordCount()==0)
	{
		moccu.AddNew();
		moccu.m_CNO="101";
		moccu.m_DNO="1001";
		moccu.m_OTIME="1-1";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="102";
		moccu.m_DNO="1002";
		moccu.m_OTIME="1-2";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="103";
		moccu.m_DNO="1003";
		moccu.m_OTIME="1-3";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="104";
		moccu.m_DNO="1004";
		moccu.m_OTIME="1-4";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="105";
		moccu.m_DNO="1005";
		moccu.m_OTIME="2-1";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="106";
		moccu.m_DNO="1006";
		moccu.m_OTIME="2-2";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="107";
		moccu.m_DNO="1001";
		moccu.m_OTIME="2-3";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="108";
		moccu.m_DNO="1002";
		moccu.m_OTIME="2-4";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="109";
		moccu.m_DNO="1003";
		moccu.m_OTIME="3-1";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="110";
		moccu.m_DNO="1004";
		moccu.m_OTIME="3-2";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="201";
		moccu.m_DNO="1005";
		moccu.m_OTIME="3-3";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="202";
		moccu.m_DNO="1006";
		moccu.m_OTIME="3-4";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="203";
		moccu.m_DNO="1001";
		moccu.m_OTIME="4-1";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="204";
		moccu.m_DNO="1002";
		moccu.m_OTIME="4-2";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="205";
		moccu.m_DNO="1003";
		moccu.m_OTIME="4-3";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="206";
		moccu.m_DNO="1004";
		moccu.m_OTIME="4-4";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="207";
		moccu.m_DNO="1005";
		moccu.m_OTIME="5-1";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="208";
		moccu.m_DNO="1006";
		moccu.m_OTIME="5-2";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="209";
		moccu.m_DNO="1001";
		moccu.m_OTIME="5-3";
		moccu.m_WNO="0";
		moccu.Update();
		moccu.AddNew();
		moccu.m_CNO="210";
		moccu.m_DNO="1002";
		moccu.m_OTIME="5-4";
		moccu.m_WNO="0";
		moccu.Update();
	}
	times=1;
	}

	
}

void CMyworkView::OnTime() 
{
	// TODO: Add your control notification handler code here
	CTimeFind dlg;
	bool find=false;
    if(dlg.DoModal()==IDOK)
	{
	m_list.DeleteAllItems();
	moccu.MoveFirst();
    for(int i=0;i<moccu.GetRecordCount();i++)
	{
		if(moccu.m_OTIME==dlg.m_time && (moccu.m_WNO==dlg.m_week || moccu.m_WNO=="0" || dlg.m_week=="0"))
		{
			m_list.InsertItem(0,moccu.m_CNO,0);
	    	m_list.SetItemText(0,1,moccu.m_OTIME);
		    if(moccu.m_WNO=="0")
				m_list.SetItemText(0,2,"每周");
		    else
			    m_list.SetItemText(0,2,moccu.m_WNO);
			find=true;
		}
		moccu.MoveNext();
	}
	times=0;
	if(find==false)
			AfxMessageBox("没有满足条件的记录!");

	}	
}

void CMyworkView::OnRoom() 
{
	// TODO: Add your control notification handler code here
	CRoomFind dlg;
	bool find=false;
    if(dlg.DoModal()==IDOK)
	{
	m_list.DeleteAllItems();
	moccu.MoveFirst();
    for(int i=0;i<moccu.GetRecordCount();i++)
	{
		if(moccu.m_CNO==dlg.m_room)
		{
			m_list.InsertItem(0,moccu.m_CNO,0);
	    	m_list.SetItemText(0,1,moccu.m_OTIME);
		    if(moccu.m_WNO=="0")
				m_list.SetItemText(0,2,"每周");
		    else
			    m_list.SetItemText(0,2,moccu.m_WNO);
			find=true;
		}
		moccu.MoveNext();
	}
	times=0;
	if(find==false)
		AfxMessageBox("没有满足条件的记录!");
	}	
}

void CMyworkView::OnReg() 
{
	// TODO: Add your control notification handler code here
	CRegDialog dlg;
	bool abil=true;
    if(dlg.DoModal()==IDOK)
	{
		moccu.MoveFirst();
		for(int i=0;i<moccu.GetRecordCount();i++)
		{
            if(moccu.m_CNO==dlg.m_room && moccu.m_OTIME==dlg.m_time && (moccu.m_WNO==dlg.m_week || moccu.m_WNO=="0" || dlg.m_time=="0"))
			{
				abil=false;
				AfxMessageBox("该教室在该时间段内不空!");
				break;
			}
			moccu.MoveNext();
		}
/*		for(i=0;i<mroom.GetRecordCount();i++)
		{
			if(mroom.m_CNO==dlg.m_room)
			{
				rabil=true;
				break;
			}
		}
		for(i=0;i<mdept.GetRecordCount();i++)
		{
			if(mdept.m_DNO==dlg.m_dept)
			{
				dabil=true;
				break;
			}
		}*/


        if(abil==true/* && rabil==true && dabil==true*/)
        {
    	m_list.DeleteAllItems();
		moccu.AddNew();
        moccu.m_CNO=dlg.m_room;
		moccu.m_DNO=dlg.m_dept;
		moccu.m_OTIME=dlg.m_time;
		moccu.m_WNO=dlg.m_week;
		moccu.Update();
		}
//		else
  //          AfxMessageBox("输入不合法!");
	}
	times=0;
	
}

void CMyworkView::OnShow() 
{
	// TODO: Add your control notification handler code here
    m_list.DeleteAllItems();
	moccu.Requery();
	if(moccu.GetRecordCount()!=0)
	{
	moccu.MoveFirst();
    for(int i=0;i<moccu.GetRecordCount();i++)
	{
		m_list.InsertItem(i,moccu.m_CNO,0);
		m_list.SetItemText(i,1,moccu.m_OTIME);
		if(moccu.m_WNO=="0")
		    m_list.SetItemText(i,2,"每周");
		else
			m_list.SetItemText(i,2,moccu.m_WNO);			
	    moccu.MoveNext();
	}
	}
}

void CMyworkView::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CDeleteDialog dlg;
	moccu.MoveFirst();
	bool find=false;
    if(dlg.DoModal()==IDOK)
	{
		for(int i=0;i<moccu.GetRecordCount();i++)
		{
            if(moccu.m_CNO==dlg.m_room && moccu.m_OTIME==dlg.m_time && moccu.m_WNO==dlg.m_week)
			{
			    moccu.Delete();
				find=true;
			}
			moccu.MoveNext();
		}
		if(find==false)
			AfxMessageBox("未发现该记录!");
	}
}

⌨️ 快捷键说明

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