home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * .FILE: contract.cpv *
- * *
- * .DESCRIPTION: Implementation of additional member functions for the class *
- * OAContract *
- * *
- * .CLASSES: *
- * *
- * .COPYRIGHT: *
- * Licensed Material - Program-Property of IBM *
- * (C) Copyright IBM Corp. 1992, 1995, 1996 - All Rights Reserved *
- * *
- * .DISCLAIMER: *
- * 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 OAContract::accountNumId = "OAContract::accountNum";
- INotificationId OAContract::companyNameId = "OAContract::companyName";
- INotificationId OAContract::projectMgrId = "OAContract::projectMgr";
- INotificationId OAContract::deptNameId = "OAContract::deptName";
- INotificationId OAContract::positionTitleId = "OAContract::positionTitle";
- INotificationId OAContract::startDateId = "OAContract::startDate";
- INotificationId OAContract::endDateId = "OAContract::endDate";
- INotificationId OAContract::currContractorId = "OAContract::currContractor";
-
- // Added after OS2 GA
- INotificationId OAContract::qryFoundId = "OAContract::qryFound";
-
- IString OAContract::accountNum() const
- {
- return iAccountNum;
- }
-
- OAContract & OAContract::setAccountNum(const IString & aAccountNum)
- {
- if (iAccountNum != aAccountNum)
- {
- iAccountNum = aAccountNum;
- notifyObservers(INotificationEvent(OAContract::accountNumId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::companyName() const
- {
- return iCompanyName;
- }
-
- OAContract & OAContract::setCompanyName(const IString & aCompanyName)
- {
- if (iCompanyName != aCompanyName)
- {
- iCompanyName = aCompanyName;
- notifyObservers(INotificationEvent(OAContract::companyNameId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::projectMgr() const
- {
- return iProjectMgr;
- }
-
- OAContract & OAContract::setProjectMgr(const IString & aProjectMgr)
- {
- if (iProjectMgr != aProjectMgr)
- {
- iProjectMgr = aProjectMgr;
- notifyObservers(INotificationEvent(OAContract::projectMgrId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::deptName() const
- {
- return iDeptName;
- }
-
- OAContract & OAContract::setDeptName(const IString & aDeptName)
- {
- if (iDeptName != aDeptName)
- {
- iDeptName = aDeptName;
- notifyObservers(INotificationEvent(OAContract::deptNameId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::positionTitle() const
- {
- return iPositionTitle;
- }
-
- OAContract & OAContract::setPositionTitle(const IString & aPositionTitle)
- {
- if (iPositionTitle != aPositionTitle)
- {
- iPositionTitle = aPositionTitle;
- notifyObservers(INotificationEvent(OAContract::positionTitleId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::startDate() const
- {
- return iStartDate;
- }
-
- OAContract & OAContract::setStartDate(const IString & aStartDate)
- {
- if (iStartDate != aStartDate)
- {
- iStartDate = aStartDate;
- notifyObservers(INotificationEvent(OAContract::startDateId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::endDate() const
- {
- return iEndDate;
- }
-
- OAContract & OAContract::setEndDate(const IString & aEndDate)
- {
- if (iEndDate != aEndDate)
- {
- iEndDate = aEndDate;
- notifyObservers(INotificationEvent(OAContract::endDateId, *this));
- } // endif
- return *this;
- }
-
- IString OAContract::currContractor() const
- {
- return iCurrContractor;
- }
-
- OAContract & OAContract::setCurrContractor(const IString & aCurrContractor)
- {
- if (iCurrContractor != aCurrContractor)
- {
- iCurrContractor = aCurrContractor;
- notifyObservers(INotificationEvent(OAContract::currContractorId, *this));
- } // endif
- return *this;
- }
-
- // Default Part Code Generation ends here.
-
- OAContract & OAContract::getContract(const IString & anAccountNum)
- {
-
- // Start data access code
-
- IProfile *p = new IProfile("contract.ini");
-
- // Needed for Windows implementation
-
- primeData(*p);
-
- // Check for this account number in the profile collection
-
- if (!p->containsKeyName("accountNum", anAccountNum))
- {
- delete p;
- throw IException("A record was not found for this contract.");
- return *this;
- }
-
- // If other data exists for this contract,
- // set the corresponding contract attributes
-
- setAccountNum(anAccountNum);
-
- if (p->containsKeyName("companyName", anAccountNum))
- setCompanyName(p->elementWithKey("companyName", anAccountNum));
- if (p->containsKeyName("projectMgr", anAccountNum))
- setProjectMgr(p->elementWithKey("projectMgr", anAccountNum));
- if (p->containsKeyName("deptName", anAccountNum))
- setDeptName(p->elementWithKey("deptName", anAccountNum));
- if (p->containsKeyName("positionTitle", anAccountNum))
- setPositionTitle(p->elementWithKey("positionTitle", anAccountNum));
- if (p->containsKeyName("startDate", anAccountNum))
- setStartDate(p->elementWithKey("startDate", anAccountNum));
- if (p->containsKeyName("endDate", anAccountNum))
- setEndDate(p->elementWithKey("endDate", anAccountNum));
- if (p->containsKeyName("currContractor", anAccountNum))
- setCurrContractor(p->elementWithKey("currContractor", anAccountNum));
-
- delete p;
-
- // End data access code
-
- // Execute event to trigger instantiation of OAContractView
- notifyObservers(INotificationEvent(qryFoundId, *this));
-
- return *this;
- }
-
- OAContract & OAContract::putContract(const IString & anAccountNum)
- {
-
- // Start data entry code
-
- IProfile *p = new IProfile("contract.ini");
-
- // Needed for Windows implementation
-
- primeData(*p);
-
- p->addOrReplaceElementWithKey("accountNum", accountNum(), anAccountNum);
-
- // If other data about this contract exists, update it in the database
-
- if (iCompanyName.length()>0)
- p->addOrReplaceElementWithKey("companyName", companyName(), anAccountNum);
- if (iProjectMgr.length()>0)
- p->addOrReplaceElementWithKey("projectMgr", projectMgr(), anAccountNum);
- if (iDeptName.length()>0)
- p->addOrReplaceElementWithKey("deptName", deptName(), anAccountNum);
- if (iPositionTitle.length()>0)
- p->addOrReplaceElementWithKey("positionTitle", positionTitle(), anAccountNum);
- if (iStartDate.length()>0)
- p->addOrReplaceElementWithKey("startDate", startDate(), anAccountNum);
- if (iEndDate.length()>0)
- p->addOrReplaceElementWithKey("endDate", endDate(), anAccountNum);
- if (iCurrContractor.length()>0)
- p->addOrReplaceElementWithKey("currContractor", currContractor(), anAccountNum);
-
- delete p;
-
- // End data entry code
-
- return *this;
- }
-
- // Copy constructor
-
- OAContract::OAContract(const OAContract & aContract)
- : IStandardNotifier(aContract),
- iAccountNum(aContract.accountNum()),
- iCompanyName(aContract.companyName()),
- iProjectMgr(aContract.projectMgr()),
- iDeptName(aContract.deptName()),
- iPositionTitle(aContract.positionTitle()),
- iStartDate(aContract.startDate()),
- iEndDate(aContract.endDate()),
- iCurrContractor(aContract.currContractor())
- {
- enableNotification();
- }
-
- // Prime profile instance in Windows with data
-
- OAContract & OAContract::primeData(IProfile & aDatabase) {
-
- IString tempKey = "123456";
-
- // Windows does not read from .ini files.
- // It uses a central registry,
- // so load initial contract data into the registry.
-
- aDatabase.addOrReplaceElementWithKey("accountNum","123456",tempKey);
- aDatabase.addOrReplaceElementWithKey("companyName","Acme Rubber Bands",tempKey);
- aDatabase.addOrReplaceElementWithKey("projectMgr","Fred W. Brown",tempKey);
- aDatabase.addOrReplaceElementWithKey("deptName","Stretch Technology",tempKey);
- aDatabase.addOrReplaceElementWithKey("positionTitle","Senior Stretch Scientist",tempKey);
- aDatabase.addOrReplaceElementWithKey("startDate","12/01/95",tempKey);
- aDatabase.addOrReplaceElementWithKey("endDate","12/31/96",tempKey);
- aDatabase.addOrReplaceElementWithKey("currContractor","Susan G. Carpenter",tempKey);
-
- return *this;
- }