⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 简单实用
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "ADDRESS.h"
#include "afxcview.h"

#include "MainFrm.h"
#include "LeftTreeView.h"
#include "PersonsListView.h"
#include "PersoninfoView.h"
#include "AddPersonDlg.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_ADD, OnAdd)
	ON_COMMAND(ID_QUERY, OnQuery)
	//}}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 toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		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) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	//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(CPersonsListView),CSize(100,100),pContext))
		return FALSE;
	m_pLeftView = (CLeftTreeView*)m_wndSplitter.GetPane(0,0);
	m_pPersonsView = (CPersonsListView*)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 PERSONSVIEW:		//CPersonsListView
		{
			if(!pView->IsKindOf(RUNTIME_CLASS(CPersonsListView)))
			{
				m_wndSplitter.DeleteView(0,1);
				m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CPersonsListView),
					CSize(rcRight.Width(),rcRight.Height()),NULL);
				m_wndSplitter.RecalcLayout();
				m_pPersonsView= (CPersonsListView*)m_wndSplitter.GetPane(0,1);
			}
			break;
		}
	case PERSONINFOVIEW:	//CPersoninfoView
		{
			if(!pView->IsKindOf(RUNTIME_CLASS(CPersoninfoView)))
			{
				m_wndSplitter.DeleteView(0,1);
				m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CPersoninfoView),
					CSize(rcRight.Width(),rcRight.Height()),NULL);
				m_wndSplitter.RecalcLayout();
				m_pPersoninfoView= (CPersoninfoView*)m_wndSplitter.GetPane(0,1);
			}
			break;
		}
	default:
		break;
	}

}

void CMainFrame::OnAdd() 
{
	// TODO: Add your command handler code here
	CAddPersonDlg dlg;
	dlg.DoModal();
	
}

void CMainFrame::OnQuery() 
{
	// TODO: Add your command handler code here
	CQueryDlg dlg;
	if( dlg.DoModal() == IDOK )
	{
		BOOL bIsFirst = TRUE;
		CString strSql,strGroupName ,strName ,
					 strAddress , strHometel , strOffice , strOfficetel ,strMobile ,
					 strEmail ,strQQ;
		//判断分类是否输入了条件
		if( dlg.m_strGroup != "" )
		{
			strGroupName = " groups = '" + dlg.m_strGroup + "'";
			bIsFirst = FALSE;
		}
		else
			strGroupName = "";

		
		//判断姓名是否输入了条件
		if( dlg.m_strName != "" )
		{
			if( bIsFirst == TRUE )
				strName = " name = '" + dlg.m_strName + "'";
			else
				strName = " and name = '" + dlg.m_strName + "'";
			bIsFirst = FALSE;
		}

		//判断地址是否输入了条件
		if(dlg.m_strAddress != "")
		{
			if( bIsFirst == TRUE )
				strAddress = " address = '" + dlg.m_strAddress + "'";
			else
				strAddress = " and address = '" + dlg.m_strAddress + "'";
			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_strMobil != "")
		{
			if( bIsFirst == TRUE )
				strMobile = " mobile = '" + dlg.m_strMobil + "'";
			else
				strMobile = " and mobile = '" + dlg.m_strMobil + "'";
			bIsFirst = FALSE;
		}

		//判断email是否输入了条件
		if(dlg.m_strEmail != "")
		{
			if( bIsFirst == TRUE )
				strEmail = " email = '" + dlg.m_strEmail + "'";
			else
				strEmail = " and email = '" + dlg.m_strEmail + "'";
			bIsFirst = FALSE;
		}

		//判断qq是否输入了条件
		if(dlg.m_strQQ != "")
		{
			if( bIsFirst == TRUE )
				strQQ = " qq = '" + dlg.m_strQQ + "'";
			else
				strQQ = " and qq = '" + dlg.m_strQQ + "'";
			bIsFirst = FALSE;
		}

		//生成完整的查询条件
		if( bIsFirst == TRUE )	//没有输入任何条件
			strSql = "select * from addresslist";
		else
			strSql = "select * from addresslist where" + strGroupName 	+ strName +
					 strAddress + strHometel + strOffice + strOfficetel + strMobile +
					 strEmail + strQQ;

		//切换到CUsersListView,根据查询条件显示住户
		SwitchToView(PERSONSVIEW);
		m_pPersonsView->ShowPersons(strSql);
	}	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -