Bethesda Car Rental: Cars Records |
|
Cars are at the center of the rental transactions of our company. A car is the main reason a customer comes to the business. In our application, we will provide all the necessary information related to a car such as its make, model, year, picture, and whether it is available. Because we know that sometimes when renting or choosing a car, a customer may want to know the options available on a particular car, we will also list these basic pieces of information. Finally, we will mark a car as available or not. This will allow the clerk processing an order to know whether the customer can rent the car or not. We will create two forms related to cars. One form will be used to enter a new car when the company acquires one. On the other hand, when interviewing a customer, if the clerk wants to see a list of the company cars, we will create a form that can help with this, allowing the clerk to navigate among cars for a review. |
Practical Learning: Processing Cars |
|
#pragma once using namespace System; [Serializable] __sealed public __gc class CCar { public: String *TagNumber; String *Make; String *Model; int Year; String *Category; int HasK7Player; int HasCDPlayer; int HasDVDPlayer; String *PictureName; int IsAvailable; public: CCar(void); CCar(String *tag, String *mk, String *mdl, int Year, String *cat, int k7, int cd, int dvd, String *pct, int avl); ~CCar(void); }; |
#include "StdAfx.h" #include ".\car.h" #using <mscorlib.dll> CCar::CCar(void) { TagNumber = S"000-000"; Make = S"Make"; Model = S"Model"; Year = 1960; Category = S"Small"; HasK7Player = 0; HasCDPlayer = 0; HasDVDPlayer = 0; PictureName = ""; IsAvailable = 0; } CCar::CCar(String *tag, String *mk, String *mdl, int yr, String *cat, int k7, int cd, int dvd, String *pct, int avl) { TagNumber = tag; Make = mk; Model = mdl; Year = yr; Category = cat; HasK7Player = k7; HasCDPlayer = cd; HasDVDPlayer = dvd; PictureName = pct; IsAvailable = avl; } CCar::~CCar(void) { } |
#pragma once #using <System.Runtime.Serialization.Formatters.Soap.dll> #include "Car.h" using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::IO; using namespace System::Runtime::Serialization::Formatters::Soap; namespace BCR2 { |
private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container * components; ArrayList *lstCars; |
System::Void NewCar_Load(System::Object * sender, System::EventArgs * e) { lstCars = new ArrayList; String *strFilename = S"Cars.bcr"; SoapFormatter *bcrSoap = new SoapFormatter(); if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstCars = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); } else { FileStream *bcrStream = new FileStream(strFilename, FileMode::OpenOrCreate, FileAccess::Write, FileShare::Write); bcrSoap->Serialize(bcrStream, lstCars); bcrStream->Close(); } // Locate the director that contains the current application DirectoryInfo* di = new DirectoryInfo(S".\\"); // Get a reference to each file in that directory FileInfo* fiArr[] = di->GetFiles(); // Display the names of the graphics files for(int i = 0; i < fiArr->Count; i++) { if( fiArr[i]->Extension->Equals(S".gif") || fiArr[i]->Extension->Equals(S".jpeg") || fiArr[i]->Extension->Equals(S".jpg") || fiArr[i]->Extension->Equals(S".bmp") || fiArr[i]->Extension->Equals(S".png") ) cboPictures->Items->Add(fiArr[i]->Name); } cboPictures->Text = S"none.gif"; } |
System::Void cboPictures_SelectedIndexChanged(System::Object * sender, System::EventArgs * e) { this->pctCar->Image = Image::FromFile(cboPictures->Text); } |
System::Void btnAddCar_Click(System::Object * sender, System::EventArgs * e) { CCar *car = new CCar; car->TagNumber = this->txtTagNumber->Text; car->Make = this->txtMake->Text; car->Model = this->txtModel->Text; car->Year = this->txtYear->Text->ToInt32(0); car->Category = this->cboCategory->Text; if( this->chkK7Player->Checked == true ) car->HasK7Player = 1; else car->HasK7Player = 0; if( this->chkCDPlayer->Checked == true ) car->HasCDPlayer = 1; else car->HasCDPlayer = 0; if( this->chkDVDPlayer->Checked == true ) car->HasDVDPlayer = 1; else car->HasDVDPlayer = 0; car->PictureName = cboPictures->Text; if( this->chkAvailable->Checked == true ) car->IsAvailable = 1; else car->IsAvailable = 0; lstCars->Add(car); String *strFilename = S"Cars.bcr"; SoapFormatter *bcrSoap = new SoapFormatter(); FileStream *bcrStream = new FileStream(strFilename, FileMode::OpenOrCreate, FileAccess::Write, FileShare::Write); bcrSoap->Serialize(bcrStream, lstCars); bcrStream->Close(); this->txtTagNumber->Text = S""; this->txtMake->Text = S""; this->txtModel->Text = S""; this->txtYear->Text = S"1960"; this->cboCategory->SelectedIndex = 0; this->chkK7Player->Checked = false; this->chkCDPlayer->Checked = false; this->chkDVDPlayer->Checked = false; cboPictures->Text = S"none.gif"; this->chkAvailable->Checked = false; this->pctCar->Image = Image::FromFile(S"none.gif"); this->txtTagNumber->Focus(); } |
System::Void btnNewCar_Click(System::Object * sender, System::EventArgs * e) { NewCar *dlgCar = new NewCar; dlgCar->ShowDialog(); } |
|
#pragma once #include "Car.h" #using <System.Runtime.Serialization.Formatters.Soap.dll> using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::IO; using namespace System::Runtime::Serialization::Formatters::Soap; |
private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container* components; ArrayList *lstCars; int CurrentPosition; |
System::Void Cars_Load(System::Object * sender, System::EventArgs * e) { lstCars = new ArrayList(); CurrentPosition = 0; String *strFilename = S"Cars.bcr"; SoapFormatter *bcrSoap = new SoapFormatter(); if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstCars = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); this->btnFirst_Click(sender, e); } } void ShowCarInformation(CCar *car) { this->txtTagNumber->Text = car->TagNumber; this->txtMake->Text = car->Make; this->txtModel->Text = car->Model; this->txtYear->Text = car->Year.ToString(); this->txtCategory->Text = car->Category; if( car->HasK7Player == 1 ) this->chkK7Player->Checked = true; else this->chkK7Player->Checked = false; if( car->HasCDPlayer == 1 ) this->chkCDPlayer->Checked = true; else this->chkCDPlayer->Checked = false; if( car->HasDVDPlayer == 1 ) this->chkDVDPlayer->Checked = true; else this->chkDVDPlayer->Checked = false; String *strPictureName = car->PictureName; try { this->pctCar->Image = Image::FromFile(car->PictureName); } catch(OutOfMemoryException *) { this->pctCar->Image = Image::FromFile(S"none.gif"); } if( car->IsAvailable == 1 ) this->chkAvailable->Checked = true; else this->chkAvailable->Checked = false; } |
System::Void btnFirst_Click(System::Object * sender, System::EventArgs * e) { if( lstCars->Count == 0 ) return; CurrentPosition = 0; CCar *car = new CCar(); car = dynamic_cast<CCar *>(this->lstCars->Item[CurrentPosition]); ShowCarInformation(car); } |
private: System::Void btnPrevious_Click(System::Object * sender, System::EventArgs * e) { if( lstCars->Count == 0 ) return; if( CurrentPosition == 0 ) return; CurrentPosition--; CCar *car = new CCar(); car = dynamic_cast<CCar *>(lstCars->Item[CurrentPosition]); ShowCarInformation(car); } |
private: System::Void btnNext_Click(System::Object * sender, System::EventArgs * e) { if( lstCars->Count == 0 ) return; if( CurrentPosition == lstCars->Count - 1 ) return; else { CurrentPosition++; CCar *car = new CCar(); car = dynamic_cast<CCar *>(lstCars->Item[CurrentPosition]); ShowCarInformation(car); } } |
private: System::Void btnLast_Click(System::Object * sender, System::EventArgs * e) { if( lstCars->Count == 0 ) return; CurrentPosition = lstCars->Count - 1; CCar *car = new CCar(); car = dynamic_cast<CCar *>(this->lstCars->Item[CurrentPosition]); ShowCarInformation(car); } |
private: System::Void btnClose_Click(System::Object * sender, System::EventArgs * e) { Close(); } |
System::Void btnCarsReview_Click(System::Object * sender, System::EventArgs * e) { Cars *frmCars = new Cars; frmCars->Show(); } |
|
||
Previous | Copyright © 2005-2016, FunctionX | Next |
|