Bethesda Car Rental: Rental Orders |
|
To main purpose of a car rental company is to rent car. This is done by receiving orders from a customer and processing such an order. To proceed, a clerk would use a form to enter the customer and the car information. In our application, we will also make sure that name of the clerk who processed an order is specified. Other than than, we will enter as much information as possible to assist the user. |
Practical Learning: Creating a Serializable Class |
(Name) | Text | TextAlign | Width |
colCategory | Category | 90 | |
colDaily | Daily | Right | |
colWeekly | Weekly | Right | |
colMonthly | Monthly | Right | |
colWeekend | Weekend | Right |
ListViewItem | ListViewSubItem | ListViewSubItem | ListViewSubItem | ListViewSubItem |
Text | Text | Text | Text | |
Economy | 32.95 | 29.75 | 22.95 | 19.95 |
Compact | 39.95 | 34.75 | 29.95 | 24.95 |
Standard | 45.95 | 39.75 | 35.95 | 32.95 |
Full Size | 49.95 | 42.75 | 38.95 | 35.95 |
Mini Van | 55.95 | 50.75 | 45.95 | 42.95 |
SUV | 55.95 | 50.75 | 45.95 | 42.95 |
Truck | 42.75 | 38.75 | 35.95 | 32.95 |
Van | 69.95 | 62.75 | 55.95 | 52.95 |
#pragma once using namespace System; [Serializable] __sealed __gc class CRentalOrder { public: int ReceiptNumber; String *ProcessedBy; String *CarSelected; String *Make; String *Model; int Year; String *CarCondition; String *CustDrvLicNbr; String *CustName; String *CustAddress; String *CustCity; String *CustState; String *CustZIPCode; String *CustCountry; String *TankLevel; long Mileage; DateTime StartDate; DateTime EndDate; int Days; double RateApplied; double SubTotal; double TaxRate; double TaxAmount; double OrderTotal; public: CRentalOrder(void); ~CRentalOrder(void); }; |
|
#pragma once #using <System.Runtime.Serialization.Formatters.Soap.dll> #include "Car.h" #include "Employee.h" #include "Customer.h" #include "RentalRates.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 *lstRentalOrders; |
System::Void RentalOrders_Load(System::Object * sender, System::EventArgs * e) { lstRentalOrders = new ArrayList; ArrayList *lstEmployees = new ArrayList; SoapFormatter *bcrSoap = new SoapFormatter(); String *strFilename = S"Employees.bcr"; if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstEmployees = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); Employee *empl = new Employee; String *firstName, *lastName, *title; cboEmployees->Items->Clear(); for(int i = 0; i < lstEmployees->Count; i++) { empl = dynamic_cast<Employee *>(lstEmployees->Item[i]); firstName = empl->FirstName; lastName = empl->LastName; title = empl->Title; cboEmployees->Items->Add(String::Concat(lastName, S", ", firstName, S" - ", title)); } } strFilename = S"Cars.bcr"; ArrayList *lstCars = new ArrayList; if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstCars = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); CCar *car = new CCar; cboCars->Items->Clear(); for(int i = 0; i < lstCars->Count; i++) { car = dynamic_cast<CCar *>(lstCars->Item[i]); cboCars->Items->Add(car->TagNumber); } } strFilename = S"Customers.bcr"; ArrayList *lstCustomers = new ArrayList; if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstCustomers = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); CCustomer *cust = new CCustomer; cboCustomers->Items->Clear(); for(int i = 0; i < lstCustomers->Count; i++) { cust = dynamic_cast<CCustomer *>(lstCustomers->Item[i]); cboCustomers->Items->Add(cust->DrvLicNbr); } } } |
System::Void cboCars_SelectedIndexChanged(System::Object * sender, System::EventArgs * e) { String *strFilename = S"Cars.bcr"; ArrayList *lstCars = new ArrayList; CCar *car = new CCar; SoapFormatter *bcrSoap = new SoapFormatter(); FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstCars = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); for(int i = 0; i < lstCars->Count; i++) { car = dynamic_cast<CCar *>(lstCars->Item[i]); if( car->TagNumber->Equals(cboCars->Text) ) { this->txtMake->Text = car->Make; this->txtModel->Text = car->Model; this->txtCarYear->Text = car->Year.ToString(); return; } } } |
System::Void cboCustomers_SelectedIndexChanged(System::Object * sender, System::EventArgs * e) { String *strFilename = S"Customers.bcr"; ArrayList *lstCustomers = new ArrayList; CCustomer *cust = new CCustomer; SoapFormatter *bcrSoap = new SoapFormatter(); FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstCustomers = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); for(int i = 0; i < lstCustomers->Count; i++) { cust = dynamic_cast<CCustomer *>(lstCustomers->Item[i]); if( cust->DrvLicNbr->Equals(cboCustomers->Text) ) { this->txtCustName->Text = cust->FullName; this->txtCustAddress->Text = cust->Address; this->txtCustCity->Text = cust->City; this->txtCustState->Text = cust->State; this->txtCustZIPCode->Text = cust->ZIPCode; this->txtCustCountry->Text = cust->Country; return; } } } |
System::Void btnRateApplied_Click(System::Object * sender, System::EventArgs * e) { RentalRates *frmRates = new RentalRates; frmRates->Show(); } |
System::Void dtpEndDate_ValueChanged(System::Object * sender, System::EventArgs * e) { DateTime dteStart = this->dtpStartDate->Value; DateTime dteEnd = this->dtpEndDate->Value; TimeSpan tme = dteEnd - dteStart; int days = tme.Days; this->txtDays->Text = days.ToString(); } |
System::Void txtRateApplied_Leave(System::Object * sender, System::EventArgs * e) { int days = this->txtDays->Text->ToInt32(0); double rateApplied = this->txtRateApplied->Text->ToDouble(0); double subTotal = days * rateApplied; this->txtSubTotal->Text = subTotal.ToString(S"F"); double taxRate = this->txtTaxRate->Text->ToDouble(0); double taxAmount = subTotal * taxRate / 100; this->txtTaxAmount->Text = taxAmount.ToString(S"F"); double totalOrder = subTotal + taxAmount; this->txtOrderTotal->Text = totalOrder.ToString(S"F"); } |
System::Void btnSave_Click(System::Object * sender, System::EventArgs * e) { static int receiptNumber = 0; ArrayList *lstRentalOrders = new ArrayList; String *strFilename = S"RentalOrders.bcr"; SoapFormatter *bcrSoap = new SoapFormatter(); if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstRentalOrders = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); CRentalOrder *order = __try_cast<CRentalOrder *>(lstRentalOrders->Item[lstRentalOrders->Count-1]); receiptNumber = order->ReceiptNumber; bcrStream->Close(); } else { FileStream *bcrStream = new FileStream(strFilename, FileMode::OpenOrCreate, FileAccess::Write, FileShare::Write); bcrSoap->Serialize(bcrStream, lstRentalOrders); bcrStream->Close(); } CRentalOrder *rntOrder = new CRentalOrder; rntOrder->ReceiptNumber = receiptNumber + 1; rntOrder->ProcessedBy = this->cboEmployees->Text; rntOrder->CarSelected = this->cboCars->Text; rntOrder->Make = this->txtMake->Text; rntOrder->Model = this->txtModel->Text; rntOrder->Year = this->txtCarYear->Text->ToInt32(0); rntOrder->CarCondition = this->cboCarConditions->Text; rntOrder->CustDrvLicNbr = this->cboCustomers->Text; rntOrder->CustName = this->txtCustName->Text; rntOrder->CustAddress = this->txtCustAddress->Text; rntOrder->CustCity = this->txtCustCity->Text; rntOrder->CustState = this->txtCustState->Text; rntOrder->CustZIPCode = this->txtCustZIPCode->Text; rntOrder->CustCountry = this->txtCustCountry->Text; rntOrder->TankLevel = this->cboTankLevels->Text; rntOrder->Mileage = this->txtMileage->Text->ToInt32(0); rntOrder->StartDate = this->dtpStartDate->Value; rntOrder->EndDate = this->dtpEndDate->Value; rntOrder->Days = this->txtDays->Text->ToInt32(0); rntOrder->RateApplied = this->txtRateApplied->Text->ToDouble(0); rntOrder->SubTotal = this->txtSubTotal->Text->ToDouble(0); rntOrder->TaxRate = this->txtTaxRate->Text->ToDouble(0); rntOrder->TaxAmount = this->txtTaxAmount->Text->ToDouble(0); rntOrder->OrderTotal = this->txtOrderTotal->Text->ToDouble(0); lstRentalOrders->Add(rntOrder); FileStream *bcrStream = new FileStream(strFilename, FileMode::OpenOrCreate, FileAccess::Write, FileShare::Write); bcrSoap->Serialize(bcrStream, lstRentalOrders); bcrStream->Close(); this->cboEmployees->Text = S""; this->cboCars->Text = S""; this->txtMake->Text = S""; this->txtModel->Text = S""; this->txtCarYear->Text = S"2000"; this->cboCarConditions->Text = S""; this->cboCustomers->Text = S""; this->txtCustAddress->Text = S""; this->txtCustAddress->Text = S""; this->txtCustCity->Text = S""; this->txtCustState->Text = S"MD"; this->txtCustZIPCode->Text = S""; this->txtCustCountry->Text = S"USA"; this->cboTankLevels->Text = S""; this->txtMileage->Text = S""; this->dtpStartDate->Value = DateTime::Now; this->dtpEndDate->Value = DateTime::Now; this->txtDays->Text = S"0"; this->txtRateApplied->Text = S"24.95"; this->txtSubTotal->Text = S"0.00"; this->txtTaxRate->Text = S"7.75"; this->txtTaxAmount->Text = S"0.00"; this->txtOrderTotal->Text = S"0.00"; this->cboEmployees->Focus(); } |
|
System::Void btnRentalOrders_Click(System::Object * sender, System::EventArgs * e) { RentalOrders *frmOrders = new RentalOrders; frmOrders->Show(); } |
System::Void btnClose_Click(System::Object * sender, System::EventArgs * e) { Close(); } |
System::Void btnOpen_Click(System::Object * sender, System::EventArgs * e) { ArrayList *lstRentalOrders = new ArrayList; String *strFilename = S"RentalOrders.bcr"; SoapFormatter *bcrSoap = new SoapFormatter(); CRentalOrder *order; int receiptNumber = this->txtReceiptNumber->Text->ToInt32(0); if( File::Exists(strFilename) ) { FileStream *bcrStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read); lstRentalOrders = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream)); bcrStream->Close(); for(int i = 0; i < lstRentalOrders->Count; i++) { order = dynamic_cast<CRentalOrder *>(lstRentalOrders->Item[i]); if( order->ReceiptNumber == receiptNumber ) { this->cboEmployees->Text = order->ProcessedBy; this->cboCars->Text = order->CarSelected; this->txtMake->Text = order->Make; this->txtModel->Text = order->Model; this->txtCarYear->Text = order->Year.ToString(); this->cboCarConditions->Text = order->CarCondition; this->cboCustomers->Text = order->CustDrvLicNbr; this->txtCustName->Text = order->CustName; this->txtCustAddress->Text = order->CustAddress; this->txtCustCity->Text = order->CustCity; this->txtCustState->Text = order->CustState; this->txtCustZIPCode->Text = order->CustZIPCode; this->txtCustCountry->Text = order->CustCountry; this->cboTankLevels->Text = order->TankLevel; this->txtMileage->Text = order->Mileage.ToString(); this->dtpStartDate->Value = order->StartDate; this->dtpEndDate->Value = order->EndDate; this->txtDays->Text = order->Days.ToString(); this->txtRateApplied->Text = order->RateApplied.ToString(); this->txtSubTotal->Text = order->SubTotal.ToString(); this->txtTaxRate->Text = order->TaxRate.ToString(); this->txtTaxAmount->Text = order->TaxAmount.ToString(); this->txtOrderTotal->Text = order->OrderTotal.ToString(); } } } else { MessageBox::Show(S"There is no rental order with that receipt number!"); return; } } |
|
||
Previous | Copyright © 2005-2016, FunctionX | |
|