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

📄 course.cpp

📁 &#61557 职责描述:
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Course.cpp : implementation file
//

#include "stdafx.h"
#include "StudentCheck.h"
#include "Course.h"
#include "CourManage.h"

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


#define COLNUM 12 // 11是记录的属性数目
 
/////////////////////////////////////////////////////////////////////////////
// CCourse dialog


CCourse::CCourse(CWnd* pParent /*=NULL*/)
	: CDialog(CCourse::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCourse)
 
	//}}AFX_DATA_INIT
	m_DepInfo.LoadDep();
	m_CurAdo.InitialDB();
	m_AllStuInfos.GetAllDBInfo(); 

//	iQueryNot=0;  //当点击记录后,禁止再查询
	//初始化数组iCheck
    for(int j=0 ; j<SIZE ;j++)
		iCheck[j]=0;

	//修改时的标识
    for(int i=0 ; i<MODSIZE ;i++)
		iModyCheck[i]=0;        //视图中的标识 
    for(int k=0 ; k<MODSIZE ;k++)
		iModyCheckBase[k]=0;   //原数据库中的标识
 
	
}
CCourse::~CCourse()
{
	m_CurAdo.ClosedDB();
}

void CCourse::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCourse)
	DDX_Control(pDX, IDC_COMB_COURSE, m_cmbAct);
	DDX_Control(pDX, IDC_DATETIME, m_dateAct);
	DDX_Control(pDX, IDC_MEMBER_LIST, m_StuActList);
	DDX_Control(pDX, IDC_CLASS_TREE, m_StuActTree);
 
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCourse, CDialog)
	//{{AFX_MSG_MAP(CCourse)
	ON_NOTIFY(TVN_SELCHANGED, IDC_CLASS_TREE, OnSelchangedClassTree)
	ON_BN_CLICKED(IDC_COU_MANAGE, OnCouManage)
	ON_CBN_DROPDOWN(IDC_COMB_COURSE, OnDropdownCombCourse)
	ON_BN_CLICKED(IDC_All_CHECK, OnAllCheck)
	ON_BN_CLICKED(IDC_AllNOT_CHECK, OnAllNotCheck)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_NOTIFY(NM_CLICK, IDC_MEMBER_LIST, OnClickMemberList)
	ON_BN_CLICKED(IDC_QUERY, OnQuery)
	ON_BN_CLICKED(IDC_MODIFY, OnModify)
	ON_NOTIFY(NM_CLICK, IDC_CLASS_TREE, OnClickClassTree)
 
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCourse message handlers

BOOL CCourse::OnInitDialog() 
{

	CDialog::OnInitDialog();
	CString strCurName;
	if(!(m_DepImageInfo.Create(IDB_BITMAP1,16,1,RGB(0,255,0))))
		AfxMessageBox("图像列表创建出错!");
	m_StuActTree.SetImageList(&m_DepImageInfo,TVSIL_NORMAL);
	HTREEITEM htRoot;
	CString strRoot = "环境学院";
	htRoot = m_StuActTree.InsertItem(strRoot);  //添加根节点
    m_StuActTree.SetItemData(htRoot,0);
	m_DepInfo.CreatTree(htRoot, m_StuActTree);
	m_StuActTree.Expand(htRoot, TVE_EXPAND);



	ReadToComb();        //把活动名称丛数据库读进Combox
//	ConstructTableName();  //设置列表框表头
 
    bTitleTree=true;
	bTitleQuery=true;
	//设置日期
	CTime time;
	m_dateAct.GetTime(time); 
	Time=time.Format("%Y-%#m-%#d");//转换实际格式
	m_StuActList.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES |LVS_EX_CHECKBOXES);
	return TRUE;
}

void CCourse::ReadToComb()
{
	//把数据库中的活动名称和ID号读进控件中
 	_bstr_t vSQL;
 
	int i=0;
 	sa_ActID.RemoveAll();
 	sa_ActName.RemoveAll();
    m_cmbAct.ResetContent();
	
	//执行SELETE语句
 	vSQL="select CourseID, CourseName from Course  order by CourseID";
 	m_CurAdo.GetRecordSet(vSQL);
 	
 	_RecordsetPtr m_pRecordset ;
 	m_pRecordset = m_CurAdo.GetRecordSet(vSQL);


 	//获取记录集中的数据
 	while (m_pRecordset->adoEOF == 0)
 	{
		sa_ActID.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("CourseID"));
 		sa_ActName.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("CourseName"));
		m_cmbAct.AddString(sa_ActName.GetAt(i));
		i++;
 		m_pRecordset->MoveNext();
 	}
 
	for(int j=0 ; j< sa_ActID.GetSize() ;j++)
	{
		m_cmbAct.SetItemData(j,atoi(sa_ActID.GetAt(j))) ;
	}
}

void CCourse::ConstructTableName()
{
	CArray <CString, LPCTSTR> TableNameAry;
	CString * pCurTableName = NULL;
	UINT nCurUINT = IDS_COL_NAME_ID; 

	TableNameAry.SetSize(COLNUM);  		
	pCurTableName = TableNameAry.GetData();

	for (int i = 0; i < COLNUM; i++)
	{
		pCurTableName[i].LoadString(nCurUINT + i);
	}

	int j;
	for (j = 0; j < COLNUM; j++)
	{
		m_StuActList.InsertColumn(j, pCurTableName[j], LVCFMT_LEFT, 100);
	}
	
	for (j = 0; j < COLNUM; j++)
	{
		m_StuActList.SetColumnWidth(j, 90);
	}
}

void CCourse::OnSelchangedClassTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here

 
	*pResult = 0;

	HTREEITEM hCurItem;
	HTREEITEM hCurChildItem;
	CString strCurClassID;
	hCurItem = m_StuActTree.GetSelectedItem();
	if (NULL != hCurItem)
	{
		hCurChildItem = m_StuActTree.GetChildItem(hCurItem);
		if (NULL == hCurChildItem) // 若某一个节点,其孩子为空,说明其为根节点,可以使用查询语句寻找具体信息
		{
			// 如果当前的所选择的叶子节点发生了变化,那么就修改当前查询语句 m_strCurQuaryInfo 
			// 并且发送消息,导致整个对话框发生刷新
			strCurClassID.Format("%d", m_StuActTree.GetItemData(hCurItem));
			m_ClassID=strCurClassID;  //把当前班级ID赋值给成员变量
			//当前选择的是班级,控制显示表头
			SetTtitleTree();
			ModityCurQueryMessage(strCurClassID);
			AfxMessageBox(strCurClassID);
		}
	}
}

void CCourse::ModityCurQueryMessage(CString _strCurClassID)
{
//传进来的是班级号 通过该号码对班级成员进行检索
	CString strStandInfo;
	CString strQuotationMark;
	strStandInfo.LoadString(IDS_STANDARD_STU_QUERY);
	strQuotationMark.LoadString(IDS_QUOTATION_MARK);
	m_strCurQuaryInfo = strStandInfo + strQuotationMark +  _strCurClassID + strQuotationMark;
//	AfxMessageBox(m_strCurQuaryInfo);
	RefreshData();
}

void CCourse::RefreshData()
{
	//刷新,这里用了一个很笨的方法:全部重新查询
	//比较好的办法是有针对性的查询
	//或者是有针对性的修改当前显示
	//时间关系,采用最简单的方式和方法进行
	
	UpdateData(TRUE);
	m_StuActList.DeleteAllItems();
	CArray <CString, LPCTSTR> StudentInfoAry;
	CString strCurColInfo;
	
	StudentInfoAry.SetSize(COLNUM);  
	CString * pCurInfo = StudentInfoAry.GetData();
	int nRecordNum = 0;

	// 如果记录集不为空
	_RecordsetPtr CurRecordset;
	_variant_t nIndex = (long)0; 
	_variant_t var;
	CString strCollege="环境学院"; //把03给替换掉
	CurRecordset = m_CurAdo.GetRecordSet(LPCTSTR(m_strCurQuaryInfo));
	while (0 == CurRecordset->adoEOF)
	{
		//取一条记录付值给数组StudentInfoAry
	
		for (int i = 0; i < COLNUM; i++)
		{
			nIndex = (long) i;
			var = CurRecordset->GetCollect(nIndex);
			pCurInfo[i] = (LPCTSTR)(_bstr_t )var;
 		}
		m_StuActList.InsertItem(nRecordNum, "");
		for (int j = 0; j < COLNUM; j++)
		{
			pCurInfo[j] = m_AllStuInfos.GetNum(pCurInfo[j]);
			if (7==j)
				pCurInfo[j]=strCollege; //修改学院
			if (j==1) //学生号
				m_StuActList.SetItemData(nRecordNum,atoi(pCurInfo[j]));
			m_StuActList.SetItemText(nRecordNum, j, pCurInfo[j]);
		}
		nRecordNum ++;
		//记录转下一条
		CurRecordset->MoveNext();
	}
}

void CCourse::OnCouManage() 
{
	// TODO: Add your control notification handler code here
	CCourManage dlg;
	dlg.DoModal();
}

void CCourse::OnDropdownCombCourse() 
{
	ReadToComb();
	UpdateData(false);
	
}

void CCourse::OnAllCheck() 
{
	//把所有的边框全部选择
    //首先在listCtrl里显示选择项
 
	for (int nCount= 0; nCount<m_StuActList.GetItemCount();nCount++)  
	{
		if(!iCheck[nCount])
		{
			iCheck[nCount] = 1;
			m_StuActList.SetCheck(nCount);
		} 
	} 	
}

void CCourse::OnAllNotCheck() 
{
	//把所有的边框全部不要选择
    //首先在listCtrl里显示选择项

	for (int nCount= 0; nCount<m_StuActList.GetItemCount();nCount++)  
	{	
		if(iCheck[nCount])
		{
			iCheck[nCount] = 0;
			m_StuActList.SetCheck(nCount,false);
		} 
	} 	
}

void CCourse::OnSave() 
{
	//获取当前选择的项的值,
	//把相关的值写入数据库中 
	CString strTemp;
	int d;
	if ((d=m_cmbAct.GetItemData(m_cmbAct.GetCurSel())) <0)
	{
		AfxMessageBox("请选择活动名称!");
		return;
	}

 
	for (int i=0 ; i<m_StuActList.GetItemCount(); i++)
	{
		if (iCheck[i])
		{
			//存储被选择的
			strTemp.Format("0%i",m_StuActList.GetItemData(i));
			sa_CheckOn.Add(strTemp);
			AfxMessageBox("参加:"+strTemp);
 
		}
		else
		{
			//存储没有被选择的
		    strTemp.Format("0%i",m_StuActList.GetItemData(i));
			sa_CheckNot.Add(strTemp);
			AfxMessageBox("没有参加:"+strTemp);
		}
	}
     
	//向数据库中写入

⌨️ 快捷键说明

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