home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
VISBUILD
/
OASEARCH
/
SKILLB.CPV
< prev
next >
Wrap
Text File
|
1995-05-13
|
5KB
|
145 lines
//****************************************************************************
// OASkillBase Class - C++ Code File (skillb.cpv) *
// *
// COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
// *
// DISCLAIMER OF WARRANTIES: *
// The following [enclosed] code is sample code created by IBM *
// Corporation. This sample code is not part of any standard IBM product *
// and is provided to you solely for the purpose of assisting you in the *
// development of your applications. The code is provided "AS IS", *
// without warranty of any kind. IBM shall not be liable for any damages *
// arising out of your use of the sample code, even if they have been *
// advised of the possibility of such damages. *
//****************************************************************************
//NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
//
// Get skills from database and populate a skill list
OASkillBase & OASkillBase::getSkills(const IString & aSkillName, IVSequence<OASkill*>* aList)
{
IProfile *p = new IProfile("skill.ini");
// Check for this skill name in the database
if (!p->containsApplication(aSkillName))
{
throw IException("A record was not found for this skill description.");
delete p;
return *this;
}
// Otherwise, empty the skill list
if (!(aList->isEmpty()))
aList->removeAll();
// Instantiate new skills and set them
unsigned long numRecs = p->numberOfKeys(aSkillName);
OASkill* tempSkill;
IString IDkey, yearkey;
int i;
for (i=1; i <= (numRecs/2); i++)
{
tempSkill = new OASkill;
tempSkill->setSkillName(aSkillName);
IDkey = "ID" + IString(i);
yearkey = "year" + IString(i);
if (p->containsKeyName(yearkey, aSkillName))
tempSkill->setYearsExp(p->elementWithKey(yearkey, aSkillName));
if (p->containsKeyName(IDkey, aSkillName))
tempSkill->setContractorID(p->elementWithKey(IDkey, aSkillName));
tempSkill->setKey(IString(i));
// Add skill to skill list
aList->addAsLast(tempSkill);
}
delete p;
return *this;
}
// Add skill to database
OASkillBase & OASkillBase::putSkill(OASkill* aSkill)
{
// Check for contractor ID
if (aSkill->contractorID().length()==0) {
throw IException("The contractor's identifier is missing. Enter the contractor's name on the Contact page and select Save.");
return *this;
}
// Check for skill description
if (aSkill->skillName().length()==0) {
throw IException("The skill description is missing. Enter it and try again.");
return *this;
}
// Check for years of experience
if (aSkill->yearsExp().length()==0) {
throw IException("The number of years of experience is missing. Enter it and try again.");
return *this;
}
IProfile *p = new IProfile("skill.ini");
IString IDkey, yearkey;
// If skill is not in the database at all, set the key index this way
if (!p->containsApplication(aSkill->skillName()))
aSkill->setKey("1");
else {
// Check to see if this record already exists for this contractor and set the key
unsigned long numRecs = p->numberOfKeys(aSkill->skillName());
IString tempID;
int flag = 0;
int i;
for (i=1; i <= (numRecs/2) ; i++) {
IDkey = "ID" + IString(i);
tempID = p->elementWithKey(IDkey, aSkill->skillName());
if (tempID == aSkill->contractorID()) {
aSkill->setKey(IString(i));
flag = 1; // Set flag to indicate record was found
i = (numRecs/2) + 1; // Terminate loop immediately
}
}
// If this is a new entry for an existing skill, set the key index this way
if (flag == 0)
aSkill->setKey(IString(1 + (numRecs/2)));
}
// Construct the database keys
IDkey = "ID" + aSkill->key();
yearkey = "year" + aSkill->key();
// Add the skill (or replace existing skill records) in database
p->addOrReplaceElementWithKey(IDkey, aSkill->contractorID(), aSkill->skillName());
p->addOrReplaceElementWithKey(yearkey, aSkill->yearsExp(), aSkill->skillName());
delete p;
return *this;
}