home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
VISBUILD
/
OASEARCH
/
CONTRCTR.CPV
< prev
next >
Wrap
Text File
|
1995-05-17
|
14KB
|
452 lines
//****************************************************************************
// OAContractor Class - C++ Code File (contrctr.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.
//
// Default Part Code Generation begins here...
INotificationId OAContractor::contractorIDId = "OAContractor::contractorID";
INotificationId OAContractor::lastNameId = "OAContractor::lastName";
INotificationId OAContractor::firstNameId = "OAContractor::firstName";
INotificationId OAContractor::middleInitialId = "OAContractor::middleInitial";
INotificationId OAContractor::homeStreetId = "OAContractor::homeStreet";
INotificationId OAContractor::homeCityId = "OAContractor::homeCity";
INotificationId OAContractor::homeStateId = "OAContractor::homeState";
INotificationId OAContractor::homeZipId = "OAContractor::homeZip";
INotificationId OAContractor::phoneNumberId = "OAContractor::phoneNumber";
INotificationId OAContractor::startDateId = "OAContractor::startDate";
INotificationId OAContractor::endDateId = "OAContractor::endDate";
INotificationId OAContractor::activeStatusId = "OAContractor::activeStatus";
INotificationId OAContractor::currentContractId = "OAContractor::currentContract";
IString OAContractor::contractorID() const
{
return iContractorID;
}
OAContractor & OAContractor::setContractorID()
{
IString tempString = iFirstName+iMiddleInitial+iLastName;
if (iContractorID != tempString)
{
iContractorID = tempString;
notifyObservers(INotificationEvent(OAContractor::contractorIDId, *this));
} // endif
return *this;
}
IString OAContractor::lastName() const
{
return iLastName;
}
OAContractor & OAContractor::setLastName(const IString & aLastName)
{
if (iLastName != aLastName)
{
iLastName = aLastName;
notifyObservers(INotificationEvent(OAContractor::lastNameId, *this));
} // endif
return *this;
}
IString OAContractor::firstName() const
{
return iFirstName;
}
OAContractor & OAContractor::setFirstName(const IString & aFirstName)
{
if (iFirstName != aFirstName)
{
iFirstName = aFirstName;
notifyObservers(INotificationEvent(OAContractor::firstNameId, *this));
} // endif
return *this;
}
IString OAContractor::middleInitial() const
{
return iMiddleInitial;
}
OAContractor & OAContractor::setMiddleInitial(const IString & aMiddleInitial)
{
if (iMiddleInitial != aMiddleInitial)
{
iMiddleInitial = aMiddleInitial;
notifyObservers(INotificationEvent(OAContractor::middleInitialId, *this));
} // endif
return *this;
}
IString OAContractor::homeStreet() const
{
return iHomeStreet;
}
OAContractor & OAContractor::setHomeStreet(const IString & aHomeStreet)
{
if (iHomeStreet != aHomeStreet)
{
iHomeStreet = aHomeStreet;
notifyObservers(INotificationEvent(OAContractor::homeStreetId, *this));
} // endif
return *this;
}
IString OAContractor::homeCity() const
{
return iHomeCity;
}
OAContractor & OAContractor::setHomeCity(const IString & aHomeCity)
{
if (iHomeCity != aHomeCity)
{
iHomeCity = aHomeCity;
notifyObservers(INotificationEvent(OAContractor::homeCityId, *this));
} // endif
return *this;
}
IString OAContractor::homeState() const
{
return iHomeState;
}
OAContractor & OAContractor::setHomeState(const IString & aHomeState)
{
if (iHomeState != aHomeState)
{
iHomeState = aHomeState;
notifyObservers(INotificationEvent(OAContractor::homeStateId, *this));
} // endif
return *this;
}
IString OAContractor::homeZip() const
{
return iHomeZip;
}
OAContractor & OAContractor::setHomeZip(const IString & aHomeZip)
{
if (iHomeZip != aHomeZip)
{
iHomeZip = aHomeZip;
notifyObservers(INotificationEvent(OAContractor::homeZipId, *this));
} // endif
return *this;
}
IString OAContractor::phoneNumber() const
{
return iPhoneNumber;
}
OAContractor & OAContractor::setPhoneNumber(const IString & aPhoneNumber)
{
if (iPhoneNumber != aPhoneNumber)
{
iPhoneNumber = aPhoneNumber;
notifyObservers(INotificationEvent(OAContractor::phoneNumberId, *this));
} // endif
return *this;
}
IString OAContractor::startDate() const
{
return iStartDate;
}
OAContractor & OAContractor::setStartDate(const IString & aStartDate)
{
if (iStartDate != aStartDate)
{
iStartDate = aStartDate;
notifyObservers(INotificationEvent(OAContractor::startDateId, *this));
} // endif
return *this;
}
IString OAContractor::endDate() const
{
return iEndDate;
}
OAContractor & OAContractor::setEndDate(const IString & aEndDate)
{
if (iEndDate != aEndDate)
{
iEndDate = aEndDate;
notifyObservers(INotificationEvent(OAContractor::endDateId, *this));
} // endif
return *this;
}
Boolean OAContractor::isActiveStatus() const
{
return iActiveStatus;
}
OAContractor & OAContractor::enableActiveStatus(const Boolean enable)
{
if (iActiveStatus != enable)
{
iActiveStatus = enable;
notifyObservers(INotificationEvent(OAContractor::activeStatusId, *this));
} // endif
return *this;
}
// Start boolean string enabler
OAContractor & OAContractor::enableActiveStatus(const IString & status)
{
Boolean tempBoolean = iActiveStatus;
if (status == "yes") iActiveStatus = true;
if (status == "no") iActiveStatus = false;
if (tempBoolean != iActiveStatus)
{
notifyObservers(INotificationEvent(OAContractor::activeStatusId, *this));
}
return *this;
}
// End boolean string enabler
IString OAContractor::currentContract() const
{
return iCurrentContract;
}
OAContractor & OAContractor::setCurrentContract(const IString & aCurrentContract)
{
if (iCurrentContract != aCurrentContract)
{
iCurrentContract = aCurrentContract;
notifyObservers(INotificationEvent(OAContractor::currentContractId, *this));
} // endif
return *this;
}
// Default Part Code Generation ends here.
OAContractor & OAContractor::getContractor()
{
// Test for missing name information
// Necessary for proper derivation of the contractorID attribute
Boolean tempLast = iLastName.isWhiteSpace() || (iLastName.length()==0);
Boolean tempFirst = iFirstName.isWhiteSpace() || (iFirstName.length()==0);
Boolean tempMiddle = iMiddleInitial.isWhiteSpace() || (iMiddleInitial.length()==0);
if (tempLast || tempFirst || tempMiddle)
{
throw IException("The name you entered is incomplete. Enter first name, middle initial, and last name.");
return *this;
}
// Start data access code
IProfile *p = new IProfile("contrctr.ini");
// Refresh the value of contractor ID
setContractorID();
// Check for this contractor ID in the profile collection
if (!p->containsKeyName("contractorID", iContractorID))
{
throw IException("A record was not found for this contractor.");
delete p;
return *this;
}
// If other data exists for this contractor,
// set the corresponding contractor attributes
if (p->containsKeyName("lastName", iContractorID))
setLastName(p->elementWithKey("lastName", iContractorID));
if (p->containsKeyName("firstName", iContractorID))
setFirstName(p->elementWithKey("firstName", iContractorID));
if (p->containsKeyName("middleInitial", iContractorID))
setMiddleInitial(p->elementWithKey("middleInitial", iContractorID));
if (p->containsKeyName("homeStreet", iContractorID))
setHomeStreet(p->elementWithKey("homeStreet", iContractorID));
if (p->containsKeyName("homeCity", iContractorID))
setHomeCity(p->elementWithKey("homeCity", iContractorID));
if (p->containsKeyName("homeState", iContractorID))
setHomeState(p->elementWithKey("homeState", iContractorID));
if (p->containsKeyName("homeZip", iContractorID))
setHomeZip(p->elementWithKey("homeZip", iContractorID));
if (p->containsKeyName("phoneNumber", iContractorID))
setPhoneNumber(p->elementWithKey("phoneNumber", iContractorID));
if (p->containsKeyName("startDate", iContractorID))
setStartDate(p->elementWithKey("startDate", iContractorID));
if (p->containsKeyName("endDate", iContractorID))
setEndDate(p->elementWithKey("endDate", iContractorID));
if (p->containsKeyName("currentContract", iContractorID))
setCurrentContract(p->elementWithKey("currentContract", iContractorID));
// Call overloaded set member function using string parameter
if (p->containsKeyName("activeStatus", iContractorID))
enableActiveStatus(p->elementWithKey("activeStatus", iContractorID));
delete p;
// End data access code
return *this;
}
OAContractor & OAContractor::putContractor()
{
// Test for missing name information
// Necessary for proper derivation of the contractorID attribute
Boolean tempLast = iLastName.isWhiteSpace() || (iLastName.length()==0);
Boolean tempFirst = iFirstName.isWhiteSpace() || (iFirstName.length()==0);
Boolean tempMiddle = iMiddleInitial.isWhiteSpace() || (iMiddleInitial.length()==0);
if (tempLast || tempFirst || tempMiddle)
{
throw IException("The name you entered is incomplete. Enter first name, middle initial, and last name.");
return *this;
}
// Start data entry code
IProfile *p = new IProfile("contrctr.ini");
// Refresh the value of contractor ID
setContractorID();
p->addOrReplaceElementWithKey("contractorID", contractorID(), iContractorID);
// If other data about this contractor exists, update it in the database
if (lastName)
p->addOrReplaceElementWithKey("lastName", lastName(), iContractorID);
if (firstName)
p->addOrReplaceElementWithKey("firstName", firstName(), iContractorID);
if (middleInitial)
p->addOrReplaceElementWithKey("middleInitial", middleInitial(), iContractorID);
if (homeStreet)
p->addOrReplaceElementWithKey("homeStreet", homeStreet(), iContractorID);
if (homeCity)
p->addOrReplaceElementWithKey("homeCity", homeCity(), iContractorID);
if (homeState)
p->addOrReplaceElementWithKey("homeState", homeState(), iContractorID);
if (homeZip)
p->addOrReplaceElementWithKey("homeZip", homeZip(), iContractorID);
if (phoneNumber)
p->addOrReplaceElementWithKey("phoneNumber", phoneNumber(), iContractorID);
if (startDate)
p->addOrReplaceElementWithKey("startDate", startDate(), iContractorID);
if (endDate)
p->addOrReplaceElementWithKey("endDate", endDate(), iContractorID);
if (currentContract)
p->addOrReplaceElementWithKey("currentContract", currentContract(), iContractorID);
if (isActiveStatus())
{
p->addOrReplaceElementWithKey("activeStatus", "yes", iContractorID);
}
else
{
p->addOrReplaceElementWithKey("activeStatus", "no", iContractorID);
}
delete p;
// End data entry code
return *this;
}
OAContractor & OAContractor::parseName(const IString & aName)
{
// aName is supplied by user in OAQueryContractor
// Test for missing information in newly entered name
if (aName.numWords()!= 3)
{
throw IException("The name you entered is incomplete. Enter first name, middle initial, and last name.");
return *this;
}
// Set name attributes and derive contractorID attribute
setFirstName(aName.word(1));
setMiddleInitial(aName.word(2));
setLastName(aName.word(3));
setContractorID();
// End added code
return *this;
}
OAContractor & OAContractor::refreshID()
{
// Refresh value of contractor ID when multiple contractors
// are entered new from OAContractorView
// Test for missing name information
// Necessary for proper derivation of the contractorID attribute
Boolean tempLast = iLastName.isWhiteSpace() || (iLastName.length()==0);
Boolean tempFirst = iFirstName.isWhiteSpace() || (iFirstName.length()==0);
Boolean tempMiddle = iMiddleInitial.isWhiteSpace() || (iMiddleInitial.length()==0);
if (tempLast || tempFirst || tempMiddle)
{
throw IException("The contractor's name is incomplete. Complete all name fields and try again.");
return *this;
}
setContractorID();
return *this;
}
// Copy constructor
OAContractor::OAContractor(const OAContractor & aContractor)
: IStandardNotifier(aContractor),
iContractorID(aContractor.contractorID()),
iLastName(aContractor.lastName()),
iFirstName(aContractor.firstName()),
iMiddleInitial(aContractor.middleInitial()),
iHomeStreet(aContractor.homeStreet()),
iHomeCity(aContractor.homeCity()),
iHomeState(aContractor.homeState()),
iHomeZip(aContractor.homeZip()),
iPhoneNumber(aContractor.phoneNumber()),
iStartDate(aContractor.startDate()),
iEndDate(aContractor.endDate()),
iActiveStatus(aContractor.isActiveStatus()),
iCurrentContract(aContractor.currentContract())
{
enableNotification();
}