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

📄 updowndlg.cpp

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

#include "stdafx.h"
#include "sm.h"
#include "student.h"
#include "class.h"
#include "studentlist.h"
#include "unitclasstree.h"
#include "UpDownDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUpDownDlg dialog


//##ModelId=40A481EF011C
CUpDownDlg::CUpDownDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUpDownDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUpDownDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


//##ModelId=40A481EF01C5
void CUpDownDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUpDownDlg)
	DDX_Control(pDX, IDC_RIGHT_SELECT_ALL_BUTTON, m_RightSelect);
	DDX_Control(pDX, IDC_LEFT_SELECT_ALL_BUTTON, m_LeftSelect);
	DDX_Control(pDX, IDC_RIGHT_TREE, m_RightTree);
	DDX_Control(pDX, IDC_RIGHT_LIST, m_RightList);
	DDX_Control(pDX, IDC_LEFT_TREE, m_LeftTree);
	DDX_Control(pDX, IDC_LEFT_LIST, m_LeftList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUpDownDlg, CDialog)
	//{{AFX_MSG_MAP(CUpDownDlg)
	ON_BN_CLICKED(IDC_TO_RIGHT_BUTTON, OnToRight)
	ON_BN_CLICKED(IDC_TO_LEFT_BUTTON, OnToLeft)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_LEFT_SELECT_ALL_BUTTON, OnLeftSelectAll)
	ON_BN_CLICKED(IDC_RIGHT_SELECT_ALL_BUTTON, OnRightSelectAll)
	ON_NOTIFY(TVN_SELCHANGED, IDC_RIGHT_TREE, OnSelchangedRightTree)
	ON_NOTIFY(TVN_SELCHANGED, IDC_LEFT_TREE, OnSelchangedLeftTree)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUpDownDlg message handlers

//##ModelId=40A481EF01E4
void CUpDownDlg::OnToRight() 
{
	if(pRightTree->GetSelectType()!=1)
	{
		AfxMessageBox("必须在右边选择一个班级!");
		return;
	}
	if(pLeftTree->GetSelectType()!=1)
	{
		AfxMessageBox("必须在左边选择一个班级!");
		return;
	}
	if(pRightTree->GetSelectClass().ID == pLeftTree->GetSelectClass().ID)
	{
		AfxMessageBox("在相同的班级移动无意义!");
		return;
	}
	MoveTo(pLeftList->GetSelecteds(), pRightTree->GetSelectClass().ID);
	pRightList->LoadForUpdown(pRightTree->GetSelectClass().ID);
	pLeftList->LoadForUpdown(pLeftTree->GetSelectClass().ID);
	
}

//##ModelId=40A481EF01E6
void CUpDownDlg::OnToLeft() 
{
	if(pRightTree->GetSelectType()!=1)
	{
		AfxMessageBox("必须在右边选择一个班级!");
		return;
	}
	if(pLeftTree->GetSelectType()!=1)
	{
		AfxMessageBox("必须在左边选择一个班级!");
		return;
	}
	MoveTo(pRightList->GetSelecteds(), pLeftTree->GetSelectClass().ID);
	pRightList->LoadForUpdown(pRightTree->GetSelectClass().ID);
	pLeftList->LoadForUpdown(pLeftTree->GetSelectClass().ID);
	
}

//##ModelId=40A481EF01F4
BOOL CUpDownDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	pLeftList = new StudentList(&m_LeftList);
	pRightList = new StudentList(&m_RightList);
	pLeftList->InitForUpDown();
	pRightList->InitForUpDown();


	pLeftTree = new UnitClassTree(&m_LeftTree);
	pRightTree = new UnitClassTree(&m_RightTree);
	pLeftTree->Load();
	pLeftTree->ExpandRoot();
	pRightTree->Load();
	pRightTree->ExpandRoot();

	
	
	// 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=40A481EF01F6
void CUpDownDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	delete pLeftTree;
	delete pRightTree;
	delete pLeftList;
	delete pRightList;

	
	// TODO: Add your message handler code here
	
}

//##ModelId=40A481EF0203
void CUpDownDlg::OnLeftSelectAll() 
{
//	static bool select = false;
//	m_LeftSelect.SetWindowText(select?"全选":"取消全选");
//	if(!select)
		pLeftList->SelectAll();
//	else
	//	pLeftList->UnSelectAll();
//	select = !select;
}

//##ModelId=40A481EF0205
void CUpDownDlg::OnRightSelectAll() 
{
/*	static bool select = false;
	m_RightSelect.SetWindowText(select?"全选":"取消全选");
	if(!select)*/
		pRightList->SelectAll();
/*	else
		pRightList->UnSelectAll();
	select = !select;*/
}

//##ModelId=40A481EF0213
void CUpDownDlg::OnSelchangedRightTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	if(pRightTree->GetSelectType()==1)
	{
		pRightList->LoadForUpdown(pRightTree->GetSelectClass().ID);
	}
	else
	{
		pRightList->Clear();
	}
	*pResult = 0;
}

//##ModelId=40A481EF0223
void CUpDownDlg::OnSelchangedLeftTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	if(pLeftTree->GetSelectType()==1)
	{
		pLeftList->LoadForUpdown(pLeftTree->GetSelectClass().ID);
	}
	else
	{
		pLeftList->Clear();
	}
	*pResult = 0;
}

//##ModelId=40A481EF0119
void CUpDownDlg::MoveTo(vector<Student> &stu_vec, long class_id)
{
/*	vector<Student>::iterator stu_iter = stu_vec.begin();
	CString s, str;
	str="";
	for(; stu_iter!=stu_vec.end(); stu_iter++)
	{
		if(stu_iter->ClassID == class_id)
			continue;
		s.Format("%ld", stu_iter->ID);
		str+=s+',';
		str+=stu_iter->Name;
		s.Format("%ld", stu_iter->Num);
		str+=s+';';
	}
	AfxMessageBox(str);*/
	set<long> num_set, def_set, t_set;
	CDaoTableDef td(&theDatabase);
	td.Open("student");
	CDaoRecordset rs;
	rs.Open(&td);
	rs.SetCurrentIndex("class_id");
	if(rs.Seek("=", &COleVariant(class_id)))
	{
		while(!rs.IsEOF())
		{
			if(rs.GetFieldValue("class_id").lVal!=class_id)
				break;
			num_set.insert(rs.GetFieldValue("number").lVal);
			rs.MoveNext();
		}
	}
	rs.Close();
	td.Close();
	if(num_set.size())
	{
		set<long>::iterator num_iter = num_set.end();
		num_iter--;
		int max_num = *num_iter;
		int add_num = stu_vec.size();
		for(int i=1; i<max_num+add_num+5; 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()));
	}
	else
	{
		for(int i=1; i<stu_vec.size()+5; i++)
			def_set.insert(i);
	}
	
	td.Open("student");
	rs.Open(&td);

	set<long>::iterator def_iter = def_set.begin();
	vector<Student>::iterator stu_iter = stu_vec.begin();


	for(; stu_iter!=stu_vec.end(); stu_iter++)
	{
		if(stu_iter->ClassID == class_id)
			continue;
		stu_iter->ClassID = class_id;
		stu_iter->Num = *def_iter++;
		stu_iter->Update(&rs);
	}

	rs.Close();
	td.Close();
}

⌨️ 快捷键说明

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