AddUserDlg.cpp
上传用户:yuxuan88
上传日期:2022-05-09
资源大小:2290k
文件大小:4k
- // AddUserDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Inhabitants.h"
- #include "AddUserDlg.h"
- #include "InhabitantsDoc.h"
- #include "MainFrm.h"
- #include "LeftTreeView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAddUserDlg dialog
- CAddUserDlg::CAddUserDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CAddUserDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CAddUserDlg)
- m_strBeeppager = _T("");
- m_nBuildingNum = 0;
- m_nCellNum = 0;
- m_strEmail = _T("");
- m_strHomeTel = _T("");
- m_strHousemaster = _T("");
- m_strMobile = _T("");
- m_strOffice = _T("");
- m_strOfficeTel = _T("");
- m_nRoomNum = 0;
- m_strSectionName = _T("");
- //}}AFX_DATA_INIT
- }
- void CAddUserDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAddUserDlg)
- DDX_Text(pDX, IDC_EDIT_BEEPPAGER, m_strBeeppager);
- DDX_Text(pDX, IDC_EDIT_BUILDINGNUM, m_nBuildingNum);
- DDX_Text(pDX, IDC_EDIT_CELLNUM, m_nCellNum);
- DDX_Text(pDX, IDC_EDIT_EMAIL, m_strEmail);
- DDX_Text(pDX, IDC_EDIT_HOMETEL, m_strHomeTel);
- DDX_Text(pDX, IDC_EDIT_HOUSEMASTER, m_strHousemaster);
- DDX_Text(pDX, IDC_EDIT_MOBILE, m_strMobile);
- DDX_Text(pDX, IDC_EDIT_OFFICE, m_strOffice);
- DDX_Text(pDX, IDC_EDIT_OFFICETEL, m_strOfficeTel);
- DDX_Text(pDX, IDC_EDIT_ROOMNUM, m_nRoomNum);
- DDX_Text(pDX, IDC_EDIT_SECTIONNAME, m_strSectionName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAddUserDlg, CDialog)
- //{{AFX_MSG_MAP(CAddUserDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAddUserDlg message handlers
- void CAddUserDlg::OnOK()
- {
- //判断输入信息的合法性
- UpdateData(TRUE);
- CEdit* p;
- if( m_strHousemaster == "" )
- {
- AfxMessageBox("请填户主姓名");
- p = (CEdit*)GetDlgItem(IDC_EDIT_HOUSEMASTER);
- p->SetFocus();
- return;
- }
- if( m_strSectionName == "" )
- {
- AfxMessageBox("请填小区名称");
- p = (CEdit*)GetDlgItem(IDC_EDIT_SECTIONNAME);
- p->SetFocus();
- return;
- }
- if( m_nBuildingNum == 0 )
- {
- AfxMessageBox("楼号不能为零");
- p = (CEdit*)GetDlgItem(IDC_EDIT_BUILDINGNUM);
- p->SetFocus();
- return;
- }
- if( m_nCellNum == 0 )
- {
- AfxMessageBox("单元号不能为零");
- p = (CEdit*)GetDlgItem(IDC_EDIT_CELLNUM);
- p->SetFocus();
- return;
- }
- if( m_nRoomNum == 0 )
- {
- AfxMessageBox("房间号不能为零");
- p = (CEdit*)GetDlgItem(IDC_EDIT_ROOMNUM);
- p->SetFocus();
- return;
- }
-
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
- CInhabitantsDoc* pDoc = (CInhabitantsDoc*)pFrame->GetActiveDocument();
-
- //让用户确认操作
- if(this->MessageBox("你真的要添加这条记录?",
- "小区居民管理系统",MB_YESNO)==IDNO)
- {
- CDialog::OnCancel();
- return;
- }
- //增加住户到数据库中
- USER user;
- user.strSectionname = m_strSectionName;
- user.nBuildingnum = m_nBuildingNum;
- user.nCellnum = m_nCellNum;
- user.nRoomnum = m_nRoomNum;
- user.strName = m_strHousemaster;
- user.strHouseTel = m_strHomeTel;
- user.strOffice = m_strOffice;
- user.strOfficeTel = m_strOfficeTel;
- user.strBeeppager = m_strBeeppager;
- user.strMobile = m_strMobile;
- user.strEmail = m_strEmail;
- switch(pDoc->AddUser(user))
- {
- case 0:
- { //已经存在该住户了
- CString str;
- str.Format( "%s小区的%d号楼的%d单元的%d房间的住户已经存在了",
- m_strSectionName,m_nBuildingNum,m_nCellNum,m_nRoomNum );
- AfxMessageBox( str );
- CEdit* p = (CEdit*)GetDlgItem(IDC_EDIT_ROOMNUM);
- p->SetFocus();
- return;
- break;
- }
- case 1:
- { //增加成功后刷新左边的树视图
- pFrame->m_pLeftView->AddUserToTree(m_strSectionName,
- m_nBuildingNum,m_nCellNum,m_nRoomNum);
- break;
- }
- default:
- return;
- break;
- }
- CDialog::OnOK();
- }