input.cpp
上传用户:hbzqs18
上传日期:2021-03-04
资源大小:46k
文件大小:4k
- // input.cpp : implementation file
- //
- #include "stdafx.h"
- #include "学生家庭经济情况调查系统.h"
- #include "input.h"
- #include <fstream.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // input dialog
- input::input(CWnd* pParent /*=NULL*/)
- : CDialog(input::IDD, pParent)
- {
- //{{AFX_DATA_INIT(input)
- m_number = _T("");
- m_jiguan = _T("");
- m_brings = 0;
- m_members = 0;
- //}}AFX_DATA_INIT
- focus = 0;
- }
- void input::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(input)
- DDX_Control(pDX, IDC_BTN_OK, m_ok);
- DDX_Text(pDX, IDC_EDIT1, m_number);
- DDX_Text(pDX, IDC_EDIT2, m_jiguan);
- DDX_Text(pDX, IDC_EDIT3, m_brings);
- DDX_Text(pDX, IDC_EDIT4, m_members);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(input, CDialog)
- //{{AFX_MSG_MAP(input)
- ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
- ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
- ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
- ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
- ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
- ON_EN_KILLFOCUS(IDC_EDIT3, OnKillfocusEdit3)
- ON_EN_KILLFOCUS(IDC_EDIT4, OnKillfocusEdit4)
- ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // input message handlers
- void input::OnBtnOk()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- ofstream outf;
- outf.open("student.dat",ios::app);
- outf<<m_number <<" "<<m_jiguan<<" "<<m_brings<<" "<<m_members<<endl;
- outf.close();
- MessageBox("输入完毕");
- m_jiguan="";
- m_brings=0;
- m_number="";
- m_members=0;
- UpdateData(FALSE);
- CButton *pBtn;
- pBtn = (CButton*)GetDlgItem(IDC_BTN_OK);
- pBtn->EnableWindow(FALSE);
- }
- void input::ValidateData()
- {
- UpdateData();
-
- if(!m_number.Compare(" ") || m_number.IsEmpty() || m_number.GetLength() !=9 )
- return;
- if(!m_jiguan.Compare(" ") || m_jiguan.IsEmpty())
- return;
- if(m_brings < 0)
- return;
-
- if(m_members < 1)
- return;
- CButton *pBtn;
- pBtn = (CButton*)GetDlgItem(IDC_BTN_OK);
- pBtn->EnableWindow();
- }
- void input::OnKillfocusEdit1()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(!m_number.Compare(" ") || m_number.IsEmpty() || m_number.GetLength() !=9 )
- {
- SetDlgItemText(IDC_STATIC_SHOW_NUMBER,"输入错误");
- return;
- }
- SetDlgItemText(IDC_STATIC_SHOW_NUMBER,"正确");
- ValidateData();
- }
- void input::OnKillfocusEdit2()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(!m_jiguan.Compare(" ") || m_jiguan.IsEmpty())
- {
- if(focus == 0)
- SetDlgItemText(IDC_STATIC_SHOW_JIGUAN,"");
- else
- SetDlgItemText(IDC_STATIC_SHOW_JIGUAN,"输入错误");
- focus++;
- return;
- }
- SetDlgItemText(IDC_STATIC_SHOW_JIGUAN,"正确");
- ValidateData();
- }
- void input::OnSetfocusEdit1()
- {
- // TODO: Add your control notification handler code here
- SetDlgItemText(IDC_STATIC_SHOW_NUMBER,"");
- }
- void input::OnSetfocusEdit2()
- {
- // TODO: Add your control notification handler code here
- SetDlgItemText(IDC_STATIC_SHOW_JIGUAN,"");
- }
- void input::OnKillfocusEdit3()
- {
- // TODO: Add your control notification handler code here
- ValidateData();
- }
- void input::OnKillfocusEdit4()
- {
- // TODO: Add your control notification handler code here
- ValidateData();
- }
- void input::OnChangeEdit4()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // send this notification unless you override the CDialog::OnInitDialog()
- // function and call CRichEditCtrl().SetEventMask()
- // with the ENM_CHANGE flag ORed into the mask.
-
- // TODO: Add your control notification handler code here
- ValidateData();
- }