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 >
Text File  |  1995-05-17  |  14KB  |  452 lines

  1. //****************************************************************************
  2. // OAContractor Class - C++ Code File (contrctr.cpv)                         *
  3. //                                                                           *
  4. // COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
  5. //                                                                           *
  6. // DISCLAIMER OF WARRANTIES:                                                 *
  7. //   The following [enclosed] code is sample code created by IBM             *
  8. //   Corporation.  This sample code is not part of any standard IBM product  *
  9. //   and is provided to you solely for the purpose of assisting you in the   *
  10. //   development of your applications.  The code is provided "AS IS",        *
  11. //   without warranty of any kind.  IBM shall not be liable for any damages  *
  12. //   arising out of your use of the sample code, even if they have been      *
  13. //   advised of the possibility of such damages.                             *
  14. //****************************************************************************
  15. //NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
  16. //
  17. // Default Part Code Generation begins here...
  18. INotificationId OAContractor::contractorIDId = "OAContractor::contractorID";
  19. INotificationId OAContractor::lastNameId = "OAContractor::lastName";
  20. INotificationId OAContractor::firstNameId = "OAContractor::firstName";
  21. INotificationId OAContractor::middleInitialId = "OAContractor::middleInitial";
  22. INotificationId OAContractor::homeStreetId = "OAContractor::homeStreet";
  23. INotificationId OAContractor::homeCityId = "OAContractor::homeCity";
  24. INotificationId OAContractor::homeStateId = "OAContractor::homeState";
  25. INotificationId OAContractor::homeZipId = "OAContractor::homeZip";
  26. INotificationId OAContractor::phoneNumberId = "OAContractor::phoneNumber";
  27. INotificationId OAContractor::startDateId = "OAContractor::startDate";
  28. INotificationId OAContractor::endDateId = "OAContractor::endDate";
  29. INotificationId OAContractor::activeStatusId = "OAContractor::activeStatus";
  30. INotificationId OAContractor::currentContractId = "OAContractor::currentContract";
  31.  
  32. IString OAContractor::contractorID() const
  33. {
  34.   return iContractorID;
  35. }
  36.  
  37. OAContractor & OAContractor::setContractorID()
  38. {
  39.   IString tempString = iFirstName+iMiddleInitial+iLastName;
  40.   if (iContractorID != tempString)
  41.   {
  42.     iContractorID = tempString;
  43.     notifyObservers(INotificationEvent(OAContractor::contractorIDId, *this));
  44.  
  45.   } // endif
  46.  
  47.   return *this;
  48. }
  49.  
  50. IString OAContractor::lastName() const
  51. {
  52.   return iLastName;
  53. }
  54.  
  55. OAContractor & OAContractor::setLastName(const IString & aLastName)
  56. {
  57.   if (iLastName != aLastName)
  58.   {
  59.     iLastName = aLastName;
  60.     notifyObservers(INotificationEvent(OAContractor::lastNameId, *this));
  61.   } // endif
  62.   return *this;
  63. }
  64.  
  65. IString OAContractor::firstName() const
  66. {
  67.   return iFirstName;
  68. }
  69.  
  70. OAContractor & OAContractor::setFirstName(const IString & aFirstName)
  71. {
  72.   if (iFirstName != aFirstName)
  73.   {
  74.     iFirstName = aFirstName;
  75.     notifyObservers(INotificationEvent(OAContractor::firstNameId, *this));
  76.   } // endif
  77.   return *this;
  78. }
  79.  
  80. IString OAContractor::middleInitial() const
  81. {
  82.   return iMiddleInitial;
  83. }
  84.  
  85. OAContractor & OAContractor::setMiddleInitial(const IString & aMiddleInitial)
  86. {
  87.   if (iMiddleInitial != aMiddleInitial)
  88.   {
  89.     iMiddleInitial = aMiddleInitial;
  90.     notifyObservers(INotificationEvent(OAContractor::middleInitialId, *this));
  91.   } // endif
  92.   return *this;
  93. }
  94.  
  95. IString OAContractor::homeStreet() const
  96. {
  97.   return iHomeStreet;
  98. }
  99.  
  100. OAContractor & OAContractor::setHomeStreet(const IString & aHomeStreet)
  101. {
  102.   if (iHomeStreet != aHomeStreet)
  103.   {
  104.     iHomeStreet = aHomeStreet;
  105.     notifyObservers(INotificationEvent(OAContractor::homeStreetId, *this));
  106.   } // endif
  107.   return *this;
  108. }
  109.  
  110. IString OAContractor::homeCity() const
  111. {
  112.   return iHomeCity;
  113. }
  114.  
  115. OAContractor & OAContractor::setHomeCity(const IString & aHomeCity)
  116. {
  117.   if (iHomeCity != aHomeCity)
  118.   {
  119.     iHomeCity = aHomeCity;
  120.     notifyObservers(INotificationEvent(OAContractor::homeCityId, *this));
  121.   } // endif
  122.   return *this;
  123. }
  124.  
  125. IString OAContractor::homeState() const
  126. {
  127.   return iHomeState;
  128. }
  129.  
  130. OAContractor & OAContractor::setHomeState(const IString & aHomeState)
  131. {
  132.   if (iHomeState != aHomeState)
  133.   {
  134.     iHomeState = aHomeState;
  135.     notifyObservers(INotificationEvent(OAContractor::homeStateId, *this));
  136.   } // endif
  137.   return *this;
  138. }
  139.  
  140. IString OAContractor::homeZip() const
  141. {
  142.   return iHomeZip;
  143. }
  144.  
  145. OAContractor & OAContractor::setHomeZip(const IString & aHomeZip)
  146. {
  147.   if (iHomeZip != aHomeZip)
  148.   {
  149.     iHomeZip = aHomeZip;
  150.     notifyObservers(INotificationEvent(OAContractor::homeZipId, *this));
  151.   } // endif
  152.   return *this;
  153. }
  154.  
  155. IString OAContractor::phoneNumber() const
  156. {
  157.   return iPhoneNumber;
  158. }
  159.  
  160. OAContractor & OAContractor::setPhoneNumber(const IString & aPhoneNumber)
  161. {
  162.   if (iPhoneNumber != aPhoneNumber)
  163.   {
  164.     iPhoneNumber = aPhoneNumber;
  165.     notifyObservers(INotificationEvent(OAContractor::phoneNumberId, *this));
  166.   } // endif
  167.   return *this;
  168. }
  169.  
  170. IString OAContractor::startDate() const
  171. {
  172.   return iStartDate;
  173. }
  174.  
  175. OAContractor & OAContractor::setStartDate(const IString & aStartDate)
  176. {
  177.   if (iStartDate != aStartDate)
  178.   {
  179.     iStartDate = aStartDate;
  180.     notifyObservers(INotificationEvent(OAContractor::startDateId, *this));
  181.   } // endif
  182.   return *this;
  183. }
  184.  
  185. IString OAContractor::endDate() const
  186. {
  187.   return iEndDate;
  188. }
  189.  
  190. OAContractor & OAContractor::setEndDate(const IString & aEndDate)
  191. {
  192.   if (iEndDate != aEndDate)
  193.   {
  194.     iEndDate = aEndDate;
  195.     notifyObservers(INotificationEvent(OAContractor::endDateId, *this));
  196.   } // endif
  197.   return *this;
  198. }
  199.  
  200. Boolean OAContractor::isActiveStatus() const
  201. {
  202.   return iActiveStatus;
  203. }
  204.  
  205. OAContractor & OAContractor::enableActiveStatus(const Boolean enable)
  206. {
  207.   if (iActiveStatus != enable)
  208.   {
  209.     iActiveStatus = enable;
  210.     notifyObservers(INotificationEvent(OAContractor::activeStatusId, *this));
  211.   } // endif
  212.   return *this;
  213. }
  214.  
  215. // Start boolean string enabler
  216.  
  217. OAContractor & OAContractor::enableActiveStatus(const IString & status)
  218. {
  219.   Boolean tempBoolean = iActiveStatus;
  220.   if (status == "yes") iActiveStatus = true;
  221.   if (status == "no") iActiveStatus = false;
  222.   if (tempBoolean != iActiveStatus)
  223.   {
  224.     notifyObservers(INotificationEvent(OAContractor::activeStatusId, *this));
  225.   }
  226.  
  227.   return *this;
  228. }
  229.  
  230. // End boolean string enabler
  231.  
  232. IString OAContractor::currentContract() const
  233. {
  234.   return iCurrentContract;
  235. }
  236.  
  237. OAContractor & OAContractor::setCurrentContract(const IString & aCurrentContract)
  238. {
  239.   if (iCurrentContract != aCurrentContract)
  240.   {
  241.     iCurrentContract = aCurrentContract;
  242.     notifyObservers(INotificationEvent(OAContractor::currentContractId, *this));
  243.   } // endif
  244.   return *this;
  245. }
  246.  
  247. // Default Part Code Generation ends here.
  248.  
  249. OAContractor & OAContractor::getContractor()
  250. {
  251. // Test for missing name information
  252. // Necessary for proper derivation of the contractorID attribute
  253.  
  254.   Boolean tempLast = iLastName.isWhiteSpace() || (iLastName.length()==0);
  255.   Boolean tempFirst = iFirstName.isWhiteSpace() || (iFirstName.length()==0);
  256.   Boolean tempMiddle = iMiddleInitial.isWhiteSpace() || (iMiddleInitial.length()==0);
  257.  
  258.   if (tempLast || tempFirst || tempMiddle)
  259.   {
  260.   throw IException("The name you entered is incomplete. Enter first name, middle initial, and last name.");
  261.   return *this;
  262.   }
  263.  
  264. // Start data access code
  265.  
  266.   IProfile *p = new IProfile("contrctr.ini");
  267.  
  268. // Refresh the value of contractor ID
  269.  
  270.    setContractorID();
  271.  
  272. // Check for this contractor ID in the profile collection
  273.  
  274.   if (!p->containsKeyName("contractorID", iContractorID))
  275.   {
  276.   throw IException("A record was not found for this contractor.");
  277.   delete p;
  278.   return *this;
  279.   }
  280.  
  281. // If other data exists for this contractor,
  282. // set the corresponding contractor attributes
  283.  
  284.   if (p->containsKeyName("lastName", iContractorID))
  285.     setLastName(p->elementWithKey("lastName", iContractorID));
  286.   if (p->containsKeyName("firstName", iContractorID))
  287.     setFirstName(p->elementWithKey("firstName", iContractorID));
  288.   if (p->containsKeyName("middleInitial", iContractorID))
  289.     setMiddleInitial(p->elementWithKey("middleInitial", iContractorID));
  290.   if (p->containsKeyName("homeStreet", iContractorID))
  291.     setHomeStreet(p->elementWithKey("homeStreet", iContractorID));
  292.   if (p->containsKeyName("homeCity", iContractorID))
  293.     setHomeCity(p->elementWithKey("homeCity", iContractorID));
  294.   if (p->containsKeyName("homeState", iContractorID))
  295.     setHomeState(p->elementWithKey("homeState", iContractorID));
  296.   if (p->containsKeyName("homeZip", iContractorID))
  297.     setHomeZip(p->elementWithKey("homeZip", iContractorID));
  298.   if (p->containsKeyName("phoneNumber", iContractorID))
  299.     setPhoneNumber(p->elementWithKey("phoneNumber", iContractorID));
  300.   if (p->containsKeyName("startDate", iContractorID))
  301.     setStartDate(p->elementWithKey("startDate", iContractorID));
  302.   if (p->containsKeyName("endDate", iContractorID))
  303.     setEndDate(p->elementWithKey("endDate", iContractorID));
  304.   if (p->containsKeyName("currentContract", iContractorID))
  305.     setCurrentContract(p->elementWithKey("currentContract", iContractorID));
  306.  
  307. // Call overloaded set member function using string parameter
  308.  
  309.   if (p->containsKeyName("activeStatus", iContractorID))
  310.     enableActiveStatus(p->elementWithKey("activeStatus", iContractorID));
  311.  
  312.   delete p;
  313.  
  314. // End data access code
  315.  
  316.   return *this;
  317. }
  318.  
  319. OAContractor & OAContractor::putContractor()
  320. {
  321.  
  322. // Test for missing name information
  323. // Necessary for proper derivation of the contractorID attribute
  324.  
  325.   Boolean tempLast = iLastName.isWhiteSpace() || (iLastName.length()==0);
  326.   Boolean tempFirst = iFirstName.isWhiteSpace() || (iFirstName.length()==0);
  327.   Boolean tempMiddle = iMiddleInitial.isWhiteSpace() || (iMiddleInitial.length()==0);
  328.  
  329.  
  330.   if (tempLast || tempFirst || tempMiddle)
  331.   {
  332.   throw IException("The name you entered is incomplete. Enter first name, middle initial, and last name.");
  333.   return *this;
  334.   }
  335.  
  336. // Start data entry code
  337.  
  338.   IProfile *p = new IProfile("contrctr.ini");
  339.  
  340. // Refresh the value of contractor ID
  341.  
  342.   setContractorID();
  343.   p->addOrReplaceElementWithKey("contractorID", contractorID(), iContractorID);
  344.  
  345. // If other data about this contractor exists, update it in the database
  346.  
  347.   if (lastName)
  348.     p->addOrReplaceElementWithKey("lastName", lastName(), iContractorID);
  349.   if (firstName)
  350.     p->addOrReplaceElementWithKey("firstName", firstName(), iContractorID);
  351.   if (middleInitial)
  352.     p->addOrReplaceElementWithKey("middleInitial", middleInitial(), iContractorID);
  353.   if (homeStreet)
  354.     p->addOrReplaceElementWithKey("homeStreet", homeStreet(), iContractorID);
  355.   if (homeCity)
  356.     p->addOrReplaceElementWithKey("homeCity", homeCity(), iContractorID);
  357.   if (homeState)
  358.     p->addOrReplaceElementWithKey("homeState", homeState(), iContractorID);
  359.   if (homeZip)
  360.     p->addOrReplaceElementWithKey("homeZip", homeZip(), iContractorID);
  361.   if (phoneNumber)
  362.     p->addOrReplaceElementWithKey("phoneNumber", phoneNumber(), iContractorID);
  363.   if (startDate)
  364.     p->addOrReplaceElementWithKey("startDate", startDate(), iContractorID);
  365.   if (endDate)
  366.     p->addOrReplaceElementWithKey("endDate", endDate(), iContractorID);
  367.   if (currentContract)
  368.     p->addOrReplaceElementWithKey("currentContract", currentContract(), iContractorID);
  369.   if (isActiveStatus())
  370.   {
  371.     p->addOrReplaceElementWithKey("activeStatus", "yes", iContractorID);
  372.   }
  373.   else
  374.   {
  375.     p->addOrReplaceElementWithKey("activeStatus", "no", iContractorID);
  376.   }
  377.  
  378.   delete p;
  379.  
  380. // End data entry code
  381.  
  382.   return *this;
  383. }
  384.  
  385. OAContractor & OAContractor::parseName(const IString & aName)
  386. {
  387.  
  388. // aName is supplied by user in OAQueryContractor
  389. // Test for missing information in newly entered name
  390.  
  391.   if (aName.numWords()!= 3)
  392.   {
  393.   throw IException("The name you entered is incomplete. Enter first name, middle initial, and last name.");
  394.   return *this;
  395.   }
  396.  
  397. // Set name attributes and derive contractorID attribute
  398.  
  399.   setFirstName(aName.word(1));
  400.   setMiddleInitial(aName.word(2));
  401.   setLastName(aName.word(3));
  402.   setContractorID();
  403.  
  404. // End added code
  405.  
  406.   return *this;
  407. }
  408.  
  409. OAContractor & OAContractor::refreshID()
  410. {
  411. // Refresh value of contractor ID when multiple contractors
  412. // are entered new from OAContractorView
  413.  
  414. // Test for missing name information
  415. // Necessary for proper derivation of the contractorID attribute
  416.  
  417.   Boolean tempLast = iLastName.isWhiteSpace() || (iLastName.length()==0);
  418.   Boolean tempFirst = iFirstName.isWhiteSpace() || (iFirstName.length()==0);
  419.   Boolean tempMiddle = iMiddleInitial.isWhiteSpace() || (iMiddleInitial.length()==0);
  420.  
  421.   if (tempLast || tempFirst || tempMiddle)
  422.   {
  423.   throw IException("The contractor's name is incomplete. Complete all name fields and try again.");
  424.   return *this;
  425.   }
  426.  
  427.   setContractorID();
  428.   return *this;
  429.  
  430. }
  431.  
  432. // Copy constructor
  433.  
  434. OAContractor::OAContractor(const OAContractor & aContractor)
  435.   : IStandardNotifier(aContractor),
  436.   iContractorID(aContractor.contractorID()),
  437.   iLastName(aContractor.lastName()),
  438.   iFirstName(aContractor.firstName()),
  439.   iMiddleInitial(aContractor.middleInitial()),
  440.   iHomeStreet(aContractor.homeStreet()),
  441.   iHomeCity(aContractor.homeCity()),
  442.   iHomeState(aContractor.homeState()),
  443.   iHomeZip(aContractor.homeZip()),
  444.   iPhoneNumber(aContractor.phoneNumber()),
  445.   iStartDate(aContractor.startDate()),
  446.   iEndDate(aContractor.endDate()),
  447.   iActiveStatus(aContractor.isActiveStatus()),
  448.   iCurrentContract(aContractor.currentContract())
  449.   {
  450.     enableNotification();
  451.   }
  452.