📄 lessonview.cpp
字号:
for(int i=Count;i>0;i--)
{
GetListCtrl().DeleteColumn(i-1);
head->DeleteItem(i-1);
}
HeadTotalLesson();
m_ViewInfo=4;
}
break;
}
}
void CLessonView::HeadMission()
{
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
GetListCtrl().ModifyStyle(0,LVS_REPORT);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
GetListCtrl().InsertColumn(0,"科目",LVCFMT_LEFT,8*tm.tmAveCharWidth,0);
GetListCtrl().InsertColumn(1,"年级",LVCFMT_LEFT,8*tm.tmAveCharWidth,1);
GetListCtrl().InsertColumn(2,"班级",LVCFMT_LEFT,8*tm.tmAveCharWidth,2);
GetListCtrl().InsertColumn(3,"周课时",LVCFMT_LEFT,8*tm.tmAveCharWidth,3);
GetListCtrl().InsertColumn(4,"备注",LVCFMT_LEFT,50*tm.tmAveCharWidth,4);
GetListCtrl().SetExtendedStyle(0);
}
void CLessonView::HeadTeacherLesson()
{
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
GetListCtrl().ModifyStyle(0,LVS_REPORT|1);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
GetListCtrl().InsertColumn(0,"星期",LVCFMT_LEFT,6*tm.tmAveCharWidth,0);
GetListCtrl().InsertColumn(1,"一",LVCFMT_CENTER,10*tm.tmAveCharWidth,1);
GetListCtrl().InsertColumn(2,"二",LVCFMT_CENTER,10*tm.tmAveCharWidth,2);
GetListCtrl().InsertColumn(3,"三",LVCFMT_CENTER,10*tm.tmAveCharWidth,3);
GetListCtrl().InsertColumn(4,"四",LVCFMT_CENTER,10*tm.tmAveCharWidth,4);
GetListCtrl().InsertColumn(5,"五",LVCFMT_CENTER,10*tm.tmAveCharWidth,5);
GetListCtrl().InsertColumn(6,"六",LVCFMT_CENTER,10*tm.tmAveCharWidth,6);
GetListCtrl().InsertColumn(7,"日",LVCFMT_CENTER,10*tm.tmAveCharWidth,7);
GetListCtrl().SetExtendedStyle(1);
}
void CLessonView::HeadClassLesson()
{
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
GetListCtrl().ModifyStyle(0,LVS_REPORT|1);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
GetListCtrl().InsertColumn(0,"星期",LVCFMT_LEFT,6*tm.tmAveCharWidth,0);
GetListCtrl().InsertColumn(1,"一",LVCFMT_CENTER,10*tm.tmAveCharWidth,1);
GetListCtrl().InsertColumn(2,"二",LVCFMT_CENTER,10*tm.tmAveCharWidth,2);
GetListCtrl().InsertColumn(3,"三",LVCFMT_CENTER,10*tm.tmAveCharWidth,3);
GetListCtrl().InsertColumn(4,"四",LVCFMT_CENTER,10*tm.tmAveCharWidth,4);
GetListCtrl().InsertColumn(5,"五",LVCFMT_CENTER,10*tm.tmAveCharWidth,5);
GetListCtrl().InsertColumn(6,"六",LVCFMT_CENTER,10*tm.tmAveCharWidth,6);
GetListCtrl().InsertColumn(7,"日",LVCFMT_CENTER,10*tm.tmAveCharWidth,7);
GetListCtrl().SetExtendedStyle(1);
}
void CLessonView::HeadGradeLesson()
{
CLessonDoc * pDoc = GetDocument();
int count=0;
for(int i=pDoc->GetGradeCount();i>0;i--)
if(pDoc->GetClassCount(i)>count)count=pDoc->GetClassCount(i);
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
GetListCtrl().ModifyStyle(0,LVS_REPORT|1);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
GetListCtrl().InsertColumn(0,"星期",LVCFMT_LEFT,6*tm.tmAveCharWidth,0);
GetListCtrl().InsertColumn(1,"一",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,1);
GetListCtrl().InsertColumn(2,"二",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,2);
GetListCtrl().InsertColumn(3,"三",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,3);
GetListCtrl().InsertColumn(4,"四",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,4);
GetListCtrl().InsertColumn(5,"五",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,5);
GetListCtrl().InsertColumn(6,"六",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,6);
GetListCtrl().InsertColumn(7,"日",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,7);
GetListCtrl().SetExtendedStyle(1);
}
void CLessonView::HeadTotalLesson()
{
CLessonDoc * pDoc = GetDocument();
int count=0;
for(int i=pDoc->GetGradeCount();i>0;i--)
count+=pDoc->GetClassCount(i);
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
GetListCtrl().ModifyStyle(0,LVS_REPORT|1);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
GetListCtrl().InsertColumn(0,"星期",LVCFMT_LEFT,6*tm.tmAveCharWidth,0);
GetListCtrl().InsertColumn(1,"一",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,1);
GetListCtrl().InsertColumn(2,"二",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,2);
GetListCtrl().InsertColumn(3,"三",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,3);
GetListCtrl().InsertColumn(4,"四",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,4);
GetListCtrl().InsertColumn(5,"五",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,5);
GetListCtrl().InsertColumn(6,"六",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,6);
GetListCtrl().InsertColumn(7,"日",LVCFMT_CENTER,count*5*tm.tmAveCharWidth,7);
GetListCtrl().SetExtendedStyle(1);
}
void CLessonView::UpdateMission()
{
GetListCtrl().DeleteAllItems();
CLessonDoc * pDoc = GetDocument();
CTeacher * teacher=pDoc->GetTeacher(pDoc->m_Info.m_SelectTeacherName);
if(teacher==NULL)return;
CMission * mission;
int Count=teacher->m_MissionArray.GetSize();
for(int i=0;i<Count;i++)
{
mission=(CMission *)teacher->m_MissionArray.GetAt(i);
mission->UpdateList(&GetListCtrl());
}
}
void CLessonView::UpdateTeacherLesson()
{
CLessonDoc * pDoc = GetDocument();
GetListCtrl().DeleteAllItems();
CTeacher * teacher=pDoc->GetTeacher(pDoc->m_Info.m_SelectTeacherName);
if(teacher==NULL)return;
CString str="";
for(int Stanza=0;Stanza<pDoc->m_Info.m_Stanza;Stanza++)
{
str.Format("第%d节",Stanza+1);
GetListCtrl().InsertItem(Stanza,str);
for(int Week=0;Week<pDoc->m_Info.m_Week;Week++)
{
str=GetSubject(teacher,Week+1,Stanza+1);
GetListCtrl().SetItemText(Stanza,Week+1,str);
}
}
}
void CLessonView::UpdateClassLesson()
{
CLessonDoc * pDoc = GetDocument();
int Grade=pDoc->m_Info.m_SelectGrade;
int Class=pDoc->m_Info.m_SelectClass;
GetListCtrl().DeleteAllItems();
CString str="";
for(int Stanza=0;Stanza<pDoc->m_Info.m_Stanza;Stanza++)
{
str.Format("第%d节",Stanza+1);
GetListCtrl().InsertItem(Stanza,str);
for(int Week=0;Week<pDoc->m_Info.m_Week;Week++)
{
str=GetSubject(Grade,Class,Week+1,Stanza+1);
GetListCtrl().SetItemText(Stanza,Week+1,str);
}
}
}
void CLessonView::UpdateGradeLesson()
{
CLessonDoc * pDoc = GetDocument();
int Grade=pDoc->m_Info.m_SelectGrade;
int ClassCount=pDoc->GetClassCount(Grade);
GetListCtrl().DeleteAllItems();
//写表头
CString str="班级";
GetListCtrl().InsertItem(0,str);
str.Empty();
for(int i=1;i<=ClassCount;i++)
{
CString tempstr;
tempstr.Format(" %d(%d)",Grade,i);
str+=tempstr;
}
for(i=1;i<=pDoc->m_Info.m_Week;i++)
GetListCtrl().SetItemText(0,i,str);
//写课程
for(int Stanza=0;Stanza<pDoc->m_Info.m_Stanza;Stanza++)
{
str.Format("第%d节",Stanza+1);
GetListCtrl().InsertItem(Stanza+1,str);
str.Empty();
for(int Week=0;Week<pDoc->m_Info.m_Week;Week++)
{
for(i=1;i<=ClassCount;i++)
{
str+=" ";
str+=GetSubject(Grade,i,Week+1,Stanza+1);
}
GetListCtrl().SetItemText(Stanza+1,Week+1,str);
str.Empty();
}
}
}
void CLessonView::UpdateTotalLesson()
{
CLessonDoc * pDoc = GetDocument();
int GradeCount=pDoc->GetGradeCount();
GetListCtrl().DeleteAllItems();
//写表头
CString str="班级";
GetListCtrl().InsertItem(0,str);
str.Empty();
for(int g=1;g<=GradeCount;g++)
{
int ClassCount=pDoc->GetClassCount(g);
for(int i=1;i<=ClassCount;i++)
{
CString tempstr;
tempstr.Format(" %d(%d)",g,i);
str+=tempstr;
}
}
for(int i=1;i<=pDoc->m_Info.m_Week;i++)
GetListCtrl().SetItemText(0,i,str);
//写课程
str.Empty();
for(int Stanza=0;Stanza<pDoc->m_Info.m_Stanza;Stanza++)
{
str.Format("第%d节",Stanza+1);
GetListCtrl().InsertItem(Stanza+1,str);
for(int Week=0;Week<pDoc->m_Info.m_Week;Week++)
{
str.Empty();
for(g=1;g<=GradeCount;g++)
{
int ClassCount=pDoc->GetClassCount(g);
for(int c=1;c<=ClassCount;c++)
{
str+=" ";
str+=GetSubject(g,c,Week+1,Stanza+1);
}
}
GetListCtrl().SetItemText(Stanza+1,Week+1,str);
}
}
}
CString CLessonView::GetSubject(CObject *Teacher, int Week, int Stanza)
{
CString Subject;Subject.Empty();
CTeacher * teacher=(CTeacher *)Teacher;
CMission * mission;
for(int i=teacher->m_MissionArray.GetSize()-1;i>=0;i--)
{
mission=(CMission *)teacher->m_MissionArray.GetAt(i);
if(mission->m_Sit[Week-1][Stanza-1])
{
Subject.Format("%d(%d)%s",mission->m_Grade,mission->m_Class,mission->m_Subject);
return Subject;
}
}
return Subject;
}
CString CLessonView::GetSubject(int Grade, int Class, int Week, int Stanza)
{
CLessonDoc * pDoc = GetDocument();
CString Subject;Subject="自习";
CTeacher * teacher;CMission * mission;
for(int i=pDoc->m_TeacherArray.GetSize()-1;i>=0;i--)
{
teacher=(CTeacher *)pDoc->m_TeacherArray.GetAt(i);
for(int j=teacher->m_MissionArray.GetSize()-1;j>=0;j--)
{
mission=(CMission *)teacher->m_MissionArray.GetAt(j);
if(mission->m_Grade==Grade&&mission->m_Class==Class&&mission->m_Sit[Week-1][Stanza-1])
{
Subject=mission->m_Subject;
return Subject;
}
}
}
return Subject;
}
void CLessonView::OnAddmission()
{
// TODO: Add your command handler code here
AddMission();
}
void CLessonView::OnUpdateAddmission(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CLessonDoc * pDoc=GetDocument();
if(pDoc->m_Info.m_ViewStatus==TEACHER_MISSION&&pDoc->m_TeacherArray.GetSize()>0)
pCmdUI->Enable();
else
pCmdUI->Enable(FALSE);
}
void CLessonView::OnDelete()
{
// TODO: Add your command handler code here
DeleteMission();
}
void CLessonView::OnUpdateDelete(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CLessonDoc * pDoc=GetDocument();
POSITION pos;int n;
pos=GetListCtrl().GetFirstSelectedItemPosition();
n=GetListCtrl().GetNextSelectedItem(pos);
if(pDoc->m_Info.m_ViewStatus==TEACHER_MISSION&&n>-1)
pCmdUI->Enable();
else
pCmdUI->Enable(FALSE);
}
void CLessonView::OnFix()
{
// TODO: Add your command handler code here
FixMission();
}
void CLessonView::OnUpdateFix(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CLessonDoc * pDoc=GetDocument();
POSITION pos;int n;
pos=GetListCtrl().GetFirstSelectedItemPosition();
n=GetListCtrl().GetNextSelectedItem(pos);
if(pDoc->m_Info.m_ViewStatus==TEACHER_MISSION&&n>-1)
pCmdUI->Enable();
else
pCmdUI->Enable(FALSE);
}
void CLessonView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CLessonDoc * pDoc=GetDocument();
if(pDoc->m_Info.m_ViewStatus==CLASS_LESSON&&pDoc->m_Info.m_SelectGrade>0&&pDoc->m_Info.m_SelectClass>0)
{
CMainFrame* pf=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CStatusBar * Bar=&pf->m_wndStatusBar;
if(m_Status==FALSE)
{
m_Status=TRUE;
////////根据点的位置确定要调的源课是哪个任务,并将"星期几","第几节"写入m_Sit数组
GetSit(point);
if(m_Sit[0]>pDoc->m_Info.m_Week||m_Sit[1]>pDoc->m_Info.m_Stanza||m_Sit[0]<1||m_Sit[1]<1)
m_Sit[0]=m_Sit[1]=0;
else
{
CMission * Mission=pDoc->GetMission(pDoc->m_Info.m_SelectGrade,pDoc->m_Info.m_SelectClass,m_Sit[0],m_Sit[1]);
//改变鼠标形状
SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR));
if(Bar&&Mission)
{
CString str;
str.Format("星期%d第%d节 %s",m_Sit[0],m_Sit[1],Mission->m_Subject);
Bar->SetPaneText(1,str);
}
}
}
else
{
m_Status=FALSE;
////////根据点的位置确定要调的目标课是哪个任务,根据m_Sit数组的内容进行调课
CChangeLessonDlg dlg;
dlg.m_pDoc=pDoc;
dlg.m_SelectWeek1=m_Sit[0];
dlg.m_SelectStanza1=m_Sit[1];
GetSit(point);
dlg.m_SelectWeek2=m_Sit[0];
dlg.m_SelectStanza2=m_Sit[1];
if(m_Sit[0]>0&&m_Sit[1]>0&&m_Sit[0]<=pDoc->m_Info.m_Week&&m_Sit[1]<=pDoc->m_Info.m_Stanza&&(m_Sit[0]!=dlg.m_SelectWeek1||m_Sit[1]!=dlg.m_SelectStanza1)&&dlg.DoModal()==IDOK)
{
if(pDoc->ChangeLesson(dlg.m_Info[0],dlg.m_Info[1],dlg.m_Info[2],dlg.m_Info[3],dlg.m_Info[4],dlg.m_Info[5])==TRUE)
pDoc->SetModifiedFlag();
mouse_event(64,0,0,0,0);
mouse_event(108,0,0,0,0);
mouse_event(256,0,0,0,0);
}
////最后将m_Sit清零
m_Sit[0]=m_Sit[1]=0;
}
}
CListView::OnLButtonDown(nFlags, point);
}
void CLessonView::GetSit(CPoint point)
{
int x=point.x;
int y=point.y;
int nItem=0;
while(x>0)
{
x=x-GetListCtrl().GetColumnWidth(nItem);
nItem++;
}
m_Sit[0]=nItem-1;
m_Sit[1]=(y-4)/13;
}
void CLessonView::OnMouseMove(UINT nFlags, CPoint point)
{m_CtrlDown=0;
// TODO: Add your message handler code here and/or call default
CLessonDoc * pDoc=GetDocument();
if(m_Sit[0]==0||m_Sit[1]==0)
{
m_Status=FALSE;
CMainFrame* pf=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CStatusBar * Bar=&pf->m_wndStatusBar;
if(Bar)
{
CString str;
str.Format("%d个教师,%d个任务",pDoc->GetTeacherCount(),pDoc->GetMissionCount());
Bar->SetPaneText(1,str);
}
return;
}
if(pDoc->m_Info.m_ViewStatus==CLASS_LESSON&&pDoc->m_Info.m_SelectGrade>0&&pDoc->m_Info.m_SelectClass>0&&m_Status)
SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR));
else
m_Status=FALSE;
CListView::OnMouseMove(nFlags, point);
}
void CLessonView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_Status=FALSE;
m_Sit[0]=m_Sit[1]=0;
CListView::OnLButtonDown(nFlags, point);
}
void CLessonView::OnFilePrintSetup()
{
// TODO: Add your command handler code here
CLessonApp * pa=(CLessonApp *)AfxGetApp();
CPageSetDlg dlg;
if(dlg.DoModal()==IDOK)
pa->m_Print.WriteReg();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -