#pragma once
#using <System.Runtime.Serialization.Formatters.Soap.dll>
#include "NewCustomer.h"
#include "Customer.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
{
. . .
public __gc class Customers : public System::Windows::Forms::Form
{
. . .
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;
ArrayList *lstCustomers;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
. . .
}
void ShowCustomers(void)
{
SoapFormatter *bcrSoap = new SoapFormatter();
String *strFilename = S"Customers.bcr";
if( File::Exists(strFilename) )
{
FileStream *bcrStream = new FileStream(strFilename, FileMode::Open,
FileAccess::Read, FileShare::Read);
ArrayList *lstCust =
dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream));
bcrStream->Close();
CCustomer* cust;
lvwCustomers->Items->Clear();
for(int i = 0; i < lstCust->Count; i++)
{
cust = dynamic_cast<CCustomer *>(lstCust->Item[i]);
ListViewItem *lviCustomer = new ListViewItem(cust->DrvLicNbr);
lviCustomer->Font = new
Drawing::Font("Georgia", 8, FontStyle::Bold);
if( i % 2 == 0 )
{
lviCustomer->BackColor = Color::Blue;
lviCustomer->ForeColor = Color::White;
}
else
{
lviCustomer->BackColor = Color::LightBlue;
lviCustomer->ForeColor = Color::Blue;
}
lviCustomer->SubItems->Add(cust->FullName);
lviCustomer->SubItems->Add(cust->Address);
lviCustomer->SubItems->Add(cust->City);
lviCustomer->SubItems->Add(cust->State);
lviCustomer->SubItems->Add(cust->ZIPCode);
lviCustomer->SubItems->Add(cust->Country);
lvwCustomers->Items->Add(lviCustomer);
}
}
}
private: System::Void Customers_Load(System::Object * sender, System::EventArgs * e)
{
lstCustomers = new ArrayList;
SoapFormatter *bcrSoap = new SoapFormatter();
String *strFilename = S"Customers.bcr";
if( File::Exists(strFilename) )
{
FileStream *bcrStream = new FileStream(strFilename, FileMode::Open,
FileAccess::Read, FileShare::Read);
lstCustomers = dynamic_cast<ArrayList *>(bcrSoap->Deserialize(bcrStream));
bcrStream->Close();
}
ShowCustomers();
}
private: System::Void btnClose_Click(System::Object * sender, System::EventArgs * e)
{
Close();
}
private: System::Void btnNewCustomer_Click(System::Object * sender, System::EventArgs * e)
{
NewCustomer *dlgCust = new NewCustomer;
if( dlgCust->ShowDialog() == DialogResult::OK )
{
String *strFilename = S"Customers.bcr";
CCustomer *cust = new CCustomer;
cust->DrvLicNbr = dlgCust->txtDrvLicNbr->Text;
cust->FullName = dlgCust->txtFullName->Text;
cust->Address = dlgCust->txtAddress->Text;
cust->City = dlgCust->txtCity->Text;
cust->State = dlgCust->txtState->Text;
cust->ZIPCode = dlgCust->txtZIPCode->Text;
cust->Country = dlgCust->txtCountry->Text;
lstCustomers->Add(cust);
FileStream *bcrStream = new FileStream(strFilename,
FileMode::OpenOrCreate,
FileAccess::Write,
FileShare::Write);
SoapFormatter *bcrSoap = new SoapFormatter();
bcrSoap->Serialize(bcrStream, lstCustomers);
bcrStream->Close();
ShowCustomers();
}
}
};
}
|