MainFrm.cpp
上传用户:yuxuan88
上传日期:2022-05-09
资源大小:2290k
文件大小:8k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "Inhabitants.h"
- #include "MainFrm.h"
- #include "LeftTreeView.h"
- #include "UsersListView.h"
- #include "UserinfoView.h"
- #include "AddUserDlg.h"
- #include "QueryDlg.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_OPERATE_ADDUSER, OnOperateAdduser)
- ON_COMMAND(ID_OPERATE_QUERY, OnOperateQuery)
- //}}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 toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- 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
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
-
- // return CFrameWnd::OnCreateClient(lpcs, pContext);
- if(!m_wndSplitter.CreateStatic(this,1,2))
- return FALSE;
- if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftTreeView),CSize(100,100),pContext))
- return FALSE;
- if(!m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CUsersListView),CSize(100,100),pContext))
- return FALSE;
- m_pLeftView = (CLeftTreeView*)m_wndSplitter.GetPane(0,0);
- m_pUsersView = (CUsersListView*)m_wndSplitter.GetPane(0,1);
- return TRUE;
- }
- /***************************************
- 功能:切换右边的视
- 参数:nViewType = 0 CUsersListView
- 1 CUserinfoView
- */
- void CMainFrame::SwitchToView(int nViewType)
- {
- CView* pView = (CView*)m_wndSplitter.GetPane(0,1);
- CRect rcRight,rcFrame;
- pView->GetClientRect(&rcRight);
- GetClientRect(&rcFrame);
- switch(nViewType)
- {
- case USERSVIEW: //CUsersListView
- {
- if(!pView->IsKindOf(RUNTIME_CLASS(CUsersListView)))
- {
- m_wndSplitter.DeleteView(0,1);
- m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CUsersListView),
- CSize(rcRight.Width(),rcRight.Height()),NULL);
- m_wndSplitter.RecalcLayout();
- m_pUsersView= (CUsersListView*)m_wndSplitter.GetPane(0,1);
- }
- break;
- }
- case USERINFOVIEW: //CUserinfoView
- {
- if(!pView->IsKindOf(RUNTIME_CLASS(CUserinfoView)))
- {
- m_wndSplitter.DeleteView(0,1);
- m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CUserinfoView),
- CSize(rcRight.Width(),rcRight.Height()),NULL);
- m_wndSplitter.RecalcLayout();
- m_pUserinfoView= (CUserinfoView*)m_wndSplitter.GetPane(0,1);
- }
- break;
- }
- default:
- break;
- }
- }
- //增加住户
- void CMainFrame::OnOperateAdduser()
- {
- CAddUserDlg dlg;
- dlg.DoModal();
- }
- //查询住户
- void CMainFrame::OnOperateQuery()
- {
- CQueryDlg dlg;
- if( dlg.DoModal() == IDOK )
- {
- BOOL bIsFirst = TRUE;
- CString strSql,strSectionname,strBuildingnum,strCellnum,strRoomnum,strHousemaster,
- strHomeTel,strOffice,strOfficeTel,strBeeppager,strMobile,strEmail;
- //判断小区是否输入了条件
- if( dlg.m_strSectionName != "" )
- {
- strSectionname = " sectionname = '" + dlg.m_strSectionName + "'";
- bIsFirst = FALSE;
- }
- else
- strSectionname = "";
- //判断楼号是否输入了条件
- if( dlg.m_nBuildingNum != 0 )
- {
- if( bIsFirst == TRUE )
- strBuildingnum.Format(" buildingnum = %d",dlg.m_nBuildingNum);
- else
- strBuildingnum.Format(" and buildingnum = %d",dlg.m_nBuildingNum);
- bIsFirst = FALSE;
- }
- else
- strBuildingnum = "";
- //判断单元号是否输入了条件
- if( dlg.m_nCellNum != 0 )
- {
- if( bIsFirst == TRUE )
- strCellnum.Format(" cellnum = %d",dlg.m_nCellNum);
- else
- strCellnum.Format(" and cellnum = %d",dlg.m_nCellNum);
- bIsFirst = FALSE;
- }
- //判断房间号是否输入了条件
- if( dlg.m_nRoomNum != 0 )
- {
- if( bIsFirst == TRUE )
- strRoomnum.Format(" roomnum = %d",dlg.m_nRoomNum);
- else
- strRoomnum.Format(" and roomnum = %d",dlg.m_nRoomNum);
- bIsFirst = FALSE;
- }
- //判断房主是否输入了条件
- if( dlg.m_strHousemaster != "" )
- {
- if( bIsFirst == TRUE )
- strHousemaster = " housemaster = '" + dlg.m_strHousemaster + "'";
- else
- strHousemaster = " and housemaster = '" + dlg.m_strHousemaster + "'";
- bIsFirst = FALSE;
- }
- //判断家庭电话是否输入了条件
- if(dlg.m_strHomeTel != "")
- {
- if( bIsFirst == TRUE )
- strHomeTel = " housetel = '" + dlg.m_strHomeTel + "'";
- else
- strHomeTel = " and housetel = '" + dlg.m_strHomeTel + "'";
- bIsFirst = FALSE;
- }
- //判断单位是否输入了条件
- if(dlg.m_strOffice != "")
- {
- if( bIsFirst == TRUE )
- strOffice = " office = '" + dlg.m_strOffice + "'";
- else
- strOffice = " and office = '" + dlg.m_strOffice + "'";
- bIsFirst = FALSE;
- }
- //判断单位电话是否输入了条件
- if(dlg.m_strOfficeTel != "")
- {
- if( bIsFirst == TRUE )
- strOfficeTel = " officetel = '" + dlg.m_strOfficeTel + "'";
- else
- strOfficeTel = " and officetel = '" + dlg.m_strOfficeTel + "'";
- bIsFirst = FALSE;
- }
- //判断寻呼机是否输入了条件
- if(dlg.m_strBeeppager != "")
- {
- if( bIsFirst == TRUE )
- strBeeppager = " beeppager = '" + dlg.m_strBeeppager + "'";
- else
- strBeeppager = " and beeppager = '" + dlg.m_strBeeppager + "'";
- bIsFirst = FALSE;
- }
- //判断手机是否输入了条件
- if(dlg.m_strMobile != "")
- {
- if( bIsFirst == TRUE )
- strMobile = " mobile = '" + dlg.m_strMobile + "'";
- else
- strMobile = " and mobile = '" + dlg.m_strMobile + "'";
- bIsFirst = FALSE;
- }
- //判断email是否输入了条件
- if(dlg.m_strEmail != "")
- {
- if( bIsFirst == TRUE )
- strEmail = " email = '" + dlg.m_strEmail + "'";
- else
- strEmail = " and email = '" + dlg.m_strEmail + "'";
- bIsFirst = FALSE;
- }
- //生成完整的查询条件
- if( bIsFirst == TRUE ) //没有输入任何条件
- strSql = "select * from house";
- else
- strSql = "select * from house where" + strSectionname + strBuildingnum +
- strCellnum + strRoomnum + strHousemaster + strHomeTel + strOffice +
- strOfficeTel + strBeeppager + strMobile + strEmail;
- //切换到CUsersListView,根据查询条件显示住户
- SwitchToView(USERSVIEW);
- m_pUsersView->ShowUsers(strSql);
- }
- }