System::Void NewPart_Load(System::Object * sender, System::EventArgs * e)
{
// Fill the Year combo box with years from 1960 to the coming year
for(int i = DateTime::Now.Year+1; i >= 1960; i--)
this->cboYears->Items->Add(i.ToString());
// We will need a reference to the XML document
XmlDocument *docXML = new XmlDocument;
// Open the Cars.xml file
docXML->Load(S"Cars.xml");
// Get a reference to the root node
XmlElement *nodRoot = docXML->DocumentElement;
// Locate each node whose name is Make
XmlNodeList *nodItems = nodRoot->GetElementsByTagName(S"Make");
// Retrieve the value of each Make node and put
// that value in the Make combo box
for(int i = 0; i < nodItems->Count; i++)
this->cboMakes->Items->Add(nodItems->ItemOf[i]->Attributes->ItemOf[S"MakeName"]->InnerText);
// Open the Makes.xml file
docXML->Load(S"PartCategories.xml");
// Get a reference to the root node
nodRoot = docXML->DocumentElement;
// Locate each node whose name is Make
nodItems = nodRoot->GetElementsByTagName(S"PartCategory");
// Retrieve the value of each Make node and put
// that value in the Make combo box
for(int i = 0; i < nodItems->Count; i++)
this->cboPartCategories->Items->Add(nodItems->ItemOf[i]->InnerText);
this->cboPartCategories->Text = S"Miscellaneous";
// We will generate a random number for the item
// To start, we will use the miliseconds as a seed
DateTime tmeNow = DateTime::Now;
int ms = tmeNow.Millisecond;
// Now we can generate a random number between 100000 and 999999
Random *rndNumber = new Random(ms);
// Generate three random characters
Char firstCharacter = static_cast<Char>(rndNumber->Next(65, 90));
Char secondCharacter = static_cast<Char>(rndNumber->Next(65, 90));
Char thirdCharacter = static_cast<Char>(rndNumber->Next(65, 90));
// Generate a random number made of 4 digits
int numberPart = rndNumber->Next(1000, 9999);
// Exclude the digits 1 and 0 because they create confusion
if( firstCharacter == 'I' || firstCharacter == 'O' )
firstCharacter = 'A';
if( secondCharacter == 'I' || secondCharacter == 'O' )
secondCharacter = 'A';
if( thirdCharacter == 'I' || thirdCharacter == 'O' )
thirdCharacter = 'A';
// Generate a random number between 1 and 3
int rndCombination = rndNumber->Next(1, 4);
String *strPartNumber = 0;
// Create a part number using some algorithm
if( rndCombination == 1 )
strPartNumber = String::Concat(firstCharacter.ToString(),
secondCharacter.ToString(),
numberPart.ToString(),
thirdCharacter.ToString());
else if( rndCombination == 2 )
strPartNumber = String::Concat(firstCharacter.ToString(),
numberPart.ToString(),
secondCharacter.ToString(),
thirdCharacter.ToString());
else if( rndCombination == 3 )
strPartNumber = String::Concat(numberPart.ToString(),
firstCharacter.ToString(),
secondCharacter.ToString(),
thirdCharacter.ToString());
else
strPartNumber = rndNumber->Next(100000, 999999).ToString();
// Display the new number in the Part # text box
this->txtPartNumber->Text = strPartNumber;
// Disable the OK button to indicate that the part is not ready
this->btnAddPart->Enabled = false;
}
|