Click here to Skip to main content
15,894,017 members
Articles / Desktop Programming / MFC

Recordsets and invoices

Rate me:
Please Sign up or sign in to vote.
3.96/5 (9 votes)
23 Sep 2005CPOL10 min read 52.8K   808   21  
How to use CRecordset with the Northwind database to create an invoice.
#include "stdafx.h"
#include "Invoice.h"
#include "InvoiceSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInvoiceSet

IMPLEMENT_DYNAMIC(CInvoiceSet, CRecordset)

CInvoiceSet::CInvoiceSet(CDatabase* pdb)
	: CRecordset(pdb)
{
	//{{AFX_FIELD_INIT(CInvoiceSet)
	m_strShipName = _T("");
	m_strShipAddress = _T("");
	m_strShipCity = _T("");
	m_strShipRegion = _T("");
	m_strShipPostalCode = _T("");
	m_strShipCountry = _T("");
	m_strCustomerID = _T("");
	m_strCompanyName = _T("");
	m_strAddress = _T("");
	m_strCity = _T("");
	m_strRegion = _T("");
	m_strPostalCode = _T("");
	m_strCountry = _T("");
	m_strEmployee = _T("");
	m_lOrderID = 0;
	m_dateOrder = CTime();
	m_dateRequired = CTime();
	m_dateShipped = CTime();
    m_strCompanyName2 = _T("");
    m_lProductID = 0;
	m_strProductName = _T("");
	m_dUnitPrice = 0.0;
	m_lQuantity = 0;
	m_dDiscount = 0.0;
	m_dFreight = 0.0;
	m_nFields = 25;
    m_nParams = 1;
	m_lOrderIDParam = 0;
    //}}AFX_FIELD_INIT
	m_nDefaultType = snapshot;
    m_strFilter = _T("Orders.OrderID = ?");
}


CString CInvoiceSet::GetDefaultConnect()
{
	return _T("ODBC;DSN=Northwind");
}

CString CInvoiceSet::GetDefaultSQL()
{
	return _T("SELECT DISTINCTROW Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, ")
           _T("Orders.ShipRegion, Orders.ShipPostalCode, Orders.ShipCountry, ")
           _T("Orders.CustomerID, Customers.CompanyName, Customers.Address, Customers.City, ")
           _T("Customers.Region, Customers.PostalCode, Customers.Country, Employees.LastName, ")
           _T("Orders.OrderID, Orders.OrderDate, Orders.RequiredDate, Orders.ShippedDate, ")
           _T("Shippers.CompanyName, [Order Details].ProductID, Products.ProductName, ")
           _T("[Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, ")
           _T("Orders.Freight FROM Shippers INNER JOIN (Products INNER JOIN ((Employees ")
           _T("INNER JOIN (Customers INNER JOIN Orders ON Customers.CustomerID = ")
           _T("Orders.CustomerID) ON Employees.EmployeeID = Orders.EmployeeID) INNER JOIN ")
           _T("[Order Details] ON Orders.OrderID = [Order Details].OrderID) ON ")
           _T("Products.ProductID = [Order Details].ProductID) ON Shippers.ShipperID = ")
           _T("Orders.ShipVia");
}

void CInvoiceSet::DoFieldExchange(CFieldExchange* pFX)
{
	//{{AFX_FIELD_MAP(CInvoiceSet)
	pFX->SetFieldType(CFieldExchange::outputColumn);
	RFX_Text(pFX, _T("[ShipName]"), m_strShipName);
	RFX_Text(pFX, _T("[ShipAddress]"), m_strShipAddress);
	RFX_Text(pFX, _T("[ShipCity]"), m_strShipCity);
	RFX_Text(pFX, _T("[ShipRegion]"), m_strShipRegion);
	RFX_Text(pFX, _T("[ShipPostalCode]"), m_strShipPostalCode);
	RFX_Text(pFX, _T("[ShipCountry]"), m_strShipCountry);
	RFX_Text(pFX, _T("[CustomerID]"), m_strCustomerID);
    RFX_Text(pFX, _T("[CompanyName]"), m_strCompanyName);
    RFX_Text(pFX, _T("[Address]"), m_strAddress);
    RFX_Text(pFX, _T("[City]"), m_strCity);
    RFX_Text(pFX, _T("[Region]"), m_strRegion);
	RFX_Text(pFX, _T("[PostalCode]"), m_strPostalCode);
	RFX_Text(pFX, _T("[Country]"), m_strCountry);
	RFX_Text(pFX, _T("[LastName]"), m_strEmployee);
	RFX_Long(pFX, _T("[OrderID]"), m_lOrderID);
	RFX_Date(pFX, _T("[OrderDate]"), m_dateOrder);
	RFX_Date(pFX, _T("[RequiredDate]"), m_dateRequired);
	RFX_Date(pFX, _T("[ShippedDate]"), m_dateShipped);
    RFX_Text(pFX, _T("[Shippers].[CompanyName]"), m_strCompanyName2);
	RFX_Long(pFX, _T("[ProductID]"), m_lProductID);
	RFX_Text(pFX, _T("[ProductName]"), m_strProductName);
	RFX_Double(pFX, _T("[UnitPrice]"), m_dUnitPrice);
	RFX_Long(pFX, _T("[Quantity]"), m_lQuantity);
	RFX_Double(pFX, _T("[Discount]"), m_dDiscount);
	RFX_Double(pFX, _T("[Freight]"), m_dFreight);
	pFX->SetFieldType(CFieldExchange::param);
	RFX_Long(pFX, _T("[OrderID]"), m_lOrderIDParam);
	//}}AFX_FIELD_MAP
}

/////////////////////////////////////////////////////////////////////////////
// CInvoiceSet diagnostics

#ifdef _DEBUG
void CInvoiceSet::AssertValid() const
{
	CRecordset::AssertValid();
}

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

//====================================================================

bool CInvoiceSet::IsOnFirstRecord( void ) const
{
	ASSERT_VALID(this);

	CRecordsetStatus status;
	GetStatus(status);
	
    return (0 == status.m_lCurrentRecord);
}

//====================================================================
 
bool CInvoiceSet::IsOnLastRecord( void ) const
{	
    ASSERT_VALID(this);

	CRecordsetStatus status;
	GetStatus(status);
	
    if (! status.m_bRecordCountFinal)
		return (false);

    return (status.m_lCurrentRecord + 1 == GetRecordCount());
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Pinnacle Business Systems
United States United States

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

HTTP 404 - File not found
Internet Information Services

Comments and Discussions