Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Руководство_по_C++_CLI.doc
Скачиваний:
1
Добавлен:
01.07.2025
Размер:
8.1 Mб
Скачать

If (File.Exists(strFilename))

{

FileStream fsCustomers = File.Open(strFilename,

FileMode::Open,

FileAccess::Read);

BinaryFormatter bfCustomers = gcnew BinaryFormatter();

Customers = (Hashtable)bfCustomers.Deserialize(fsCustomers);

fsCustomers->Close();

for each(DictionaryEntry de in Customers)

{

if ((string)de.Key == strPhoneNumber)

{

found = true;

strPhoneNumber = (string)de.Key;

strCustomerName = (string)de.Value;

}

}

if (found == true)

{

Console::WriteLine(L"\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

Console::WriteLine(L"-/- Georgetown Cleaning Services -/-");

Console::WriteLine(L"------------------------------------");

Console::WriteLine(L"Customer Name: {0}", strCustomerName);

Console::WriteLine(L"Phone Number: {0}", strPhoneNumber);

Console::WriteLine(L"------------------------------------\n");

}

else // If the customer information was not found in a file

{

Console::WriteLine(L"This is the first cleaning order "

"of this customer");

FileStream fsCustomer = gcnew FileStream(strFilename,

FileMode::Create,

FileAccess::Write);

BinaryFormatter bfCustomer = gcnew BinaryFormatter();

Console::Write(L"Enter Customer Name: ");

strCustomerName = Console::ReadLine();

Customers->Add(strPhoneNumber, strCustomerName);

bfCustomer->Serialize(fsCustomer, Customers);

fsCustomer->Close();

}

}

else

Console::WriteLine(L"The Customers list was not found");

}

public void ProcessOrder()

{

// These two pieces of information are used for money change

double AmountTended;

double Difference;

Console::WriteLine(L"-/- Georgetown Cleaning Services -/-");

this->IdentifyCustomer();

try

{

Console::Write(L"Enter the order date(mm/dd/yyyy): ");

depot->OrderDate = DateTime::Parse(Console::ReadLine());

}

catch (FormatException)

{

Console::WriteLine(L"The value you entered is not a valid date");

}

try

{

Console::Write(L"Enter the order time(hh:mm AM/PM): ");

depot->OrderTime = DateTime::Parse(Console::ReadLine());

}

catch

{

Console::WriteLine(L"The value you entered is not a valid time");

}

// Request the quantity of each category of items

try

{

Console::Write(L"Number of Shirts: ");

depot->NumberOfShirts =

unsigned int::Parse(Console::ReadLine());

if (depot->NumberOfShirts < unsigned int.MinValue)

throw new OverflowException(L"Negative value not "

"allowed for shirts");

}

catch (FormatException)

{

Console::WriteLine(L"The value you typed for the number of "

"shirts is not a valid number");

}

try

{

Console::Write(L"Number of Pants: ");

depot->NumberOfPants =

unsigned int::Parse(Console::ReadLine());

}

catch (FormatException)

{

Console::WriteLine(L"The value you typed for the number of "

"pair or pants is not a valid number");

}

try

{

Console::Write(L"Number of Other Items: ");

depot->NumberOtherItems = unsigned int::Parse(Console::ReadLine());

}

catch (FormatException)

{

Console::WriteLine(L"The value you typed for the number of "

"other items is not a valid number");

}

// Perform the necessary calculations

depot->SubTotalShirts =

depot->NumberOfShirts * depot->PriceOneShirt;

depot->SubTotalPants =

depot->NumberOfPants * depot->PriceAPairOfPants;

depot->SubTotalOtherItems =

depot->NumberOtherItems * depot->PriceOtherItems;

// Calculate the "temporary" total of the order

depot->TotalOrder = depot->SubTotalShirts +

depot->SubTotalPants +

depot->SubTotalOtherItems;

// Calculate the tax amount using a constant rate

depot->TaxAmount = depot->TotalOrder * depot->TaxRate;

// Add the tax amount to the total order

depot->SalesTotal = depot->TotalOrder + depot->TaxAmount;

// Communicate the total to the user...

Console::WriteLine(L"\nThe Total order is: {0:C}", depot->SalesTotal);

// and request money for the order

try

{

Console::Write(L"Amount Tended? ");

AmountTended = double::Parse(Console::ReadLine());

}

catch (FormatException)

{

Console::WriteLine(L"You were asked to enter an "

"amount of money but...");

}

// Calculate the difference owed to the customer

// or that the customer still owes to the store

Difference = AmountTended - depot->SalesTotal;

this->PreviewReceipt();

this->SaveCleaningOrder();

}

public void PreviewReceipt()

{

Console::WriteLine();

// Display the receipt

Console::WriteLine(L"====================================");

Console::WriteLine(L"-/- Georgetown Cleaning Services -/-");

Console::WriteLine(L"====================================");

Console::WriteLine(L"Customer: {0}", this->strCustomerName);

Console::WriteLine(L"Home Phone: {0}", this->strPhoneNumber);

Console::WriteLine(L"Order Date: {0:D}", depot->OrderDate);

Console::WriteLine(L"Order Time: {0:t}", depot->OrderTime);

Console::WriteLine(L"------------------------------------");

Console::WriteLine(L"Item Type Qty Unit/Price Sub-Total");

Console::WriteLine(L"------------------------------------");

Console::WriteLine(L"Shirts {0,3} {1,4} {2,6}",

depot->NumberOfShirts,

depot->PriceOneShirt,

depot->SubTotalShirts);

Console::WriteLine(L"Pants {0,3} {1,4} {2,6}",

depot->NumberOfPants,

depot->PriceAPairOfPants,

depot->SubTotalPants);

Console::WriteLine(L"Other Items {0,3} {1,4} {2,6}",

depot->NumberOtherItems,

depot->PriceOtherItems,

depot->SubTotalOtherItems);

Console::WriteLine(L"------------------------------------");

Console::WriteLine(L"Total Order: {0,6}",

depot->TotalOrder.ToString(L"C"));

Console::WriteLine(L"Tax Rate: {0,6}",

depot->TaxRate.ToString(L"P"));

Console::WriteLine(L"Tax Amount: {0,6}",

depot->TaxAmount.ToString(L"C"));

Console::WriteLine(L"Net Price: {0,6}",

depot->SalesTotal.ToString(L"C"));

Console::WriteLine(L"------------------------------------");

Console::WriteLine(L"Amount Tended: {0,6}",

AmountTended.ToString(L"C"));

Console::WriteLine(L"Difference: {0,6}",

Difference.ToString(L"C"));

Console::WriteLine(L"====================================");

}

public void SaveCleaningOrder()

{

int highReceiptNumber = 0;

FileStream fsCleaningOrders = nullptr;

BinaryFormatter bfCleaningOrders = gcnew BinaryFormatter();

String ^ strFilename =

"C:\Georgetown Cleaning Services\CleaningOrders.gco";