College Park Auto-Shop |
|
Introduction |
Most of the time, when you are asked to create an application that would be used to manage a business such as a car repair shop, you would think of a database. Such an application can also be created using regular programming. For example, you can easily and safely use the features of file processing or file handling to create and manage the application. File processing allows you to create values and store them to a medium to be able to retrieve them when needed. As other topics on this site indicate, the Microsoft Foundation Class library provides an impressive support for file processing. We are going to use the Document/View features of the MFC to create an application that can be used to process customer repair orders for a car repair business. |
Based on experience we have had to a car repair shop or from calling a friend to fix our car, there are things we should keep in mind when preparing the application. Because we are working for a business, we need some information about the customer and the car to repair. We also need to describe what is wrong with the car. After getting the information about the customer, we can start repairing the car. Most of the times, when a car gets repaired, there are parts that the technician buys. These parts are charged to the customers and included in the bill. Of course, the customer should know what parts were used to fix the car. For this reason, we will make sure that our application specifies this by creating an area for the technician to enter them. Besides the parts, a customer may also need to know what specific jobs were performed on the car. Therefore, we will create an area where the customer can list the jobs performed. At this time, we can start creating the application. |
Practical Learning: Introducing the Application |
|
Identifier | Type | Value Variable |
IDC_CUSTOMERNAME | CString | m_CustomerName |
IDC_CUSTOMERADDRESS | CString | m_CustomerAddress |
IDC_CUSTOMERCITY | CString | m_CustomerCity |
IDC_CUSTOMERSTATE | CString | m_CustomerState |
IDC_CUSTOMERZIPCODE | CString | m_CustomerZIPCode |
IDC_CARYEAR | CString | m_CarYear |
IDC_MAKE | CString | m_Make |
IDC_MODEL | CString | m_Model |
IDC_PROBLEMDESCRIPTION | CString | m_ProblemDescription |
IDC_PART1NAME | CString | m_Part1Name |
IDC_PART1UNITPRICE | CString | m_Part1UnitPrice |
IDC_PART1QUANTITY | CString | m_Part1Quantity |
IDC_PART1SUBTOTAL | CString | m_Part1SubTotal |
IDC_PART2NAME | CString | m_Part2Name |
IDC_PART2UNITPRICE | CString | m_Part2UnitPrice |
IDC_PART2QUANTITY | CString | m_Part2Quantity |
IDC_PART2SUBTOTAL | CString | m_Part2SubTotal |
IDC_PART3NAME | CString | m_Part3Name |
IDC_PART3UNITPRICE | CString | m_Part3UnitPrice |
IDC_PART3QUANTITY | CString | m_Part3Quantity |
IDC_PART3SUBTOTAL | CString | m_Part3SubTotal |
IDC_PART4NAME | CString | m_Part4Name |
IDC_PART4UNITPRICE | CString | m_Part4UnitPrice |
IDC_PART4QUANTITY | CString | m_Part4Quantity |
IDC_PART4SUBTOTAL | CString | m_Part4SubTotal |
IDC_PART5NAME | CString | m_Part5Name |
IDC_PART5UNITPRICE | CString | m_Part5UnitPrice |
IDC_PART5QUANTITY | CString | m_Part5Quantity |
IDC_PART5SUBTOTAL | CString | m_Part5SubTotal |
IDC_JOB1DESCRIPTION | CString | m_Job1Description |
IDC_JOB1PRICE | CString | m_Job1Price |
IDC_JOB2DESCRIPTION | CString | m_Job2Description |
IDC_JOB2PRICE | CString | m_Job2Price |
IDC_JOB3DESCRIPTION | CString | m_Job3Description |
IDC_JOB3PRICE | CString | m_Job3Price |
IDC_JOB4DESCRIPTION | CString | m_Job4Description |
IDC_JOB4PRICE | CString | m_Job4Price |
IDC_JOB5DESCRIPTION | CString | m_Job5Description |
IDC_JOB5PRICE | CString | m_Job5Price |
IDC_REPAIRDATE | CString | m_RepairDate |
IDC_TIMEREADY | CString | m_TimeReady |
IDC_TOTALPARTS | CString | m_TotalParts |
IDC_TOTALLABOR | CString | m_TotalLabor |
IDC_TAXRATE | CString | m_TaxRate |
IDC_TAXAMOUNT | CString | m_TaxAmount |
IDC_REPAIRTOTAL | CString | m_RepairTotal |
IDC_NOTES | CString | m_Notes |
, m_TotalParts(_T("0.00")) , m_TotalLabor(_T("0.00")) , m_TaxRate(_T("7.75")) , m_TaxAmount(_T("0.00")) , m_RepairTotal(_T("0.00")) , m_Notes(_T("")) |
void CCPAS2View::CalculateRepairTotal(void) { UpdateData(); double Part1UnitPrice, Part2UnitPrice, Part3UnitPrice, Part4UnitPrice, Part5UnitPrice; int Part1Quantity, Part2Quantity, Part3Quantity, Part4Quantity, Part5Quantity; double Part1SubTotal, Part2SubTotal, Part3SubTotal, Part4SubTotal, Part5SubTotal; double Job1Price, Job2Price, Job3Price, Job4Price, Job5Price; double TotalParts, TotalLabor, TaxRate, TaxAmount, RepairTotal; Part1UnitPrice = atof(this->m_Part1UnitPrice); Part1Quantity = atoi(this->m_Part1Quantity); Part1SubTotal = Part1UnitPrice * Part1Quantity; m_Part1SubTotal.Format("$%.2f", Part1SubTotal); Part2UnitPrice = atof(this->m_Part2UnitPrice); Part2Quantity = atoi(this->m_Part2Quantity); Part2SubTotal = Part2UnitPrice * Part2Quantity; m_Part2SubTotal.Format("$%.2f", Part2SubTotal); Part3UnitPrice = atof(this->m_Part3UnitPrice); Part3Quantity = atoi(this->m_Part3Quantity); Part3SubTotal = Part3UnitPrice * Part3Quantity; m_Part3SubTotal.Format("$%.2f", Part3SubTotal); Part4UnitPrice = atof(this->m_Part4UnitPrice); Part4Quantity = atoi(this->m_Part4Quantity); Part4SubTotal = Part4UnitPrice * Part4Quantity; m_Part4SubTotal.Format("$%.2f", Part4SubTotal); Part5UnitPrice = atof(this->m_Part5UnitPrice); Part5Quantity = atoi(this->m_Part5Quantity); Part5SubTotal = Part5UnitPrice * Part5Quantity; m_Part5SubTotal.Format("$%.2f", Part5SubTotal); Job1Price = atof(this->m_Job1Price); Job2Price = atof(this->m_Job2Price); Job3Price = atof(this->m_Job3Price); Job4Price = atof(this->m_Job4Price); Job5Price = atof(this->m_Job5Price); TotalParts = Part1SubTotal + Part2SubTotal + Part3SubTotal + Part4SubTotal + Part5SubTotal; m_TotalParts.Format("$%.2f", TotalParts); TotalLabor = Job1Price + Job2Price + Job3Price + Job4Price + Job5Price; m_TotalLabor.Format("$%.2f", TotalLabor); TaxRate = atof(this->m_TaxRate) / 100; TaxAmount = (TotalParts + TotalLabor) * TaxRate; RepairTotal = TotalParts + TotalLabor + TaxAmount; m_TaxAmount.Format("$%.2f", TaxAmount); m_RepairTotal.Format("$%.2f", RepairTotal); UpdateData(FALSE); } |
void CCPAS2View::OnEnKillfocusPart1quantity() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusPart2quantity() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusPart3quantity() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusPart4quantity() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusPart5quantity() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusJob1price() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusJob2price() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusJob3price() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusJob4price() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusJob5price() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
void CCPAS2View::OnEnKillfocusTaxrate() { // TODO: Add your control notification handler code here CalculateRepairTotal(); } |
// CPAS2Doc.h : interface of the CCPAS2Doc class // #pragma once class CCPAS2Doc : public CDocument { protected: // create from serialization only CCPAS2Doc(); DECLARE_DYNCREATE(CCPAS2Doc) // Attributes public: CString CustomerName; CString CustomerAddress; CString CustomerCity; CString CustomerState; CString CustomerZIPCode; CString CarYear; CString Make; CString Model; CString ProblemDescription; CString Part1Name; CString Part1UnitPrice; CString Part1Quantity; CString Part1SubTotal; CString Part2Name; CString Part2UnitPrice; CString Part2Quantity; CString Part2SubTotal; CString Part3Name; CString Part3UnitPrice; CString Part3Quantity; CString Part3SubTotal; CString Part4Name; CString Part4UnitPrice; CString Part4Quantity; CString Part4SubTotal; CString Part5Name; CString Part5UnitPrice; CString Part5Quantity; CString Part5SubTotal; CString Job1Description; CString Job1Price; CString Job2Description; CString Job2Price; CString Job3Description; CString Job3Price; CString Job4Description; CString Job4Price; CString Job5Description; CString Job5Price; CString RepairDate; CString TotalParts; CString TotalLabor; CString TaxRate; CString TaxAmount; CString RepairTotal; CString Notes; // Operations public: // Overrides public: virtual BOOL OnNewDocument(); virtual void Serialize(CArchive& ar); // Implementation public: virtual ~CCPAS2Doc(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: DECLARE_MESSAGE_MAP() }; |
// CCPAS2Doc serialization void CCPAS2Doc::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar << CustomerName << CustomerAddress << CustomerCity << CustomerState << CustomerZIPCode << CarYear << Make << Model << ProblemDescription << Part1Name << Part1UnitPrice << Part1Quantity << Part1SubTotal << Part2Name << Part2UnitPrice << Part2Quantity << Part2SubTotal << Part3Name << Part3UnitPrice << Part3Quantity << Part3SubTotal << Part4Name << Part4UnitPrice << Part4Quantity << Part4SubTotal << Part5Name << Part5UnitPrice << Part5Quantity << Part5SubTotal << Job1Description << Job1Price << Job2Description << Job2Price << Job3Description << Job3Price << Job4Description << Job4Price << Job5Description << Job5Price << RepairDate << TotalParts << TotalLabor << TaxRate << TaxAmount << RepairTotal << Notes; } else { ar >> CustomerName >> CustomerAddress >> CustomerCity >> CustomerState >> CustomerZIPCode >> CarYear >> Make >> Model >> ProblemDescription >> Part1Name >> Part1UnitPrice >> Part1Quantity >> Part1SubTotal >> Part2Name >> Part2UnitPrice >> Part2Quantity >> Part2SubTotal >> Part3Name >> Part3UnitPrice >> Part3Quantity >> Part3SubTotal >> Part4Name >> Part4UnitPrice >> Part4Quantity >> Part4SubTotal >> Part5Name >> Part5UnitPrice >> Part5Quantity >> Part5SubTotal >> Job1Description >> Job1Price >> Job2Description >> Job2Price >> Job3Description >> Job3Price >> Job4Description >> Job4Price >> Job5Description >> Job5Price >> RepairDate >> TotalParts >> TotalLabor >> TaxRate >> TaxAmount >> RepairTotal >> Notes; } } |
void CCPAS2View::OnFileSave() { // TODO: Add your command handler code here this->UpdateData(); CCPAS2Doc *pDoc = GetDocument(); pDoc->CustomerName = this->m_CustomerName; pDoc->CustomerAddress = this->m_CustomerAddress; pDoc->CustomerCity = this->m_CustomerCity; pDoc->CustomerState = this->m_CustomerState; pDoc->CustomerZIPCode = this->m_CustomerZIPCode; pDoc->CarYear = this->m_CarYear;; pDoc->Make = this->m_Make; pDoc->Model = this->m_Model; pDoc->ProblemDescription = this->m_ProblemDescription; pDoc->Part1Name = this->m_Part1Name; pDoc->Part1UnitPrice = this->m_Part1UnitPrice; pDoc->Part1Quantity = this->m_Part1Quantity; pDoc->Part1SubTotal = this->m_Part1SubTotal; pDoc->Part2Name = this->m_Part2Name; pDoc->Part2UnitPrice = this->m_Part2UnitPrice; pDoc->Part2Quantity = this->m_Part2Quantity; pDoc->Part2SubTotal = this->m_Part2SubTotal; pDoc->Part3Name = this->m_Part3Name; pDoc->Part3UnitPrice = this->m_Part3UnitPrice; pDoc->Part3Quantity = this->m_Part3Quantity; pDoc->Part3SubTotal = this->m_Part3SubTotal; pDoc->Part4Name = this->m_Part4Name; pDoc->Part4UnitPrice = this->m_Part4UnitPrice; pDoc->Part4Quantity = this->m_Part4UnitPrice; pDoc->Part4SubTotal = this->m_Part4SubTotal; pDoc->Part5Name = this->m_Part5Name; pDoc->Part5UnitPrice = this->m_Part5UnitPrice; pDoc->Part5Quantity = this->m_Part5Quantity; pDoc->Part5SubTotal = this->m_Part5SubTotal; pDoc->Job1Description = this->m_Job1Description; pDoc->Job1Price = this->m_Job1Price; pDoc->Job2Description = this->m_Job2Description; pDoc->Job2Price = this->m_Job2Price; pDoc->Job3Description = this->m_Job3Description; pDoc->Job3Price = this->m_Job3Price; pDoc->Job4Description = this->m_Job4Description; pDoc->Job4Price = this->m_Job4Price; pDoc->Job5Description = this->m_Job5Description; pDoc->Job5Price = this->m_Job5Price; pDoc->RepairDate = this->m_RepairDate; pDoc->TotalParts = this->m_TotalParts; pDoc->TotalLabor = this->m_TotalLabor; pDoc->TaxRate = this->m_TaxRate; pDoc->TaxAmount = this->m_TaxAmount; pDoc->RepairTotal = this->m_RepairTotal; pDoc->Notes = this->m_Notes; CFile fleCPAS; char strFilter[] = { "Car Repair Files (*.cps)|*.cps|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||" }; CFileDialog FileDlg(FALSE, ".cps", NULL, 0, strFilter); if( FileDlg.DoModal() == IDOK ) { fleCPAS.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite); CArchive ar(&fleCPAS, CArchive::store); pDoc->Serialize(ar); ar.Close(); } else return; fleCPAS.Close(); } |
void CCPAS2View::OnFileOpen() { // TODO: Add your command handler code here this->UpdateData(); CCPAS2Doc *pDoc = GetDocument(); CFile fleCPAS; char strFilter[] = { "Car Repair Files (*.cps)|*.cps|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||" }; CFileDialog FileDlg(FALSE, ".cps", NULL, 0, strFilter); if( FileDlg.DoModal() == IDOK ) { if( fleCPAS.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE ) return; CArchive ar(&fleCPAS, CArchive::load); pDoc->Serialize(ar); this->m_CustomerName = pDoc->CustomerName; this->m_CustomerAddress = pDoc->CustomerAddress; this->m_CustomerCity = pDoc->CustomerCity; this->m_CustomerState = pDoc->CustomerState; this->m_CustomerZIPCode = pDoc->CustomerZIPCode; this->m_CarYear = pDoc->CarYear; this->m_Make = pDoc->Make; this->m_Model = pDoc->Model; this->m_ProblemDescription = pDoc->ProblemDescription; this->m_Part1Name = pDoc->Part1Name; this->m_Part1UnitPrice = pDoc->Part1UnitPrice; this->m_Part1Quantity = pDoc->Part1Quantity; this->m_Part1SubTotal = pDoc->Part1SubTotal; this->m_Part2Name = pDoc->Part2Name; this->m_Part2UnitPrice = pDoc->Part2UnitPrice; this->m_Part2Quantity = pDoc->Part2Quantity; this->m_Part2SubTotal = pDoc->Part2SubTotal; this->m_Part3Name = pDoc->Part3Name; this->m_Part3UnitPrice = pDoc->Part3UnitPrice; this->m_Part3Quantity = pDoc->Part3Quantity; this->m_Part3SubTotal = pDoc->Part3SubTotal; this->m_Part4Name = pDoc->Part4Name; this->m_Part4UnitPrice = pDoc->Part4UnitPrice; this->m_Part4UnitPrice = pDoc->Part4Quantity; this->m_Part4SubTotal = pDoc->Part4SubTotal; this->m_Part5Name = pDoc->Part5Name; this->m_Part5UnitPrice = pDoc->Part5UnitPrice; this->m_Part5Quantity = pDoc->Part5Quantity; this->m_Part5SubTotal = pDoc->Part5SubTotal; this->m_Job1Description = pDoc->Job1Description; this->m_Job1Price = pDoc->Job1Price; this->m_Job2Description = pDoc->Job2Description; this->m_Job2Price = pDoc->Job2Price; this->m_Job3Description = pDoc->Job3Description; this->m_Job3Price = pDoc->Job3Price; this->m_Job4Description = pDoc->Job4Description; this->m_Job4Price = pDoc->Job4Price; this->m_Job5Description = pDoc->Job5Description; this->m_Job5Price = pDoc->Job5Price; this->m_RepairDate = pDoc->RepairDate; this->m_TotalParts = pDoc->TotalParts; this->m_TotalLabor = pDoc->TotalLabor; this->m_TaxRate = pDoc->TaxRate; this->m_TaxAmount = pDoc->TaxAmount; this->m_RepairTotal = pDoc->RepairTotal; this->m_Notes = pDoc->Notes; ar.Close(); } else return; fleCPAS.Close(); UpdateData(FALSE); } |
// MainFrm.cpp : implementation of the CMainFrame class // . . . ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction . . . int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; . . . this->SetWindowText("College Park Auto-Shop - Repair Orders"); this->CenterWindow(); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; cs.style &= ~FWS_ADDTOTITLE; return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics . . . |
|
Copyright © 2005 FunctionX, Inc. |
|