📄 studentinfodlg.cpp
字号:
// StudentInfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StudentInfo.h"
#include "StudentInfoDlg.h"
#include "Link.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentInfoDlg dialog
CStudentInfoDlg::CStudentInfoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStudentInfoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudentInfoDlg)
m_strNo = _T("");
m_strName = _T("");
m_strGender = _T("");
m_strName3 = _T("");
m_strNo3 = _T("");
m_nChn2 = 0;
m_nEng2 = 0;
m_nMath2 = 0;
m_strName2 = _T("");
m_strNo2 = _T("");
m_nAll = 0;
m_strGender2 = _T("");
m_nNum = 0;
m_nOrder = 0;
m_fRate = 0.0f;
m_fChnAvg = 0.0f;
m_fEngAvg = 0.0f;
m_fMathAvg = 0.0f;
m_fRateChn = 0.0f;
m_fRateEng = 0.0f;
m_fRateMath = 0.0f;
m_nChn = 0;
m_nEng = 0;
m_nMath = 0;
//}}AFX_DATA_INIT
m_nFlag=0;
m_nViewFlag=0;
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CStudentInfoDlg::~CStudentInfoDlg()
{
CFile file("学籍信息.db", CFile::modeCreate | CFile::modeWrite);
CArchive ar(&file, CArchive::store);
int len;
len=m_link.ListSize();
ar<<len;
Node *curNode;
curNode=m_link.GetFront();
while(curNode!=NULL)
{
ar<<(CObject *)curNode;
curNode=curNode->NextNode();
}
}
void CStudentInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentInfoDlg)
DDX_Text(pDX, IDC_EDIT_N0, m_strNo);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
DDX_Text(pDX, IDC_EDIT_GENDER, m_strGender);
DDX_Text(pDX, IDC_EDIT_NAME3, m_strName3);
DDX_Text(pDX, IDC_EDIT_NO3, m_strNo3);
DDX_Text(pDX, IDC_EDIT_CHN2, m_nChn2);
DDX_Text(pDX, IDC_EDIT_ENG2, m_nEng2);
DDX_Text(pDX, IDC_EDIT_MATH2, m_nMath2);
DDX_Text(pDX, IDC_EDIT_NAME2, m_strName2);
DDX_Text(pDX, IDC_EDIT_NO2, m_strNo2);
DDX_Text(pDX, IDC_EDIT_ALL, m_nAll);
DDX_Text(pDX, IDC_EDIT_GENDER2, m_strGender2);
DDX_Text(pDX, IDC_EDIT_NUM, m_nNum);
DDX_Text(pDX, IDC_EDIT_ORDER, m_nOrder);
DDX_Text(pDX, IDC_EDIT_CHNAVG, m_fChnAvg);
DDX_Text(pDX, IDC_EDIT_ENGAVG, m_fEngAvg);
DDX_Text(pDX, IDC_EDIT_MATHAVG, m_fMathAvg);
DDX_Text(pDX, IDC_EDIT_RATECHN, m_fRateChn);
DDX_Text(pDX, IDC_EDIT_RATEENG, m_fRateEng);
DDX_Text(pDX, IDC_EDIT_RATEMATH, m_fRateMath);
DDX_Text(pDX, IDC_EDIT_CHN, m_nChn);
DDX_Text(pDX, IDC_EDIT_ENG, m_nEng);
DDX_Text(pDX, IDC_EDIT_MATH, m_nMath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudentInfoDlg, CDialog)
//{{AFX_MSG_MAP(CStudentInfoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_INPUT, OnBtnInput)
ON_BN_CLICKED(IDC_BTN_SEARCH, OnBtnSearch)
ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
ON_BN_CLICKED(IDC_BTN_STATE, OnBtnState)
ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
ON_BN_CLICKED(IDC_BTN_PREV, OnBtnPrev)
ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentInfoDlg message handlers
BOOL CStudentInfoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ModifyStyle(0, WS_MINIMIZEBOX,0 );
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
OnBtnOk();
CFile file("学籍信息.db", CFile::modeRead);
CArchive ar(&file, CArchive::load);
int len;
ar>>len;
Node *curNode;
for(int i=0; i<len; i++)
{
ar>>curNode;
m_link.InsertRear(&curNode->data);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CStudentInfoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStudentInfoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStudentInfoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStudentInfoDlg::OnBtnInput()
{
// TODO: Add your control notification handler code here
UpdateData();
if(8!=m_strNo.GetLength())
{
MessageBox("请输入8位的学号!");
return;
}
int nNo=atoi(m_strNo);
if(nNo<=0 || nNo>99999999)
{
MessageBox("请输入8位的学号!");
return;
}
Node* pNode=m_link.SearchByNo(m_strNo);
if(pNode!=NULL)
{
MessageBox("该学号已存在,学号不能重复!");
return;
}
if("男"!=m_strGender && "女"!=m_strGender)
{
MessageBox("请在性别项输入“男”或“女”!");
return;
}
if(m_nChn<0 || m_nChn>100)
{
MessageBox("请在语文成绩项输入0—100的数字!");
return;
}
if(m_nMath<0 || m_nMath>100)
{
MessageBox("请在数学成绩项输入0—100的数字!");
return;
}
if(m_nEng<0 || m_nEng>100)
{
MessageBox("请在英语成绩项输入0—100的数字!");
return;
}
struct1 item;
item.num=m_strNo;
item.name=m_strName;
item.sex=m_strGender;
item.score[0]=m_nChn;
item.score[1]=m_nMath;
item.score[2]=m_nEng;
m_link.InsertRear(&item);
MessageBox("录入数据成功!");
}
void CStudentInfoDlg::OnBtnSearch()
{
// TODO: Add your control notification handler code here
m_link.obArray.RemoveAll();
m_nViewFlag=0;
Node* pNode;
UpdateData();
if(m_strNo3!="")
{
if(8!=m_strNo3.GetLength())
{
MessageBox("请输入8位的学号!");
return;
}
int nNo=atoi(m_strNo3);
if(nNo<=0 || nNo>99999999)
{
MessageBox("请输入8位的学号!");
return;
}
pNode=m_link.SearchByNo(m_strNo3);
if(pNode==NULL)
{
MessageBox("该学号不存在!");
return;
}
if(m_strName3!="")
if(pNode->data.name!=m_strName3)
{
MessageBox("学号姓名不匹配!");
return;
}
}
else
{
if(m_strName3=="")
{
MessageBox("请输入学号或姓名!");
return;
}
pNode=m_link.SearchByName(m_strName3);
if(pNode==NULL)
{
MessageBox("该姓名不存在!");
return;
}
}
m_strNo2=pNode->data.num;
m_strName2=pNode->data.name;
m_strGender2=pNode->data.sex;
m_nChn2=pNode->data.score[0];
m_nMath2=pNode->data.score[1];
m_nEng2=pNode->data.score[2];
m_nAll=m_nChn2+m_nMath2+m_nEng2;
m_nOrder=m_link.Paiming(pNode);
m_nFlag=1;
OnBtnOk();
UpdateData(FALSE);
if(m_link.obArray.GetSize()<2)
((CButton*)GetDlgItem(IDC_BTN_NEXT))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_BTN_PREV))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_BTN_NEXT))->Invalidate();
}
void CStudentInfoDlg::OnBtnDel()
{
// TODO: Add your control notification handler code here
UpdateData();
if(8!=m_strNo3.GetLength())
{
MessageBox("请输入8位的学号!");
return;
}
int nNo=atoi(m_strNo3);
if(nNo<=0 || nNo>99999999)
{
MessageBox("请输入8位的学号!");
return;
}
if(2==MessageBox(
"本功能只根据学号删除信息!\n您确定要删除该学号标识的学生信息吗?",
NULL, MB_OKCANCEL))
return;
Node* pNode=m_link.SearchByNo(m_strNo3);
m_link.Delete(pNode->data.name);
MessageBox("删除信息成功!");
}
void CStudentInfoDlg::OnBtnOk()
{
// TODO: Add your control notification handler code here
static CRect rectLarge;
static CRect rectSmall;
if(rectLarge.IsRectNull())
{
GetWindowRect(&rectLarge);
CStudentInfoDlg* pDlg=(CStudentInfoDlg* )GetDlgItem(IDC_SEPARATOR);
pDlg->GetWindowRect(&rectSmall);
rectSmall.left=rectLarge.left;
rectSmall.top=rectLarge.top;
rectSmall.bottom=rectLarge.bottom;
}
if(m_nFlag)
{
SetWindowPos(NULL, 0, 0, rectLarge.Width(), rectLarge.Height(),
SWP_NOMOVE | SWP_NOZORDER);
m_nFlag=0;
}
else
SetWindowPos(NULL, 0, 0, rectSmall.Width(), rectSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
void CStudentInfoDlg::OnBtnState()
{
// TODO: Add your control notification handler code here
m_nNum=m_link.ListSize();
m_fRateChn=m_link.Passrate(0);
m_fRateMath=m_link.Passrate(1);
m_fRateEng=m_link.Passrate(2);
m_fChnAvg=m_link.Average(0);
m_fMathAvg=m_link.Average(1);
m_fEngAvg=m_link.Average(2);
UpdateData(FALSE);
}
void CStudentInfoDlg::OnBtnPrev()
{
// TODO: Add your control notification handler code here
if(m_nViewFlag==m_link.obArray.GetSize()-1)
((CButton*)GetDlgItem(IDC_BTN_NEXT))->EnableWindow();
Node * pNode=(Node*)m_link.obArray.GetAt(--m_nViewFlag);
m_strNo2=pNode->data.num;
m_strName2=pNode->data.name;
m_strGender2=pNode->data.sex;
m_nChn2=pNode->data.score[0];
m_nMath2=pNode->data.score[1];
m_nEng2=pNode->data.score[2];
m_nAll=m_nChn2+m_nMath2+m_nEng2;
m_nOrder=m_link.Paiming(pNode);
UpdateData(FALSE);
if(m_nViewFlag==0)
((CButton*)GetDlgItem(IDC_BTN_PREV))->EnableWindow(FALSE);
}
void CStudentInfoDlg::OnBtnNext()
{
// TODO: Add your control notification handler code here
if(m_nViewFlag==0)
((CButton*)GetDlgItem(IDC_BTN_PREV))->EnableWindow();
Node * pNode=(Node*)m_link.obArray.GetAt(++m_nViewFlag);
m_strNo2=pNode->data.num;
m_strName2=pNode->data.name;
m_strGender2=pNode->data.sex;
m_nChn2=pNode->data.score[0];
m_nMath2=pNode->data.score[1];
m_nEng2=pNode->data.score[2];
m_nAll=m_nChn2+m_nMath2+m_nEng2;
m_nOrder=m_link.Paiming(pNode);
UpdateData(FALSE);
if(m_nViewFlag==m_link.obArray.GetSize()-1)
((CButton*)GetDlgItem(IDC_BTN_NEXT))->EnableWindow(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -