AddPersonDlg.cpp
上传用户:tyjx315
上传日期:2015-01-18
资源大小:1685k
文件大小:3k
- // AddPersonDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SuperMarket.h"
- #include "AddPersonDlg.h"
- #include "afxdb.h"
- #include "EnrolDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAddPersonDlg dialog
- CAddPersonDlg::CAddPersonDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CAddPersonDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CAddPersonDlg)
- m_number = _T("");
- m_name = _T("");
- m_age = _T("");
- //}}AFX_DATA_INIT
- }
- void CAddPersonDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAddPersonDlg)
- DDX_Control(pDX, IDC_COMBO2, m_department);
- DDX_Control(pDX, IDC_COMBO1, m_sex);
- DDX_Text(pDX, IDC_EDIT1, m_number);
- DDX_Text(pDX, IDC_EDIT2, m_name);
- DDX_Text(pDX, IDC_EDIT4, m_age);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAddPersonDlg, CDialog)
- //{{AFX_MSG_MAP(CAddPersonDlg)
- ON_BN_CLICKED(IDC_SET_SECRET, OnSetSecret)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAddPersonDlg message handlers
- void CAddPersonDlg::OnOK()
- {
- // TODO: Add extra validation here
- CDatabase dbTemp;
- CRecordset rs( &dbTemp);
- CString strSQL,sex,department;
- int age=0,count=0;
- UpdateData();
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 员工信息 where number='"+m_number+"'");
- if(rs.IsEOF())
- {
- m_sex.GetWindowText(department);
- m_department.GetWindowText(sex);
- if(m_number.GetAt(0) != 'Y')
- {
- MessageBox("员工编号类型首字母为Y!如Y001");
- return;
- }
- if(m_number==""||m_name==""||sex==""||department==""||m_age=="")
- {
- MessageBox("请保证信息的完整性!");
- return;
- }
- else
- {
- age=atoi(m_age);
- count=strlen(m_number);
- if(count==4 && (age>17 && age<71) && (sex == "男" || sex == "女") && (department == "财务部门" || department == "客服部门" || department == "物流部门" || department == "销售部门" || department == "人事部门"))
- {
- strSQL="insert into 员工信息([number],[name],[age],[sex],[department]) values ('"+m_number+"','"+m_name+"','"+m_age+"','"+sex+"','"+department+"')";
- dbTemp.ExecuteSQL(strSQL);
- UpdateData();
- MessageBox("添加员工信息成功!");
- }
- else
- {
- if(count!=4)
- {
- MessageBox("编号不是4位!");
- return;
- }
- if(age<18 || age>65)
- {
- MessageBox("年龄超过界限!(18-65)");
- return;
- }
-
- }
- }
- }
- else
- {
- MessageBox("这个编号的员工已经存在!n请另外取编号!");
- return;
- }
- m_number="";
- m_name="";
- m_age="";
- m_sex.SetCurSel(0);
- m_department.SetCurSel(0);
- UpdateData(false);
- rs.Close();
- dbTemp.Close();
-
- // CDialog::OnOK();
- }
- void CAddPersonDlg::OnSetSecret() //新员工注册
- {
- // TODO: Add your control notification handler code here
- CEnrolDlg E_Dlg;
- E_Dlg.DoModal();
-
-
- }