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

📄 shopinglistdoc.cpp

📁 AppWizard has created this ShopingList application for you. This application not only demonstrates
💻 CPP
字号:
// ShopingListDoc.cpp : implementation of the CShopingListDoc class
//


#include "stdafx.h"
#include "ShopingList.h"

#include "ShopingListDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShopingListDoc

IMPLEMENT_DYNCREATE(CShopingListDoc, CDocument)

BEGIN_MESSAGE_MAP(CShopingListDoc, CDocument)
	//{{AFX_MSG_MAP(CShopingListDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShopingListDoc construction/destruction

CShopingListDoc::CShopingListDoc()
{
	// TODO: add one-time construction code here
	OpenDB();
}

CShopingListDoc::~CShopingListDoc()
{
	CloseDB();
}

BOOL CShopingListDoc::OnNewDocument()
{
	/*if (!CDocument::OnNewDocument())
		return FALSE;

	// ja - open / create the db
	OpenDB();*/

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CShopingListDoc serialization

void CShopingListDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{	
	}
	else
	{	
	}

}

/////////////////////////////////////////////////////////////////////////////
// CShopingListDoc diagnostics

#ifdef _DEBUG
void CShopingListDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CShopingListDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CShopingListDoc commands

BOOL CShopingListDoc::CreateDB()
{
	//ja -  Create database
	CCeDBDatabase m_Mydb;
	CEOID poid;  
	CCeDBProp SortProps[1] = {
		CCeDBProp(CCeDBProp::Type_String, PROP_DESCRIPTION,
		           CCeDBProp::Sort_Ascending | CCeDBProp::Sort_CaseInsensitive)
	};

	if (!(poid = m_Mydb.Create(DB_NAME,DB_IDENT,1,SortProps))) 
		return FALSE;

	// ja - open db
	if (!m_Mydb.Open(poid))
		return FALSE;

	return TRUE;
}

BOOL CShopingListDoc::OpenDB()
{
	if (!CCeDBDatabase::Exists(DB_NAME))
	{
		if (!CreateDB())
			return FALSE;
	}	
	else
	{
		m_Mydb.Open(DB_NAME);
	}

	return TRUE;
}

BOOL CShopingListDoc::AddRecord(CString sDescription, int nQTY, float fStore1, float fStore2, float fStore3, float fStore4)
{
	// ja - convert all floats to strings because we cannot store floats
	WCHAR wcDescription[255], wcStore1[10], wcStore2[10], wcStore3[10], wcStore4[10];
	
	swprintf(wcDescription,_T("%s"),sDescription);
	swprintf(wcStore1,_T("%.2f"),fStore1);
	swprintf(wcStore2,_T("%.2f"),fStore2);
	swprintf(wcStore3,_T("%.2f"),fStore3);
	swprintf(wcStore4,_T("%.2f"),fStore4);

	// Add records
	CCeDBRecord rec;
	CCeDBProp props[6];

	// ja - i cant pass in a cstring here?
	props[0] = CCeDBProp(wcDescription,PROP_DESCRIPTION);
	props[1] = CCeDBProp((USHORT)nQTY,  PROP_QTY);
	props[2] = CCeDBProp(wcStore1, PROP_STORE1);
	props[3] = CCeDBProp(wcStore2,PROP_STORE2);
	props[4] = CCeDBProp(wcStore3,PROP_STORE3);
	props[5] = CCeDBProp(wcStore4,PROP_STORE4);
	rec.AddProps(props,6);
	
	if (!m_Mydb.AddRecord(&rec))
		return FALSE;

	rec.DeleteAllProps();
	
	return TRUE;
}

BOOL CShopingListDoc::CloseDB()
{
	m_Mydb.Close();
	return TRUE;
}

⌨️ 快捷键说明

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