indexdlg.cpp

来自「VC开发环境下」· C++ 代码 · 共 218 行

CPP
218
字号
#include "..\project1\wizindexdlg.h"
#include "..\project1\wizindexdlg.h"
#include "..\project1\wizindexdlg.h"
#include "..\project1\wizindexdlg.h"
#include "..\project1\wizindexdlg.h"
#include "..\project1\wizindexdlg.h"
// IndexDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IndexEditor.h"
#include "IndexDlg.h"
#include ".\indexdlg.h"

#include "IndexList.h"


// CIndexDlg dialog

IMPLEMENT_DYNAMIC(CIndexDlg, CDialog)
CIndexDlg::CIndexDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIndexDlg::IDD, pParent)
	, m_strName(_T(""))
	, m_strDescription(_T(""))
	, m_strCreateDate(_T(""))
	, m_pIndexList(NULL)
{
}

CIndexDlg::~CIndexDlg()
{
}

void CIndexDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_CREATE_DATE_TEXT, m_staticCreateDateText);
	DDX_Text(pDX, IDC_INDEX_NAME, m_strName);
	DDX_Text(pDX, IDC_INDEX_DES, m_strDescription);
	DDV_MaxChars(pDX, m_strName, 256);
	DDX_Text(pDX, IDC_STATIC_CREATE_DATE, m_strCreateDate);
	DDV_MaxChars(pDX, m_strCreateDate, 256);
}


BEGIN_MESSAGE_MAP(CIndexDlg, CDialog)
END_MESSAGE_MAP()
// CIndexDlg message handlers

//Show indexsystem property or add a new index
BOOL CIndexDlg::ShowDialog(IGHIndexs *pIndexSystem, BOOL bIsProperty/* =FALSE */)
{
	assert(pIndexSystem);
	
	IGHIndexsPtr cpIndexs=pIndexSystem;
	if (bIsProperty)  //Show IndexSystem property
	{
		//Initialize
		CComBSTR bstrName;
		cpIndexs->get_Name(&bstrName);
		m_strName=bstrName;

		CComBSTR bstrDes;
		cpIndexs->get_Description(&bstrDes);
		m_strDescription=bstrDes;

		DATE         createDate;
		cpIndexs->get_CreatedDate(&createDate);

		COleDateTime oleCreateDate(createDate);		
		m_strCreateDate=oleCreateDate.Format(_T("%Y-%m-%d %A %H:%M:%S"));

		m_iState=1;

		// Show dialog
		if (DoModal()==IDOK)
		{
			CComBSTR bstrGetName(m_strName);
			cpIndexs->put_Name(bstrGetName);

			CComBSTR bstrGetDes(m_strDescription);
			cpIndexs->put_Description(bstrGetDes);

			return TRUE;
		}
		else
			return FALSE;
	
	}
	else  //Add Index
	{
		m_strName=_T("");
		m_strDescription=_T("");
		m_strCreateDate=_T("");
		m_iState=2;
		
		//Show Dialog
		if (DoModal()==IDOK)
		{
			IGHIndexPtr cpIndex;
			if(S_OK!=cpIndex.CreateInstance(CLSID_GHIndex))
				return FALSE;
			
			CComBSTR bstrGetName(m_strName);
			cpIndex->put_Name(bstrGetName);

			CComBSTR bstrGetDes(m_strDescription);
			cpIndex->put_Description(bstrGetDes);
			
			cpIndexs->Add(cpIndex);

			return TRUE;
		}
		return FALSE;
	}	
}

//Show index property
BOOL CIndexDlg::ShowDialog(IGHIndex *pIndex)
{
	assert(pIndex);
	IGHIndexPtr cpIndex=pIndex;

	//Initialize
	CComBSTR bstrName;
	cpIndex->get_Name(&bstrName);
	m_strName=bstrName;

	CComBSTR bstrDes;
	cpIndex->get_Description(&bstrDes);
	m_strDescription=bstrDes;
	
	m_strCreateDate=_T("");

	m_iState=3;

	// Show dialog
	if (DoModal()==IDOK)
	{
		CComBSTR bstrGetName(m_strName);
		cpIndex->put_Name(bstrGetName);

		CComBSTR bstrGetDes(m_strDescription);
		cpIndex->put_Description(bstrGetDes);

		return TRUE;
	}

	return FALSE;
}

void CIndexDlg::Initial(CWnd* pParent)
{
	assert(pParent);
	assert(pParent->IsKindOf(RUNTIME_CLASS(CIndexList)));

	m_pIndexList=pParent;
}

void CIndexDlg::OnOK()
{
	if (!UpdateData(TRUE))
	{
		TRACE(traceAppMsg, 0, "UpdateData failed during dialog termination.\n");
		// the UpdateData routine will set focus to correct item
		return;
	}
	
	if (m_iState==2)  //Add a new Index,the index name can't equally exist index's name
	{
		if (m_strName.IsEmpty())
		{
			AfxMessageBox(IDS_INDEX_ERROR_CANNOT_EMPTY,MB_OK|MB_ICONWARNING);
			return;
		}

		assert(m_pIndexList);
		CIndexList *pList=(CIndexList*)m_pIndexList;
		if(pList->IsExist(m_strName))
		{
			AfxMessageBox(IDS_INDEX_ERROR_CANNOT_REPEAT,MB_OK|MB_ICONWARNING);
			return;
		}
	}

	EndDialog(IDOK);
	//CDialog::OnOK();
}

BOOL CIndexDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	CString strCaption;
	switch(m_iState)
	{
	case 1:  // Initialize IndexSystem Property Dialog
		strCaption.LoadString(IDS_INDEX_DLG_CAPTION_PROPERTY);
		m_staticCreateDateText.ShowWindow(SW_SHOW);
		break;
	case 2: // Initialize Add Index's Dialog		
		strCaption.LoadString(IDS_INDEX_DLG_CAPTION_ADD);
		m_staticCreateDateText.ShowWindow(SW_HIDE);
		break;
	case 3:  //Initialize Index Property Dialog
		strCaption.LoadString(IDS_INDEX_DLG_CAPTION_PROPERTY);
		m_staticCreateDateText.ShowWindow(SW_HIDE);
		break;
	default:
		ASSERT(FALSE);
	}
	
	SetWindowText(strCaption);
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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