📄 stuactive.cpp
字号:
//把相关的值写入数据库中
CTime time;
CString strTemp;
m_dateAct.GetTime(time);
Time=time.Format("%Y-%m-%d");//转换实际格式
int d,f;
if ((d=m_cmbAct.GetItemData(m_cmbAct.GetCurSel())) <0)
{
AfxMessageBox("请选择活动名称!");
return;
}
if ((f=m_cmbType.GetItemData(m_cmbType.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);
}
}
//向数据库中写入
if (InsertStuAct())
AfxMessageBox("成功保存数据!");
}
BOOL CStuActive::InsertStuAct()
{
CString strStuNum,strActID,strTypeID,strTime;
_bstr_t vSQL;
int nCheck,nUnCheck;
nCheck=0;
nUnCheck=0;
strActID.Format("%d",m_cmbAct.GetItemData(m_cmbAct.GetCurSel()));
strTypeID.Format("%d",m_cmbType.GetItemData(m_cmbType.GetCurSel()));
strTime=Time;
if (m_StuActList.GetItemCount()<=0)
{
AfxMessageBox("列表控件里,无学生记录!!!");
return false;
}
//插入所有该班的学生
for(int i=0 ; i< m_StuActList.GetItemCount(); i++)
{
//判断该学生是否参加该活动
if (iCheck[i])
{
//参加活动的学生要小于,sa_CheckOn实际存储的
if (nCheck<sa_CheckOn.GetSize())
{
//参加活动的学生
strStuNum=sa_CheckOn.GetAt(nCheck);
vSQL="Insert into StuActivity(StudentNum,ActID,ActTypeID,ActDateTime ,IsAct) \
VALUES ( '" +strStuNum +"','"+strActID+"','"+strTypeID+"','"+strTime+"','1')";
m_CurAdo.ExecuteSQL(vSQL);
nCheck++;
}
}
else
{
//不参加活动的学生要小于,sa_CheckNot实际存储的
if (nUnCheck<sa_CheckNot.GetSize())
{
//没参加活动学生
strStuNum=sa_CheckNot.GetAt(nUnCheck);
vSQL="Insert into StuActivity(StudentNum,ActID,ActTypeID,ActDateTime ,IsAct) \
VALUES ( '" +strStuNum +"','"+strActID+"','"+strTypeID+"','"+strTime+"','0')";
m_CurAdo.ExecuteSQL(vSQL);
nUnCheck++;
}
}
}
return true;
}
void CStuActive::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
/* CString str;
str.Format("%d",m_cmbAct.GetItemData(m_cmbAct.GetCurSel()));
AfxMessageBox("您选择的: "+str);*/
}
void CStuActive::OnDropdownCombo1()
{
// TODO: Add your control notification handler code here
ReadToComb();
UpdateData(false);
}
void CStuActive::OnAllNotCheck()
{
//把所有的边框全部不要选择
//首先在listCtrl里显示选择项
for (int nCount= 0; nCount<m_StuActList.GetItemCount();nCount++)
{
if(iCheck[nCount])
{
iCheck[nCount] = 0;
m_StuActList.SetCheck(nCount,false);
}
}
}
void CStuActive::OnExit()
{
this->OnOK();
}
void CStuActive::OnQuery()
{
//通过选择班级、课程、时间来查询显示该班每个人的出勤情况
//1.能够在列表控件里显示每个人的出勤信息
//2、并能够对每个人的出勤信息进行修改
GetDlgItem(IDC_MODIFY)->EnableWindow(true);
GetDlgItem(IDC_All_CHECK)->EnableWindow(false);
GetDlgItem(IDC_AllNOT_CHECK)->EnableWindow(false);
GetDlgItem(IDC_SAVE_DATA)->EnableWindow(false);
ShowQueryTitle(); //设置标题头
QueryData(); //查询数据库
}
void CStuActive::OnModify()
{
//修改,仅仅是对从数据库中查到的数据进行修改
//仅修改学生是否缺勤,
//因此,课程,日期应该值为不可用
GetDlgItem(IDC_COMBO1)->EnableWindow(false);
GetDlgItem(IDC_COMBO24)->EnableWindow(false);
GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(false);
//对学生出勤情况进行修改
CString StuActID; //记录ID
_bstr_t vSQL;
CString strTemp;
if (m_StuActList.GetItemCount()<=0)
{
AfxMessageBox("列表控件里,无学生记录!!!");
return ;
}
//插入所有该班的学生
for(int i=0 ; i< m_StuActList.GetItemCount(); i++)
{
StuActID.Format("%d",m_StuActList.GetItemData(i));
//判断该学生是否参加该活动
if (iModyCheck[i] !=iModyCheckBase[i])
{
strTemp.Format("%d",iModyCheck[i]);
//该学生的出勤状态被修改,应该更新数据库
vSQL = "Update StuActivity Set IsAct= " + strTemp
+ " Where StuActID= " + StuActID;
m_CurAdo.ExecuteSQL(vSQL);
AfxMessageBox(" 修改了: " + StuActID);
}
}
}
void CStuActive::ShowQueryTitle()
{
//在列表框中显示标题
if (bTitleQuery)
{
int nColumnCount = m_StuActList.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (int i=0;i < nColumnCount;i++)
m_StuActList.DeleteColumn(0);
m_StuActList.InsertColumn(0,"学号",LVCFMT_LEFT,100);
m_StuActList.InsertColumn(1,"姓名",LVCFMT_LEFT,80);
m_StuActList.InsertColumn(2,"班级名称",LVCFMT_LEFT,150);
m_StuActList.InsertColumn(3,"活动名称",LVCFMT_LEFT,100);
m_StuActList.InsertColumn(4,"活动类型",LVCFMT_LEFT,80);
m_StuActList.InsertColumn(5,"参加活动时间",LVCFMT_LEFT,80);
m_StuActList.InsertColumn(6,"是否参加活动",LVCFMT_LEFT,80);
m_StuActList.InsertColumn(7,"ID",LVCFMT_LEFT,80);
bTitleQuery=false;
bTitleTree=true;
UpdateData(0);
}
}
void CStuActive::QueryData()
{
//联合多个表格进行查询,主要就是了解该课程,该时间下的学生的出勤情况
//对StuCourse表中的项,ID为主键
CString strActID,strTime,strClassID,strActTypeID;
//获取时间控件的值
CTime time;
m_dateAct.GetTime(time);
Time=time.Format("%Y-%m-%d"); //转换实际格式
strActID.Format("%d", m_cmbAct.GetItemData(m_cmbAct.GetCurSel()));
strActTypeID.Format("%d", m_cmbType.GetItemData(m_cmbType.GetCurSel()));
strTime = Time;
CString strMarkSharp;
strMarkSharp.LoadString(IDS_MARK_SHARP);
strClassID=m_ClassID;
if (strClassID.GetLength()<8)
{
AfxMessageBox("请选择班级!!!");
return;
}
int nColumn=8; //要显示8列数据
//设置SELECT语句
_bstr_t vSQL;
CString strSQL;
vSQL = "select Student.StudentNum,Name, ClassName,ActName,ActTypeName,ActDateTime, IsAct, \
StuActivity.StuActID from Student, Activity, StuActivity,ActType, \
Class where Student.ClassID='" \
+ m_ClassID + "' and Student.ClassID=Class.ClassID "\
+ " and Student.StudentNum=StuActivity.StudentNum " +" and StuActivity.ActDateTime= " \
+ strMarkSharp + strTime + strMarkSharp + " and StuActivity.ActID= " \
+ strActID + " and StuActivity.ActID=Activity.ActID " + " and ActType.ActTypeID = " \
+ strActTypeID + " and ActType.ActTypeID = StuActivity.ActTypeID "\
+ " ORDER BY StuActivity.StuActID ";
AfxMessageBox(vSQL);
m_StuActList.DeleteAllItems();
CArray <CString, LPCTSTR> StudentInfoAry;
CString strCurColInfo;
StudentInfoAry.SetSize(nColumn);
CString * pCurInfo = StudentInfoAry.GetData();
int nRecordNum = 0;
//执行SELETE语句,如果记录集不为空
_RecordsetPtr CurRecordset;
_variant_t nIndex = (long)0;
_variant_t var;
int iModCheBase=0;
CurRecordset = m_CurAdo.GetRecordSet(vSQL);
while (0 == CurRecordset->adoEOF)
{
//取一条记录付值给数组StudentInfoAry
for (int i = 0; i < nColumn; i++)
{
nIndex = (long) i;
var = CurRecordset->GetCollect(nIndex);
pCurInfo[i] = (LPCTSTR)(_bstr_t )var;
}
m_StuActList.InsertItem(nRecordNum, "");
for (int j = 0; j < nColumn; j++)
{
if(j==7)//表示stuActID
m_StuActList.SetItemData(nRecordNum,atoi(pCurInfo[j]));
if (6==j) //是否出勤
{
if (1==atoi(pCurInfo[j]))
{
iModyCheckBase[iModCheBase] = 1; //保存该学生的选择状态
m_StuActList.SetCheck(nRecordNum, true);
m_StuActList.SetItemText(nRecordNum,j,"是");
iModCheBase++;
}
else
{
iModyCheckBase[iModCheBase] = 0;
m_StuActList.SetCheck(nRecordNum, false);
m_StuActList.SetItemText(nRecordNum,j,"否");
iModCheBase++;
}
}
else
m_StuActList.SetItemText(nRecordNum, j, pCurInfo[j]);
}
nRecordNum ++;
//记录转下一条
CurRecordset->MoveNext();
}
for(int k=0 ; k<iModCheBase ;k++)
iModyCheck[k]=iModyCheckBase[k]; //原数据库中的标识赋值给待变的
}
void CStuActive::OnClickClassTree(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
HTREEITEM hCurItem;
HTREEITEM hCurChildItem;
CString strCurClassID;
hCurItem = m_StuActTree.GetSelectedItem();
if (NULL != hCurItem)
{
hCurChildItem = m_StuActTree.GetChildItem(hCurItem);
if (NULL == hCurChildItem) // 若某一个节点,其孩子为空,说明其为根节点,可以使用查询语句寻找具体信息
{
GetDlgItem(IDC_MODIFY)->EnableWindow(false);
GetDlgItem(IDC_All_CHECK)->EnableWindow(true);
GetDlgItem(IDC_AllNOT_CHECK)->EnableWindow(true);
GetDlgItem((IDC_SAVE_DATA))->EnableWindow(true);
GetDlgItem(IDC_COMBO1)->EnableWindow(true);
GetDlgItem(IDC_COMBO24)->EnableWindow(true);
GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(true);
// 如果当前的所选择的叶子节点发生了变化,那么就修改当前查询语句 m_strCurQuaryInfo
// 并且发送消息,导致整个对话框发生刷新
strCurClassID.Format("%d", m_StuActTree.GetItemData(hCurItem));
m_ClassID=strCurClassID; //把当前班级ID赋值给成员变量
//当前选择的是班级,控制显示表头
SetTtitleTree();
ModityCurQueryMessage(strCurClassID);
}
}
*pResult = 0;
}
void CStuActive::SetTtitleTree()
{
CString str1;
if (bTitleTree)
{
int nColumnCount = m_StuActList.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (int i=0;i < nColumnCount;i++)
{
m_StuActList.DeleteColumn(0);
}
ConstructTableName(); //设置列表框表头
bTitleTree=false;
bTitleQuery=true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -