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

📄 studentdlg.cpp

📁 课程设计的简单Access学生数据库系统
💻 CPP
字号:
// StudentDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SM.h"
#include "SMDlg.h"
#include "Student.h"
#include "StudentDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStudentDlg dialog


//##ModelId=40A481F30021
CStudentDlg::CStudentDlg(Student* data, CWnd* pParent /*=NULL*/)
	: CDialog(CStudentDlg::IDD, pParent), TD(&theDatabase)
{
	//{{AFX_DATA_INIT(CStudentDlg)
	m_Num = 0;
	m_Sex = 0;
	m_Mail = _T("");
	m_Name = _T("");
	m_Remark = _T("");
	//}}AFX_DATA_INIT
	if(data)
	{
		Mode = 1;
		pData = data;
	}
	else
	{
		Mode = 0;
		pData = new Student();
		pData->Birthday.SetDate(1982, 2, 1);
		if(((CSMDlg*)AfxGetMainWnd())->pUnitClassTree->GetSelectType())
			pData->ClassID = ((CSMDlg*)AfxGetMainWnd())->pUnitClassTree->GetSelectClass().ID;
	}
	m_Num = pData->Num;
	m_Name = pData->Name;
	m_Sex = !pData->Sex;
	m_Mail = pData->EMail;
	m_Remark = pData->Remark;
	m_ClassID = pData->ClassID;
	m_Birthday = pData->Birthday;

	TD.Open("student");
	RS.Open(&TD);
}


//##ModelId=40A481F3008C
void CStudentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudentDlg)
	DDX_Control(pDX, IDC_TREE1, m_Tree);
	DDX_CBIndex(pDX, IDC_COMBO_NUM, m_Num);
	DDX_CBIndex(pDX, IDC_COMBO_SEX, m_Sex);
	DDX_Control(pDX, IDC_DTPICKER1, m_DateTime);
	DDX_Text(pDX, IDC_EDIT_MAIL, m_Mail);
	DDX_Text(pDX, IDC_EDIT_NAME, m_Name);
	DDX_Text(pDX, IDC_EDIT4, m_Remark);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStudentDlg, CDialog)
	//{{AFX_MSG_MAP(CStudentDlg)
	ON_WM_DESTROY()
	ON_WM_CANCELMODE()
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudentDlg message handlers

//##ModelId=40A481F3009C
BOOL CStudentDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	NumBox.Attach(GetDlgItem(IDC_COMBO_NUM)->m_hWnd);
	pTree = new UnitClassTree(&m_Tree);
	pTree->Load();
	pTree->SetSelectClass(m_ClassID);
	m_DateTime.SetDay(COleVariant((short)m_Birthday.GetDay(), VT_I2));
	m_DateTime.SetYear(COleVariant((short)m_Birthday.GetYear(), VT_I2));
	m_DateTime.SetMonth(COleVariant((short)m_Birthday.GetMonth(), VT_I2));
	UpdateData(false);
	SetNumComboBox();
	
	
	// TODO: Add extra initialization here
	
	return true;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//##ModelId=40A481F3009E
void CStudentDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	RS.Close();
	TD.Close();
	if(!Mode)
		delete pData;
	delete pTree;
	NumBox.Detach();
	
	// TODO: Add your message handler code here
	
}

//##ModelId=40A481F300AB
void CStudentDlg::OnCancelMode() 
{
	CDialog::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

//##ModelId=40A481F300BB
void CStudentDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	if(!pTree->IsSelected() || pTree->GetSelectType()==0)
	{
		AfxMessageBox("必须选择一个班级.");
		return;
	}
	if(m_Name=="")
	{
		AfxMessageBox("请输入姓名!");
		return;
	}
	m_Birthday.SetDate(m_DateTime.GetYear().intVal, 
					   m_DateTime.GetMonth().intVal,
					   m_DateTime.GetDay().intVal
					   );
	pData->Set(pData->ID, m_Name, m_Sex==0, m_Birthday, m_ClassID, NumMap[m_Num], m_Mail, m_Remark);

	if(!Mode)
	{
		pData->AddNew(&RS);
	}
	else
	{
		pData->Update(&RS);
	}

	CDialog::EndDialog(pData->ID);
}

//##ModelId=40A481F300BD
void CStudentDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::EndDialog(0);
}



//##ModelId=40A481F300CB
void CStudentDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	if(pTree->IsSelected() && pTree->GetSelectType())
	{
		m_ClassID = pTree->GetSelectClass().ID;
		SetNumComboBox();
	}
	else
	{
		NumBox.Clear();
		while(0!=NumBox.GetCount())
			NumBox.DeleteString(0);
	}
	*pResult = 0;
}

//##ModelId=40A481F2039A
void CStudentDlg::SetNumComboBox()
{
	NumBox.Clear();
	while(0!=NumBox.GetCount())
			NumBox.DeleteString(0);
	set<int> num_set, t_set, def_set;
	long i;

	RS.SetCurrentIndex("Class_ID");
	if(RS.Seek("=", &COleVariant(m_ClassID)))
	{
		while(!RS.IsEOF())
		{
			if(RS.GetFieldValue("Class_ID").lVal!=m_ClassID)
				break;
			num_set.insert(RS.GetFieldValue("Number").lVal);
			RS.MoveNext();
		}
	}
	
	set<int>::iterator num_iter = num_set.end();
	if(num_set.size())
	{
		num_iter--;
		int max_num = *num_iter;
		for(i=1; i<max_num+10;i++)
			t_set.insert(i);

		set_difference(t_set.begin(), t_set.end(), num_set.begin(), num_set.end(), 
				inserter(def_set, def_set.begin()));
	

		if(Mode)
			def_set.insert(pData->Num);
	}
	else
	{
		for(i=1; i<10;i++)
			def_set.insert(i);
	}

	CString s;
	
	set<int>::iterator iter;
	for(iter=def_set.begin(), i=0; iter!=def_set.end()&&i<10; iter++,i++)
	{
		TRACE("def_set[%d]=%d\n", i,*iter);
		NumMap[i] = *iter;
		s.Format("%d", *iter);
		NumBox.AddString(s);
	}
	NumBox.SetCurSel(0);
}

⌨️ 快捷键说明

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