home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / oasearch / contract.cpv next >
Encoding:
Text File  |  1996-02-20  |  9.3 KB  |  284 lines

  1. /******************************************************************************
  2. * .FILE:        contract.cpv                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation of additional member functions for the class   *
  5. *               OAContract                                                    *
  6. *                                                                             *
  7. * .CLASSES:                                                                   *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1995, 1996 - All Rights Reserved           *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. // Default Part Code Generation begins here...
  26. INotificationId OAContract::accountNumId = "OAContract::accountNum";
  27. INotificationId OAContract::companyNameId = "OAContract::companyName";
  28. INotificationId OAContract::projectMgrId = "OAContract::projectMgr";
  29. INotificationId OAContract::deptNameId = "OAContract::deptName";
  30. INotificationId OAContract::positionTitleId = "OAContract::positionTitle";
  31. INotificationId OAContract::startDateId = "OAContract::startDate";
  32. INotificationId OAContract::endDateId = "OAContract::endDate";
  33. INotificationId OAContract::currContractorId = "OAContract::currContractor";
  34.  
  35. // Added after OS2 GA
  36. INotificationId OAContract::qryFoundId = "OAContract::qryFound";
  37.  
  38. IString OAContract::accountNum() const
  39. {
  40.   return iAccountNum;
  41. }
  42.  
  43. OAContract & OAContract::setAccountNum(const IString & aAccountNum)
  44. {
  45.   if (iAccountNum != aAccountNum)
  46.   {
  47.     iAccountNum = aAccountNum;
  48.     notifyObservers(INotificationEvent(OAContract::accountNumId, *this));
  49.   } // endif
  50.   return *this;
  51. }
  52.  
  53. IString OAContract::companyName() const
  54. {
  55.   return iCompanyName;
  56. }
  57.  
  58. OAContract & OAContract::setCompanyName(const IString & aCompanyName)
  59. {
  60.   if (iCompanyName != aCompanyName)
  61.   {
  62.     iCompanyName = aCompanyName;
  63.     notifyObservers(INotificationEvent(OAContract::companyNameId, *this));
  64.   } // endif
  65.   return *this;
  66. }
  67.  
  68. IString OAContract::projectMgr() const
  69. {
  70.   return iProjectMgr;
  71. }
  72.  
  73. OAContract & OAContract::setProjectMgr(const IString & aProjectMgr)
  74. {
  75.   if (iProjectMgr != aProjectMgr)
  76.   {
  77.     iProjectMgr = aProjectMgr;
  78.     notifyObservers(INotificationEvent(OAContract::projectMgrId, *this));
  79.   } // endif
  80.   return *this;
  81. }
  82.  
  83. IString OAContract::deptName() const
  84. {
  85.   return iDeptName;
  86. }
  87.  
  88. OAContract & OAContract::setDeptName(const IString & aDeptName)
  89. {
  90.   if (iDeptName != aDeptName)
  91.   {
  92.     iDeptName = aDeptName;
  93.     notifyObservers(INotificationEvent(OAContract::deptNameId, *this));
  94.   } // endif
  95.   return *this;
  96. }
  97.  
  98. IString OAContract::positionTitle() const
  99. {
  100.   return iPositionTitle;
  101. }
  102.  
  103. OAContract & OAContract::setPositionTitle(const IString & aPositionTitle)
  104. {
  105.   if (iPositionTitle != aPositionTitle)
  106.   {
  107.     iPositionTitle = aPositionTitle;
  108.     notifyObservers(INotificationEvent(OAContract::positionTitleId, *this));
  109.   } // endif
  110.   return *this;
  111. }
  112.  
  113. IString OAContract::startDate() const
  114. {
  115.   return iStartDate;
  116. }
  117.  
  118. OAContract & OAContract::setStartDate(const IString & aStartDate)
  119. {
  120.   if (iStartDate != aStartDate)
  121.   {
  122.     iStartDate = aStartDate;
  123.     notifyObservers(INotificationEvent(OAContract::startDateId, *this));
  124.   } // endif
  125.   return *this;
  126. }
  127.  
  128. IString OAContract::endDate() const
  129. {
  130.   return iEndDate;
  131. }
  132.  
  133. OAContract & OAContract::setEndDate(const IString & aEndDate)
  134. {
  135.   if (iEndDate != aEndDate)
  136.   {
  137.     iEndDate = aEndDate;
  138.     notifyObservers(INotificationEvent(OAContract::endDateId, *this));
  139.   } // endif
  140.   return *this;
  141. }
  142.  
  143. IString OAContract::currContractor() const
  144. {
  145.   return iCurrContractor;
  146. }
  147.  
  148. OAContract & OAContract::setCurrContractor(const IString & aCurrContractor)
  149. {
  150.   if (iCurrContractor != aCurrContractor)
  151.   {
  152.     iCurrContractor = aCurrContractor;
  153.     notifyObservers(INotificationEvent(OAContract::currContractorId, *this));
  154.   } // endif
  155.   return *this;
  156. }
  157.  
  158. // Default Part Code Generation ends here.
  159.  
  160. OAContract & OAContract::getContract(const IString & anAccountNum)
  161. {
  162.  
  163. // Start data access code
  164.  
  165.   IProfile *p = new IProfile("contract.ini");
  166.  
  167. // Needed for Windows implementation
  168.  
  169.    primeData(*p);
  170.  
  171. // Check for this account number in the profile collection
  172.  
  173.   if (!p->containsKeyName("accountNum", anAccountNum))
  174.   {
  175.   delete p;
  176.   throw IException("A record was not found for this contract.");
  177.   return *this;
  178.   }
  179.  
  180. // If other data exists for this contract,
  181. // set the corresponding contract attributes
  182.  
  183.   setAccountNum(anAccountNum);
  184.  
  185.   if (p->containsKeyName("companyName", anAccountNum))
  186.     setCompanyName(p->elementWithKey("companyName", anAccountNum));
  187.   if (p->containsKeyName("projectMgr", anAccountNum))
  188.     setProjectMgr(p->elementWithKey("projectMgr", anAccountNum));
  189.   if (p->containsKeyName("deptName", anAccountNum))
  190.     setDeptName(p->elementWithKey("deptName", anAccountNum));
  191.   if (p->containsKeyName("positionTitle", anAccountNum))
  192.     setPositionTitle(p->elementWithKey("positionTitle", anAccountNum));
  193.   if (p->containsKeyName("startDate", anAccountNum))
  194.     setStartDate(p->elementWithKey("startDate", anAccountNum));
  195.   if (p->containsKeyName("endDate", anAccountNum))
  196.     setEndDate(p->elementWithKey("endDate", anAccountNum));
  197.   if (p->containsKeyName("currContractor", anAccountNum))
  198.     setCurrContractor(p->elementWithKey("currContractor", anAccountNum));
  199.  
  200.   delete p;
  201.  
  202. // End data access code
  203.  
  204. // Execute event to trigger instantiation of OAContractView
  205.   notifyObservers(INotificationEvent(qryFoundId, *this));
  206.  
  207.   return *this;
  208. }
  209.  
  210. OAContract & OAContract::putContract(const IString & anAccountNum)
  211. {
  212.  
  213. // Start data entry code
  214.  
  215.   IProfile *p = new IProfile("contract.ini");
  216.  
  217. // Needed for Windows implementation
  218.  
  219.    primeData(*p);
  220.  
  221.   p->addOrReplaceElementWithKey("accountNum", accountNum(), anAccountNum);
  222.  
  223. // If other data about this contract exists, update it in the database
  224.  
  225.   if (iCompanyName.length()>0)
  226.     p->addOrReplaceElementWithKey("companyName", companyName(), anAccountNum);
  227.   if (iProjectMgr.length()>0)
  228.     p->addOrReplaceElementWithKey("projectMgr", projectMgr(), anAccountNum);
  229.   if (iDeptName.length()>0)
  230.     p->addOrReplaceElementWithKey("deptName", deptName(), anAccountNum);
  231.   if (iPositionTitle.length()>0)
  232.     p->addOrReplaceElementWithKey("positionTitle", positionTitle(), anAccountNum);
  233.   if (iStartDate.length()>0)
  234.     p->addOrReplaceElementWithKey("startDate", startDate(), anAccountNum);
  235.   if (iEndDate.length()>0)
  236.     p->addOrReplaceElementWithKey("endDate", endDate(), anAccountNum);
  237.   if (iCurrContractor.length()>0)
  238.     p->addOrReplaceElementWithKey("currContractor", currContractor(), anAccountNum);
  239.  
  240.   delete p;
  241.  
  242. // End data entry code
  243.  
  244.   return *this;
  245. }
  246.  
  247. // Copy constructor
  248.  
  249. OAContract::OAContract(const OAContract & aContract)
  250.   : IStandardNotifier(aContract),
  251.   iAccountNum(aContract.accountNum()),
  252.   iCompanyName(aContract.companyName()),
  253.   iProjectMgr(aContract.projectMgr()),
  254.   iDeptName(aContract.deptName()),
  255.   iPositionTitle(aContract.positionTitle()),
  256.   iStartDate(aContract.startDate()),
  257.   iEndDate(aContract.endDate()),
  258.   iCurrContractor(aContract.currContractor())
  259.   {
  260.     enableNotification();
  261.   }
  262.  
  263. // Prime profile instance in Windows with data
  264.  
  265. OAContract & OAContract::primeData(IProfile & aDatabase) {
  266.  
  267.   IString tempKey = "123456";
  268.  
  269. // Windows does not read from .ini files.
  270. // It uses a central registry,
  271. // so load initial contract data into the registry.
  272.  
  273.   aDatabase.addOrReplaceElementWithKey("accountNum","123456",tempKey);
  274.   aDatabase.addOrReplaceElementWithKey("companyName","Acme Rubber Bands",tempKey);
  275.   aDatabase.addOrReplaceElementWithKey("projectMgr","Fred W. Brown",tempKey);
  276.   aDatabase.addOrReplaceElementWithKey("deptName","Stretch Technology",tempKey);
  277.   aDatabase.addOrReplaceElementWithKey("positionTitle","Senior Stretch Scientist",tempKey);
  278.   aDatabase.addOrReplaceElementWithKey("startDate","12/01/95",tempKey);
  279.   aDatabase.addOrReplaceElementWithKey("endDate","12/31/96",tempKey);
  280.   aDatabase.addOrReplaceElementWithKey("currContractor","Susan G. Carpenter",tempKey);
  281.  
  282.   return *this;
  283. }
  284.