📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "xskq.h"
#include "MainFrm.h"
#include "StudentRecordSet.h"
#include "StudentAddDlg.h"
#include "SystemConfig.h"
#include "ConfigRecordSet.h"
#include "StudentSearchDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_ATTEND, OnAttend)
ON_COMMAND(ID_SEARCH_STUDENT, OnSearchStudent)
ON_COMMAND(ID_SEARCH_ATTEND, OnSearchAttend)
ON_COMMAND(ID_STUDENT_ADD, OnStudentAdd)
ON_COMMAND(ID_STUDENT_EDIT, OnStudentEdit)
ON_COMMAND(ID_STUDENT_DELETE, OnStudentDelete)
ON_COMMAND(ID_SYSTEM_CONFIG, OnSystemConfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnAttend()
{
// TODO: Add your command handler code here
}
void CMainFrame::OnSearchStudent()
{
// TODO: Add your command handler code here
CStudentSearchDlg dlg;
if( dlg.DoModal() == IDOK )
{
BOOL bIsFirst = TRUE;
CString strSql,StudentGrade,StudentClass,StudentID,StudentName,
StudentSex;
//判断年级是否输入了条件
if( dlg.m_StudentGrade != "" )
{
StudentGrade = " StudentGrade = '" + dlg.m_StudentGrade + "'";
bIsFirst = FALSE;
}
else
StudentGrade = "";
//判断班级是否输入了条件
if( dlg.m_StudentClass != "" )
{
if( bIsFirst == TRUE )
StudentClass = "StudentClass = '" + dlg.m_StudentClass + "'";
else
StudentClass =" and StudentClass = '" + dlg.m_StudentClass +"'";
bIsFirst = FALSE;
}
else
StudentClass = "";
//判断学号是否输入了条件
if( dlg.m_StudentID != "" )
{
if( bIsFirst == TRUE )
StudentID = "StudentID = '" + dlg.m_StudentID + "'";
else
StudentID =" and StudentID = '" + dlg.m_StudentID +"'";
bIsFirst = FALSE;
}
//判断姓名是否输入了条件
if( dlg.m_StudentName != "" )
{
if( bIsFirst == TRUE )
StudentName = "StudentName = '" + dlg.m_StudentName + "'";
else
StudentName =" and StudentName = '" + dlg.m_StudentName +"'";
bIsFirst = FALSE;
}
//判断性别是否输入了条件
if( dlg.m_StudentSex != "" )
{
if( bIsFirst == TRUE )
StudentSex = " StudentSex = '" + dlg.m_StudentSex + "'";
else
StudentSex = " and StudentSex = '" + dlg.m_StudentSex + "'";
bIsFirst = FALSE;
}
//生成完整的查询条件
if( bIsFirst == TRUE ) //没有输入任何条件
strSql = "select * from student";
else
strSql = "select * from student where" + StudentGrade + StudentClass +
StudentID + StudentName + StudentSex;
//切换到CUsersListView,根据查询条件显示住户
m_ListView->ShowStudent(strSql);
}
}
void CMainFrame::OnSearchAttend()
{
// TODO: Add your command handler code here
}
void CMainFrame::OnStudentAdd()
{
// TODO: Add your command handler code here
//创建CStudentAddDlg的实例
CStudentAddDlg m_StudentAddDlg;
//弹出增加用户信息的对话框,如果点击了取消,则退出
if(m_StudentAddDlg.DoModal()!=IDOK)
return;
CStudentRecordSet m_StudentRecordSet;
try
{
if(m_StudentRecordSet.IsOpen())
m_StudentRecordSet.Close();
m_StudentRecordSet.m_strFilter.Format("StudentName='%s'order by StudentID ASC",
m_StudentAddDlg.m_StudentName.operator LPCTSTR());
m_StudentRecordSet.Open(CRecordset::snapshot,NULL,CRecordset::none);
if(!m_StudentRecordSet.IsEOF())
{
m_StudentRecordSet.Close();
AfxMessageBox("同名用户已经存在");
return;
}
m_StudentRecordSet.AddNew();
m_StudentRecordSet.m_StudentGrade=m_StudentAddDlg.m_StudentGrade;
m_StudentRecordSet.m_StudentClass=m_StudentAddDlg.m_StudentClass;
m_StudentRecordSet.m_StudentID=m_StudentAddDlg.m_StudentID;
m_StudentRecordSet.m_StudentName=m_StudentAddDlg.m_StudentName;
m_StudentRecordSet.m_StudentSex=m_StudentAddDlg.m_StudentSex;
m_StudentRecordSet.m_StudentAddr=m_StudentAddDlg.m_StudentAddr;
m_StudentRecordSet.m_StudentPhone=m_StudentAddDlg.m_StudentPhone;
if(m_StudentRecordSet.CanUpdate())
{
m_StudentRecordSet.Update();
}
if(m_StudentRecordSet.IsOpen())
m_StudentRecordSet.Close();
AfxMessageBox("用户信息增加成功");
}
catch(CDBException *e)
{
e->ReportError();
//e->Delete();
return;
}
}
void CMainFrame::OnStudentEdit()
{
// TODO: Add your command handler code here
//调用EditCurStudent操作,进行用户记录的编辑
m_ListView->EditCurStudent();
}
void CMainFrame::OnStudentDelete()
{
// TODO: Add your command handler code here
//增加删除确认,用户选择“确定”之后,方删除记录
if (MessageBox("是否删除这条记录?","删除确认",MB_YESNO|MB_ICONQUESTION)==IDYES)
{
//执行删除操作
m_ListView->DelCurStudent();
}
}
void CMainFrame::OnSystemConfig()
{
// TODO: Add your command handler code here
//创建CSystemConfigDlg的实例
CSystemConfig m_SystemConfig;
//弹出系统配置的对话框,如果点击了取消,则退出
if(m_SystemConfig.DoModal()!=IDOK)
return;
CConfigRecordSet m_ConfigRecordSet;
try
{
if(!m_ConfigRecordSet.IsOpen())
m_ConfigRecordSet.Open();
if(!m_ConfigRecordSet.IsBOF())
{
m_ConfigRecordSet.MoveFirst();
m_ConfigRecordSet.Delete();
}
m_ConfigRecordSet.AddNew();
m_ConfigRecordSet.m_SchoolHour=m_SystemConfig.m_SchoolHour;
m_ConfigRecordSet.m_SchoolHour2=m_SystemConfig.m_SchoolHour2;
m_ConfigRecordSet.m_SchoolMinute=m_SystemConfig.m_SchoolMinute;
m_ConfigRecordSet.m_SchoolMinute2=m_SystemConfig.m_SchoolMinute2;
if(m_ConfigRecordSet.CanUpdate())
{
m_ConfigRecordSet.Update();
}
if(m_ConfigRecordSet.IsOpen())
m_ConfigRecordSet.Close();
AfxMessageBox("系统配置成功");
}
catch(CDBException *e)
{
e->ReportError();
//e->Delete();
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -